Exemplo n.º 1
0
 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.add_items = self.plugins_view_add_items
     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.connect("press-return", self.on_plugins_view_press_return)
             
     self.plugins_view.set_column_titles([_("Name"), _("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)
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()    
Exemplo n.º 3
0
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.add_items = self.plugins_view_add_items
        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.connect("press-return", self.on_plugins_view_press_return)
                
        self.plugins_view.set_column_titles([_("Name"), _("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 plugins_view_add_items(self, items, insert_pos=None, clear_first=False):
        for item in items:
            item.plugins_view = self
        TreeView.add_items(self.plugins_view, items, insert_pos, clear_first)    
        
    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_press_return(self, widget, items):    
        if len(items) > 0:
            item = items[0]
            self.toggle_plugin_status(item)
        
    def on_plugins_view_single_click(self, widget, item, column, x, y):
        if column == 2:
            self.toggle_plugin_status(item)
            
    def toggle_plugin_status(self, item):        
        plugin = item.plugin
        will_enable = not item.enabled
        if will_enable:
            try:
                self.plugins.enable_plugin(plugin)
            except Exception, e:    
                print e
                return
        else: