Python gtk 模块,TreeStore() 实例源码

我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用gtk.TreeStore()

项目:griffith    作者:Strit    | 项目源码 | 文件源码
def loans_treeview(self):
    self.loans_treemodel = gtk.TreeStore(str, str, str)  # move to self.widgets
    self.widgets['movie']['loan_history'].set_model(self.loans_treemodel)
    self.widgets['movie']['loan_history'].set_headers_visible(True)
    # loan date
    renderer = gtk.CellRendererText()
    self.date_column = gtk.TreeViewColumn(_('Loan Date'), renderer, text=0)
    self.date_column.set_resizable(True)
    self.widgets['movie']['loan_history'].append_column(self.date_column)
    self.date_column.set_sort_column_id(0)
    # return date
    renderer = gtk.CellRendererText()
    self.return_column = gtk.TreeViewColumn(_('Return Date'), renderer, text=1)
    self.return_column.set_resizable(True)
    self.widgets['movie']['loan_history'].append_column(self.return_column)
    # loan to
    renderer = gtk.CellRendererText()
    self.loaner_column = gtk.TreeViewColumn(_('Loaned To'), renderer, text=2)
    self.loaner_column.set_resizable(True)
    self.widgets['movie']['loan_history'].append_column(self.loaner_column)
项目:pyttrss    作者:balanceofcowards    | 项目源码 | 文件源码
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()
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def people_treeview(self, create=True):
    row = None
    self.p_treemodel = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
    self.widgets['preferences']['treeview'].set_model(self.p_treemodel)
    self.widgets['preferences']['treeview'].set_headers_visible(True)

    if create is True:
        # name column
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn(_('Name'), renderer, text=0)
        column.set_resizable(True)
        column.set_sort_column_id(0)
        self.widgets['preferences']['treeview'].append_column(column)
        # email column
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn(_('E-mail'), renderer, text=1)
        column.set_resizable(True)
        column.set_sort_column_id(1)
        self.widgets['preferences']['treeview'].append_column(column)
    # add data to treeview
    self.p_treemodel.clear()
    for i in self.db.session.query(db.Person.name, db.Person.email).order_by(db.Person.name.asc()):
        myiter = self.p_treemodel.insert_before(None, None)
        self.p_treemodel.set_value(myiter, 0, i.name)
        self.p_treemodel.set_value(myiter, 1, i.email)
    self.widgets['preferences']['treeview'].show()
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def web_results(self):
    self.treemodel_results = gtk.TreeStore(str, str)
    self.widgets['results']['treeview'].set_model(self.treemodel_results)
    self.widgets['results']['treeview'].set_headers_visible(False)
    # column ids
    renderer = gtk.CellRendererText()
    column1 = gtk.TreeViewColumn(None, renderer, text=0)
    column1.set_visible(False)
    self.widgets['results']['treeview'].append_column(column1)
    # column titles
    renderer = gtk.CellRendererText()
    column2 = gtk.TreeViewColumn(None, renderer, text=1)
    column2.set_resizable(True)
    column2.set_sort_column_id(1)
    self.widgets['results']['treeview'].append_column(column2)
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def preferences(self):
    self.widgets['preferences']['db_type'].insert_text(0, 'SQLite3 (internal)')
    self.widgets['preferences']['db_type'].insert_text(1, 'PostgreSQL')
    self.widgets['preferences']['db_type'].insert_text(2, 'MySQL')
    self.widgets['preferences']['db_type'].insert_text(3, 'Microsoft SQL')
    self.widgets['preferences']['db_host'].set_text(self.config.get('host', '', section='database'))
    self.widgets['preferences']['db_port'].set_value(int(self.config.get('port', 0, section='database')))
    self.widgets['preferences']['db_user'].set_text(self.config.get('user', '', section='database'))
    self.widgets['preferences']['db_passwd'].set_text(self.config.get('passwd', '', section='database'))
    self.widgets['preferences']['db_name'].set_text(self.config.get('name', '', section='database'))
    db_type = self.config.get('type', 'sqlite', section='database')
    if db_type == 'postgres':
        self.widgets['preferences']['db_type'].set_active(1)
    elif db_type == 'mysql':
        self.widgets['preferences']['db_type'].set_active(2)
    elif db_type == 'mssql':
        self.widgets['preferences']['db_type'].set_active(3)
    else:
        self.widgets['preferences']['db_type'].set_active(0)

    # add completion data
    treemodel = gtk.TreeStore(str)
    for name in (os.path.basename(x)[:-3] for x in glob("%s/*.db" % self.locations['home'])):
        myiter = treemodel.append(None)
        treemodel.set_value(myiter, 0, name)
    completion = gtk.EntryCompletion()
    completion.set_minimum_key_length(0)
    self.widgets['preferences']['db_name'].set_completion(completion)
    completion.set_model(treemodel)
    completion.set_text_column(0)
