def load_cips(self, a=None, b=None, do_remove=False): log.debug("Load clips, do_remove: %s" % do_remove) if do_remove: for child in self.clipvbox.get_children(): log.debug("Remove clip: %s" % child) self.clipvbox.remove(child) clips = self.clips_settings.get_value() log.debug("All clips to load: %s" % clips) if clips and clips != ['']: loader = ModuleLoader('clips') for name in clips: try: ClipClass = loader.get_module(name) log.debug("Load clip: %s" % name) clip = ClipClass() clip.connect('load_module', self._on_module_button_clicked) clip.connect('load_feature', self.on_clip_load_feature) clip.show_all() self.clipvbox.pack_start(clip, False, False, 0) except Exception, e: log.error(traceback.print_exc()) if name in self.clips_settings.get_value(): new_list = self.clips_settings.get_value().remove(name) self.clips_settings.set_value(new_list)
def load_modules(self, *args, **kwargs): log.debug("Loading modules...") loader = ModuleLoader(self._feature) self._boxes = [] for child in self._box.get_children(): self._box.remove(child) for category, category_name in loader.get_categories(): modules = loader.get_modules_by_category(category) if modules: module_to_loads = self._setting.get_value() for module in modules: if module.is_user_extension() and module.get_name() not in module_to_loads: modules.remove(module) category_box = CategoryBox(modules=modules, category_name=category_name) self._connect_signals(category_box) self._boxes.append(category_box) self._box.pack_start(category_box, False, False, 0) self.rebuild_boxes()
def load_cips(self, a=None, b=None, do_remove=False): log.debug("Load clips, do_remove: %s" % do_remove) if do_remove: for child in self.clipvbox.get_children(): log.debug("Remove clip: %s" % child) self.clipvbox.remove(child) clips = self.clips_settings.get_value() if clips and clips != ['']: loader = ModuleLoader('clips') self._clips = [] self._up_clips = [] self._showed_clips = [] self._down_clips = [] self.clipvbox.set_data('direction', 0) for name in clips: try: ClipClass = loader.get_module(name) log.debug("Load clip: %s" % name) clip = ClipClass() clip.connect('load_module', self._on_module_button_clicked) clip.connect('load_feature', self.on_clip_load_feature) self._clips.append(clip) except Exception, e: log.error(traceback.print_exc()) if name in self.clips_settings.get_value(): new_list = self.clips_settings.get_value().remove(name) self.clips_settings.set_value(new_list)
def update_model(self, a=None, b=None, expand=False): self.janitor_model.clear() self.result_model.clear() size_list = [] loader = ModuleLoader('janitor') plugin_to_load = self.janitor_setting.get_value() system_text = _('System') iter = self.janitor_model.append(None, (None, icon.get_from_name('ubuntu-logo'), system_text, "<b><big>%s</big></b>" % system_text, None, None, None)) for plugin in loader.get_modules_by_category('system'): if plugin.is_user_extension() and plugin.get_name() not in plugin_to_load: log.debug("User extension: %s not in setting to load" % plugin.get_name()) continue size_list.append(Gtk.Label(label=plugin.get_title()).get_layout().get_pixel_size()[0]) self.janitor_model.append(iter, (False, None, plugin.get_title(), plugin.get_title(), plugin(), None, None)) personal_text = _('Personal') iter = self.janitor_model.append(None, (None, icon.get_from_name('system-users'), personal_text, "<b><big>%s</big></b>" % personal_text, None, None, None)) for plugin in loader.get_modules_by_category('personal'): if plugin.is_user_extension() and plugin.get_name() not in plugin_to_load: log.debug("User extension: %s not in setting to load" % plugin.get_name()) continue size_list.append(Gtk.Label(label=plugin.get_title()).get_layout().get_pixel_size()[0]) self.janitor_model.append(iter, (False, None, plugin.get_title(), plugin.get_title(), plugin(), None, None)) if size_list: self.max_janitor_view_width = max(size_list) + 80 if expand: self._expand_janitor_view()
def test_module(self): feature, module = ModuleLoader.search_module_for_name('nautilus_test') self.assertEqual(feature, 'overview') self.assertEqual(module, None) feature, module = ModuleLoader.search_module_for_name('Nautilus') self.assertEqual(feature, 'module_test') self.assertEqual(module.__name__, 'Nautilus') feature, module = ModuleLoader.search_module_for_name('DesktopRecovery') self.assertEqual(feature, 'module_test') self.assertEqual(module.__name__, 'DesktopRecovery')
def _update_clip_model(self, feature=None): clips = self.clips_setting.get_value() loader = ModuleLoader("clips") self.clip_model.clear() for clip_name in clips: ClipClass = loader.get_module(clip_name) self.clip_model.append((True, ClipClass.get_pixbuf(), ClipClass.get_name())) for name, ClipClass in loader.module_table.items(): if name not in clips: self.clip_model.append((False, ClipClass.get_pixbuf(), ClipClass.get_name()))
def setup_rencently_used(self, *args): log.debug("Overview page: setup_rencently_used") used_list = self.rencently_used_settings.get_value() for child in self.rencently_used_vbox.get_children(): self.rencently_used_vbox.remove(child) for name in used_list: feature, module = ModuleLoader.search_module_for_name(name) if module: button = Gtk.Button() button.set_relief(Gtk.ReliefStyle.NONE) hbox = Gtk.HBox(spacing=6) button.add(hbox) image = Gtk.Image.new_from_pixbuf(module.get_pixbuf(size=16)) hbox.pack_start(image, False, False, 0) label = Gtk.Label(label=module.get_title()) label.set_ellipsize(Pango.EllipsizeMode.END) label.set_alignment(0, 0.5) hbox.pack_start(label, True, True, 0) button.connect('clicked', self._on_module_button_clicked, name) button.show_all() self.rencently_used_vbox.pack_start(button, False, False, 0)
def setup_recently_used(self, *args): used_list = self.recently_used_settings.get_value() log.debug("Overview page: setup_recently_used, %d used items found", len(used_list)) for child in self.recently_used_box.get_children(): self.recently_used_box.remove(child) for name in used_list: feature, module = ModuleLoader.search_module_for_name(name) if module: button = Gtk.Button() button.set_relief(Gtk.ReliefStyle.NONE) hbox = Gtk.HBox(spacing=6) button.add(hbox) image = Gtk.Image.new_from_pixbuf(module.get_pixbuf(size=16)) hbox.pack_start(image, False, False, 0) label = Gtk.Label(label=module.get_title()) label.set_ellipsize(Pango.EllipsizeMode.END) label.set_alignment(0, 0.5) hbox.pack_start(label, True, True, 0) button.connect('clicked', self._on_module_button_clicked, name) self.recently_used_box.pack_start(button, False, False, 0) self.on_recently_scrolled_window_size_allocate()
def _update_clip_model(self, feature=None): clips = self.clips_setting.get_value() loader = ModuleLoader('clips') self.clip_model.clear() for clip_name in clips: ClipClass = loader.get_module(clip_name) self.clip_model.append( (True, ClipClass.get_pixbuf(), ClipClass.get_name())) for name, ClipClass in loader.module_table.items(): if name not in clips: self.clip_model.append( (False, ClipClass.get_pixbuf(), ClipClass.get_name()))
def _update_feature_model(self, feature): module_list = getattr(self, '%s_setting' % feature).get_value() or [] loader = ModuleLoader(feature, user_only=True) model = getattr(self, '%s_model' % feature) model.clear() for name, klass in loader.module_table.items(): if klass.get_pixbuf(): model.append( (name in module_list, klass.get_pixbuf(), klass.get_name())) else: model.append((name in module_list, klass.get_name()))
def search(self, text): modules = ModuleLoader.fuzz_search(text) self._boxes = [] for child in self._box.get_children(): self._box.remove(child) if modules: category_box = CategoryBox(modules=modules, category_name=_('Results')) self._connect_signals(category_box) self._boxes.append(category_box) self._box.pack_start(category_box, False, False, 0) self.rebuild_boxes() else: self.no_result_box.label.set_markup(_('Your filter "<b>%s</b>" does not match any items.') % text) self._box.pack_start(self.no_result_box, False, False, 0)
def _load_module(self, name): feature, module = ModuleLoader.search_module_for_name(name) if module: self.select_target_feature(feature) if name in self.loaded_modules: module, index = self.get_module_and_index(name) else: try: page = module() except Exception, e: log.error(e) module = create_broken_module_class(name) page = module() page.show_all() index = self.notebook.append_page(page, Gtk.Label(label=name)) self._save_loaded_info(name, module, index) self.navigation_dict[feature] = name, None self.set_current_module(module, index) self.update_jump_buttons()
def on_install_extension(self, dialog_label, klass, feature, setting, update_func, error_message): dialog = Gtk.FileChooserDialog(dialog_label, action=Gtk.FileChooserAction.OPEN, buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT)) filter = Gtk.FileFilter() filter.set_name(_('Ubuntu Tweak Extension (*.py, *.tar.gz)')) filter.add_pattern('*.py') filter.add_pattern('*.tar.gz') dialog.add_filter(filter) dialog.set_current_folder(self.clips_location_setting.get_value() or GLib.get_home_dir()) filename = '' install_done = False not_extension = False if dialog.run() == Gtk.ResponseType.ACCEPT: filename = dialog.get_filename() dialog.destroy() if filename: self.clips_location_setting.set_value(os.path.dirname(filename)) log.debug("Start to check the class in %s" % filename) if filename.endswith('.tar.gz'): tar_file = TarFile(filename) if tar_file.is_valid(): tar_file.extract(TEMP_ROOT) #TODO if multi-root if tar_file.get_root_name(): temp_dir = os.path.join(TEMP_ROOT, tar_file.get_root_name()) if ModuleLoader.is_target_class(temp_dir, klass): target = os.path.join(ModuleLoader.get_user_extension_dir(feature), os.path.basename(temp_dir)) copy = True if os.path.exists(target): dialog = QuestionDialog(message=_("Would you like to remove it then install again?"), title=_('"%s" has already installed' % os.path.basename(target))) response = dialog.run() dialog.destroy() if response == Gtk.ResponseType.YES: shutil.rmtree(target) else: copy = False if copy: log.debug("Now copying tree...") shutil.move(temp_dir, target) else: shutil.rmtree(temp_dir) else: not_extension = True else: if ModuleLoader.is_target_class(filename, klass): shutil.copy(filename, ModuleLoader.get_user_extension_dir(feature)) install_done = True else: not_extension = True if install_done: update_func(feature) # To force empty the clips_setting to make load_cips value = setting.get_value() setting.set_value(['']) setting.set_value(value) if not_extension: ErrorDialog(message=error_message % os.path.basename(filename)).launch()
(WELCOME, BROKEN, APPLICATIONS, STARTUP, DESKTOP, PERSONAL, SYSTEM, TOTAL) = range(8) MODULES_TABLE = [ [WELCOME, 'ubuntu-tweak', _("Welcome"), show_welcome, None], [BROKEN, '', _("Broken Modules"), None, 'broken'], [APPLICATIONS, '', _("Applications"), None, 'application'], [STARTUP, '', _("Startup"), None, 'startup'], [DESKTOP, '', _("Desktop"), None, 'desktop'], [PERSONAL, '', _("Personal"), None, 'personal'], [SYSTEM, '', _("System"), None, 'system'], ] MLOADER = ModuleLoader(modules.__path__[0]) class UpdateDialog(DownloadDialog): def __init__(self, parent=None): DownloadDialog.__init__(self, url=TweakSettings.get_url(), title=_('Download Ubuntu Tweak %s') % TweakSettings.get_version(), parent=parent) def on_downloaded(self, downloader): super(UpdateDialog, self).on_downloaded(downloader) os.system('xdg-open %s' % self.downloader.get_downloaded_file())
def on_install_extension(self, dialog_label, klass, feature, setting, update_func, error_message): dialog = Gtk.FileChooserDialog( dialog_label, action=Gtk.FileChooserAction.OPEN, buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT)) filter = Gtk.FileFilter() filter.set_name(_('Ubuntu Tweak Extension (*.py, *.tar.gz)')) filter.add_pattern('*.py') filter.add_pattern('*.tar.gz') dialog.add_filter(filter) dialog.set_current_folder(self.clips_location_setting.get_value() or GLib.get_home_dir()) filename = '' install_done = False not_extension = False if dialog.run() == Gtk.ResponseType.ACCEPT: filename = dialog.get_filename() dialog.destroy() if filename: self.clips_location_setting.set_value(os.path.dirname(filename)) log.debug("Start to check the class in %s" % filename) if filename.endswith('.tar.gz'): tar_file = TarFile(filename) if tar_file.is_valid(): tar_file.extract(TEMP_ROOT) #TODO if multi-root if tar_file.get_root_name(): temp_dir = os.path.join(TEMP_ROOT, tar_file.get_root_name()) if ModuleLoader.is_target_class(temp_dir, klass): target = os.path.join( ModuleLoader.get_user_extension_dir(feature), os.path.basename(temp_dir)) copy = True if os.path.exists(target): dialog = QuestionDialog(message=_( "Would you like to remove it then install again?"), title=_( '"%s" has already installed' % os.path.basename(target))) response = dialog.run() dialog.destroy() if response == Gtk.ResponseType.YES: shutil.rmtree(target) else: copy = False if copy: log.debug("Now copying tree...") shutil.move(temp_dir, target) else: shutil.rmtree(temp_dir) else: not_extension = True else: if ModuleLoader.is_target_class(filename, klass): shutil.copy(filename, ModuleLoader.get_user_extension_dir(feature)) install_done = True else: not_extension = True if install_done: update_func(feature) # To force empty the clips_setting to make load_cips value = setting.get_value() setting.set_value(['']) setting.set_value(value) if not_extension: ErrorDialog(message=error_message % os.path.basename(filename)).launch()
def update_model(self, a=None, b=None, expand=False): self.janitor_model.clear() self.result_model.clear() size_list = [] loader = ModuleLoader('janitor') plugin_to_load = self.plugins_setting.get_value() system_text = _('System') iter = self.janitor_model.append( None, (None, icon.get_from_name('distributor-logo'), system_text, "<b><big>%s</big></b>" % system_text, None, None, None)) for plugin in loader.get_modules_by_category('system'): if plugin.is_user_extension() and plugin.get_name( ) not in plugin_to_load: log.debug("User extension: %s not in setting to load" % plugin.get_name()) continue size_list.append( Gtk.Label( label=plugin.get_title()).get_layout().get_pixel_size()[0]) self.janitor_model.append( iter, (False, None, plugin.get_title(), plugin.get_title(), plugin(), None, None)) personal_text = _('Personal') iter = self.janitor_model.append( None, (None, icon.get_from_name('system-users'), personal_text, "<b><big>%s</big></b>" % personal_text, None, None, None)) for plugin in loader.get_modules_by_category('personal'): if plugin.is_user_extension() and plugin.get_name( ) not in plugin_to_load: log.debug("User extension: %s not in setting to load" % plugin.get_name()) continue size_list.append( Gtk.Label( label=plugin.get_title()).get_layout().get_pixel_size()[0]) self.janitor_model.append( iter, (False, None, plugin.get_title(), plugin.get_title(), plugin(), None, None)) app_text = _('Apps') iter = self.janitor_model.append( None, (None, icon.get_from_name('gnome-app-install'), app_text, "<b><big>%s</big></b>" % app_text, None, None, None)) for plugin in loader.get_modules_by_category('application'): if plugin.is_user_extension() and plugin.get_name( ) not in plugin_to_load: log.debug("User extension: %s not in setting to load" % plugin.get_name()) continue size_list.append( Gtk.Label( label=plugin.get_title()).get_layout().get_pixel_size()[0]) self.janitor_model.append( iter, (False, None, plugin.get_title(), plugin.get_title(), plugin(), None, None)) if size_list: self.max_janitor_view_width = max(size_list) + 80 if expand: self._expand_janitor_view()