当前位置: 首页>>代码示例>>Python>>正文


Python TreeView.clear方法代码示例

本文整理汇总了Python中dtk.ui.treeview.TreeView.clear方法的典型用法代码示例。如果您正苦于以下问题:Python TreeView.clear方法的具体用法?Python TreeView.clear怎么用?Python TreeView.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dtk.ui.treeview.TreeView的用法示例。


在下文中一共展示了TreeView.clear方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: UninstallPage

# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import clear [as 别名]
class UninstallPage(gtk.VBox):
    '''
    class docs
    '''
	
    def __init__(self, bus_interface, data_manager):
        '''
        init docs
        '''
        # Init.
        gtk.VBox.__init__(self)
        self.bus_interface = bus_interface        
        self.data_manager = data_manager

        self.search_flag = False
        self.uninstall_change_items = {"add": [], "delete": []}
        
        self.message_bar = MessageBar(32)
        self.message_bar.search_entry.entry.connect("changed", self.search_cb)
        self.message_bar.search_button.connect("clicked", self.search_cb)
        self.treeview = TreeView(enable_drag_drop=False)
        self.treeview.set_expand_column(0)

        top_hbox = gtk.HBox()
        top_hbox.pack_start(self.message_bar)

        self.pack_start(top_hbox, False, False)
        self.pack_start(self.treeview, True, True)
        
        self.treeview.connect("items-change", self.update_message_bar)
        
        self.fetch_uninstall_info()
        
        self.treeview.draw_mask = self.draw_mask

    def search_cb(self, widget, event=None):
        if not self.search_flag:
            self.cache_items = [item for item in self.treeview.visible_items]
        results = []
        keywords = self.message_bar.search_entry.get_text().strip()

        if keywords != "":
            self.search_flag = True
            # TODO: comment this search_query api, there are many problems for this api
            '''
            pkg_names = self.data_manager.search_query(map(lambda word: word.encode("utf8"), keywords.split(" ")))
            for item in self.cache_items:
                if item.pkg_name in pkg_names:
                    results.append(item)
            '''
            for item in self.cache_items:
                if keywords in item.pkg_name:
                    results.append(item)
            self.treeview.clear()
            self.treeview.add_items(results)
        else:
            self.treeview.clear()
            self.search_flag = False

            # for add items
            if self.uninstall_change_items["add"] != []:
                for item in self.uninstall_change_items["add"]:
                    self.cache_items.append(item)
                self.uninstall_change_items["add"] = []

            # for delete items
            if self.uninstall_change_items["delete"] != []:
                for item in self.uninstall_change_items["delete"]:
                    if item in self.cache_items:
                        self.cache_items.remove(item)
                self.uninstall_change_items["delete"] = []

            self.treeview.add_items(self.cache_items)

    def normal_search_cb(self, keywords):
        pass
        
    def update_message_bar(self, treeview):    
        self.message_bar.set_message(_("%s applications can be uninstalled") % len(treeview.visible_items))
        
    def draw_mask(self, cr, x, y, w, h):
        '''
        Draw mask interface.
        
        @param cr: Cairo context.
        @param x: X coordiante of draw area.
        @param y: Y coordiante of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        draw_vlinear(cr, x, y, w, h,
                     [(0, ("#FFFFFF", 0.9)),
                      (1, ("#FFFFFF", 0.9)),]
                     )
        
    def update_action_status(self, pkg_infos):
        pkg_items = []
        for (pkg_name, action_status) in pkg_infos:
            pkg_item = None
            for item in self.treeview.visible_items:
#.........这里部分代码省略.........
开发者ID:PeterDaveHello,项目名称:deepin-software-center,代码行数:103,代码来源:uninstall_page.py

示例2: UninstallPage

# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import clear [as 别名]
class UninstallPage(gtk.VBox):
    '''
    class docs
    '''
	
    def __init__(self, bus_interface, data_manager):
        '''
        init docs
        '''
        # Init.
        gtk.VBox.__init__(self)
        self.bus_interface = bus_interface        
        self.data_manager = data_manager

        self.search_flag = False
        self.uninstall_change_items = {"add": [], "delete": []}
        
        self.message_bar = MessageBar(32)
        self.message_bar.search_entry.entry.connect("changed", self.search_cb)
        self.message_bar.search_button.connect("clicked", self.search_cb)
        self.treeview = TreeView(enable_drag_drop=False)
        self.treeview.set_expand_column(0)

        top_hbox = gtk.HBox()
        top_hbox.pack_start(self.message_bar)

        self.pack_start(top_hbox, False, False)
        self.pack_start(self.treeview, True, True)
        
        self.treeview.connect("items-change", self.update_message_bar)
        
        self.white_kernel_pkg_names = self.get_white_kernel_pkg_names()
        self.fetch_uninstall_info()
        
        self.treeview.draw_mask = self.draw_mask

    def search_cb(self, widget, event=None):
        if not self.search_flag:
            self.cache_items = [item for item in self.treeview.visible_items]
        results = []
        keywords = self.message_bar.search_entry.get_text().strip()

        if keywords != "":
            self.search_flag = True
            # TODO: comment this search_query api, there are many problems for this api
            '''
            pkg_names = self.data_manager.search_query(map(lambda word: word.encode("utf8"), keywords.split(" ")))
            for item in self.cache_items:
                if item.pkg_name in pkg_names:
                    results.append(item)
            '''
            for item in self.cache_items:
                if keywords in item.pkg_name:
                    results.append(item)
            self.treeview.clear()
            self.treeview.add_items(results)
        else:
            self.treeview.clear()
            self.search_flag = False

            # for add items
            if self.uninstall_change_items["add"] != []:
                for item in self.uninstall_change_items["add"]:
                    self.cache_items.append(item)
                self.uninstall_change_items["add"] = []

            # for delete items
            if self.uninstall_change_items["delete"] != []:
                for item in self.uninstall_change_items["delete"]:
                    if item in self.cache_items:
                        self.cache_items.remove(item)
                self.uninstall_change_items["delete"] = []

            self.treeview.add_items(self.cache_items)

    def normal_search_cb(self, keywords):
        pass
        
    def update_message_bar(self, treeview):    
        self.message_bar.set_message(_("%s applications can be uninstalled") % len(treeview.visible_items))
        
    def draw_mask(self, cr, x, y, w, h):
        '''
        Draw mask interface.
        
        @param cr: Cairo context.
        @param x: X coordiante of draw area.
        @param y: Y coordiante of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        draw_vlinear(cr, x, y, w, h,
                     [(0, ("#FFFFFF", 0.9)),
                      (1, ("#FFFFFF", 0.9)),]
                     )
        
    def update_action_status(self, pkg_infos):
        pkg_items = []
        for (pkg_name, action_status) in pkg_infos:
            pkg_item = None
