Python gi.repository.Gtk 模块,TreeStore() 实例源码

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

项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def create_tree(self, imps):
        # Create the column
        imports = Gtk.TreeViewColumn()
        imports.set_title("Imports")
        imports.set_spacing(5)

        self.treestore = Gtk.TreeStore(GdkPixbuf.Pixbuf, str)

        rendererPix = Gtk.CellRendererPixbuf()
        rendererText = Gtk.CellRendererText()
        imports.pack_start(rendererPix, False)
        imports.pack_start(rendererText, True)
        imports.set_attributes(rendererText, text=1)
        imports.set_attributes(rendererPix, pixbuf=0)

        # Iterate imports and add to the tree
        for element in imps.keys():
            it = self.treestore.append(None, [self.fcn_pix, element])
            for imp in imps[element]:
                self.treestore.append(it, [self.imp_pix, imp[0] + '\t' + imp[1]])

        # Add column to tree
        self.append_column(imports)
        self.set_model(self.treestore)
        self.expand_all()
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def create_classes_tree(self):

        self.treestore = Gtk.TreeStore(GdkPixbuf.Pixbuf, str, str)

        renderer_pix = Gtk.CellRendererPixbuf()
        renderer_text = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn()
        column.set_title("Offset")
        column.set_spacing(5)
        column.pack_start(renderer_pix, True)
        column.pack_start(renderer_text, False)
        column.set_attributes(renderer_pix, pixbuf=0)
        column.set_attributes(renderer_text, text=1)
        self.append_column(column)

        renderer_text = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn("Name", renderer_text, text=2)
        column.set_sort_column_id(2)
        self.append_column(column)

        self.set_model(self.treestore)
        self.expand_all()
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def populate_tree(self, groups):
        """ Accepts an array of n rows made of 2 elements each, and returns a TreeView."""

        store = Gtk.TreeStore(GdkPixbuf.Pixbuf, str, str)

        for group in groups:
            #header = '<span background=\"#5a58ff\" foreground=\"white\"><b> ' + group.replace('_', ' ').capitalize() + '\t</b></span>'
            header = group.replace('_', ' ').capitalize()
            it = store.append(None, [self.pix, header, ''])
            for row in eval('self.' + group):
                store.append(it, [None, row[0], row[1]])

        tv = Gtk.TreeView(store)
        #tv.set_rules_hint(True)
        #tv.set_enable_tree_lines(True)
        tv.set_show_expanders(False)
        tv.set_level_indentation(10)
        tv.expand_all()

        return tv
项目:gpt    作者:encarsia    | 项目源码 | 文件源码
def get_tree_data(self,directory,parent=None):
        """Creates TreeStore table"""
        for dirs in sorted(os.listdir(directory)):
            path=os.path.join(directory,dirs)
            if os.path.isdir(path):
                os.chdir(dirs)
                #count media
                vidcount = len(glob.glob('*.MP4'))
                imgcount = len(glob.glob('*.JPG'))
                #size of directory, subdiretories exclued
                size = sum([os.path.getsize(f) for f in os.listdir('.') if os.path.isfile(f)])
                humansize = self.sizeof_fmt(size)
                try:
                    #4th/5th position in file name of last element in sorted list of sequences (e.g. Seq_03_010.JPG)
                    seq = int(sorted(glob.glob('Seq_*_*.*'))[-1][4:6])
                except:
                    seq = 0
                #transmit row to treestore
                row = self.builder.get_object("treestore1").append(parent,[dirs,vidcount,imgcount,humansize,path,seq,False,size])
                #read subdirs as child rows
                self.get_tree_data(path,row)
                os.chdir("..")
