def format_value(value, format='short'): """ Formats a length value :param value: the length in seconds :type value: float :param format: verbosity of the output, possible values are: * short: "1:02:42" * long: "1h, 2m, 42s" * verbose: "1 hour, 2 minutes, 42 seconds" :type format: string :returns: the formatted value :rtype: string """ span = TimeSpan(value) text = '' if format == 'verbose': if span.days > 0: text += ngettext('%d day, ', '%d days, ', span.days) % span.days if span.hours > 0: text += ngettext('%d hour, ', '%d hours, ', span.hours) % span.hours text += ngettext('%d minute, ', '%d minutes, ', span.minutes) % span.minutes text += ngettext('%d second', '%d seconds', span.seconds) % span.seconds elif format == 'long': if span.days > 0: # TRANSLATORS: Short form of an amount of days text += _('%dd, ') % span.days if span.hours > 0: # TRANSLATORS: Short form of an amount of hours text += _('%dh, ') % span.hours # TRANSLATORS: Short form of an amount of minutes text += _('%dm, ') % span.minutes # TRANSLATORS: Short form of an amount of seconds text += _('%ds') % span.seconds elif format == 'short': if span.days > 0: # TRANSLATORS: Short form of an amount of days text += _('%dd ') % span.days if span.hours > 0 or text: # always show hours when > 1 day # TRANSLATORS: Time duration (hours:minutes:seconds) text += _('%d:%02d:%02d') % (span.hours, span.minutes, span.seconds) else: # TRANSLATORS: Time duration (minutes:seconds) text += _('%d:%02d') % (span.minutes, span.seconds) else: raise ValueError( 'Invalid argument "%s" passed to parameter ' '"format" for tag "__length", possible arguments are ' '"short", "long" and "verbose"' % format ) return text
def on_replace_clicked(self, widget): tracks = [row[2] for row in self.tracks_list.get_model() if row[1]] replace_str = self.replace_entry.get_text().strip() if replace_str: query = ngettext( "Replace '{old_tag}' with '{new_tag}' on {amount} track?", "Replace '{old_tag}' with '{new_tag}' on {amount} tracks?", len(tracks), ).format( old_tag=self.search_str, new_tag=replace_str, amount=len(tracks), ) else: query = ngettext( "Delete '{tag}' from {amount} track?", "Delete '{tag}' from {amount} tracks?", len(tracks), ).format(tag=self.search_str, amount=len(tracks)) if dialogs.yesno(self, query) != Gtk.ResponseType.YES: return for track in tracks: groups = gt_common._get_track_groups(track, self.tagname) if self.search_str != '': groups.discard(self.search_str) if replace_str != '': groups.add(replace_str) if not gt_common.set_track_groups(track, groups): return dialogs.info(self, "Tags successfully renamed!") self.reset()
def on_find_clicked(self, widget): self.search_str = self.search_entry.get_text().strip() self.tagname = gt_common.get_tagname() # freeze update model = self.tracks_list.get_model() self.tracks_list.freeze_child_notify() self.tracks_list.set_model(None) model.clear() idx = self.playlists.get_active() if idx != -1 and self.search_str != '': smart, name = self.playlists.get_model()[idx] if smart: pl = self.exaile.smart_playlists.get_playlist(name) else: pl = self.exaile.playlists.get_playlist(name) if hasattr(pl, 'get_playlist'): pl = pl.get_playlist(self.exaile.collection) for track in pl: groups = gt_common._get_track_groups(track, self.tagname) if self.search_str != '' and self.search_str not in groups: continue name = ' - '.join([ track.get_tag_display('artist'), track.get_tag_display('album'), track.get_tag_display('title'), ]) model.append((True, name, track)) # unfreeze, draw it up self.tracks_list.set_model(model) self.tracks_list.thaw_child_notify() self.found_label.set_text( ngettext('{amount} track found', '{amount} tracks found', len(model)).format(amount=len(model))) self.replace.set_sensitive(len(model) != 0)
def _load_plugin_list(self): """ Loads the plugin list """ plugins = self.plugins.list_installed_plugins() uncategorized = _('Uncategorized') plugins_dict = {uncategorized: []} failed_list = [] self.plugin_to_path = {} for plugin_name in plugins: try: info = self.plugins.get_plugin_info(plugin_name) compatible = self.plugins.is_compatible(info) broken = self.plugins.is_potentially_broken(info) except Exception: failed_list += [plugin_name] continue # determine icon to show if broken: icon = 'dialog-error' elif not compatible: icon = 'dialog-warning' else: icon = None enabled = plugin_name in self.plugins.enabled_plugins plugin_data = (plugin_name, info['Name'], str(info['Version']), enabled, icon, broken, compatible, True) if 'Category' in info: cat = plugins_dict.setdefault(info['Category'], []) cat.append(plugin_data) else: plugins_dict[uncategorized].append(plugin_data) self.list.set_model(None) self.model.clear() def categorykey(item): if item[0] == uncategorized: return '\xff' * 10 return xl.unicode.strxfrm(item[0]) plugins_dict = sorted(plugins_dict.iteritems(), key=categorykey) for category, plugins_list in plugins_dict: plugins_list.sort(key=lambda x: xl.unicode.strxfrm(x[1])) it = self.model.append( None, (None, category, '', False, '', False, True, False)) for plugin_data in plugins_list: pit = self.model.append(it, plugin_data) path = self.model.get_string_from_iter(pit) self.plugin_to_path[plugin_data[0]] = path self.list.set_model(self.filter_model) # TODO: Keep track of which categories are already expanded, and only expand those self.list.expand_all() if failed_list: self.message.show_error( _('Could not load plugin info!'), ngettext('Failed plugin: %s', 'Failed plugins: %s', len(failed_list)) % ', '.join(failed_list))
def _load_plugin_list(self): """ Loads the plugin list """ plugins = self.plugins.list_installed_plugins() uncategorized = _('Uncategorized') plugins_dict = {uncategorized: []} failed_list = [] for plugin in plugins: try: info = self.plugins.get_plugin_info(plugin) compatible = self.plugins.is_compatible(info) broken = self.plugins.is_potentially_broken(info) except Exception: failed_list += [plugin] continue # determine icon to show if broken or not compatible: icon = Gtk.STOCK_DIALOG_WARNING else: icon = Gtk.STOCK_APPLY enabled = plugin in self.plugins.enabled_plugins plugin_data = (plugin, info['Name'], str(info['Version']), enabled, icon, broken, compatible, True) if 'Category' in info: if info['Category'] in plugins_dict: plugins_dict[info['Category']].append(plugin_data) else: plugins_dict[info['Category']] = [plugin_data] else: plugins_dict[uncategorized].append(plugin_data) self.list.set_model(None) self.model.clear() def categorykey(item): if item[0] == uncategorized: return '\xff' * 10 return xl.common.strxfrm(item[0]) plugins_dict = sorted(plugins_dict.iteritems(), key=categorykey) for category, plugins_list in plugins_dict: plugins_list.sort(key=lambda x: xl.common.strxfrm(x[1])) it = self.model.append( None, (None, category, '', False, '', False, True, False)) for plugin in plugins_list: self.model.append(it, plugin) self.list.set_model(self.filter_model) # TODO: Keep track of which categories are already expanded, and only expand those self.list.expand_all() if failed_list: self.message.show_error( _('Could not load plugin info!'), ngettext('Failed plugin: %s', 'Failed plugins: %s', len(failed_list)) % ', '.join(failed_list))
def _load_plugin_list(self): """ Loads the plugin list """ plugins = self.plugins.list_installed_plugins() uncategorized = _('Uncategorized') plugins_dict = { uncategorized: [] } failed_list = [] for plugin in plugins: try: info = self.plugins.get_plugin_info(plugin) compatible = self.plugins.is_compatible(info) broken = self.plugins.is_potentially_broken(info) except Exception: failed_list += [plugin] continue # determine icon to show if broken or not compatible: icon = Gtk.STOCK_DIALOG_WARNING else: icon = Gtk.STOCK_APPLY enabled = plugin in self.plugins.enabled_plugins plugin_data = (plugin, info['Name'], str(info['Version']), enabled, icon, broken, compatible, True) if 'Category' in info: if info['Category'] in plugins_dict: plugins_dict[info['Category']].append(plugin_data) else: plugins_dict[info['Category']] = [plugin_data] else: plugins_dict[uncategorized].append(plugin_data) self.list.set_model(None) self.model.clear() def categorykey(item): if item[0] == uncategorized: return '\xff' * 10 return xl.common.strxfrm(item[0]) plugins_dict = sorted(plugins_dict.iteritems(), key=categorykey) for category, plugins_list in plugins_dict: plugins_list.sort(key=lambda x: xl.common.strxfrm(x[1])) it = self.model.append(None, (None, category, '', False, '', False, True, False)) for plugin in plugins_list: self.model.append(it, plugin) self.list.set_model(self.filter_model) # TODO: Keep track of which categories are already expanded, and only expand those self.list.expand_all() if failed_list: self.message.show_error(_('Could not load plugin info!'), ngettext( 'Failed plugin: %s', 'Failed plugins: %s', len(failed_list) ) % ', '.join(failed_list) )
class PluginManager(object): """ Gui to manage plugins """ def __init__(self, preferences, builder): """ Initializes the manager """ self.preferences = preferences builder.connect_signals(self) self.plugins = main.exaile().plugins self.message = dialogs.MessageBar( parent=builder.get_object('preferences_pane'), buttons=gtk.BUTTONS_CLOSE) self.message.connect('response', self.on_messagebar_response) self.list = builder.get_object('plugin_tree') self.enabled_cellrenderer = builder.get_object('enabled_cellrenderer') if main.exaile().options.Debug: reload_cellrenderer = common.ClickableCellRendererPixbuf() reload_cellrenderer.props.stock_id = gtk.STOCK_REFRESH reload_cellrenderer.props.xalign = 1 reload_cellrenderer.connect('clicked', self.on_reload_cellrenderer_clicked) name_column = builder.get_object('name_column') name_column.pack_start(reload_cellrenderer) name_column.add_attribute(reload_cellrenderer, 'visible', 3) self.version_label = builder.get_object('version_label') self.author_label = builder.get_object('author_label') self.name_label = builder.get_object('name_label') self.description = builder.get_object('description_view') self.model = builder.get_object('model') self.filter_model = self.model.filter_new() self.show_incompatible_cb = builder.get_object('show_incompatible_cb') self.show_broken_cb = builder.get_object('show_broken_cb') self.filter_model.set_visible_func(self._model_visible_func) self.status_column = builder.get_object('status_column') self._set_status_visible() selection = self.list.get_selection() selection.connect('changed', self.on_selection_changed) self._load_plugin_list() glib.idle_add(selection.select_path, (0, )) glib.idle_add(self.list.grab_focus) def _load_plugin_list(self): """ Loads the plugin list """ plugins = self.plugins.list_installed_plugins() uncategorized = _('Uncategorized') plugins_dict = {uncategorized: []} failed_list = [] for plugin in plugins: try: info = self.plugins.get_plugin_info(plugin) compatible = self.plugins.is_compatible(info) broken = self.plugins.is_potentially_broken(info) except Exception, e: failed_list += [plugin] continue # determine icon to show if broken or not compatible: icon = gtk.STOCK_DIALOG_WARNING else: icon = gtk.STOCK_APPLY enabled = plugin in self.plugins.enabled_plugins plugin_data = (plugin, info['Name'], info['Version'], enabled, icon, broken, compatible, True) if 'Category' in info: if info['Category'] in plugins_dict: plugins_dict[info['Category']].append(plugin_data) else: plugins_dict[info['Category']] = [plugin_data] else: plugins_dict[uncategorized].append(plugin_data) self.list.set_model(None) self.model.clear() plugins_dict = sorted( plugins_dict.iteritems(), key=lambda x: 'zzzz' if x[0] == uncategorized else locale.strxfrm(x[0])) for category, plugins_list in plugins_dict: plugins_list.sort(key=lambda x: locale.strxfrm(x[1])) it = self.model.append( None, (None, category, '', False, '', False, True, False)) for plugin in plugins_list: self.model.append(it, plugin) self.list.set_model(self.filter_model) # TODO: Keep track of which categories are already expanded, and only expand those self.list.expand_all() if failed_list: self.message.show_error( _('Could not load plugin info!'), ngettext('Failed plugin: %s', 'Failed plugins: %s', len(failed_list)) % ', '.join(failed_list))
def _load_plugin_list(self): """ Loads the plugin list """ plugins = self.plugins.list_installed_plugins() uncategorized = _('Uncategorized') plugins_dict = {uncategorized: []} failed_list = [] self.plugin_to_path = {} for plugin_name in plugins: try: info = self.plugins.get_plugin_info(plugin_name) compatible = self.plugins.is_compatible(info) broken = self.plugins.is_potentially_broken(info) except Exception: failed_list += [plugin_name] continue # determine icon to show if not compatible: icon = 'dialog-error' elif broken: icon = 'dialog-warning' else: icon = None enabled = plugin_name in self.plugins.enabled_plugins plugin_data = ( plugin_name, info['Name'], str(info['Version']), enabled, icon, broken, compatible, True, ) if 'Category' in info: cat = plugins_dict.setdefault(info['Category'], []) cat.append(plugin_data) else: plugins_dict[uncategorized].append(plugin_data) self.list.set_model(None) self.model.clear() def categorykey(item): if item[0] == uncategorized: return '\xff' * 10 return xl.unicode.strxfrm(item[0]) plugins_dict = sorted(plugins_dict.iteritems(), key=categorykey) for category, plugins_list in plugins_dict: plugins_list.sort(key=lambda x: xl.unicode.strxfrm(x[1])) it = self.model.append( None, (None, category, '', False, '', False, True, False) ) for plugin_data in plugins_list: pit = self.model.append(it, plugin_data) path = self.model.get_string_from_iter(pit) self.plugin_to_path[plugin_data[0]] = path self.list.set_model(self.filter_model) # TODO: Keep track of which categories are already expanded, and only expand those self.list.expand_all() if failed_list: self.message.show_error( _('Could not load plugin info!'), ngettext('Failed plugin: %s', 'Failed plugins: %s', len(failed_list)) % ', '.join(failed_list), )