#.........这里部分代码省略.........
开发者ID:electricface,项目名称:deepin-software-center,代码行数:103,代码来源:uninstall_page.py

示例3: SearchUI

# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import clear [as 别名]
class SearchUI(DialogBox):
    def __init__(self):
        DialogBox.__init__(
            self, _("Lyrics search"), 460, 300, DIALOG_MASK_MULTIPLE_PAGE, close_callback=self.hide_all, 
            modal=False, window_hint=None, skip_taskbar_hint=False, window_pos=gtk.WIN_POS_CENTER)
        
        self.artist_entry = InputEntry()
        self.artist_entry.set_size(130, 23)
        self.title_entry = InputEntry()
        self.title_entry.set_size(130, 23)
        artist_label = Label(_("Artist:"))
        title_label = Label(_("Title:"))
        right_align = gtk.Alignment()
        right_align.set(0, 0, 0, 1)
        
        self.search_button = Button(_("Search"))
        self.search_button.connect("clicked", self.search_lyric_cb)
        self.process_id = 0
        
        info_box = gtk.HBox(spacing=25)
        
        control_box = gtk.HBox(spacing=5)
        title_box = gtk.HBox(spacing=5)        
        title_box.pack_start(title_label, False, False)
        title_box.pack_start(self.title_entry)
        artist_box = gtk.HBox(spacing=5)
        artist_box.pack_start(artist_label, False, False)
        artist_box.pack_start(self.artist_entry)
        control_box.pack_start(title_box, False, False)
        control_box.pack_start(artist_box, False, False)
        
        info_box.pack_start(control_box, False, False)
        info_box.pack_start(self.search_button, False, False)
        
        sort_items = [ lambda items, reverse : self.sort_by_key(items, reverse, "title"),
                       lambda items, reverse : self.sort_by_key(items, reverse, "artist")]
        self.result_view = TreeView()
        self.result_view.set_expand_column(0)
        self.result_view.connect("double-click-item", self.double_click_cb)
        self.result_view.set_column_titles([_("Title"), _("Artist")], sort_items)
        self.result_view.draw_mask = self.draw_view_mask
        
        self.prompt_label = Label("")
        download_button = Button(_("Download"))
        download_button.connect("clicked", self.download_lyric_cb)
        cancel_button = Button(_("Close"))
        cancel_button.connect("clicked", lambda w: self.hide_all())
        
        info_box_align = gtk.Alignment()
        info_box_align.set_padding(5, 0, 5, 0)
        info_box_align.add(info_box)
        
        self.body_box.set_spacing(5)
        self.body_box.pack_start(info_box_align, False, False)
        self.body_box.pack_start(self.result_view, True, True)
        self.left_button_box.set_buttons([self.prompt_label])
        self.right_button_box.set_buttons([download_button, cancel_button])
        self.lrc_manager = LrcManager()
        
    def show_window(self):    
        DialogBox.show_window(self)
        self.present()
                
    def draw_view_mask(self, cr, x, y, width, height):            
        draw_alpha_mask(cr, x, y, width, height, "layoutMiddle")
        
    def sort_by_key(self, items, sort_reverse, sort_key):    
        return sorted(items, reverse=sort_reverse, key=lambda item: getattr(item, sort_key))
        
    def double_click_cb(self, widget, item, colume, x, y):   
        self.download_lyric_cb(widget)
        
    def search_engine(self, artist, title, pid):    
        
        ting_result = poster.query_lrc_info(artist, title)
        self.render_lyrics(ting_result, pid=pid)
        
        ttplayer_result = TTPlayer().request(artist, title)
        self.render_lyrics(ttplayer_result, pid=pid)
        
        ttpod_result = TTPod().request(artist, title)        
        self.render_lyrics(ttpod_result, pid=pid)
        
        duomi_result = DUOMI().request(artist, title)
        self.render_lyrics(duomi_result, pid=pid, last=True)
        
        
    def search_lyric_cb(self, widget):
        self.result_view.clear()
        artist = self.artist_entry.entry.get_text()
        title = self.title_entry.entry.get_text()
        # widget.set_sensitive(False)
        self.prompt_label.set_text(_("Now searching..."))
        if artist == "" and title == "":
            self.prompt_label.set_text(_("Not found!"))
            return
        self.process_id += 1
        utils.ThreadLoad(self.search_engine, artist, title, self.process_id).start()
        
    @post_gui
