我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用gtk.CellRendererToggle()。
def __init__(self): self.xml = gtk.glade.XML(util.sibpath(__file__,"gladereactor.glade")) d = {} for m in reflect.prefixedMethods(self, "on_"): d[m.im_func.__name__] = m self.xml.signal_autoconnect(d) self.xml.get_widget('window1').connect('destroy', lambda w: self.stop()) self.servers = self.xml.get_widget("servertree") sel = self.servers.get_selection() sel.set_mode(gtk.SELECTION_SINGLE) sel.connect("changed", self.servers_selection_changed) ## argh coredump: self.servers_selection_changed(sel) self.xml.get_widget('suspend').set_sensitive(0) self.xml.get_widget('disconnect').set_sensitive(0) # setup model, connect it to my treeview self.model = gtk.ListStore(str, object, gobject.TYPE_BOOLEAN, gobject.TYPE_BOOLEAN) self.servers.set_model(self.model) self.servers.set_reorderable(1) self.servers.set_headers_clickable(1) # self.servers.set_headers_draggable(1) # add a column for col in [ gtk.TreeViewColumn('Server', gtk.CellRendererText(), text=0), gtk.TreeViewColumn('Reading', gtk.CellRendererToggle(), active=2), gtk.TreeViewColumn('Writing', gtk.CellRendererToggle(), active=3)]: self.servers.append_column(col) col.set_resizable(1) sup.__init__(self)
def do_render(self, win, widget, background_area, cell_area, expose_area, flags): if self.data_type in ['bool', 'boolean'] : cell_area.width = 30 chk = gtk.CellRendererToggle() chk.set_active(self.param_value == '1') chk.render(win, widget, background_area, cell_area, expose_area, flags) else : gtk.CellRendererText.do_render(self, win, widget, background_area, cell_area, expose_area, flags)
def new(self): self.treeHosts = self.get_widget('treeHosts') self.treeStore = gtk.TreeStore( gobject.TYPE_BOOLEAN, gobject.TYPE_STRING, gobject.TYPE_OBJECT ) for x in self.terms: self.treeStore.append( None, (False, x[0], x[1]) ) self.treeHosts.set_model( self.treeStore ) crt = gtk.CellRendererToggle() crt.set_property('activatable', True) crt.connect('toggled', self.on_active_toggled) col = gtk.TreeViewColumn(_("Activar"), crt, active=0) self.treeHosts.append_column( col ) self.treeHosts.append_column(gtk.TreeViewColumn(_("Host"), gtk.CellRendererText(), text=1 )) self.get_widget("txtCommands").history = [] #-- Wcluster.new } #-- Wcluster custom methods { # Write your own methods here
def _make_view(self): colnum = -1 for typ, cap in self.columns: colnum += 1 if colnum == 0: continue # Key column if typ in [gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_FLOAT]: rend = gtk.CellRendererText() rend.set_property("ellipsize", pango.ELLIPSIZE_END) column = gtk.TreeViewColumn(cap, rend, text=colnum) elif typ in [gobject.TYPE_BOOLEAN]: rend = gtk.CellRendererToggle() rend.connect("toggled", self._toggle, colnum) column = gtk.TreeViewColumn(cap, rend, active=colnum) else: raise Exception("Unsupported type %s" % typ) column.set_sort_column_id(colnum) self.__view.append_column(column) self.__view.connect("button_press_event", self._mouse)
def make_view(self, columns): self._view = gtk.TreeView(self._store) for _type, _col in columns: if _col.startswith("__"): continue index = columns.index((_type, _col)) if _type == gobject.TYPE_STRING or \ _type == gobject.TYPE_INT or \ _type == gobject.TYPE_FLOAT: rend = gtk.CellRendererText() column = gtk.TreeViewColumn(_col, rend, text=index) column.set_resizable(True) rend.set_property("ellipsize", pango.ELLIPSIZE_END) elif _type == gobject.TYPE_BOOLEAN: rend = gtk.CellRendererToggle() rend.connect("toggled", self._toggle, index) column = gtk.TreeViewColumn(_col, rend, active=index) else: raise Exception("Unknown column type (%i)" % index) column.set_sort_column_id(index) self._view.append_column(column) self._view.connect("button_press_event", self.mouse_cb)
def make_view(self): editable = [self.col_nloc, self.col_name, self.col_comm] self.__store = gtk.ListStore(gobject.TYPE_BOOLEAN, # Import gobject.TYPE_INT, # Source loc gobject.TYPE_INT, # Destination loc gobject.TYPE_STRING, # Name gobject.TYPE_STRING, # Frequency gobject.TYPE_STRING, # Comment gobject.TYPE_BOOLEAN, gobject.TYPE_STRING) self.__view = gtk.TreeView(self.__store) self.__view.show() tips = gtk.Tooltips() for k in self.caps.keys(): t = self.types[k] if t == gobject.TYPE_BOOLEAN: rend = gtk.CellRendererToggle() rend.connect("toggled", self._toggle, k) column = gtk.TreeViewColumn(self.caps[k], rend, active=k, sensitive=self.col_okay, activatable=self.col_okay) else: rend = gtk.CellRendererText() if k in editable: rend.set_property("editable", True) rend.connect("edited", self._edited, k) column = gtk.TreeViewColumn(self.caps[k], rend, text=k, sensitive=self.col_okay) if k == self.col_nloc: column.set_cell_data_func(rend, self._render, k) if k in self.tips.keys(): LOG.debug("Doing %s" % k) lab = gtk.Label(self.caps[k]) column.set_widget(lab) tips.set_tip(lab, self.tips[k]) lab.show() column.set_sort_column_id(k) self.__view.append_column(column) self.__view.set_tooltip_column(self.col_tmsg) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.add(self.__view) sw.show() return sw