Example #1
0
 def showMessage(self, message):
     settings = PuddleConfig()
     should_show = settings.get("OnceOnlyErrors", self.name, True)
     self.__label.setText(message)
     if should_show:
         self.setModal(True)
         self.show()
Example #2
0
 def showMessage(self, message):
     settings = PuddleConfig()
     should_show = settings.get("OnceOnlyErrors", self.name, True)
     self.__label.setText(message)
     if should_show:
         self.setModal(True)
         self.show()
Example #3
0
    def applySettings(self, control):
        listbox = control.listbox
        text = unicode(self._text.text())
        listbox.trackPattern = text

        albumdisp = unicode(self._albumdisp.text())
        listbox.albumPattern = albumdisp

        sort_combo = self._sortoptions
        sort_options_text = [unicode(sort_combo.itemText(i)) for i in 
            range(sort_combo.count())]
        sort_options = split_strip(sort_options_text)
        listbox.setSortOptions(sort_options)

        listbox.sort(sort_options[sort_combo.currentIndex()])
        
        useragent = unicode(self._ua.toPlainText())
        set_useragent(useragent)

        listbox.jfdi = self.jfdi.isChecked()
        listbox.matchFields = [z.strip() for z in
            unicode(self.matchFields.text()).split(u',')]
        listbox.albumBound = self.albumBound.value() / 100.0
        listbox.trackBound = self.trackBound.value() / 100.0
        
        cparser = PuddleConfig(os.path.join(CONFIGDIR, 'tagsources.conf'))
        set_value = lambda s,v: cparser.set('tagsources', s, v)
        set_value('trackpattern', text)
        set_value('albumpattern', albumdisp)
        set_value('sortoptions', sort_options_text)
        set_value('useragent', useragent)
        set_value('album_bound', self.albumBound.value())
        set_value('track_bound', self.trackBound.value())
        set_value('jfdi', listbox.jfdi)
        set_value('match_fields', listbox.matchFields)
Example #4
0
    def loadSettings(self):
        cparser = PuddleConfig(os.path.join(CONFIGDIR, 'tagsources.conf'))

        trackpattern = cparser.get('tagsources', 'trackpattern',
                                   '%track% - %title%')

        self._text.setText(trackpattern)

        sortoptions = cparser.get('tagsources', 'sortoptions',
                                  [u'artist, album', u'album, artist'])
        self._sortoptions.clear()
        self._sortoptions.addItems(sortoptions)

        albumformat = cparser.get(
            'tagsources', 'albumpattern',
            u'%artist% - %album% $if(%__numtracks%, [%__numtracks%], "")')
        self._albumdisp.setText(albumformat)

        self._ua.setText(
            cparser.get('tagsources', 'useragent',
                        'puddletag/' + puddlestuff.version_string))

        self.albumBound.setValue(
            cparser.get('tagsources', 'album_bound', 70, True))
        self.trackBound.setValue(
            cparser.get('tagsources', 'track_bound', 80, True))
        self.jfdi.setChecked(
            bool(cparser.get('tagsources', 'jfdi', True, True)))

        fields = cparser.get('tagsources', 'match_fields', ['artist', 'title'])
        fields = u', '.join(z.strip() for z in fields)
        self.matchFields.setText(fields)
Example #5
0
def check_file(path, resource):
    if not os.path.exists(path):
        create_file(path, resource)
    else:
        cparser = PuddleConfig(path)
        version = cparser.get('info', 'version', 0)
        if version < __version__:
            create_file(path, resource)
Example #6
0
def check_file(path, resource):
    if not os.path.exists(path):
        create_file(path, resource)
    else:
        cparser = PuddleConfig(path)
        version = cparser.get('info', 'version', 0)
        if version < __version__:
            create_file(path, resource)
Example #7
0
 def _loadSettings(self):
     cparser = PuddleConfig()
     section = 'autonumbering'
     self._start.setValue(cparser.get(section, 'start', 1))
     self._separator.setCheckState(
         cparser.get(section, 'separator', Qt.Unchecked))
     self._padlength.setValue(cparser.get(section, 'padlength', 1))
     self._restart_numbering.setCheckState(
         cparser.get(section, 'restart', Qt.Unchecked))
