示例#1
0
    def loadLib(self):
        """Loads the currently selected library.

        Emits 'adddock' signal if successful with a LibraryTree class as its
        widget.
        """
        p = ProgressWin(self, 0,
            translate('MusicLib', 'Loading music library...'), False)
        p.show()
        t = PuddleThread(self._loadLib, self)
        t.start()
        while t.isRunning():
            QApplication.processEvents()
        library = t.retval
        p.close()
        QApplication.processEvents()
        if isinstance(library, basestring):
            error_msg = library
            msg = translate('MusicLib',
                'An error occured while loading the %1 library: <b>%2</b>')
            msg = msg.arg(self.currentlib['name']).arg(error_msg)
            
            QMessageBox.critical(self, translate('Defaults', "Error"),
                msg, QMessageBox.Ok, QMessageBox.NoButton,
                QMessageBox.NoButton)
        else:
            dialog = partial(LibraryDialog, library)
            self.emit(SIGNAL('adddock'),
                translate('MusicLib', 'Music Library'), dialog, RIGHTDOCK)
            self.close()
示例#2
0
    def loadLib(self):
        """Loads the currently selected library.

        Emits 'adddock' signal if successful with a LibraryTree class as its
        widget.
        """
        p = ProgressWin(self, 0,
                        translate('MusicLib', 'Loading music library...'),
                        False)
        p.show()
        t = PuddleThread(self._loadLib, self)
        t.start()
        while t.isRunning():
            QApplication.processEvents()
        library = t.retval
        p.close()
        QApplication.processEvents()
        if isinstance(library, basestring):
            error_msg = library
            msg = translate(
                'MusicLib',
                'An error occured while loading the %1 library: <b>%2</b>')
            msg = msg.arg(self.currentlib['name']).arg(error_msg)

            QMessageBox.critical(self, translate('Defaults',
                                                 "Error"), msg, QMessageBox.Ok,
                                 QMessageBox.NoButton, QMessageBox.NoButton)
        else:
            dialog = partial(LibraryDialog, library)
            self.emit(SIGNAL('adddock'), translate('MusicLib',
                                                   'Music Library'), dialog,
                      RIGHTDOCK)
            self.close()
示例#3
0
    def _start(self):
        mtp = self.profile
        tag_groups = split_files(self._status['selectedfiles'],
            mtp.file_pattern)

        search_msg = translate('Masstagging',
            'An error occured during the search: <b>%s</b>')

        retrieve_msg = translate('Masstagging',
            'An error occured during album retrieval: <b>%s</b>')

        def search_error(error, mtp):
            thread.emit(SIGNAL('statusChanged'),
                search_msg % unicode(error))

        def retrieval_error(error, mtp):
            thread.emit(SIGNAL('statusChanged'),
                retrieve_msg % unicode(error))

        def run_masstag():
            replace_fields = []
            for files in tag_groups:
                mtp.clear()

                
                masstag(mtp, files, self.__flag, search_error,
                    retrieval_error)

                retrieved = merge_tsp_tracks(mtp.profiles)
                ret = match_files(files, retrieved,
                        mtp.track_bound, mtp.fields,
                        mtp.jfdi, mtp.leave_existing, True)[0]

                if ret:
                    thread.emit(SIGNAL('enable_preview_mode'))
                    thread.emit(SIGNAL('setpreview'), ret)

                set_status('<hr width="45%" /><br />')

        def finished(value):
            if not (value is True):
                set_status(translate('Masstagging',
                    '<b>Lookups completed.</b>'))
            self._startButton.setText(translate('Masstagging', '&Search'))
            self.__flag.stop = False

        thread = PuddleThread(run_masstag, self)
        self.connect(thread, SIGNAL('setpreview'), SIGNAL('setpreview'))
        self.connect(thread, SIGNAL('enable_preview_mode'),
            SIGNAL('enable_preview_mode'))
        self.connect(thread, SIGNAL('threadfinished'), finished)
        self.connect(thread, SIGNAL('statusChanged'), set_status)
        
        thread.start()
