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 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()
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()
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()
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()
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()')) def hasChildren(self, index): item = index.internalPointer()
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()')) def hasChildren(self, index):
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()