项目:PyIDE    作者:raggesilver    | 项目源码 | 文件源码
def populateFileSystemTreeStore(self, treeStore, path, parent=None):
        itemCounter = 0
        # iterate over the items in the path
        _list = os.listdir(path)
        _list.sort(key=str.lower)
        for item in _list:
            # Get the absolute path of the item
            itemFullname = os.path.join(path, item)
            # Extract metadata from the item
            itemMetaData = os.stat(itemFullname)
            # Determine if the item is a folder
            itemIsFolder = stat.S_ISDIR(itemMetaData.st_mode)
            # Generate an icon from the default icon theme
            itemIcon = None
            try:
                itemIcon = Gtk.IconTheme.get_default().load_icon("folder" if itemIsFolder else "gnome-mime-text-x-c" if os.path.splitext(itemFullname)[1] == '.c' else "gnome-mime-text-x-c++" if os.path.splitext(itemFullname)[1] == '.cpp' else "gnome-mime-text-x-python" if os.path.splitext(itemFullname)[1] == '.py' else "application-json" if os.path.splitext(itemFullname)[1] == '.json' else "text-x-markdown" if os.path.splitext(itemFullname)[1] == '.md' else "text-x-cmake" if os.path.basename(itemFullname) == 'Makefile' else "gnome-mime-image" if os.path.splitext(itemFullname)[1] in ['.png', '.jpg', '.jpeg', '.gif'] else "text-x-script" if not self.is_exe(os.path.join(self.projectPath, itemFullname)) else "application-x-executable", 22, 0)
            except:
                itemIcon = Gtk.IconTheme.get_default().load_icon("text-x-script", 22, 0)

            # print('{} is equal to Makefile? {}'.format(itemFullname, itemFullname == 'Makefile'))
            # Append the item to the TreeStore
            currentIter = treeStore.append(parent, [item, itemIcon, itemFullname])
            # add dummy if current item was a folder
            if itemIsFolder: treeStore.append(currentIter, [None, None, None])
            #increment the item counter
            itemCounter += 1
        # add the dummy node back if nothing was inserted before
        if itemCounter < 1: treeStore.append(parent, [None, None, None])
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def create_tree(self):
        # Scrolled Window
        self.sw = Gtk.ScrolledWindow()
        self.sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
        self.sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)

        self.store = Gtk.ListStore(str, str)
        self.tree = Gtk.TreeView(self.store)

        self.sw.add(self.tree)

        self.tree.set_rules_hint(True)

        # Connect right click popup search menu
        self.popup_handler = self.tree.connect('button-press-event', self.popup_menu)

        # Create the column
        bblocks = Gtk.TreeViewColumn()
        bblocks.set_title("Basic Blocks")

        cell = Gtk.CellRendererText()
        bblocks.pack_start(cell, True)
        bblocks.add_attribute(cell, "text", 0)

        self.treestore = Gtk.TreeStore(str)

        # Add column to tree
        self.tree.append_column(bblocks)
        self.tree.set_model(self.treestore)
        self.tree.expand_all()
项目:plotcommander    作者:FilipDominec    | 项目源码 | 文件源码
def populateFileSystemTreeStore(treeStore, path, parent=None):
    itemCounter = 0
    for item in os.listdir(path):                           # iterate over the items in the path
        itemFullname = os.path.join(path, item)             # Get the absolute path of the item
        itemMetaData = os.stat(itemFullname)                # Extract metadata from the item
        itemIsFolder = stat.S_ISDIR(itemMetaData.st_mode)   # Determine if the item is a folder
        itemIcon = Gtk.IconTheme.get_default().load_icon("folder" if itemIsFolder else "empty", 8, 0) # Generate a default icon
        currentIter = treeStore.append(parent, [item, itemIcon, itemFullname])      # Append the item to the TreeStore
        if itemIsFolder: treeStore.append(currentIter, [None, None, None])      # add dummy if current item was a folder
        itemCounter += 1                                    #increment the item counter
    if itemCounter < 1: treeStore.append(parent, [None, None, None])        # add the dummy node back if nothing was inserted before