Example #8
0
def get_menus(section, filepath=None):
    cparser = PuddleConfig()
    if not filepath:
        filepath = menu_path
    cparser.filename = filepath
    menus = []
    settings = cparser.data
    temp = settings[section]
    menus = [(z, temp[z]) for z in settings[section + 'attrs']['order']]
    return menus
Example #9
0
def get_menus(section, filepath=None):
    cparser = PuddleConfig()
    if not filepath:
        filepath = menu_path
    cparser.filename = filepath
    menus = []
    settings = cparser.data
    temp = settings[section]
    menus = [(z, temp[z]) for z in settings[section + 'attrs']['order']]
    return menus
Example #10
0
    def loadSettings(self):
        cparser = PuddleConfig(os.path.join(CONFIGDIR, 'tagsources.conf'))

        trackpattern = cparser.get('tagsources', 'trackpattern',
            '%track% - %title%')

        self._text.setText(trackpattern)

        sortoptions = cparser.get('tagsources', 'sortoptions',
            [u'artist, album', u'album, artist'])
        self._sortoptions.clear()
        self._sortoptions.addItems(sortoptions)

        albumformat = cparser.get('tagsources', 'albumpattern',
            u'%artist% - %album% $if(%__numtracks%, [%__numtracks%], "")')
        self._albumdisp.setText(albumformat)

        self._ua.setText(cparser.get('tagsources',
            'useragent', 'puddletag/' + puddlestuff.version_string))

        self.albumBound.setValue(
            cparser.get('tagsources', 'album_bound', 70, True))
        self.trackBound.setValue(
            cparser.get('tagsources', 'track_bound', 80, True))
        self.jfdi.setChecked(
            bool(cparser.get('tagsources', 'jfdi', True, True)))

        fields = cparser.get('tagsources', 'match_fields',
            ['artist', 'title'])
        fields = u', '.join(z.strip() for z in fields)
        self.matchFields.setText(fields)
Example #11
0
    def _loadSettings(self):
        cparser = PuddleConfig()
        section = 'autonumbering'
        self._start.setValue(cparser.get(section, 'start', 1))
        self._separator.setCheckState(
            cparser.get(section, 'separator', Qt.Unchecked))
        self._padlength.setValue(cparser.get(section, 'padlength', 1))

        self._restart_numbering.setCheckState(
            cparser.get(section, 'restart', Qt.Unchecked))

        self.count_by_group.setCheckState(
            cparser.get(section, 'count_by_group', Qt.Unchecked))

        self.showDirectorySplittingOptions(
            self._restart_numbering.checkState())

        self.grouping.setText(cparser.get(section, 'grouping', '%__dirpath%'))

        output_field_text = cparser.get(section, 'output_field', 'track')
        if not output_field_text:
            output_field_text = 'track'

        last_output_field_index = self.output_field.findText(output_field_text)
        if last_output_field_index > -1:
            self.output_field.setCurrentIndex(last_output_field_index)
Example #12
0
def load_source_prefs(name, preferences):
    cparser = PuddleConfig(TAGSOURCE_CONFIG)
    ret = []
    for option in preferences:
        if option[1] == COMBO:
            ret.append(cparser.get(name, option[0], option[2][1]))
        elif option[1] == SPINBOX:
            ret.append(cparser.get(name, option[0], option[2][2]))
        else:
            ret.append(cparser.get(name, option[0], option[2]))
    return ret
Example #13
0
def load_source_prefs(name, preferences):
    cparser = PuddleConfig(TAGSOURCE_CONFIG)
    ret = []
    for option in preferences:
        if option[1] == COMBO:
            ret.append(cparser.get(name, option[0], option[2][1]))
        elif option[1] == SPINBOX:
            ret.append(cparser.get(name, option[0], option[2][2]))
        else:
            ret.append(cparser.get(name, option[0], option[2]))
    return ret
Example #14
0
def save_macro(filename, name, funcs):
    f = open(filename, 'w')
    f.close()
    cparser = PuddleConfig(filename)
    cparser.set('info', 'name', name)
    set_value = lambda i, key, value: cparser.set('Func%d' % i, key, value)
    for i, func in enumerate(funcs):
        set_value(i, FIELDS, func.tag)
        set_value(i, FUNC_NAME, func.function.__name__)
        set_value(i, FUNC_MODULE, func.function.__module__)
        set_value(i, ARGS, func.args)