#.........这里部分代码省略.........
开发者ID:electricface,项目名称:deepin-music-player,代码行数:103,代码来源:lyrics_search.py

示例4: PluginsManager

# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import clear [as 别名]
class PluginsManager(gtk.VBox):
    
    def __init__(self):
        gtk.VBox.__init__(self)
        
        self.set_spacing(5)
        self.plugins = utils.get_main_window().plugins
        self.plugins_view = TreeView()
        self.plugins_view.set_expand_column(0)
        self.plugins_view.draw_mask = self.plugins_view_draw_mask
        self.plugins_view.set_size_request(420, 330)        
        self.plugins_view.connect("single-click-item", self.on_plugins_view_single_click)
                
        self.plugins_view.set_column_titles([_("Add-on"), _("Version"), _("Enable"), ""],
                                            (self.sort_by_title, self.sort_by_title,
                                             self.sort_by_title, self.sort_by_title))
        plugins_view_align = set_widget_gravity(self.plugins_view, gravity=(1, 1, 1, 1),
                                                paddings=(10, 0, 0, 0))
        
        self.plugin_infos = PluginInfos()
        self.plugin_infos.set_size_request(420, 90)
        
        # plugin info
        self.pack_start(plugins_view_align, False, True)
        self.pack_start(self.plugin_infos, False, True)
        
    def sort_by_title(self, items, reverse):    
        return sorted(items, key=lambda item: item.plugin, reverse=reverse)
    
    def plugins_view_draw_mask(self, cr, x, y, width, height):
        draw_alpha_mask(cr, x, y, width, height, "layoutLeft")
        
    def flush_plugins(self):
        self.__load_plugin_list()
        
    def __load_plugin_list(self):    
        
        # clear plugins_view items.
        self.plugins_view.clear()
        
        plugins = self.plugins.list_installed_plugins()
        plugins_list = []
        failed_list = []
        
        for plugin in plugins:
            try:
                info = self.plugins.get_plugin_info(plugin)
            except Exception:    
                failed_list.append(plugin)
                continue
            
            enabled  = plugin in self.plugins.enabled_plugins
            plugins_list.append((plugin, info, enabled))
            
        plugins_list.sort(key=lambda x: locale.strxfrm(x[1]["Name"]))
        plugins_items = [PluginItem(*args) for args in plugins_list]
        self.plugins_view.add_items(plugins_items)
        
    def on_plugins_view_single_click(self, widget, item, column, x, y):
        if column == 2:
            plugin = item.plugin
            will_enable = not item.enabled
            if will_enable:
                try:
                    self.plugins.enable_plugin(plugin)
                except Exception, e:    
                    print e
                    return
            else:    
                try:
                    self.plugins.disable_plugin(plugin)
                except Exception, e:    
                    print e
                    return
            item.toggle_enabled()    
