我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用gtk.TreeView()。
def __init__(self): super(ShowLastPackets.PacketList, self).__init__() self.set_properties(hscrollbar_policy=gtk.POLICY_AUTOMATIC, vscrollbar_policy=gtk.POLICY_AUTOMATIC) self.table_model = gtk.ListStore(*([str]*4)) treeview = gtk.TreeView(self.table_model) treeview.show() self.add(treeview) def add_column(descr, colid): column = gtk.TreeViewColumn(descr, gtk.CellRendererText(), text=colid) treeview.append_column(column) add_column("Time", self.COLUMN_TIME) add_column("Interface", self.COLUMN_INTERFACE) add_column("Size", self.COLUMN_SIZE) add_column("Contents", self.COLUMN_CONTENTS)
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 show(self, articles): treestore = gtk.TreeStore(str, str, str, int) for article in articles: entry = [article['title'], article['link'], article['id'], 700] treestore.append(None, entry) treeview = gtk.TreeView(treestore) tvcolumn = gtk.TreeViewColumn('Articles: {}'.format(len(articles))) treeview.append_column(tvcolumn) cell = gtk.CellRendererText() tvcolumn.pack_start(cell, True) tvcolumn.add_attribute(cell, 'text', 0) tvcolumn.add_attribute(cell, 'weight', 3) self.window.add(treeview) self.window.set_position(gtk.WIN_POS_CENTER_ON_PARENT) treeview.connect("row-activated", self.open_article, treestore) treeview.connect("cursor-changed", self.skip_article, treestore) self.window.show_all()
def __init__(self, columns): gtk.HBox.__init__(self, True, 0) self.columns = columns types = tuple([x for x, y in columns]) self.__store = gtk.ListStore(*types) self.__view = gtk.TreeView(self.__store) self.pack_start(self.__view, 1, 1, 1) self.__toggle_connected = False self._make_view() self.__view.show()
def __init__(self, fontfile): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_title("%s - pyftinspect" % fontfile) self.window.connect("delete_event", self._delete_event) self.window.set_size_request(400, 600) self.scrolled_window = gtk.ScrolledWindow() self.window.add(self.scrolled_window) self.font = ttLib.TTFont(fontfile, lazy=True) self.treemodel = FontTreeModel(self.font) self.treeview = gtk.TreeView(self.treemodel) #self.treeview.set_reorderable(True) for i in range(2): col_name = ('Key', 'Value')[i] col = gtk.TreeViewColumn(col_name) col.set_sort_column_id(-1) self.treeview.append_column(col) cell = gtk.CellRendererText() col.pack_start(cell, True) col.add_attribute(cell, 'text', i) self.treeview.set_search_column(1) self.scrolled_window.add(self.treeview) self.window.show_all()
def __init__(self, visualizer, node_index, statistics_collector): InformationWindow.__init__(self) self.win = gtk.Dialog(parent=visualizer.window, flags=gtk.DIALOG_DESTROY_WITH_PARENT|gtk.DIALOG_NO_SEPARATOR, buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)) self.win.connect("response", self._response_cb) self.win.set_title("Statistics for node %i" % node_index) self.visualizer = visualizer self.statistics_collector = statistics_collector self.node_index = node_index self.viz_node = visualizer.get_node(node_index) self.table_model = gtk.ListStore(*([str]*13)) treeview = gtk.TreeView(self.table_model) treeview.show() self.win.vbox.add(treeview) def add_column(descr, colid): column = gtk.TreeViewColumn(descr, gtk.CellRendererText(), text=colid) treeview.append_column(column) add_column("Interface", self.COLUMN_INTERFACE) add_column("Tx Packets", self.COLUMN_TX_PACKETS) add_column("Tx Bytes", self.COLUMN_TX_BYTES) add_column("Tx pkt/1s", self.COLUMN_TX_PACKET_RATE) add_column("Tx bit/1s", self.COLUMN_TX_BIT_RATE) add_column("Rx Packets", self.COLUMN_RX_PACKETS) add_column("Rx Bytes", self.COLUMN_RX_BYTES) add_column("Rx pkt/1s", self.COLUMN_RX_PACKET_RATE) add_column("Rx bit/1s", self.COLUMN_RX_BIT_RATE) self.visualizer.add_information_window(self) self.win.show()
def make_pixbuf(self, tvcolumn, cell, model, iter): """make_pixbuf Create icons for TreeView menu. """ category = model.get_value(iter, 0) if category == 'Kernel': stock = self.Kernel_image elif category == 'CPU': stock = self.CPU_image elif category == 'RAM': stock = self.RAM_image elif category == 'Sound Modules': stock = self.Sound_Modules_image elif category == 'Sound Devices': stock = self.Sound_Devices_image elif category == 'Asound': stock = self.Asound_image else: stock = 'gtk-stop' cell.set_property('pixbuf', stock) return
def _create_treeview(self, model): cell_text = gtk.CellRendererText() cell_icon = gtk.CellRendererPixbuf() column = gtk.TreeViewColumn() column.pack_start(cell_icon, False) column.add_attribute(cell_icon, 'stock_id', 1) column.pack_start(cell_text, True) column.set_cell_data_func(cell_text, self.render_name_cell) treeview = gtk.TreeView(model) treeview.append_column(column) treeview.set_headers_visible(False) treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE) treeview.connect('key_press_event', self.on_treeview_key_press) return treeview
def _build_ui(self): self._display = gtk.Table(20, 2) self._store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT) self._tree = gtk.TreeView(self._store) rend = gtk.CellRendererText() tvc = gtk.TreeViewColumn('Element', rend, text=0) self._tree.append_column(tvc) self._tree.connect('button_press_event', self._tree_click) self._tree.set_size_request(200, -1) self.root = gtk.HBox(False, 3) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.add(self._tree) sw.show() self.root.pack_start(sw, 0, 0, 0) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.add_with_viewport(self._display) sw.show() self.root.pack_start(sw, 1, 1, 1) self._tree.show() self._display.show() self.root.show()
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 __init__(self, rthread): super(SettingsEditor, self).__init__(rthread) # The main box self.root = gtk.HBox(False, 0) # The pane paned = gtk.HPaned() paned.show() self.root.pack_start(paned, 1, 1, 0) # The selection tree self._store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_INT) self._view = gtk.TreeView(self._store) self._view.get_selection().connect("changed", self._view_changed_cb) self._view.append_column( gtk.TreeViewColumn("", gtk.CellRendererText(), text=0)) self._view.show() scrolled_window = gtk.ScrolledWindow() scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolled_window.add_with_viewport(self._view) scrolled_window.set_size_request(200, -1) scrolled_window.show() paned.pack1(scrolled_window) # The settings notebook self._notebook = gtk.Notebook() self._notebook.set_show_tabs(False) self._notebook.set_show_border(False) self._notebook.show() paned.pack2(self._notebook) self._changed = False self._settings = None job = common.RadioJob(self._get_settings_cb, "get_settings") job.set_desc("Getting radio settings") self.rthread.submit(job)
def __init__(self, visualizer, node_index): InformationWindow.__init__(self) self.win = gtk.Dialog(parent=visualizer.window, flags=gtk.DIALOG_DESTROY_WITH_PARENT|gtk.DIALOG_NO_SEPARATOR, buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)) self.win.set_default_size(gtk.gdk.screen_width()/2, gtk.gdk.screen_height()/2) self.win.connect("response", self._response_cb) self.win.set_title("OLSR routing table for node %i" % node_index) self.visualizer = visualizer self.node_index = node_index self.table_model = gtk.ListStore(str, str, str, int) treeview = gtk.TreeView(self.table_model) treeview.show() sw = gtk.ScrolledWindow() sw.set_properties(hscrollbar_policy=gtk.POLICY_AUTOMATIC, vscrollbar_policy=gtk.POLICY_AUTOMATIC) sw.show() sw.add(treeview) self.win.vbox.add(sw) # Dest. column = gtk.TreeViewColumn('Destination', gtk.CellRendererText(), text=self.COLUMN_DESTINATION) treeview.append_column(column) # Next hop column = gtk.TreeViewColumn('Next hop', gtk.CellRendererText(), text=self.COLUMN_NEXT_HOP) treeview.append_column(column) # Interface column = gtk.TreeViewColumn('Interface', gtk.CellRendererText(), text=self.COLUMN_INTERFACE) treeview.append_column(column) # Num. Hops column = gtk.TreeViewColumn('Num. Hops', gtk.CellRendererText(), text=self.COLUMN_NUM_HOPS) treeview.append_column(column) self.visualizer.add_information_window(self) self.win.show()
def __init__(self, visualizer, node_index): InformationWindow.__init__(self) self.win = gtk.Dialog(parent=visualizer.window, flags=gtk.DIALOG_DESTROY_WITH_PARENT|gtk.DIALOG_NO_SEPARATOR, buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)) self.win.connect("response", self._response_cb) self.win.set_title("IPv4 routing table for node %i" % node_index) self.visualizer = visualizer self.node_index = node_index self.table_model = gtk.ListStore(str, str, str, str, int) treeview = gtk.TreeView(self.table_model) treeview.show() sw = gtk.ScrolledWindow() sw.set_properties(hscrollbar_policy=gtk.POLICY_AUTOMATIC, vscrollbar_policy=gtk.POLICY_AUTOMATIC) sw.show() sw.add(treeview) self.win.vbox.add(sw) self.win.set_default_size(600, 300) # Dest. column = gtk.TreeViewColumn('Destination', gtk.CellRendererText(), text=self.COLUMN_DESTINATION) treeview.append_column(column) # Next hop column = gtk.TreeViewColumn('Next hop', gtk.CellRendererText(), text=self.COLUMN_NEXT_HOP) treeview.append_column(column) # Interface column = gtk.TreeViewColumn('Interface', gtk.CellRendererText(), text=self.COLUMN_INTERFACE) treeview.append_column(column) # Type column = gtk.TreeViewColumn('Type', gtk.CellRendererText(), text=self.COLUMN_TYPE) treeview.append_column(column) # Prio column = gtk.TreeViewColumn('Prio', gtk.CellRendererText(), text=self.COLUMN_PRIO) treeview.append_column(column) self.visualizer.add_information_window(self) self.win.show()
def create_treeview(self): self.treeview = gtk.TreeView(self.treestore) self.treeview.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_VERTICAL) self.builder.get_object("feat_scrolledwindow").add(self.treeview) self.treeview.add_events(gdk.BUTTON_PRESS_MASK) self.treeview.connect('button-press-event', self.pop_menu) self.treeview.connect('row_activated', self.tv_row_activated) self.treeview.connect('key_press_event', self.tv_key_pressed_event) # icon and name col = gtk.TreeViewColumn(_("Name")) cell = gtk.CellRendererPixbuf() cell.set_fixed_size(treeview_icon_size, treeview_icon_size) self.tv1_icon_cell = cell col.pack_start(cell, expand = False) col.set_cell_data_func(cell, self.get_col_icon) col.set_min_width(int(self.col_width_adj.get_value())) self.name_cell = gtk.CellRendererText() col.pack_start(self.name_cell, expand = True) col.set_cell_data_func(self.name_cell, self.get_col_name) col.set_resizable(True) self.name_cell.set_property('ellipsize', self.pref.name_ellipsis) self.name_cell.set_property('xpad', 2) self.treeview.append_column(col) # value col = gtk.TreeViewColumn(_("Value")) cell = CellRendererMx(self.treeview) cell.edited = self.edited cell.set_preediting(self.get_editinfo) cell.set_refresh_fn(self.get_selected_feature) col.pack_start(cell, expand = True) col.set_cell_data_func(cell, self.get_col_value) col.set_min_width(200) col.set_resizable(True) self.treeview.append_column(col) self.treeview.set_tooltip_column(1) self.treeview.connect("cursor-changed", self.get_selected_feature) self.treeview.set_model(self.master_filter)
def create_second_treeview(self): self.treeview2 = gtk.TreeView() self.treeview2.add_events(gdk.BUTTON_PRESS_MASK) self.treeview2.connect('button-press-event', self.pop_menu) self.treeview2.connect('cursor-changed', self.tv2_selected) self.treeview2.connect('row_activated', self.tv_row_activated) self.treeview2.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_VERTICAL) self.treeview2.set_show_expanders(self.pref.tv2_expandable) if self.pref.tv2_expandable : self.treeview2.set_level_indentation(-5) else : self.treeview2.set_level_indentation(12) # icon and name col = gtk.TreeViewColumn(_("Name")) cell = gtk.CellRendererPixbuf() cell.set_fixed_size(treeview_icon_size, treeview_icon_size) self.tv2_icon_cell = cell col.pack_start(cell, expand = False) col.set_cell_data_func(cell, self.get_col_icon) self.name_cell2 = gtk.CellRendererText() self.name_cell2.set_property('xpad', 2) self.name_cell2.set_property('ellipsize', self.pref.name_ellipsis) col.pack_start(self.name_cell2, expand = True) col.set_cell_data_func(self.name_cell2, self.get_col_name) col.set_resizable(True) col.set_min_width(int(self.col_width_adj.get_value())) self.treeview2.append_column(col) # value col = gtk.TreeViewColumn(_("Value")) cell = CellRendererMx(self.treeview2) cell.set_property("editable", True) cell.edited = self.edited cell.set_preediting(self.get_editinfo) cell.set_refresh_fn(self.get_selected_feature) col.pack_start(cell, expand = False) col.set_cell_data_func(cell, self.get_col_value) col.set_resizable(True) col.set_min_width(200) self.treeview2.append_column(col) self.treeview2.set_tooltip_column(1) self.treeview2.set_model(self.treestore) self.treeview2.set_model(self.details_filter) self.params_scroll.add(self.treeview2) self.treeview2.connect('key-press-event', self.tv_key_pressed_event)
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