Example #15
0
def save_macro(filename, name, funcs):
    f = open(filename, 'w')
    f.close()
    cparser = PuddleConfig(filename)
    cparser.set('info', 'name', name)
    set_value = lambda i, key, value: cparser.set('Func%d' % i, key, value)
    for i, func in enumerate(funcs):
        set_value(i, FIELDS, func.tag)
        set_value(i, FUNC_NAME, func.function.__name__)
        set_value(i, FUNC_MODULE, func.function.__module__)
        set_value(i, ARGS, func.args)
Example #16
0
def get_actions(parent, filepath=None):
    cparser = PuddleConfig()
    if not filepath:
        filepath = shortcut_path
    cparser.filename = filepath
    setting = cparser.data
    actions = []
    for section in cparser.sections():
        if section.startswith('shortcut'):
            values = dict([(str(k), v) for k,v in  setting[section].items()])
            actions.append(create_action(parent, **values))
    return actions
Example #17
0
def get_actions(parent, filepath=None):
    cparser = PuddleConfig()
    if not filepath:
        filepath = shortcut_path
    cparser.filename = filepath
    setting = cparser.data
    actions = []
    for section in cparser.sections():
        if section.startswith('shortcut'):
            values = dict([(str(k), v) for k, v in setting[section].items()])
            actions.append(create_action(parent, **values))
    return actions
Example #18
0
    def _loadSettings(self):
        cparser = PuddleConfig()
        section = 'autonumbering'
        self._start.setValue(cparser.get(section, 'start', 1))
        self._separator.setCheckState(
            cparser.get(section, 'separator', Qt.Unchecked))
        self._padlength.setValue(cparser.get(section, 'padlength', 1))
        
        self._restart_numbering.setCheckState(
            cparser.get(section, 'restart', Qt.Unchecked))

        self.count_by_group.setCheckState(
            cparser.get(section, 'count_by_group', Qt.Unchecked))
        
        self.showDirectorySplittingOptions(self._restart_numbering.checkState())
        
        self.grouping.setText(cparser.get(section, 'grouping', '%__dirpath%'))
        
        output_field_text = cparser.get(section, 'output_field', 'track')
        if not output_field_text:
            output_field_text = 'track'

        last_output_field_index = self.output_field.findText(output_field_text)
        if last_output_field_index > -1:
            self.output_field.setCurrentIndex(last_output_field_index)
Example #19
0
def load_macro_info(filename):
    modules = defaultdict(lambda: defaultdict(lambda: {}))
    for function in functions.values():
        if isinstance(function, PluginFunction):
            f = function.function
            modules[f.__module__][f.__name__] = function
        else:
            modules[function.__module__][function.__name__] = function
    cparser = PuddleConfig(filename)
    funcs = []
    name = cparser.get('info', 'name', u'')

    def get_func_index(funcname):
        if funcname.startswith('Func'):
            return int(funcname[4:].strip())
        else:
            return funcname

    for section in sorted(cparser.sections(), key=get_func_index):
        if section.startswith(u'Func'):
            get = partial(cparser.get, section)
            func_name = get(FUNC_NAME, u'')
            fields = get(FIELDS, [])
            func_module = get(FUNC_MODULE, u'')
            arguments = get(ARGS, [])
            try:
                func = Function(modules[func_module][func_name], fields)
            except IndexError:
                continue
            except AttributeError:
                continue
            newargs = []
            for i, (control, arg) in enumerate(zip(func.controls, arguments)):
                if control == CHECKBOX:
                    if arg == False or arg == u'False':
                        newargs.append(False)
                    else:
                        newargs.append(True)
                elif control == SPINBOX:
                    newargs.append(int(arg))
                else:
                    newargs.append(arg)
            if func.controls:
                func.args = newargs
            else:
                func.args = arguments
            funcs.append(func)
    return [funcs, name]    
