def reset_queue(self): """Slot called by the `resetQueue` signal and is responsible for clearing the worker's queue. """ verify_thread_affinity() log.debug(u'reset_queue()', self) self.interrupt = True QUEUES[self.queue_type].clear() self.interrupt = False
def thread_started(thread): """Signals the model an item has been updated.""" cnx = QtCore.Qt.QueuedConnection thread.updateRow.connect(self.updateRow, QtCore.Qt.DirectConnection) self.startCheckQueue.connect(lambda: log.debug( 'startCheckQueue -> worker.startCheckQueue', self)) self.startCheckQueue.connect(thread.startCheckQueue, cnx) self.stopCheckQueue.connect(lambda: log.debug( 'stopCheckQueue -> worker.stopCheckQueue', self)) self.stopCheckQueue.connect(thread.stopCheckQueue, cnx) self.startCheckQueue.emit()
def load_saved_filter_text(self): log.debug('load_saved_filter_text()', self) model = self.model().sourceModel() task_folder = model.task_folder() if not task_folder: log.error('load_saved_filter_text(): Data key not yet set') return cls = model.__class__.__name__ k = u'widget/{}/{}/filtertext'.format(cls, task_folder) v = settings.local_settings.value(k) v = v if v else u'' self.model().set_filter_text(v)
def _connect_signals(self): QtCore.QCoreApplication.instance().aboutToQuit.connect(self.quit) QtGui.QGuiApplication.instance().lastWindowClosed.connect(self.quit) self.started.connect( lambda: log.debug(u'started --> move_worker_to_thread', self)) self.started.connect(self.move_worker_to_thread)
def get_mode(self): """Return the current application mode.""" lockfile_info = QtCore.QFileInfo(get_lockfile_path()) for entry in _scandir.scandir(lockfile_info.path()): if entry.is_dir(): continue path = entry.path if not path.endswith(u'.lock'): continue with open(path, 'r') as f: data = f.read() try: data = int(data.strip()) if data == common.SynchronisedMode: log.debug(u'Current application mode is `SoloMode`') return common.SoloMode except: log.error(u'Error getting the current application mode.') log.debug(u'Current application mode is `SynchronisedMode`') return common.SynchronisedMode
def move_worker_to_thread(self): """Slot called when the thread is started. We'll move the worker to the thread and connnect all signals needed to communicate with the worker. """ log.debug(u'move_worker_to_thread()', self) self.worker.moveToThread(self) cnx = QtCore.Qt.QueuedConnection if self.worker.thread() == QtWidgets.QApplication.instance().thread(): s = u'The worker cannot be used in the main gui thread.' log.error(s) raise RuntimeError(s) self.resetQueue.connect( lambda: log.debug(u'resetQueue --> worker.resetQueue', self)) self.resetQueue.connect(self.worker.resetQueue, cnx) self.queueModel.connect( lambda: log.debug(u'queueModel --> worker.queueModel', self)) self.queueModel.connect(self.worker.queueModel, cnx) self.startCheckQueue.connect(lambda: log.debug( u'startCheckQueue --> worker.startCheckQueue', self)) self.startCheckQueue.connect(self.worker.startCheckQueue, cnx) self.stopCheckQueue.connect(lambda: log.debug( u'stopCheckQueue --> worker.stopCheckQueue', self)) self.stopCheckQueue.connect(self.worker.stopCheckQueue, cnx) self.worker.updateRow.connect(self.updateRow, cnx) self.worker.modelLoaded.connect(self.modelLoaded, cnx)
def set_model(self, *args, **kwargs): super(FilesWidget, self).set_model(*args, **kwargs) model = self.model().sourceModel() model.modelReset.connect( lambda: log.debug('modelReset -> load_saved_filter_text', model)) model.modelReset.connect(self.load_saved_filter_text)
def set_task_folder(self, val): """Slot used to save task folder to the model instance and the local settings. Each subfolder inside the root folder, defined by``parent_path``, corresponds to a `key`. We use these keys to save model data associated with these folders. It's important to make sure the key we're about to set corresponds to an existing folder. We will use a reasonable default if the folder does not exist. """ log.debug('set_task_folder({})'.format(val), self) try: k = u'activepath/task_folder' stored_value = settings.local_settings.value(k) stored_value = stored_value.lower( ) if stored_value else stored_value self._task_folder = self._task_folder.lower( ) if self._task_folder else self._task_folder val = val.lower() if val else val # Nothing to do for us when the parent is not set if not self.parent_path: return if self._task_folder is None and stored_value: self._task_folder = stored_value.lower() # We are in sync with a valid value set already if stored_value is not None and self._task_folder == val == stored_value: val = None return # We only have to update the local settings, the model is # already set if self._task_folder == val and val != stored_value: settings.local_settings.setValue(k, val) return if val is not None and val == self._task_folder: val = None return # Let's check the asset folder before setting # the key to make sure we're pointing at a valid folder path = u'/'.join(self.parent_path) entries = [f.name.lower() for f in _scandir.scandir(path)] if not entries: val = None self._task_folder = val return # The key is valid if val in entries: self._task_folder = val settings.local_settings.setValue(k, val) return # The new proposed task_folder does not exist but the old one is # valid. We'll just stick with the old value instead... if val not in entries and self._task_folder in entries: val = self._task_folder.lower() settings.local_settings.setValue(k, self._task_folder) return # And finally, let's try to revert to a fall-back... if val not in entries and u'scenes' in entries: val = u'scenes' self._task_folder = val settings.local_settings.setValue(k, val) return # All else... let's select the first folder val = entries[0].lower() self._task_folder = val settings.local_settings.setValue(k, val) except: log.error(u'Could not set task folder') finally: if not self.model_data(): self.__initdata__() else: self.sort_data()
def set_model(self, *args): super(FavouritesWidget, self).set_model(*args) self.favouritesChanged.connect( self.model().sourceModel().modelDataResetRequested) self.favouritesChanged.connect(lambda: log.debug( 'favouritesChanged -> modelDataResetRequested', self))