我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用gi.repository.Gtk.ToggleButton()。
def _do_button_toggled(self, btn: Gtk.ToggleButton): """Handler for when a button is toggled. Emits `nvim-switch-buffer` if the button was toggled ON, and the widget isn't in the middle of an update. Also avoids toggling off buttons, since the user can't "unswitch" to a buffer. :btn: the toggled button. """ if not self.props.updating: if btn.get_active(): id = self.bids[self.btns.index(btn)] self.emit('nvim-switch-buffer', id) else: btn.set_active(True)
def on_button_toggled(self, button, name): if button.get_active(): # this part is to deactivate all button when one is activated for i in self.vbox: if type(i) == Gtk.ToggleButton: if i != button: i.set_active(False) else: k = 0 # this part is to activate button 1 when all is deactivated for i in self.vbox: if type(i) == Gtk.ToggleButton: m = i.get_active() k = k + m if k == 0: self.button1.set_active(True)
def update(self, buflist: list, bufcurr: int): """Updates the widget's buttons. Increases the internal button cache if needed, then displays the appropriate amount of buttons, updating their state. :buflist: list of tuples (buffer-number, buffer-name, buffer-modified). :bufcurr: the active buffer's number. """ self.props.updating = True self.bids = [id for id, *_ in buflist] for _ in range(len(buflist) - len(self.btns)): ico = Gtk.Image(icon_name='document-edit-symbolic') btn = Gtk.ToggleButton(None, can_focus=False, image=ico) btn.connect('toggled', self._do_button_toggled) self.btns.append(btn) for btn in self.get_children(): self.remove(btn) for btn, (id, name, modified) in zip(self.btns, buflist): btn.set_label(name) btn.set_active(id == bufcurr) btn.set_always_show_image(modified) self.add(btn) self.show_all() self.props.updating = False
def __init__(self): Gtk.HBox.__init__(self) self.checkbox_dict = {} for x in range(1, mpd.interval.max_interval + 1): self.checkbox_dict[x] = c \ = Gtk.ToggleButton(mpd.interval.short_name[x]) c.connect('toggled', self.on_toggle) c.show() self.pack_start(c, True, True, 0)
def soltogglebutton(self, i): if i >= 0: btn = Gtk.ToggleButton(solmisation_syllables[i]) btn.connect('toggled', self.select_element_cb, i) else: btn = Gtk.ToggleButton() btn.set_sensitive(False) btn.show() return btn
def __init__(self,parent): Gtk.Grid.__init__(self) self.set_border_width(10) self.vbox = Gtk.VBox(spacing=6) self.vbox = Gtk.Box(spacing=6) self.add(self.vbox) self.button1 = Gtk.ToggleButton("Button1") self.button1.connect("toggled", self.on_button_toggled, "1") self.button1.set_active(True) #self.button1img = Gtk.Image.new_from_icon_name("filenew", Gtk.IconSize.MENU) #self.button1.set_image(self.button1img) self.vbox.pack_start(self.button1, True, True, 0) self.button2 = Gtk.ToggleButton("Button 2") self.button2.connect("toggled", self.on_button_toggled, "2") self.vbox.pack_start(self.button2, True, True, 0) self.button3 = Gtk.ToggleButton("Button 3") self.button3.connect("toggled", self.on_button_toggled, "3") self.vbox.pack_start(self.button3, True, True, 0) self.attach(self.button1, 0, 0, 1, 1) self.attach(self.button2, 1, 0, 3, 1) self.attach(self.button3, 2, 0, 1, 1)
def create_synonyms_flowbox(self): label_Synonyms=Gtk.Label() label_Synonyms.set_markup("<u><b>Synonyms</b></u>") self.vbox_left2.pack_start(label_Synonyms,False,True,0) self.scrolled=Gtk.ScrolledWindow() self.scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self.flowbox=Gtk.FlowBox() self.flowbox.set_valign(Gtk.Align.START) self.flowbox.set_max_children_per_line(7) self.flowbox.set_selection_mode(Gtk.SelectionMode.NONE) self.toggle_button_list=[] for i in range(100): x=Gtk.ToggleButton(label=str(i)) self.toggle_button_list.append(x) for i in range(100): self.toggle_button_list[i].connect('clicked',self.toggle_button_clicked) for i in self.toggle_button_list: self.flowbox.add(i) self.scrolled.add(self.flowbox) self.add(self.scrolled) self.vbox_left2.pack_start(self.scrolled,True,True,0) #########signal callback functions######################
def make_button(icon, tooltip, toggle): if toggle: button = Gtk.ToggleButton() else: button = Gtk.Button() button.set_always_show_image(True) button.set_image(icon) button.set_border_width(3) button.set_relief(Gtk.ReliefStyle.NONE) button.set_can_focus(False) if tooltip: button.set_tooltip_text(tooltip) return button
def _build_header_bar(self): """Setup window headerbar.""" # Header bar headerbar = Gtk.HeaderBar() headerbar_container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=3) title = Gtk.Label() title.set_text(_("Icon Chooser")) title.get_style_context().add_class("title") headerbar_container.pack_start(title, False, False, 0) subtitle = Gtk.Label() subtitle.get_style_context().add_class("subtitle") subtitle_text = ", ".join(self._folders) subtitle.set_text(subtitle_text) subtitle.set_ellipsize(Pango.EllipsizeMode.END) subtitle.set_tooltip_text(subtitle_text) subtitle.props.max_width_chars = 30 headerbar_container.pack_start(subtitle, False, False, 0) headerbar.set_custom_title(headerbar_container) headerbar.set_show_close_button(False) # Search Button self._search_btn = Gtk.ToggleButton() search_icn = Gio.ThemedIcon(name="system-search-symbolic") search_img = Gtk.Image.new_from_gicon(search_icn, Gtk.IconSize.BUTTON) self._search_btn.set_image(search_img) # Cancel Button cancel_button = Gtk.Button() cancel_button.set_label(_("Cancel")) cancel_button.connect("clicked", self.close_window) headerbar.pack_start(cancel_button) headerbar.pack_end(self._search_btn) self.set_titlebar(headerbar)