开发者ID:WilliamRen,项目名称:deepin-music-player,代码行数:77,代码来源:plugins_view.py

示例5: SessionView

# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import clear [as 别名]

#.........这里部分代码省略.........
        self.delete_button.connect("clicked", self.delete_autostart)
        self.delete_button.set_sensitive(False)
        
        foot_box = FootBox(adjustment=15)
        foot_box.set_buttons([add_button, self.delete_button])
        self.pack_start(align, True, True)
        
        self.pack_end(foot_box, False, False)
        #self.pack_end(self.new_box, False, False)

        self.show_all()

        self._init_monitor()

    def disable_delete_button(self, value):
        self.delete_button.set_sensitive(not value)
    def _init_monitor(self):
        self.library_monitor = LibraryMonitor(get_user_config_dir())
        self.library_monitor.set_property("monitored", True)
        self.library_monitor.connect("file-added", self.refresh_list)
        self.library_monitor.connect("location-removed", self.refresh_list)

    def right_press_item(self, widget,  x_root, y_root, current_item, select_items):
        self.tmp_editing_session = current_item.item
        for item in select_items:
            item.unselect()
        if current_item != None:
            current_item.select()
            if self.open_dialog == False:
                dialog = NewSessionDialog(confirm_callback = self.edit_done, cancel_callback = self.cancel_callback)
                dialog.name_entry.set_text(current_item.item.name)
                dialog.exec_entry.set_text(current_item.item.exec_)
                dialog.desc_entry.set_text(current_item.item.comment)
                dialog.place_center()
                dialog.show_all()
                self.open_dialog = True

    def create_session_item(self, dialog):
        name = dialog.name_entry.get_text()
        exec_ = dialog.exec_entry.get_text()
        comment = dialog.desc_entry.get_text()
        session_manager.add(name, exec_, comment)
        self.open_dialog = False

    def expose_line(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        style.draw_out_line(cr, rect, exclude=["left", "right", "top"])
    
    def sort_method(self):
        pass

    def add_autostart(self, widget):
        if self.open_dialog == False:
            dialog = NewSessionDialog(confirm_callback= self.create_session_item, cancel_callback = self.cancel_callback)
            dialog.show_all()
            self.open_dialog = True

    def delete_autostart(self, widget):
        items = map(lambda row: self.tree.visible_items[row], self.tree.select_rows)
        item = items[0].item
        item.delete()
        self.tree.delete_select_items()
        if self.tree.visible_items == []:
            self.tree.add_items([NothingItem()])

    def edit_done(self, dialog):
        self.tmp_editing_session.set_name(dialog.name_entry.get_text())
        self.tmp_editing_session.set_exec(dialog.exec_entry.get_text())
        self.tmp_editing_session.set_comment(dialog.desc_entry.get_text())
        self.tmp_editing_session.save()
        self.tmp_editing_session = None
        items = map(lambda row: self.tree.visible_items[row], self.tree.select_rows)
        self.tree.redraw_request(items, True)
        self.open_dialog = False

    def cancel_callback(self):
        self.tmp_editing_session = None
        self.open_dialog = False

    def pack(self, parent, widget_list, expand=False, fill=False):
        for w in widget_list:
            parent.pack_start(w, expand, fill)

    def draw_mask(self, cr, x, y, w, h):
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(x, y, w, h)
        cr.fill()

    def get_list(self):
        usr_list = session_manager.list_autostart_items()
        if usr_list:
            return map(lambda w: SessionItem(self, w), usr_list)
        else:
            return [NothingItem()]

    def refresh_list(self, widget, gfile):
        self.tree.clear()
        self.tree.add_items(self.get_list())
        self.tree.show()
开发者ID:electricface,项目名称:deepin-system-settings,代码行数:104,代码来源:session_view.py


注:本文中的dtk.ui.treeview.TreeView.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。