示例#4
0
 def saveSettings(self, parent=None):
     if parent is None:
         self._library.save()
     else:
         win = ProgressWin(None, 0,
             translate('MusicLib', 'Saving music library...'),
             False)
         win.show()
         QApplication.processEvents()
         thread = PuddleThread(lambda: self._library.save(), parent)
         thread.start()
         while thread.isRunning():
             QApplication.processEvents()
         QApplication.processEvents()
         win.close()
         QApplication.processEvents()
示例#5
0
 def saveSettings(self, parent=None):
     if parent is None:
         self._library.save()
     else:
         win = ProgressWin(None, 0,
                           translate('MusicLib', 'Saving music library...'),
                           False)
         win.show()
         QApplication.processEvents()
         thread = PuddleThread(lambda: self._library.save(), parent)
         thread.start()
         while thread.isRunning():
             QApplication.processEvents()
         QApplication.processEvents()
         win.close()
         QApplication.processEvents()
示例#6
0
    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()
示例#7
0
        self.emit(SIGNAL('retrieving'))
        def fetch_func():
            try:
                return self.tagsource.retrieve(item.itemData)
            except RetrievalError, e:
                self.emit(SIGNAL("statusChanged"), 
                    translate("WebDB", 'An error occured: %1').arg(unicode(e)))
                return
            except Exception, e:
                traceback.print_exc()
                self.emit(SIGNAL("statusChanged"),
                    translate("WebDB", 'An unhandled error occured: %1').arg(unicode(e)))
                return

        item.retrieving = True
        thread = PuddleThread(fetch_func, self)
        self.emit(SIGNAL("statusChanged"), translate("WebDB", "Retrieving album tracks..."))
        thread.start()
        while thread.isRunning():
            QApplication.processEvents()
        val = thread.retval
        if val:
            info, tracks = val
            fillItem(item, info, tracks, self.trackPattern)
            self.emit(SIGNAL("statusChanged"), translate("WebDB", "Retrieval complete."))
            item.retrieving = False
        else:
            if not item.childCount():
                self.emit(SIGNAL('collapse'), index)
        self.emit(SIGNAL('retrievalDone()'))
示例#8
0
                return self.tagsource.retrieve(item.itemData)
            except RetrievalError, e:
                self.emit(
                    SIGNAL("statusChanged"),
                    translate("WebDB", 'An error occured: %1').arg(unicode(e)))
                return
            except Exception, e:
                traceback.print_exc()
                self.emit(
                    SIGNAL("statusChanged"),
                    translate("WebDB", 'An unhandled error occured: %1').arg(
                        unicode(e)))
                return

        item.retrieving = True
        thread = PuddleThread(fetch_func, self)
        self.emit(SIGNAL("statusChanged"),
                  translate("WebDB", "Retrieving album tracks..."))
        thread.start()
        while thread.isRunning():
            QApplication.processEvents()
        val = thread.retval
        if val:
            info, tracks = val
            fillItem(item, info, tracks, self.trackPattern)
            self.emit(SIGNAL("statusChanged"),
                      translate("WebDB", "Retrieval complete."))
            item.retrieving = False
        else:
            if not item.childCount():
                self.emit(SIGNAL('collapse'), index)
示例#9
0
    def selectDirs(self, dirlist):
        if self._threadRunning:
            return
        if not self.isVisible():
            return
        if not self._select:
            self._select = True
            return
        load = self._load
        self._load = False
        if not dirlist:
            self._load = False
            self.selectionModel().clear()
            self._load = load
            return

        if isinstance(dirlist, basestring):
            dirlist = [dirlist]
        self._threadRunning = True
        self.setEnabled(False)
        self.selectionModel().clear()
        selectindex = self.selectionModel().select
        getindex = self.model().index
        parent = self.model().parent

        def func():
            toselect = []
            toexpand = []
            for d in dirlist:
                if not os.path.exists(d):
                    continue
                if isinstance(d, str):
                    try:
                        d = unicode(d, 'utf8')
                    except (UnicodeEncodeError, UnicodeDecodeError):
                        pass
                index = getindex(d)
                toselect.append(index)
                i = parent(index)
                parents = []
                while i.isValid():
                    parents.append(i)
                    i = parent(i)
                toexpand.extend(parents)
            return (toselect, toexpand)

        def finished(val):
            qmutex.lock()
            select = val[0]
            expand = val[1]
            if select:
                self.setCurrentIndex(select[0])
                self.scrollTo(select[0])
            [selectindex(z, QItemSelectionModel.Select) for z in select]
            if expand:
                [self.expand(z) for z in expand]
            self.blockSignals(False)
            self.setEnabled(True)
            self._load = load
            self._threadRunning = False
            qmutex.unlock()
        dirthread = PuddleThread(func, self)
        self.connect(dirthread, SIGNAL('threadfinished'), finished)
        dirthread.start()