Example #20
0
def load_macro_info(filename):
    modules = defaultdict(lambda: defaultdict(lambda: {}))
    for function in functions.values():
        if isinstance(function, PluginFunction):
            f = function.function
            modules[f.__module__][f.__name__] = function
        else:
            modules[function.__module__][function.__name__] = function
    cparser = PuddleConfig(filename)
    funcs = []
    name = cparser.get('info', 'name', u'')

    def get_func_index(funcname):
        if funcname.startswith('Func'):
            return int(funcname[4:].strip())
        else:
            return funcname

    for section in sorted(cparser.sections(), key=get_func_index):
        if section.startswith(u'Func'):
            get = partial(cparser.get, section)
            func_name = get(FUNC_NAME, u'')
            fields = get(FIELDS, [])
            func_module = get(FUNC_MODULE, u'')
            arguments = get(ARGS, [])
            try:
                func = Function(modules[func_module][func_name], fields)
            except IndexError:
                continue
            except AttributeError:
                continue
            newargs = []
            for i, (control, arg) in enumerate(zip(func.controls, arguments)):
                if control == CHECKBOX:
                    if arg == False or arg == u'False':
                        newargs.append(False)
                    else:
                        newargs.append(True)
                elif control == SPINBOX:
                    newargs.append(int(arg))
                else:
                    newargs.append(arg)
            if func.controls:
                func.args = newargs
            else:
                func.args = arguments
            funcs.append(func)
    return [funcs, name]
Example #21
0
def context_menu(section, actions, filepath=None):
    cparser = PuddleConfig(filepath)
    if not filepath:
        filepath = menu_path
        cparser.filename = filepath
    order = [translate('Menus', z) for z in cparser.get(section, 'order', [])]
    if not order:
        return
    texts = [unicode(action.text()) for action in actions]
    menu = QMenu()
    for action in order:
        if action in texts:
            menu.addAction(actions[texts.index(action)])
        elif action == SEPARATOR:
            menu.addSeparator()
    return menu
Example #22
0
def context_menu(section, actions, filepath=None):
    cparser = PuddleConfig(filepath)
    if not filepath:
        filepath = menu_path
        cparser.filename = filepath
    order = [translate('Menus', z) for z in cparser.get(section, 'order', [])]
    if not order:
        return
    texts = [unicode(action.text()) for action in actions]
    menu = QMenu()
    for action in order:
        if action in texts:
            menu.addAction(actions[texts.index(action)])
        elif action == SEPARATOR:
            menu.addSeparator()
    return menu
Example #23
0
    def loadSettings(self):
        settings = PuddleConfig(os.path.join(CONFIGDIR, 'tagsources.conf'))
        get = lambda s, k, i=False: settings.get('tagsources', s, k, i)

        source = get('lastsource', 'Musicbrainz')
        self.__sourceFields = [
            settings.get('tagsourcetags', ts.name, []) for ts in self.__sources
        ]

        index = self.sourcelist.findText(source)
        if index == -1:
            index = 0
        self.sourcelist.setCurrentIndex(index)
        self.__fieldsEdit.setTags(self.__sourceFields[index])
        df = get('trackpattern', u'%track% - %title%')
        self.listbox.trackPattern = df

        albumformat = get(
            'albumpattern',
            u'%artist% - %album%$if(%__numtracks%, [%__numtracks%], "")')
        self.listbox.albumPattern = albumformat

        sort_options = get('sortoptions', [u'artist, album', u'album, artist'])
        sort_options = split_strip(sort_options)
        self.listbox.setSortOptions(sort_options)

        sortindex = get('lastsort', 0)
        self.listbox.sort(sort_options[sortindex])

        filepath = os.path.join(CONFIGDIR, 'mappings')
        self.setMapping(audioinfo.loadmapping(filepath))

        useragent = get('useragent', '')
        if useragent:
            set_useragent(useragent)

        checkstate = get('existing', False)
        self.__updateEmpty.setChecked(checkstate)

        checkstate = get('autoretrieve', False)
        self.__autoRetrieve.setChecked(checkstate)

        self.listbox.albumBound = get('album_bound', 70, True) / 100.0
        self.listbox.trackBound = get('track_bound', 80, True) / 100.0
        self.listbox.jfdi = bool(get('jfdi', True, True))
        self.listbox.matchFields = get('match_fields', ['artist', 'title'])