项目:pytimetrack    作者:fhackerz    | 项目源码 | 文件源码
def __init__(self):
        Gtk.TreeView.__init__(self)
        self.task_store = Gtk.TreeStore(str, str)
        self.set_model(self.task_store)
        column = Gtk.TreeViewColumn(_('Tasks'), Gtk.CellRendererText(), text=0)
        self.append_column(column)
        self.connect('notify::tasks', self.tasks_changed)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, db, cache, icons, icon_size=AppGenericStore.ICON_SIZE,
                 global_icon_cache=True):
        AppGenericStore.__init__(
            self, db, cache, icons, icon_size, global_icon_cache)
        Gtk.TreeStore.__init__(self)
        self.set_column_types(self.COL_TYPES)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def clear(self):
        # reset the tranaction map because it will now be invalid
        self.transaction_path_map = {}
        Gtk.TreeStore.clear(self)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, db, cache, icons, icon_size=AppGenericStore.ICON_SIZE,
                 global_icon_cache=True):
        AppGenericStore.__init__(
            self, db, cache, icons, icon_size, global_icon_cache)
        Gtk.TreeStore.__init__(self)
        self.set_column_types(self.COL_TYPES)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def clear(self):
        # reset the tranaction map because it will now be invalid
        self.transaction_path_map = {}
        Gtk.TreeStore.clear(self)
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def __init__(self):
        Gtk.Dialog.__init__(self, _("GNU Solfege Preferences"),
             solfege.win, 0,
             (Gtk.STOCK_HELP, Gtk.ResponseType.HELP, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE))
        cfg.ConfigUtils.__init__(self, 'configwindow')
        self.connect('response', self.apply_and_close)
        # We do this so that the window is only hidden when the
        # user click on the close button provided by the window manager.
        self.connect('delete-event', self.on_destroy)#lambda w, e: True)

        hbox = Gtk.HBox()
        hbox.set_spacing(gu.hig.SPACE_LARGE)
        hbox.set_border_width(gu.hig.SPACE_SMALL)
        self.vbox.pack_start(hbox, True, True, 0)

        frame = Gtk.Frame()
        self.g_pages = Gtk.TreeStore(str)
        self.g_pview = Gtk.TreeView(self.g_pages)
        self.g_pview.set_headers_visible(False)
        hbox.pack_start(frame, False, False, 0)
        frame.add(self.g_pview)

        self.g_page_box = Gtk.HBox()
        hbox.pack_start(self.g_page_box, True, True, 0)
        self.m_page_mapping = {}

        def cursor_changed(treeview):
            path, col = treeview.get_cursor()
            if not path:
                return
            path = tuple(path)
            for key, page in self.m_page_mapping.items():

                if key == path:
                    page.show()

                else:
                    page.hide()
            self.m_page_mapping[path].show_all()
        tvcol = Gtk.TreeViewColumn("Col 0")
        self.g_pview.append_column(tvcol)
        cell = Gtk.CellRendererText()
        tvcol.pack_start(cell, True)
        tvcol.add_attribute(cell, 'text', 0)
        hbox.show_all()

        self.create_midi_config()
        self.create_user_config()
        self.create_external_programs_config()
        self.create_gui_config()
        self.create_practise_config()
        self.create_sound_config()
        self.create_statistics_config()
        self.g_pview.connect('cursor-changed', cursor_changed)
项目:bcloud    作者:wangYanJava    | 项目源码 | 文件源码
def __init__(self, parent, app, title=_('Save to..')):
        self.parent = parent
        self.app = app
        super().__init__(title, app.window, Gtk.DialogFlags.MODAL,
                         (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                         Gtk.STOCK_OK, Gtk.ResponseType.OK))
        self.set_default_size(440, 480)
        self.set_border_width(10)
        self.set_default_response(Gtk.ResponseType.OK)

        box = self.get_content_area()

        control_box = Gtk.Box()
        box.pack_start(control_box, False, False, 0)

        mkdir_button = Gtk.Button.new_with_label(_('Create Folder'))
        control_box.pack_end(mkdir_button, False, False, 0)
        mkdir_button.connect('clicked', self.on_mkdir_clicked)

        reload_button = Gtk.Button.new_with_label(_('Reload'))
        control_box.pack_end(reload_button, False, False, 5)
        reload_button.connect('clicked', self.on_reload_clicked)

        scrolled_win = Gtk.ScrolledWindow()
        box.pack_start(scrolled_win, True, True, 5)

        # disname, path, empty, loaded
        self.treestore = Gtk.TreeStore(str, str, bool, bool)
        self.treeview = Gtk.TreeView(model=self.treestore)
        self.selection = self.treeview.get_selection()
        scrolled_win.add(self.treeview)
        icon_cell = Gtk.CellRendererPixbuf(icon_name='folder')
        name_cell = Gtk.CellRendererText()
        name_col = Gtk.TreeViewColumn(_('Folder'))
        name_col.pack_start(icon_cell, False)
        name_col.pack_start(name_cell, True)
        if Config.GTK_LE_36:
            name_col.add_attribute(name_cell, 'text', NAME_COL)
        else:
            name_col.set_attributes(name_cell, text=NAME_COL)
        self.treeview.append_column(name_col)
        self.treeview.connect('row-expanded', self.on_row_expanded)

        box.show_all()

        self.reset()
