def loadSettings(self, filename=None, actions=None): self._names = [] self._hotkeys = [] if filename is None: filename = os.path.join(ACTIONDIR, 'action_shortcuts') self._listbox.clear() cparser = PuddleConfig(filename) if actions is None: self._actions = load_actions() else: self._actions = actions from puddlestuff.puddletag import status if status['actions']: shortcuts = dict( (unicode(a.text()), unicode(a.shortcut().toString())) for a in status['actions']) else: shortcuts = {} for section in sorted(cparser.sections()): if section.startswith('Shortcut'): name = cparser.get(section, NAME, 'Default') self._names.append(name) filenames = cparser.get(section, FILENAMES, []) shortcut = shortcuts.get(name, u'') self.addShortcut(name, filenames, shortcut, select=False) self._hotkeys.append(shortcut)
def savePlayList(self): tags = status['selectedfiles'] if not tags: tags = status['alltags'] settings = PuddleConfig() try: dirname = self._lastdir[0] except IndexError: dirname = constants.HOMEDIR filepattern = settings.get('playlist', 'filepattern', 'puddletag.m3u') default = encode_fn(findfunc.tagtofilename(filepattern, tags[0])) f = unicode( QFileDialog.getSaveFileName( self, translate("Playlist", 'Save Playlist...'), os.path.join(dirname, default))) if f: if settings.get('playlist', 'extinfo', 1, True): pattern = settings.get('playlist', 'extpattern', '%artist% - %title%') else: pattern = None reldir = settings.get('playlist', 'reldir', 0, True) windows_separator = settings.get('playlist', 'windows_separator', 0, False) m3u.exportm3u(tags, f, pattern, reldir, windows_separator)
def loadSettings(self, filename=None, actions=None): self._names = [] self._hotkeys = [] if filename is None: filename = os.path.join(ACTIONDIR, 'action_shortcuts') self._listbox.clear() cparser = PuddleConfig(filename) if actions is None: self._actions = load_actions() else: self._actions = actions from puddlestuff.puddletag import status if status['actions']: shortcuts = dict((unicode(a.text()), unicode(a.shortcut().toString())) for a in status['actions']) else: shortcuts = {} for section in sorted(cparser.sections()): if section.startswith('Shortcut'): name = cparser.get(section, NAME, 'Default') self._names.append(name) filenames = cparser.get(section, FILENAMES, []) shortcut = shortcuts.get(name, u'') self.addShortcut(name, filenames, shortcut, select=False) self._hotkeys.append(shortcut)
def load_patterns(filepath=None): settings = PuddleConfig(filepath) return [settings.get('editor', 'patterns', ['%artist% - $num(%track%,2) - %title%', '%artist% - %album% - $num(%track%,2) - %title%', '%artist% - %title%', '%artist% - %album%', '%artist% - Track %track%', '%artist% - %title%']), settings.get('editor', 'index', 0, True)]
def __init__(self, parent=None): QWidget.__init__(self, parent) cparser = PuddleConfig() get_color = lambda key, default: QColor.fromRgb(*cparser.get( 'extendedtags', key, default, True)) add = get_color('add', [0, 255, 0]) edit = get_color('edit', [255, 255, 0]) remove = get_color('remove', [255, 0, 0]) get_color = lambda key, default: QColor.fromRgb(*cparser.get( 'table', key, default, True)) preview = get_color('preview_color', [192, 255, 192]) selection_default = QPalette().color(QPalette.Mid).getRgb()[:-1] selection = get_color('selected_color', selection_default) colors = (add, edit, remove, preview, selection) text = translate( "Colour Settings", '<p>Below are the backgrounds used for various controls in puddletag. <br /> Double click the desired action to change its colour.</p>' ) label = QLabel(text) self.listbox = QTableWidget(0, 1, self) self.listbox.setEditTriggers(QAbstractItemView.NoEditTriggers) header = self.listbox.horizontalHeader() self.listbox.setSortingEnabled(False) header.setVisible(True) header.setStretchLastSection(True) self.listbox.setHorizontalHeaderLabels(['Action']) self.listbox.setRowCount(len(colors)) titles = [ (translate("Colour Settings", 'Row selected in file-view.'), selection), (translate("Colour Settings", 'Row colour for files with previews.'), preview), (translate("Colour Settings", 'Field added in Extended Tags.'), add), (translate("Colour Settings", 'Field edited in Extended Tags.'), edit), (translate("Colour Settings", 'Field removed in Extended Tags.'), remove), ] for i, z in enumerate(titles): self.listbox.setItem(i, 0, StatusWidgetItem(*z)) vbox = QVBoxLayout() vbox.addWidget(label) vbox.addWidget(self.listbox) self.setLayout(vbox) self.connect(self.listbox, SIGNAL('cellDoubleClicked(int,int)'), self.edit)
def _load(filename): cparser = PuddleConfig(filename) confirmations = {} for section in cparser.sections(): if section.startswith(SECTION): name = cparser.get(section, NAME, u'') desc = cparser.get(section, DESC, u'') value = cparser.get(section, VALUE, True) confirmations[name] = [value, desc] return confirmations
def convert_mtp(filename): cparser = PuddleConfig(filename) info_section = 'info' name = cparser.get(info_section, NAME, u'') numsources = cparser.get(info_section, 'numsources', 0) album_bound = cparser.get(info_section, ALBUM_BOUND, 70) / 100.0 track_bound = cparser.get(info_section, TRACK_BOUND, 80) / 100.0 match_fields = cparser.get(info_section, FIELDS, ['artist', 'title']) pattern = cparser.get(info_section, PATTERN, u'%artist% - %album%/%track% - %title%') jfdi = cparser.get(info_section, JFDI, True) desc = cparser.get(info_section, DESC, u'') existing = cparser.get(info_section, EXISTING_ONLY, False) ts_profiles = [] for num in range(numsources): section = 'config%s' % num get = lambda key, default: cparser.get(section, key, default) source = DummyTS() source.name = get('source', u'') fields = fields_from_text(get('fields', u'')) no_result = get('no_match', 0) ts_profiles.append(TagSourceProfile(None, source, fields, no_result)) return MassTagProfile(name, desc, match_fields, None, pattern, ts_profiles, album_bound, track_bound, jfdi, existing, u'')
def load_patterns(filepath=None): settings = PuddleConfig(filepath) return [ settings.get('editor', 'patterns', [ '%artist% - $num(%track%,2) - %title%', '%artist% - %album% - $num(%track%,2) - %title%', '%artist% - %title%', '%artist% - %album%', '%artist% - Track %track%', '%artist% - %title%' ]), settings.get('editor', 'index', 0, True) ]
def connect_action_shortcuts(actions): cparser = PuddleConfig() cparser.filename = ls.menu_path for action in actions: shortcut = cparser.get('shortcuts', unicode(action.text()), '') if shortcut: action.setShortcut(shortcut)
def loadSettings(self): settings = QSettings(QT_CONFIG, QSettings.IniFormat) header = self.header() header.restoreState(settings.value('dirview/header').toByteArray()) hide = settings.value('dirview/hide', QVariant(True)).toBool() self.setHeaderHidden(hide) if self.isVisible() == False: return cparser = PuddleConfig() d = cparser.get('main', 'lastfolder', '/') while not os.path.exists(d): d = os.path.dirname(d) if not d: return def expand_thread_func(): index = self.model().index(d) parents = [] while index.isValid(): parents.append(index) index = index.parent() return parents def expandindexes(indexes): self.setEnabled(False) [self.expand(index) for index in indexes] self.setEnabled(True) thread = PuddleThread(expand_thread_func, self) thread.connect(thread, SIGNAL('threadfinished'), expandindexes) thread.start()
def _loadSettings(self, actions): cparser = PuddleConfig(os.path.join(CONFIGDIR, 'user_shortcuts')) for action in actions: shortcut = cparser.get('shortcuts', unicode(action.text()), '') if shortcut: action.setShortcut(QKeySequence(shortcut))
def __init__(self, parent = None): QWidget.__init__(self, parent) cparser = PuddleConfig() get_color = lambda key, default: QColor.fromRgb( *cparser.get('extendedtags', key, default, True)) add = get_color('add', [0,255,0]) edit = get_color('edit', [255,255,0]) remove = get_color('remove', [255,0,0]) get_color = lambda key, default: QColor.fromRgb( *cparser.get('table', key, default, True)) preview = get_color('preview_color', [192, 255, 192]) selection_default = QPalette().color(QPalette.Mid).getRgb()[:-1] selection = get_color('selected_color', selection_default) colors = (add, edit, remove, preview, selection) text = translate("Colour Settings", '<p>Below are the backgrounds used for various controls in puddletag. <br /> Double click the desired action to change its colour.</p>') label = QLabel(text) self.listbox = QTableWidget(0, 1, self) self.listbox.setEditTriggers(QAbstractItemView.NoEditTriggers) header = self.listbox.horizontalHeader() self.listbox.setSortingEnabled(False) header.setVisible(True) header.setStretchLastSection (True) self.listbox.setHorizontalHeaderLabels(['Action']) self.listbox.setRowCount(len(colors)) titles = [ (translate("Colour Settings", 'Row selected in file-view.'), selection), (translate("Colour Settings", 'Row colour for files with previews.'), preview), (translate("Colour Settings", 'Field added in Extended Tags.'), add), (translate("Colour Settings", 'Field edited in Extended Tags.'), edit), (translate("Colour Settings", 'Field removed in Extended Tags.'), remove),] for i, z in enumerate(titles): self.listbox.setItem(i, 0, StatusWidgetItem(*z)) vbox = QVBoxLayout() vbox.addWidget(label) vbox.addWidget(self.listbox) self.setLayout(vbox) self.connect(self.listbox, SIGNAL('cellDoubleClicked(int,int)'), self.edit)
def load_gen_settings(setlist, extras=False): settings = PuddleConfig() settings.filename = os.path.join(settings.savedir, 'gensettings') ret = [] for setting in setlist: desc = setting[0] default = setting[1] ret.append([desc, settings.get(desc, 'value', default)]) return ret
def load_settings(filename=None, actions=None): if filename is None: filename = FILENAME if not os.path.exists(os.path.dirname(filename)): os.makedirs(os.path.dirname(filename)) cparser = PuddleConfig(filename) actions = load_actions() if actions is None else actions shortcuts = [] for section in sorted(cparser.sections()): if section.startswith(SHORTCUT_SECTION): name = cparser.get(section, NAME, 'Default') filenames = cparser.get(section, FILENAMES, []) shortcuts.append([name, filenames]) return actions, shortcuts
def editSortOptions(self): cparser = PuddleConfig() options = cparser.get('table', 'sortoptions', ['__filename,track,__dirpath','track, album', '__filename,album,__dirpath']) from puddlestuff.webdb import SortOptionEditor win = SortOptionEditor(options, self) self.connect(win, SIGNAL('options'), self.applySortOptions) win.show()
def create_tool_windows(parent, extra=None): """Creates the dock widgets for the main window (parent) using the modules stored in puddlestuff/mainwin. Returns (the toggleViewActions of the docks, the dockWidgets the mselves).""" actions = [] docks = [] cparser = PuddleConfig() cparser.filename = ls.menu_path widgets = ( mainwin.tagpanel, mainwin.artwork, mainwin.dirview, mainwin.patterncombo, mainwin.filterwin, puddlestuff.webdb, mainwin.storedtags, mainwin.logdialog, puddlestuff.masstag.dialogs, ) controls = [z.control for z in widgets] controls.extend(mainwin.action_dialogs.controls) if extra: controls.extend(extra) for z in controls: name = z[0] try: if not z[2]: PuddleDock._controls[name] = z[1](status=status) continue except IndexError: pass p = PuddleDock(z[0], z[1], parent, status) parent.addDockWidget(z[2], p) try: if z[4]: p.setFloating(True) p.move(parent.rect().center()) except IndexError: pass p.setVisible(z[3]) docks.append(p) action = p.toggleViewAction() action.setText(name) scut = cparser.get("winshortcuts", name, "") if scut: action.setShortcut(scut) actions.append(action) return actions, docks
def load_plugins(plugins=None, parent=None): [sys.path.insert(0, d) for d in PLUGIN_DIRS] cparser = PuddleConfig() to_load = cparser.get('plugins', 'to_load', []) functions = {} tagsources = [] dialogs = [] musiclibs = [] modules = [] functions_no_preview = [] join = os.path.join if plugins is None: plugins = [] [plugins.extend(get_plugins(d)) for d in PLUGIN_DIRS] plugins.sort(key=lambda d: d.get(NAME, u'')) for plugin in plugins: if plugin[MODULE_NAME] not in to_load: continue try: module = __import__(plugin[MODULE_NAME]) except: logging.exception(u'Failed to load plugin: ' + plugin['name']) continue if hasattr(module, 'functions'): functions.update(module.functions) if hasattr(module, 'functions_no_preview'): functions_no_preview.extend(module.functions_no_preview) if hasattr(module, 'tagsources'): tagsources.extend(module.tagsources) if hasattr(module, 'dialogs'): dialogs.extend(module.dialogs) if hasattr(module, 'musiclibs'): musiclibs.extend(module.musiclibs) modules.append(module) for d in PLUGIN_DIRS: del (sys.path[0]) return { FUNCTIONS: functions, TAGSOURCE: tagsources, DIALOGS: dialogs, MUSICLIBS: musiclibs, MODULES: modules, FUNCTIONS_NO_PREVIEW: functions_no_preview }
def clipboard_to_tag(parent=None): win = helperwin.ImportTextFile(parent, clipboard = True) win.setModal(True) win.patterncombo.addItems(status['patterns']) cparser = PuddleConfig() last_dir = cparser.get('importwindow', 'lastdir', HOMEDIR) win.lastDir = last_dir last_pattern = cparser.get('importwindow', 'lastpattern', u'') if last_pattern: win.patterncombo.setEditText(last_pattern) def fin_edit(taglist, pattern): cparser.set('importwindow', 'lastdir', win.lastDir) cparser.set('importwindow', 'lastpattern', pattern) emit('writeselected', taglist) win.connect(win, SIGNAL("Newtags"), fin_edit) win.show()
def clipboard_to_tag(parent=None): win = helperwin.ImportTextFile(parent, clipboard=True) win.setModal(True) win.patterncombo.addItems(status['patterns']) cparser = PuddleConfig() last_dir = cparser.get('importwindow', 'lastdir', HOMEDIR) win.lastDir = last_dir last_pattern = cparser.get('importwindow', 'lastpattern', u'') if last_pattern: win.patterncombo.setEditText(last_pattern) def fin_edit(taglist, pattern): cparser.set('importwindow', 'lastdir', win.lastDir) cparser.set('importwindow', 'lastpattern', pattern) emit('writeselected', taglist) win.connect(win, SIGNAL("Newtags"), fin_edit) win.show()
def editSortOptions(self): cparser = PuddleConfig() options = cparser.get('table', 'sortoptions', [ '__filename,track,__dirpath', 'track, album', '__filename,album,__dirpath' ]) from puddlestuff.webdb import SortOptionEditor win = SortOptionEditor(options, self) self.connect(win, SIGNAL('options'), self.applySortOptions) win.show()
def loadsets(): algos = [] if not os.path.exists(DUPEDIR): os.makedirs(DUPEDIR) saveset(**DEFAULTSET) files = [os.path.join(DUPEDIR, z) for z in os.listdir(DUPEDIR)] sets = [] cparser = PuddleConfig() for f in files: cparser.filename = f name = cparser.get('info', 'name', '') disp = cparser.get('info', 'disp', []) algos = [] for section in cparser.sections(): if section == 'info': continue tags = cparser.get(section, 'tags', []) threshold = float(cparser.get(section, 'threshold', '0.85')) func = cparser.get(section, 'func', '') matchcase = cparser.get(section, 'matchcase', True) maintag = cparser.get(section, 'maintag', 'artist') algos.append(Algo(tags, threshold, func, matchcase)) sets.append([name, disp, algos, maintag]) return sets
def savePlayList(self): tags = status['selectedfiles'] if not tags: tags = status['alltags'] settings = PuddleConfig() try: dirname = self._lastdir[0] except IndexError: dirname = constants.HOMEDIR filepattern = settings.get('playlist', 'filepattern','puddletag.m3u') default = encode_fn(findfunc.tagtofilename(filepattern, tags[0])) f = unicode(QFileDialog.getSaveFileName(self, translate("Playlist", 'Save Playlist...'), os.path.join(dirname, default))) if f: if settings.get('playlist', 'extinfo', 1, True): pattern = settings.get('playlist', 'extpattern','%artist% - %title%') else: pattern = None reldir = settings.get('playlist', 'reldir', 0, True) windows_separator = settings.get('playlist', 'windows_separator', 0, False) m3u.exportm3u(tags, f, pattern, reldir, windows_separator)
def load_plugins(plugins=None, parent=None): [sys.path.insert(0, d) for d in PLUGIN_DIRS] cparser = PuddleConfig() to_load = cparser.get('plugins', 'to_load', []) functions = {} tagsources = [] dialogs = [] musiclibs = [] modules = [] functions_no_preview = [] join = os.path.join if plugins is None: plugins = [] [plugins.extend(get_plugins(d)) for d in PLUGIN_DIRS] plugins.sort(key=lambda d: d.get(NAME, u'')) for plugin in plugins: if plugin[MODULE_NAME] not in to_load: continue try: module = __import__(plugin[MODULE_NAME]) except: print u'Failed to load plugin: ', plugin['name'] traceback.print_exc() continue if hasattr(module, 'functions'): functions.update(module.functions) if hasattr(module, 'functions_no_preview'): functions_no_preview.extend(module.functions_no_preview) if hasattr(module, 'tagsources'): tagsources.extend(module.tagsources) if hasattr(module, 'dialogs'): dialogs.extend(module.dialogs) if hasattr(module, 'musiclibs'): musiclibs.extend(module.musiclibs) modules.append(module) for d in PLUGIN_DIRS: del(sys.path[0]) return {FUNCTIONS: functions, TAGSOURCE: tagsources, DIALOGS: dialogs, MUSICLIBS: musiclibs, MODULES: modules, FUNCTIONS_NO_PREVIEW: functions_no_preview}
def text_file_to_tag(parent=None): dirpath = status['selectedfiles'][0].dirpath win = helperwin.ImportTextFile(parent) cparser = PuddleConfig() last_dir = cparser.get('importwindow', 'lastdir', HOMEDIR) if win.openFile(dirpath=last_dir): win.close() return win.setModal(True) win.patterncombo.addItems(status['patterns']) last_pattern = cparser.get('importwindow', 'lastpattern', u'') if last_pattern: win.patterncombo.setEditText(last_pattern) def fin_edit(taglist, pattern): cparser.set('importwindow', 'lastdir', win.lastDir) cparser.set('importwindow', 'lastpattern', pattern) emit('writeselected', taglist) win.connect(win, SIGNAL("Newtags"), fin_edit) win.show()
def updateOrder(self): self.listbox.clear() self.macros = self.loadMacros() cparser = PuddleConfig() to_check = cparser.get('actions', 'checked', []) for i, m in sorted(self.macros.items()): func_name = m.name item = QListWidgetItem(func_name) item.setFlags(item.flags() | Qt.ItemIsEditable) if func_name in to_check: item.setCheckState(Qt.Checked) else: item.setCheckState(Qt.Unchecked) self.listbox.addItem(item)
def loadsettings(filepath = None): settings = PuddleConfig() if filepath: settings.filename = filepath else: settings.filename = os.path.join(CONFIGDIR, 'tagpanel') numrows = settings.get('panel','numrows',-1, True) if numrows > -1: sections = settings.sections() d = {} for row in xrange(numrows): section = unicode(row) tags = settings.get(section, 'tags', ['']) titles = settings.get(section, 'titles', ['']) d[row] = zip(titles, tags) else: titles = ['&Artist', '&Title', 'Al&bum', 'T&rack', u'&Year', "&Genre", '&Comment'] tags = ['artist', 'title', 'album', 'track', u'year', 'genre', 'comment'] newtags = zip(titles, tags) d = {0:[newtags[0]], 1:[newtags[1]], 2: [newtags[2]], 3:[newtags[3], newtags[4], newtags[5]] , 4:[newtags[6]]} return d
def savePlayList(self): tags = status["selectedfiles"] if not tags: tags = status["alltags"] settings = PuddleConfig() try: dirname = self._lastdir[0] except IndexError: dirname = constants.HOMEDIR filepattern = settings.get("playlist", "filepattern", "puddletag.m3u") default = encode_fn(findfunc.tagtofilename(filepattern, tags[0])) f = unicode( QFileDialog.getSaveFileName(self, translate("Playlist", "Save Playlist..."), os.path.join(dirname, default)) ) if f: if settings.get("playlist", "extinfo", 1, True): pattern = settings.get("playlist", "extpattern", "%artist% - %title%") else: pattern = None reldir = settings.get("playlist", "reldir", 0, True) windows_separator = settings.get("playlist", "windows_separator", 0, False) m3u.exportm3u(tags, f, pattern, reldir, windows_separator)
def mtp_from_file(filename=CONFIG, tag_sources=None): if tag_sources is None: tag_sources = {} else: tag_sources = dict((z.name, z) for z in tag_sources) cparser = PuddleConfig(filename) info_section = 'info' name = cparser.get(info_section, NAME, '') numsources = cparser.get(info_section, 'numsources', 0) album_bound = cparser.get(info_section, ALBUM_BOUND, 70) / 100.0 track_bound = cparser.get(info_section, TRACK_BOUND, 80) / 100.0 match_fields = cparser.get(info_section, FIELDS, ['artist', 'title']) pattern = cparser.get(info_section, PATTERN, '%artist% - %album%/%track% - %title%') jfdi = cparser.get(info_section, JFDI, True) desc = cparser.get(info_section, DESC, u'') leave_existing = cparser.get(info_section, EXISTING_ONLY, False) regexps = u'' ts_profiles = [] for num in range(numsources): section = 'config%s' % num get = lambda key, default: cparser.get(section, key, default) source = tag_sources.get(get('source', u''), None) no_result = get('no_match', 0) fields = fields_from_text(get('fields', u'')) replace_fields = fields_from_text(get('replace_fields', u'')) ts_profiles.append(TagSourceProfile(None, source, fields, no_result, replace_fields)) mtp = MassTagProfile(name, desc, match_fields, None, pattern, ts_profiles, album_bound, track_bound, jfdi, leave_existing, regexps) return mtp
def mtp_from_file(filename=CONFIG, tag_sources=None): if tag_sources is None: tag_sources = {} else: tag_sources = dict((z.name, z) for z in tag_sources) cparser = PuddleConfig(filename) info_section = 'info' name = cparser.get(info_section, NAME, '') numsources = cparser.get(info_section, 'numsources', 0) album_bound = cparser.get(info_section, ALBUM_BOUND, 70) / 100.0 track_bound = cparser.get(info_section, TRACK_BOUND, 80) / 100.0 match_fields = cparser.get(info_section, FIELDS, ['artist', 'title']) pattern = cparser.get(info_section, PATTERN, '%artist% - %album%/%track% - %title%') jfdi = cparser.get(info_section, JFDI, True) desc = cparser.get(info_section, DESC, u'') leave_existing = cparser.get(info_section, EXISTING_ONLY, False) regexps = u'' ts_profiles = [] for num in range(numsources): section = 'config%s' % num get = lambda key, default: cparser.get(section, key, default) source = tag_sources.get(get('source', u''), None) no_result = get('no_match', 0) fields = fields_from_text(get('fields', u'')) replace_fields = fields_from_text(get('replace_fields', u'')) ts_profiles.append( TagSourceProfile(None, source, fields, no_result, replace_fields)) mtp = MassTagProfile(name, desc, match_fields, None, pattern, ts_profiles, album_bound, track_bound, jfdi, leave_existing, regexps) return mtp
def create_tool_windows(parent, extra=None): """Creates the dock widgets for the main window (parent) using the modules stored in puddlestuff/mainwin. Returns (the toggleViewActions of the docks, the dockWidgets the mselves).""" actions = [] docks = [] cparser = PuddleConfig() cparser.filename = ls.menu_path widgets = (mainwin.tagpanel, mainwin.artwork, mainwin.dirview, mainwin.patterncombo, mainwin.filterwin, puddlestuff.webdb, mainwin.storedtags, mainwin.logdialog, puddlestuff.masstag.dialogs) controls = [z.control for z in widgets] controls.extend(mainwin.action_dialogs.controls) if extra: controls.extend(extra) for z in controls: name = z[0] try: if not z[2]: PuddleDock._controls[name] = z[1](status=status) continue except IndexError: pass p = PuddleDock(z[0], z[1], parent, status) parent.addDockWidget(z[2], p) try: if z[4]: p.setFloating(True) p.move(parent.rect().center()) except IndexError: pass p.setVisible(z[3]) docks.append(p) action = p.toggleViewAction() action.setText(name) scut = cparser.get('winshortcuts', name, '') if scut: action.setShortcut(scut) actions.append(action) return actions, docks
def create_actions(parent): enable_preview = QAction('Enabl&e Preview Mode', parent) enable_preview.setShortcut('Ctrl+Shift+P') obj.connect(enable_preview, SIGNAL('triggered()'), toggle_preview_mode) clear_selection = PreviewAction('Clear Selected &Files', parent) clear_selection.setShortcut('Ctrl+Shift+F') obj.connect(clear_selection, SIGNAL('triggered()'), clear_selected) write = PreviewAction('&Write Previews', parent) write.setShortcut('Ctrl+W') obj.connect(write, SIGNAL('triggered()'), lambda: emit('writepreview')) revert = PreviewAction('&Undo Last Clear', parent) revert.setShortcut('Ctrl+Shift+Z') obj.connect(revert, SIGNAL('triggered()'), undo_last) sort = QAction('Sort &By', parent) obj.connect(sort, SIGNAL('triggered()'), sort_by_fields) clear_cells = PreviewAction('Clear Selected &Cells', parent) obj.connect(clear_cells, SIGNAL('triggered()'), clear_selected_cells) cparser = PuddleConfig() options = cparser.get('table', 'sortoptions', [ '__filename,track,__dirpath', 'track, album', '__filename,album,__dirpath' ]) global _sort_action _sort_action = sort sort_actions = set_sort_options(options) preview_actions = [clear_selection, write, revert, clear_cells] toggle = partial(toggle_preview_display, enable_preview, preview_actions) obj.receives.append(['previewModeChanged', toggle]) [connect_shortcut(z, FILESSELECTED) for z in preview_actions] return [enable_preview, clear_selection, write, revert, sort, clear_cells ] + sort_actions
def create_actions(parent): enable_preview = QAction('Enabl&e Preview Mode', parent) enable_preview.setShortcut('Ctrl+Shift+P') obj.connect(enable_preview, SIGNAL('triggered()'), toggle_preview_mode) clear_selection = PreviewAction('Clear Selected &Files', parent) clear_selection.setShortcut('Ctrl+Shift+F') obj.connect(clear_selection, SIGNAL('triggered()'), clear_selected) write = PreviewAction('&Write Previews', parent) write.setShortcut('Ctrl+W') obj.connect(write, SIGNAL('triggered()'), lambda: emit('writepreview')) revert = PreviewAction('&Undo Last Clear', parent) revert.setShortcut('Ctrl+Shift+Z') obj.connect(revert, SIGNAL('triggered()'), undo_last) sort = QAction('Sort &By', parent) obj.connect(sort, SIGNAL('triggered()'), sort_by_fields) clear_cells = PreviewAction('Clear Selected &Cells', parent) obj.connect(clear_cells, SIGNAL('triggered()'), clear_selected_cells) cparser = PuddleConfig() options = cparser.get('table', 'sortoptions', ['__filename,track,__dirpath','track, album', '__filename,album,__dirpath']) global _sort_action _sort_action = sort sort_actions = set_sort_options(options) preview_actions = [clear_selection, write, revert, clear_cells] toggle = partial(toggle_preview_display, enable_preview, preview_actions) obj.receives.append(['previewModeChanged', toggle]) [connect_shortcut(z, FILESSELECTED) for z in preview_actions] return [enable_preview, clear_selection, write, revert, sort, clear_cells] + sort_actions
def __init__(self, parent=None): super(PluginConfig, self).__init__(parent) winsettings('pluginconfig', self) self._listbox = QListWidget() info_display = InfoWidget() hbox = QHBoxLayout() hbox.addWidget(self._listbox, 0) hbox.addWidget(info_display, 1) vbox = QVBoxLayout() vbox.addLayout(hbox) vbox.addWidget( QLabel( translate( "Plugin Settings", '<b>Loading/unloading plugins requires a restart.</b>'))) self.setLayout(vbox) plugins = [] [plugins.extend(get_plugins(d)) for d in PLUGIN_DIRS] cparser = PuddleConfig() to_load = cparser.get('plugins', 'to_load', []) plugins.sort(key=lambda d: d.get(NAME, u'')) for plugin in plugins: item = QListWidgetItem() item.setText(plugin[NAME]) if plugin[MODULE_NAME] in to_load: item.setCheckState(Qt.Checked) else: item.setCheckState(Qt.Unchecked) item.plugin = plugin self._listbox.addItem(item) self.connect( self._listbox, SIGNAL('currentItemChanged(QListWidgetItem*, QListWidgetItem *)'), lambda item, previous: info_display.changeInfo(item.plugin))
def __init__(self, parent = None): super(PluginConfig, self).__init__(parent) winsettings('pluginconfig', self) self._listbox = QListWidget() info_display = InfoWidget() hbox = QHBoxLayout() hbox.addWidget(self._listbox, 0) hbox.addWidget(info_display, 1) vbox = QVBoxLayout() vbox.addLayout(hbox) vbox.addWidget( QLabel(translate("Plugin Settings", '<b>Loading/unloading plugins requires a restart.</b>'))) self.setLayout(vbox) plugins = [] [plugins.extend(get_plugins(d)) for d in PLUGIN_DIRS] cparser = PuddleConfig() to_load = cparser.get('plugins', 'to_load', []) plugins.sort(key=lambda d: d.get(NAME, u'')) for plugin in plugins: item = QListWidgetItem() item.setText(plugin[NAME]) if plugin[MODULE_NAME] in to_load: item.setCheckState(Qt.Checked) else: item.setCheckState(Qt.Unchecked) item.plugin = plugin self._listbox.addItem(item) self.connect(self._listbox, SIGNAL('currentItemChanged(QListWidgetItem*, QListWidgetItem *)'), lambda item, previous: info_display.changeInfo(item.plugin))
def __init__(self): object.__init__(self) cparser = PuddleConfig() musicdir = cparser.get('exampletagsource', 'musicdir', HOMEDIR) self.preferences = [['Music &Directory: ', TEXT, musicdir]] self.applyPrefs([musicdir])
class RetrievalError(WebServiceError): def __init__(self, msg, code=0): WebServiceError.__init__(self, msg) self.code = code class SubmissionError(WebServiceError): def __init__(self, msg, code=0): WebServiceError.__init__(self, msg) self.code = code cover_pattern = u'%artist% - %album%' COVERDIR = join(CONFIGDIR, 'covers') cparser = PuddleConfig() COVERDIR = cparser.get('tagsources', 'coverdir', COVERDIR) SAVECOVERS = False status_obj = QObject() user_agent = "puddletag/" + puddlestuff.version_string mapping = {} def get_encoding(page, decode=False, default=None): encoding = None match = re.search('<\?xml(.+)\?>', page) if match: enc = re.search('''encoding(?:\s*)=(?:\s*)["'](.+?)['"]''', match.group(), re.I) if enc: encoding = enc.groups()[0]
def restoreSettings(self): scts = action_shortcuts.create_action_shortcuts( mainwin.funcs.applyaction, self) self.addShortcuts('&Actions', scts) connect_actions(scts, PuddleDock._controls) cparser = PuddleConfig() settings = QSettings(constants.QT_CONFIG, QSettings.IniFormat) gensettings = {} controls = PuddleDock._controls.values() for control in controls: if hasattr(control, 'loadSettings'): control.loadSettings() if hasattr(control, 'gensettings'): t = load_gen_settings(control.gensettings) gensettings[control] = dict(t) for control, val in gensettings.items(): control.applyGenSettings(val, 0) self._lastdir = [ encode_fn(cparser.get('main', 'lastfolder', constants.HOMEDIR)) ] mapping = { u'VorbisComment': { u'date': u'year', u'tracknumber': u'track', u'musicbrainz_albumid': u'mbrainz_album_id', u'musicbrainz_artistid': u'mbrainz_artist_id', u'musicbrainz_trackid': u'mbrainz_track_id' }, u'MP4': { u'MusicBrainz Track Id': u'mbrainz_track_id', u'MusicBrainz Artist Id': u'mbrainz_artist_id', u'MusicBrainz Album Id': u'mbrainz_album_id' }, u'ID3': { u'ufid:http://musicbrainz.org': u'mbrainz_track_id', u'MusicBrainz Album Id': u'mbrainz_album_id', u'MusicBrainz Artist Id': u'mbrainz_artist_id' }, u'APEv2': { u'musicbrainz_albumid': u'mbrainz_album_id', u'musicbrainz_artistid': u'mbrainz_artist_id', u'musicbrainz_trackid': u'mbrainz_track_id' } } filepath = os.path.join(cparser.savedir, 'mappings') audioinfo.setmapping(audioinfo.loadmapping(filepath, mapping)) status['genres'] = genres.load_genres() connect_controls(controls + [mainwin.previews.obj]) cover_pattern = cparser.get('tags', 'cover_pattern', 'folder') status['cover_pattern'] = cover_pattern winsettings('mainwin', self) if cparser.get("main", "maximized", True): self.showMaximized() QApplication.processEvents() if constants.FS_ENC == "ascii": QMessageBox.warning( self, "puddletag", translate( "Errors", "Your filesystem encoding was detected as <b>ASCII</b>. <br />" "You won't be able to rename files using accented, <br />" " cyrillic or any characters outside the ASCII alphabet.")) for control, val in gensettings.items(): control.applyGenSettings(val, 1) h = self._table.horizontalHeader() h.restoreState(settings.value('table/header').toByteArray()) self.restoreState(settings.value('main/state').toByteArray()) confirmations.load() shortcutsettings.ActionEditorDialog._loadSettings(status['actions']) update_settings() QApplication.processEvents()
class RetrievalError(WebServiceError): def __init__(self, msg, code=0): WebServiceError.__init__(self, msg) self.code = code class SubmissionError(WebServiceError): def __init__(self, msg, code=0): WebServiceError.__init__(self, msg) self.code = code cparser = PuddleConfig() COVERDIR = cparser.get('tagsources', 'coverdir', join(CONFIGDIR, 'covers')) COVER_PATTERN = u'%artist% - %album%' SAVECOVERS = False mapping = {} status_obj = QObject() useragent = "puddletag/" + puddlestuff.version_string def get_encoding(page, decode=False, default=None): encoding = None match = re.search('<\?xml(.+)\?>', page) if match: enc = re.search('''encoding(?:\s*)=(?:\s*)["'](.+?)['"]''', match.group(), re.I) if enc:
def __init__(self, parent=None, status=None): QWidget.__init__(self, parent) self._edited = False self._status = status self._filespec = QLineEdit() speclabel = QLabel( translate( "Tag Settings", '&Restrict incoming files to (eg. "*.mp3; *.ogg; *.aac")')) speclabel.setBuddy(self._filespec) v1_options = [ translate("Tag Settings", 'Remove ID3v1 tag.'), translate( "Tag Settings", "Update the ID3v1 tag's " "values only if an ID3v1 tag is present."), translate( "Tag Settings", "Create an ID3v1 tag if it's " "not present. Otherwise update it.") ] self._v1_combo = QComboBox() self._v1_combo.addItems(v1_options) v1_label = QLabel( translate( "Tag Settings", "puddletag writes " "only &ID3v2 tags.<br />What should be done " "with the ID3v1 tag upon saving?")) v1_label.setBuddy(self._v1_combo) self.coverPattern = QLineEdit('folder.jpg') cover_label = QLabel( translate('Tag Settings', 'Default &pattern to use when saving artwork.')) cover_label.setBuddy(self.coverPattern) layout = QVBoxLayout() vbox = QVBoxLayout() layout.addWidget(cover_label) layout.addWidget(self.coverPattern) layout.addWidget(speclabel) layout.addWidget(self._filespec) vbox.addWidget(v1_label) vbox.addWidget(self._v1_combo) group = QGroupBox(translate('Tag Settings', 'ID3 Options')) self.id3_v24 = QRadioButton( translate('Tag Settings', 'Write ID3v2.&4'), group) self.id3_v24.setChecked(True) self.id3_v23 = QRadioButton( translate('Tag Settings', 'Write ID3v2.&3'), group) group.setLayout(vbox) vbox.addWidget(self.id3_v24) vbox.addWidget(self.id3_v23) vbox.addStretch() layout.addWidget(group) self.setLayout(layout) cparser = PuddleConfig() index = cparser.get('id3tags', 'v1_option', 2) self._v1_combo.setCurrentIndex(index) v2_option = cparser.get('id3tags', 'v2_option', 4) if v2_option == 3: self.id3_v23.setChecked(True) filespec = u';'.join(cparser.get('table', 'filespec', [])) self._filespec.setText(filespec) cover_pattern = cparser.get('tags', 'cover_pattern', 'folder') self.coverPattern.setText(cover_pattern)
def restoreSettings(self): scts = action_shortcuts.create_action_shortcuts( mainwin.funcs.applyaction, self) self.addShortcuts('&Actions', scts) connect_actions(scts, PuddleDock._controls) cparser = PuddleConfig() settings = QSettings(constants.QT_CONFIG, QSettings.IniFormat) gensettings = {} controls = PuddleDock._controls.values() for control in controls: if hasattr(control, 'loadSettings'): control.loadSettings() if hasattr(control, 'gensettings'): t = load_gen_settings(control.gensettings) gensettings[control] = dict(t) for control, val in gensettings.items(): control.applyGenSettings(val, 0) self._lastdir = [encode_fn(cparser.get( 'main', 'lastfolder', constants.HOMEDIR))] mapping = { u'VorbisComment': {u'date': u'year', u'tracknumber': u'track', u'musicbrainz_albumid': u'mbrainz_album_id', u'musicbrainz_artistid': u'mbrainz_artist_id', u'musicbrainz_trackid': u'mbrainz_track_id'}, u'MP4': {u'MusicBrainz Track Id': u'mbrainz_track_id', u'MusicBrainz Artist Id': u'mbrainz_artist_id', u'MusicBrainz Album Id': u'mbrainz_album_id'}, u'ID3': {u'ufid:http://musicbrainz.org': u'mbrainz_track_id', u'MusicBrainz Album Id': u'mbrainz_album_id', u'MusicBrainz Artist Id': u'mbrainz_artist_id'}, u'APEv2': {u'musicbrainz_albumid': u'mbrainz_album_id', u'musicbrainz_artistid': u'mbrainz_artist_id', u'musicbrainz_trackid': u'mbrainz_track_id'}} filepath = os.path.join(cparser.savedir, 'mappings') audioinfo.setmapping(audioinfo.loadmapping(filepath, mapping)) status['genres'] = genres.load_genres() connect_controls(controls + [mainwin.previews.obj]) cover_pattern = cparser.get('tags', 'cover_pattern', 'folder') status['cover_pattern'] = cover_pattern winsettings('mainwin', self) if cparser.get("main", "maximized", True): self.showMaximized() QApplication.processEvents() if constants.FS_ENC == "ascii": QMessageBox.warning(self, "puddletag", translate("Errors", "Your filesystem encoding was detected as <b>ASCII</b>. <br />" "You won't be able to rename files using accented, <br />" " cyrillic or any characters outside the ASCII alphabet.")) for control, val in gensettings.items(): control.applyGenSettings(val, 1) h = self._table.horizontalHeader() h.restoreState(settings.value('table/header').toByteArray()) self.restoreState(settings.value('main/state').toByteArray()) confirmations.load() shortcutsettings.ActionEditorDialog._loadSettings(status['actions']) update_settings() QApplication.processEvents()
def __init__(self, parent = None, status=None): QWidget.__init__(self, parent) self._edited = False self._status = status self._filespec = QLineEdit() speclabel = QLabel(translate("Tag Settings", '&Restrict incoming files to (eg. "*.mp3; *.ogg; *.aac")')) speclabel.setBuddy(self._filespec) v1_options = [translate("Tag Settings",'Remove ID3v1 tag.'), translate("Tag Settings", "Update the ID3v1 tag's " "values only if an ID3v1 tag is present."), translate("Tag Settings", "Create an ID3v1 tag if it's " "not present. Otherwise update it.")] self._v1_combo = QComboBox() self._v1_combo.addItems(v1_options) v1_label = QLabel(translate("Tag Settings", "puddletag writes " "only &ID3v2 tags.<br />What should be done " "with the ID3v1 tag upon saving?")) v1_label.setBuddy(self._v1_combo) self.coverPattern = QLineEdit('folder.jpg') cover_label = QLabel(translate('Tag Settings', 'Default &pattern to use when saving artwork.')) cover_label.setBuddy(self.coverPattern) layout = QVBoxLayout() vbox = QVBoxLayout() layout.addWidget(cover_label) layout.addWidget(self.coverPattern) layout.addWidget(speclabel) layout.addWidget(self._filespec) vbox.addWidget(v1_label) vbox.addWidget(self._v1_combo) group = QGroupBox(translate('Tag Settings', 'ID3 Options')) self.id3_v24 = QRadioButton(translate('Tag Settings', 'Write ID3v2.&4'), group) self.id3_v24.setChecked(True) self.id3_v23 = QRadioButton(translate('Tag Settings', 'Write ID3v2.&3'), group) group.setLayout(vbox) vbox.addWidget(self.id3_v24) vbox.addWidget(self.id3_v23) vbox.addStretch() layout.addWidget(group) self.setLayout(layout) cparser = PuddleConfig() index = cparser.get('id3tags', 'v1_option', 2) self._v1_combo.setCurrentIndex(index) v2_option = cparser.get('id3tags', 'v2_option', 4) if v2_option == 3: self.id3_v23.setChecked(True) filespec = u';'.join(cparser.get('table', 'filespec', [])) self._filespec.setText(filespec) cover_pattern = cparser.get('tags', 'cover_pattern', 'folder') self.coverPattern.setText(cover_pattern)
def load_fields(): cparser = PuddleConfig(CONFIGPATH) return cparser.get('view_all_fields', 'fields', ['__filename', '__dirpath'])