Example #24
0
    def loadSettings(self):
        settings = PuddleConfig(os.path.join(CONFIGDIR, 'tagsources.conf'))
        get = lambda s, k, i=False: settings.get('tagsources', s, k, i)

        source = get('lastsource', 'Musicbrainz')
        self.__sourceFields = [settings.get('tagsourcetags', ts.name, [])
            for ts in self.__sources]

        index = self.sourcelist.findText(source)
        if index == -1:
            index = 0
        self.sourcelist.setCurrentIndex(index)
        self.__fieldsEdit.setTags(self.__sourceFields[index])
        df = get('trackpattern', u'%track% - %title%')
        self.listbox.trackPattern = df

        albumformat = get('albumpattern',
            u'%artist% - %album%$if(%__numtracks%, [%__numtracks%], "")')
        self.listbox.albumPattern = albumformat

        sort_options = get('sortoptions',
            [u'artist, album', u'album, artist'])
        sort_options = split_strip(sort_options)
        self.listbox.setSortOptions(sort_options)

        sortindex = get('lastsort', 0)
        self.listbox.sort(sort_options[sortindex])

        filepath = os.path.join(CONFIGDIR, 'mappings')
        self.setMapping(audioinfo.loadmapping(filepath))

        useragent = get('useragent', '')
        if useragent:
            set_useragent(useragent)

        checkstate = get('existing', False)
        self.__updateEmpty.setChecked(checkstate)

        checkstate = get('autoretrieve', False)
        self.__autoRetrieve.setChecked(checkstate)

        self.listbox.albumBound = get('album_bound', 70, True) / 100.0
        self.listbox.trackBound = get('track_bound', 80, True) / 100.0
        self.listbox.jfdi = bool(get('jfdi', True, True))
        self.listbox.matchFields = get('match_fields', ['artist', 'title'])
Example #25
0
    def loadSettings(self):
        cparser = PuddleConfig()
        self.get_fieldlist = gettaglist()
        get = lambda k,v : cparser.get('extendedtags', k, v, True)
        add = QColor.fromRgb(*get('add', [255, 255, 0]))
        edit = QColor.fromRgb(*get('edit', [0, 255,0]))
        remove = QColor.fromRgb(*get('remove', [255, 0, 0]))

        self._colors = {ADD: QBrush(add),
            EDIT: QBrush(edit), REMOVE: QBrush(remove)}

        item = self.table.item
        for row in xrange(self.table.rowCount()):
            field_item = self.get_item(row, 0)
            field_item.statusColors = self._colors
            field_item.status = field_item.status
            
            val_item = self.get_item(row, 1)
            val_item.statusColors = self._colors
            val_item.status = val_item.status
Example #26
0
    def loadSettings(self):
        cparser = PuddleConfig()
        self.get_fieldlist = gettaglist()
        get = lambda k, v: cparser.get('extendedtags', k, v, True)
        add = QColor.fromRgb(*get('add', [255, 255, 0]))
        edit = QColor.fromRgb(*get('edit', [0, 255, 0]))
        remove = QColor.fromRgb(*get('remove', [255, 0, 0]))

        self._colors = {
            ADD: QBrush(add),
            EDIT: QBrush(edit),
            REMOVE: QBrush(remove)
        }

        item = self.table.item
        for row in xrange(self.table.rowCount()):
            field_item = self.get_item(row, 0)
            field_item.statusColors = self._colors
            field_item.status = field_item.status

            val_item = self.get_item(row, 1)
            val_item.statusColors = self._colors
            val_item.status = val_item.status
Example #27
0
    def applySettings(self, control):
        listbox = control.listbox
        text = unicode(self._text.text())
        listbox.trackPattern = text

        albumdisp = unicode(self._albumdisp.text())
        listbox.albumPattern = albumdisp

        sort_combo = self._sortoptions
        sort_options_text = [
            unicode(sort_combo.itemText(i)) for i in range(sort_combo.count())
        ]
        sort_options = split_strip(sort_options_text)
        listbox.setSortOptions(sort_options)

        listbox.sort(sort_options[sort_combo.currentIndex()])

        useragent = unicode(self._ua.toPlainText())
        set_useragent(useragent)

        listbox.jfdi = self.jfdi.isChecked()
        listbox.matchFields = [
            z.strip() for z in unicode(self.matchFields.text()).split(u',')
        ]
        listbox.albumBound = self.albumBound.value() / 100.0
        listbox.trackBound = self.trackBound.value() / 100.0

        cparser = PuddleConfig(os.path.join(CONFIGDIR, 'tagsources.conf'))
        set_value = lambda s, v: cparser.set('tagsources', s, v)
        set_value('trackpattern', text)
        set_value('albumpattern', albumdisp)
        set_value('sortoptions', sort_options_text)
        set_value('useragent', useragent)
        set_value('album_bound', self.albumBound.value())
        set_value('track_bound', self.trackBound.value())
        set_value('jfdi', listbox.jfdi)
        set_value('match_fields', listbox.matchFields)