示例#10
0
class StoredTags(QScrollArea):
    def __init__(self, parent=None, status = None):
        QScrollArea.__init__(self, parent)
        self.emits = []
        self.receives = self.receives = [(SELECTIONCHANGED, self.load)]
        self._labels = []
        font = QFont()
        font.setBold(True)
        self._boldfont = font
        self._init()
        self.setWidgetResizable(True)
        self._status = status
        self._loading = False
        self._lastfilepath = None

    def _init(self):
        widget = QWidget()
        self._grid = QGridLayout()
        self._grid.setColumnStretch(1, 1)
        self._grid.setMargin(3)
        widget.setLayout(self._grid)
        self.setWidget(widget)
        #self.connect(widget, SIGNAL('wheelEvent'), self._hScroll)

    def load(self):
        audios = self._status['selectedfiles']
        if not self.isVisible():
            return
        if audios:
            filepath = audios[0].filepath
            if self._status['previewmode'] and filepath == self._lastfilepath:
                return
            self._lastfilepath = filepath
        else:
            self._init()
            return

        def retrieve_tag():
            if not os.path.exists(filepath):
                return
            try:
                audio = audioinfo._Tag(filepath)
                tags = tag_versions.tags_in_file(filepath)
            except (OSError, IOError), e:
                audio = {'Error': [e.strerror]}

            if isinstance(audio, audioinfo.id3.Tag):
                if u'ID3v2.4' in tags:
                    tags.remove(u'ID3v2.4')
                if u'ID3v2.3' in tags:
                    tags.remove(u'ID3v2.3')
                if u'ID3v2.2' in tags:
                    tags.remove(u'ID3v2.2')
            elif hasattr(audio, 'apev2') and audio.apev2:
                if u'APEv2' in tags:
                    tags.remove('APEv2')

            ret = [(audio['__tag_read'], sort_dict(audio.usertags))]

            for tag in tags:
                if not tag == audio['__tag_read']:
                    try:
                        ret.append((tag, sort_dict(tag_versions.tag_values(filepath, tag))))
                    except:
                        continue
            return ret

        def _load(tags):
            #print 'loading', time.time()
            while self._loading:
                QApplication.processEvents()
            self._loading = True
            self._init()
            if not tags:
                self._loading = False
                return

            grid = self._grid

            offset = 1
            for title, values in tags:
                if not values:
                    continue
                t_label = QLabel(title)
                t_label.setFont(self._boldfont)
                grid.addWidget(t_label, offset - 1, 0)
                for row, (tag, value) in enumerate(values):
                    field = QLabel(u'%s:' % tag)
                    field.setAlignment(Qt.AlignTop | Qt.AlignLeft)
                    grid.addWidget(field, row + offset, 0)
                    vlabel = QLabel(value)
                    grid.addWidget(vlabel, row + offset, 1)
                grid.setRowMinimumHeight(grid.rowCount(),
                    vlabel.sizeHint().height())
                offset += grid.rowCount() + 1
            vbox = QVBoxLayout()
            vbox.addStretch()
            grid.addLayout(vbox,offset + 1 + offset,0, -1, -1)
            grid.setRowStretch(offset + 1, 1)
            self._loading = False

        thread = PuddleThread(retrieve_tag, self)
        thread.connect(thread, SIGNAL('threadfinished'), _load)
        #print 'starting thread', time.time()
        thread.start()