项目:poseidon    作者:sidus-dev    | 项目源码 | 文件源码
def user_agent(self):

    if self.tabs[self.current_page][0]\
    .scrolled_window.get_name() != "webview": return True

    window = build_window(self, 0, 0)
    window.set_titlebar(build_headerbar("User Agent", None, 1))

    scrolled_window = Gtk.ScrolledWindow()
    scrolled_window.set_size_request(400, 300)

    tree = Gtk.TreeView()
    tree.connect('row-activated', self.new_user_agent)
    column = Gtk.TreeViewColumn()
    column.set_title(_("Double click item to switch"))

    cell = Gtk.CellRendererText()
    column.pack_start(cell, True)
    column.add_attribute(cell, "text", 0)

    treestore = Gtk.TreeStore(str, str)

    ua_browsers_list = []
    ua_mobile_list = []
    ua_crawlers_list = []

    treestore.append(None, ["Default", ""])

    browsers = treestore.append(None, ["Browsers", None])
    for c, i in enumerate(ua_browsers_dsc): ua_browsers_list.append([i, ua_browsers_val[c]])
    ua_browsers_list.sort()
    for c, i in enumerate(ua_browsers_list): treestore.append(browsers, [ua_browsers_list[c][0], ua_browsers_list[c][1]])

    mobile = treestore.append(None, ["Mobile Browsers", None])
    for c, i in enumerate(ua_mobile_dsc): ua_mobile_list.append([i, ua_mobile_val[c]])
    ua_mobile_list.sort()
    for c, i in enumerate(ua_mobile_list): treestore.append(mobile, [ua_mobile_list[c][0], ua_mobile_list[c][1]])

    crawlers = treestore.append(None, ["Crawlers", None])
    for c, i in enumerate(ua_crawlers_dsc): ua_crawlers_list.append([i, ua_crawlers_val[c]])
    ua_crawlers_list.sort()
    for c, i in enumerate(ua_crawlers_list): treestore.append(crawlers, [ua_crawlers_list[c][0], ua_crawlers_list[c][1]])

    tree.append_column(column)
    tree.set_model(treestore)
    scrolled_window.add(tree)

    window.add(scrolled_window)
    window.show_all()
项目:king-phisher-plugins    作者:securestate    | 项目源码 | 文件源码
def __init__(self, application, config, wd_history):
        self.application = application
        self.config = config
        self.treeview = sftp_utilities.get_object('SFTPClient.notebook.page_stfp.' + self.treeview_name)
        self.notebook = sftp_utilities.get_object('SFTPClient.notebook')
        self.wd_history = collections.deque(wd_history, maxlen=3)
        self.cwd = None
        self.col_name = Gtk.CellRendererText()
        self.col_name.connect('edited', self.signal_text_edited)
        col_text = Gtk.CellRendererText()
        col_img = Gtk.CellRendererPixbuf()

        col = Gtk.TreeViewColumn('Files')
        col.pack_start(col_img, False)
        col.pack_start(self.col_name, True)
        col.add_attribute(self.col_name, 'text', 0)
        col.add_attribute(col_img, 'pixbuf', 1)
        col.set_property('resizable', True)
        col.set_sort_column_id(0)

        self.treeview.append_column(col)
        self.treeview.append_column(sftp_utilities.get_treeview_column('Permissions', col_text, 3, m_col_sort=3, resizable=True))
        self.treeview.append_column(sftp_utilities.get_treeview_column('Size', col_text, 4, m_col_sort=5, resizable=True))
        self.treeview.append_column(sftp_utilities.get_treeview_column('Date Modified', col_text, 6, m_col_sort=6, resizable=True))

        self.treeview.connect('button_press_event', self.signal_tv_button_press)
        self.treeview.connect('key-press-event', self.signal_tv_key_press)
        self.treeview.connect('row-expanded', self.signal_tv_expand_row)
        self.treeview.connect('row-collapsed', self.signal_tv_collapse_row)
        self._tv_model = Gtk.TreeStore(
            str,               # 0 base name
            GdkPixbuf.Pixbuf,  # 1 icon
            str,               # 2 full path
            str,               # 3 permissions
            str,               # 4 human readable size
            GTYPE_LONG,        # 5 size in bytes
            str                # 6 modified timestamp
        )
        self._tv_model.set_sort_column_id(0, Gtk.SortType.ASCENDING)
        self._tv_model_filter = self._tv_model.filter_new()
        self._tv_model_filter.set_visible_func(self._filter_entries)
        self.refilter = self._tv_model_filter.refilter
        self._tv_model_sort = Gtk.TreeModelSort(model=self._tv_model_filter)
        self.treeview.set_model(self._tv_model_sort)

        self._wdcb_model = Gtk.ListStore(str)  # working directory combobox
        self.wdcb_dropdown = sftp_utilities.get_object(self.working_directory_combobox_name)
        self.wdcb_dropdown.set_model(self._wdcb_model)
        self.wdcb_dropdown.set_entry_text_column(0)
        self.wdcb_dropdown.connect('changed', sftp_utilities.DelayedChangedSignal(self.signal_combo_changed))

        self.show_hidden = False
        self._get_popup_menu()