Example #28
0
 def saveSettings(self):
     settings = PuddleConfig()
     settings.filename = os.path.join(CONFIGDIR, 'tagsources.conf')
     settings.set('tagsources', 'lastsource', self.sourcelist.currentText())
     for i, ts in enumerate(self.__sources):
         settings.set('tagsourcetags', ts.name, self.__sourceFields[i])
     settings.set('tagsources', 'lastsort', self.listbox.lastSortIndex)
     settings.set('tagsources', 'existing', self.__updateEmpty.isChecked())
     settings.set('tagsources', 'autoretrieve',
                  self.__autoRetrieve.isChecked())
Example #29
0
 def _applyPrefs(self, prefs):
     self.curSource.applyPrefs(prefs)
     cparser = PuddleConfig(TAGSOURCE_CONFIG)
     name = self.curSource.name
     for section, value in zip(self.curSource.preferences, prefs):
         cparser.set(name, section[0], value)
Example #30
0
 def _saveSettings(self):
     cparser = PuddleConfig()
     section = 'autonumbering'
     cparser.set(section, 'start', self._start.value())
     cparser.set(section, 'separator', self._separator.checkState())
     cparser.set(section, 'count_by_group', self.count_by_group.checkState())
     cparser.set(section, 'numtracks', self._numtracks.value())
     cparser.set(section, 'restart', self._restart_numbering.checkState())
     cparser.set(section, 'padlength', self._padlength.value())
     cparser.set(section, 'grouping', self.grouping.text())
     cparser.set(section, 'output_field', self.output_field.currentText())
Example #31
0
 def saveState(self, name):
     settings = PuddleConfig()
     settings.set("OnceOnlyErrors", name, True)
     self.close()
Example #32
0
 def saveSettings(self):
     settings = PuddleConfig()
     settings.filename = os.path.join(CONFIGDIR, 'tagsources.conf')
     settings.set('tagsources', 'lastsource', self.sourcelist.currentText())
     for i, ts in enumerate(self.__sources):
         settings.set('tagsourcetags', ts.name, self.__sourceFields[i])
     settings.set('tagsources', 'lastsort', self.listbox.lastSortIndex)
     settings.set('tagsources', 'existing', self.__updateEmpty.isChecked())
     settings.set('tagsources', 'autoretrieve',
         self.__autoRetrieve.isChecked())
Example #33
0
 def _saveSettings(self):
     cparser = PuddleConfig()
     section = 'autonumbering'
     cparser.set(section, 'start', self._start.value())
     cparser.set(section, 'separator', self._separator.checkState())
     cparser.set(section, 'numtracks', self._numtracks.value())
     cparser.set(section, 'restart', self._restart_numbering.checkState())
     cparser.set(section, 'padlength', self._padlength.value())
Example #34
0
 def _applyPrefs(self, prefs):
     self.curSource.applyPrefs(prefs)
     cparser = PuddleConfig(TAGSOURCE_CONFIG)
     name = self.curSource.name
     for section, value in zip(self.curSource.preferences, prefs):
         cparser.set(name, section[0], value)
Example #35
0
 def saveState(self, name):
     settings = PuddleConfig()
     settings.set("OnceOnlyErrors", name, True)
     self.close()
Example #36
0
 def _saveSettings(self):
     cparser = PuddleConfig()
     section = 'autonumbering'
     cparser.set(section, 'start', self._start.value())
     cparser.set(section, 'separator', self._separator.checkState())
     cparser.set(section, 'count_by_group',
                 self.count_by_group.checkState())
     cparser.set(section, 'numtracks', self._numtracks.value())
     cparser.set(section, 'restart', self._restart_numbering.checkState())
     cparser.set(section, 'padlength', self._padlength.value())
     cparser.set(section, 'grouping', self.grouping.text())
     cparser.set(section, 'output_field', self.output_field.currentText())