我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用gi.repository.Gtk.CellRendererToggle()。
def __init__(self): Gtk.ScrolledWindow.__init__(self) self.list = Gtk.ListStore(str, bool) self.view = Gtk.TreeView(self.list) self.view.set_hexpand(True) text_renderer = Gtk.CellRendererText() check_renderer = Gtk.CellRendererToggle() name_column = Gtk.TreeViewColumn('Gtk color list', text_renderer, text=0) check_column = Gtk.TreeViewColumn('', check_renderer, active=1) self.view.append_column(check_column) self.view.append_column(name_column) self.view.connect('row-activated', self.row_activated) self.add(self.view) names = ['active_text_color', 'inactive_text_color', 'active_text_shadow_color', 'inactive_text_shadow_color', 'active_border_color', 'inactive_border_color', 'active_color_1', 'active_color_2', 'active_highlight_1', 'active_highlight_2', 'active_mid_1', 'active_mid_2', 'active_shadow_1', 'active_shadow_2', 'inactive_color_1', 'inactive_color_2', 'inactive_highlight_1', 'inactive_highlight_2', 'inactive_mid_1', 'inactive_mid_2', 'inactive_shadow_1', 'inactive_shadow_2'] for name in names: self.list.append([name, False])
def build_data_stores(self): """Build stores for GUI dataviews""" self.store = dict() # custom icons self.ied = {'Name': 0, 'State': 1} self.store['custom_icons'] = Gtk.ListStore(str, bool) self.store['custom_icons'].append(["Simple Icon Group", False]) renderer_toggle = Gtk.CellRendererToggle() renderer_toggle.connect("toggled", self.on_custom_icon_toggled) self.gui['custom_icons_treeview'].append_column(Gtk.TreeViewColumn("Name", Gtk.CellRendererText(), text=0)) self.gui['custom_icons_treeview'].append_column(Gtk.TreeViewColumn("State", renderer_toggle, active=1)) self.gui['custom_icons_treeview'].set_model(self.store['custom_icons']) # color list self.ced = {'Color': 0, 'Alpha': 1, 'Offset': 2, 'RGBA': 3} colorstore_visible_keys = [k for k in self.ced.keys() if k != 'RGBA'] self.store['colorlist'] = Gtk.ListStore(str, float, int, str) for key in sorted(colorstore_visible_keys, key=lambda k: self.ced[k]): self.gui['colorlist_treeview'].append_column( Gtk.TreeViewColumn(key, Gtk.CellRendererText(), text=self.ced[key]) ) self.gui['colorlist_treeview'].set_model(self.store['colorlist']) # gradient direction self.ded = {'Coord': 0, 'Value': 1} self.store['direction'] = Gtk.ListStore(str, int) self.gui['renderer_spin'] = Gtk.CellRendererSpin(editable=True, adjustment=Gtk.Adjustment(0, 0, 100, 5, 0, 0)) self.signals['direction_edited'] = self.gui['renderer_spin'].connect("edited", self.on_direction_edited) self.gui['direction_treeview'].append_column(Gtk.TreeViewColumn("Coord", Gtk.CellRendererText(), text=0)) self.gui['direction_treeview'].append_column(Gtk.TreeViewColumn("Value", self.gui['renderer_spin'], text=1)) self.gui['direction_treeview'].set_model(self.store['direction'])
def refresh_schema(self): cursor = self.conn.cursor() cursor.execute('SELECT * FROM %s LIMIT 1' % self.table) for column in self.data_tree.get_columns(): self.data_tree.remove_column(column) self.columns = [] # TODO get rid of manual incrementing i = 0 for description in cursor.description: s = None if description.type_code == 16: renderer = Gtk.CellRendererToggle() self.columns.append(bool) column = Gtk.TreeViewColumn(description.name.replace('_', '__'), renderer, active=i) else: renderer = Gtk.CellRendererText() renderer.set_property('editable', True) renderer.connect('edited', self.on_text_edit, i) renderer.set_property('placeholder-text', 'Null') renderer.set_property('ellipsize', Pango.EllipsizeMode.END) self.columns.append(str) column = Gtk.TreeViewColumn(description.name.replace('_', '__'), renderer, text=i) column.set_clickable(True) column.set_resizable(True) column.set_fixed_width(100) if i == 0: # TODO Should this be here? self.order = description.name column.set_sort_indicator(True) column.set_sort_order(1) self.last_selected_column = column column.connect('clicked', self.on_column_click, description.name) self.data_tree.append_column(column) i += 1 self.store = Gtk.ListStore(*self.columns) self.data_tree.set_model(self.store)
def __init__(self): Gtk.Window.__init__(self, title="EFI boot manager") self.set_border_width(10) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6) self.add(vbox) self.store = EFIStore(self) self.tree = Gtk.TreeView(self.store, vexpand=True) vbox.add(self.tree) renderer_text = Gtk.CellRendererText() renderer_check = Gtk.CellRendererToggle(radio=False) renderer_radio = Gtk.CellRendererToggle(radio=True) renderer_check.connect("toggled", self.store.change_active) renderer_radio.connect("toggled", self.store.change_boot_next) self.tree.append_column(Gtk.TreeViewColumn("BootNum", renderer_text, text=0)) self.tree.append_column(Gtk.TreeViewColumn("Name", renderer_text, text=1)) self.tree.append_column(Gtk.TreeViewColumn("Loader", renderer_text, text=2)) self.tree.append_column(Gtk.TreeViewColumn("Active", renderer_check, active=3)) self.tree.append_column(Gtk.TreeViewColumn("NextBoot", renderer_radio, active=4)) for column in self.tree.get_columns(): column.set_resizable(True) column.set_min_width(75) hb = Gtk.HeaderBar() hb.set_show_close_button(True) hb.props.title = "EFI boot manager" self.set_titlebar(hb) clear_btn = btn_with_icon("edit-clear-all-symbolic") clear_btn.connect("button-press-event", self.discard_changes) hb.pack_end(clear_btn) write_btn = btn_with_icon("document-save-symbolic") write_btn.connect("button-press-event", self.apply_changes) hb.pack_end(write_btn) hbox = Gtk.HButtonBox() hbox.set_layout(Gtk.ButtonBoxStyle.EXPAND) vbox.add(hbox) up = btn_with_icon("go-up-symbolic") down = btn_with_icon("go-down-symbolic") new = btn_with_icon("list-add-symbolic") delete = btn_with_icon("list-remove-symbolic") hbox.add(up) hbox.add(down) hbox.add(new) hbox.add(delete) up.connect("button-press-event", self.up) down.connect("button-press-event", self.down) new.connect("button-press-event", self.new) delete.connect("button-press-event", self.delete) self.connect("delete-event", self.quit) self.set_default_size(300, 260)
def __init__(self, parent, app, title, source_url, save_path): '''???BT???????. source_url - ???BT????, ?????????. ???????, ???magent:???????. ''' super().__init__(title, app.window, Gtk.DialogFlags.MODAL, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK)) self.app = app self.source_url = source_url self.save_path = save_path self.set_default_response(Gtk.ResponseType.OK) self.set_default_size(520, 480) self.set_border_width(10) box = self.get_content_area() select_all_button = Gtk.ToggleButton.new_with_label(_('Select All')) select_all_button.props.halign = Gtk.Align.START select_all_button.props.margin_bottom = 5 select_all_button.connect('toggled', self.on_select_all_toggled) box.pack_start(select_all_button, False, False, 0) scrolled_win = Gtk.ScrolledWindow() box.pack_start(scrolled_win, True, True, 0) # check, name, size, humansize self.liststore = Gtk.ListStore(bool, str, GObject.TYPE_INT64, str) self.treeview = Gtk.TreeView(model=self.liststore) self.treeview.set_tooltip_column(NAME_COL) scrolled_win.add(self.treeview) check_cell = Gtk.CellRendererToggle() check_cell.connect('toggled', self.on_check_cell_toggled) check_col = Gtk.TreeViewColumn('', check_cell, active=CHECK_COL) self.treeview.append_column(check_col) name_cell = Gtk.CellRendererText(ellipsize=Pango.EllipsizeMode.END, ellipsize_set=True) name_col = Gtk.TreeViewColumn(_('Name'), name_cell, text=NAME_COL) name_col.set_expand(True) self.treeview.append_column(name_col) size_cell = Gtk.CellRendererText() size_col = Gtk.TreeViewColumn(_('Size'), size_cell, text=HUMANSIZE_COL) self.treeview.append_column(size_col) box.show_all() self.request_data()
def setup_ui_tasks(self, widget): self.janitor_model.set_sort_column_id(self.JANITOR_NAME, Gtk.SortType.ASCENDING) #add janitor columns janitor_column = Gtk.TreeViewColumn() renderer = Gtk.CellRendererToggle() renderer.connect('toggled', self.on_janitor_check_button_toggled) janitor_column.pack_start(renderer, False) janitor_column.add_attribute(renderer, 'active', self.JANITOR_CHECK) self.janitor_view.append_column(janitor_column) janitor_column = Gtk.TreeViewColumn() renderer = Gtk.CellRendererPixbuf() janitor_column.pack_start(renderer, False) janitor_column.add_attribute(renderer, 'pixbuf', self.JANITOR_ICON) janitor_column.set_cell_data_func(renderer, self.icon_column_view_func, self.JANITOR_ICON) renderer = Gtk.CellRendererText() renderer.set_property('ellipsize', Pango.EllipsizeMode.END) janitor_column.pack_start(renderer, True) janitor_column.add_attribute(renderer, 'markup', self.JANITOR_DISPLAY) renderer = Gtk.CellRendererSpinner() janitor_column.pack_start(renderer, False) janitor_column.add_attribute(renderer, 'active', self.JANITOR_SPINNER_ACTIVE) janitor_column.add_attribute(renderer, 'pulse', self.JANITOR_SPINNER_PULSE) self.janitor_view.append_column(janitor_column) #end janitor columns #new result columns result_display_renderer = self.builder.get_object('result_display_renderer') result_display_renderer.set_property('ellipsize', Pango.EllipsizeMode.END) result_icon_renderer= self.builder.get_object('result_icon_renderer') self.result_column.set_cell_data_func(result_icon_renderer, self.icon_column_view_func, self.RESULT_ICON) #end new result columns self.scan_button.set_visible(not self.is_auto_scan()) self.update_model() self._expand_janitor_view() self.hpaned1.connect('notify::position', self.on_move_handle)