项目:gnome-connection-manager    作者:mjun    | 项目源码 | 文件源码
def initLeftPane(self):
        global groups       

        self.treeModel = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gtk.gdk.Pixbuf)
        self.treeServers.set_model(self.treeModel)

        self.treeServers.set_level_indentation(5)
        #Force the alternating row colors, by default it's off with one column
        self.treeServers.set_property('rules-hint', True)
        gtk.rc_parse_string( """
                style "custom-treestyle"{
                    GtkTreeView::allow-rules = 1
                }
                widget "*treeServers*" style "custom-treestyle"
            """)
        column = gtk.TreeViewColumn()
        column.set_title('Servers')
        self.treeServers.append_column( column )

        renderer = gtk.CellRendererPixbuf()
        column.pack_start(renderer, expand=False)
        column.add_attribute(renderer, 'pixbuf', 2)

        renderer = gtk.CellRendererText()
        column.pack_start(renderer, expand=True)
        column.add_attribute(renderer, 'text', 0)

        self.treeServers.set_has_tooltip(True)
        self.treeServers.connect('query-tooltip', self.on_treeServers_tooltip)
        self.loadConfig()
        self.updateTree()
项目:gnome-connection-manager    作者:mjun    | 项目源码 | 文件源码
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
项目:linux-pentest-util    作者:fikr4n    | 项目源码 | 文件源码
def __init__(self, parser, max_tree_depth):
        self.parser = parser
        self._max_tree_depth = max_tree_depth
        self.search_thread = None
        self.search_lock = threading.Lock()
        self.name_entry = name_entry = gtk.Entry()
        name_entry.connect('activate', self.on_name_entry_activate)
        search_button = self.search_button = gtk.Button(stock=gtk.STOCK_FIND)
        search_button.connect('clicked', self.on_search)
        search_button.set_no_show_all(True)
        search_button.show()
        stop_button = self.stop_button = gtk.Button(stock=gtk.STOCK_STOP)
        stop_button.connect('clicked', self.stop_search)
        stop_button.set_no_show_all(True)
        self.progress = progress = gtk.ProgressBar()
        progress.set_size_request(-1, 8)
        name_box = gtk.HBox(spacing=8)
        name_box.set_border_width(8)
        name_box.pack_start(name_entry, True, True)
        name_box.pack_start(search_button, False)
        name_box.pack_start(stop_button, False)
        self.store = gtk.TreeStore(str, str, str, str)  # name, icon, fnstyle, info
        self.treeview = treeview = self._create_treeview(self.store)
        scroller = gtk.ScrolledWindow()
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroller.add(treeview)
        settings_view = SettingsView(max_depth_value=max_tree_depth)
        settings_view.on_max_depth_changed = self.on_max_depth_changed
        extension = gtk.expander_new_with_mnemonic('_Settings')
        extension.add(settings_view.view)
        vbox = gtk.VBox()
        vbox.pack_start(name_box, False)
        vbox.pack_start(progress, False)
        vbox.pack_start(scroller, True, True)
        vbox.pack_start(extension, False)
        self.window = window = gtk.Window()
        window.set_title(Application.title)
        window.set_default_size(800, 600)
        window.set_icon(Application.get_icon())
        window.add(vbox)
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
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()
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
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)