项目:king-phisher-plugins    作者:securestate    | 项目源码 | 文件源码
def __init__(self, queue):
        self.queue = queue
        self.scroll = sftp_utilities.get_object('SFTPClient.notebook.page_stfp.scrolledwindow_transfer_statuses')
        self.treeview_transfer = sftp_utilities.get_object('SFTPClient.notebook.page_stfp.treeview_transfer_statuses')
        self._tv_lock = threading.RLock()

        col_text = Gtk.CellRendererText()
        col_img = Gtk.CellRendererPixbuf()
        col = Gtk.TreeViewColumn('')
        col.pack_start(col_img, False)
        col.add_attribute(col_img, 'pixbuf', 0)
        self.treeview_transfer.append_column(col)

        self.treeview_transfer.append_column(sftp_utilities.get_treeview_column('Local File', col_text, 1, m_col_sort=1, resizable=True))
        self.treeview_transfer.append_column(sftp_utilities.get_treeview_column('Remote File', col_text, 2, m_col_sort=2, resizable=True))
        self.treeview_transfer.append_column(sftp_utilities.get_treeview_column('Status', col_text, 3, m_col_sort=3, resizable=True))

        col_bar = Gtk.TreeViewColumn('Progress')
        progress = Gtk.CellRendererProgress()
        col_bar.pack_start(progress, True)
        col_bar.add_attribute(progress, 'value', 4)
        col_bar.set_property('resizable', True)
        col_bar.set_min_width(125)
        self.treeview_transfer.append_column(col_bar)

        self.treeview_transfer.append_column(sftp_utilities.get_treeview_column('Size', col_text, 5, m_col_sort=3, resizable=True))
        self._tv_model = Gtk.TreeStore(GdkPixbuf.Pixbuf, str, str, str, int, str, object)
        self.treeview_transfer.connect('size-allocate', self.signal_tv_size_allocate)
        self.treeview_transfer.connect('button_press_event', self.signal_tv_button_pressed)

        self.treeview_transfer.set_model(self._tv_model)
        self.treeview_transfer.show_all()

        self.popup_menu = Gtk.Menu.new()

        self.menu_item_paused = Gtk.CheckMenuItem.new_with_label('Paused')
        menu_item = self.menu_item_paused
        menu_item.connect('toggled', self.signal_menu_toggled_paused)
        self.popup_menu.append(menu_item)

        self.menu_item_cancel = Gtk.MenuItem.new_with_label('Cancel')
        menu_item = self.menu_item_cancel
        menu_item.connect('activate', self.signal_menu_activate_cancel)
        self.popup_menu.append(menu_item)

        menu_item = Gtk.SeparatorMenuItem()
        self.popup_menu.append(menu_item)

        menu_item = Gtk.MenuItem.new_with_label('Clear')
        menu_item.connect('activate', self.signal_menu_activate_clear)
        self.popup_menu.append(menu_item)
        self.popup_menu.show_all()