我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用gtk.SELECTION_SINGLE。
def create_list_view(col_label,): # create list widget list_ = gtk.ListStore(str) list_view = gtk.TreeView(model=list_) list_view.set_rules_hint(True) list_view.get_selection().set_mode(gtk.SELECTION_SINGLE) # Add Colums renderer = gtk.CellRendererText() renderer.set_data("column", COLUMN_SUGGESTION) column = gtk.TreeViewColumn(col_label, renderer,text=COLUMN_SUGGESTION) list_view.append_column(column) return list_view
def update_view(self): global con iv = self.builder.get_object("iconview1") model = gtk.ListStore(str, gtk.gdk.Pixbuf) with con: cur = con.cursor() cur.execute("select * from dump") rows = cur.fetchall() for (cookie, angent, photo, info, url) in rows: try: pixbuf = gtk.gdk.pixbuf_new_from_file(photo) model.append([info, pixbuf]) except: pass iv.set_model(model) iv.set_text_column(0) iv.set_pixbuf_column(1) iv.set_orientation(gtk.ORIENTATION_VERTICAL) iv.set_selection_mode(gtk.SELECTION_SINGLE) iv.set_columns(1) iv.set_item_width(-1) iv.set_size_request(72, -1) self.builder.get_object("window1").show_all() return True
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 get_selection(self): """get_selection Creates text appropriate to choices """ # get selection from listview self.choice = self.treeview1.get_selection() self.choice.set_mode(gtk.SELECTION_SINGLE) self.model, self.row_reference = self.choice.get_selected() self.choice = self.liststore.get_value(self.row_reference, 0) # Create command line command_ref = "self." + self.choice.replace(' ','_') + "_func" command = eval(command_ref) # GUI output # Make clean textbuffer self.textbuffer = gtk.TextBuffer(None) # Create headline style self.headline = self.textbuffer.create_tag('headline', weight=700, scale=pango.SCALE_LARGE) # navigate to start of buffer place = self.textbuffer.get_start_iter() # Create pixbuf icon reference icon = eval("self." + self.choice.replace(' ','_') + "_image") # Insert icon at top of page self.textbuffer.insert_pixbuf(place, icon) # Print appropriate text underneath text = " " + self.choice + ": \n\n" + commands.getoutput(command) self.textbuffer.insert_at_cursor(text) iter0 = self.textbuffer.get_iter_at_line(0) iter1 = self.textbuffer.get_iter_at_line(1) self.textbuffer.apply_tag(self.headline,iter0,iter1) self.textview1.set_buffer(self.textbuffer) return