def item_clicked(self, item): """This method open the dialog box when the user click on the item in charge of the output path :param item: The current item clicked :type item: libs.widget.TableWidgetItem """ if item.column() == 1: logger.info('Choose output destination') combobox = self.cellWidget(item.row(), 2) plugin = combobox.itemData( combobox.currentIndex(), QtCore.Qt.UserRole) extension = plugin.extension result = QtWidgets.QFileDialog.getSaveFileName( parent=self, caption='Select the destination file', dir=item.text(), filter=extension, ) path = result[0] if not path: return if not path.endswith('.%s' % extension): path = '%s.%s' % (path, extension) item.setText(path)
def run(self): try: result = self.fn(*self.args, **self.kwargs) logger.info('function %s done.' % self.fn) except Exception as e: print(e) logger.warning(e)
def reload_plugins(self): """Reset the list of all plugins and initiate the walk over the main provided plugin package to load all available plugins """ self.plugins = [] self.seen_paths = [] logger.info(f'Looking for plugins under package {self.plugin_package}') self.walk_package(self.plugin_package)
def __init__(self, fn, *args, **kwargs): super(Runnable, self).__init__() self.fn = fn self.args = args self.kwargs = kwargs logger.info('Init worker')
def create_settings_file(self): """This function creates the setting file if it doesn't exist""" logger.info('Detecting settings files') if not os.path.exists(os.path.dirname(self.settings_path)): os.makedirs(os.path.dirname(self.settings_path)) settings = QtCore.QSettings(self.settings_path, QtCore.QSettings.IniFormat) logger.info('Setting file at %s' % self.settings_path) return settings
def open_settings_file(self): """This function open the settings file and return the settings object :return: The settings object :rtype: QSettings """ logger.info('Oppening settings file.') if not os.path.exists(self.settings_path): logger.warning('Settings file doesn\'t exist: %s' % self.settings_path) return None settings = QtCore.QSettings(self.settings_path, QtCore.QSettings.IniFormat) return settings
def disable_plugin_manager(self, disable): """This method disable/enable the plugin manager :param disable: The status of the disable :type disable: bool """ if not isinstance(disable, bool): logger.warning('Disable must be a boolean.') return self._disable = disable if self._disable: logger.info('Disable plugin manager') else: logger.info('Enable plugin manager') if not self._disable: self.reload_plugins()
def result_convert_file(self, result): """This method is called by the signal from the threadpool. If the file has been converted correctly, the result will be True. If the conversion failed, the result will be False :param result: Dictionnary of the result of the conversion. The result key is the result of the conversion, the row key is the row of the converted item in the table :type result: dict """ item = self.tab_conversion_files.cellWidget(result['row'], 3) if result['result']: item.set_done() logger.info('Conversion Done.') else: item.set_error() logger.warning('Conversion Failed.')
def walk_package(self, package): """Recursively walk the supplied package to retrieve all plugins """ imported_package = __import__(package, fromlist=['blah']) for _, pluginname, ispkg in pkgutil.iter_modules( imported_package.__path__, imported_package.__name__ + '.'): if not ispkg: plugin_module = __import__(pluginname, fromlist=['blah']) clsmembers = inspect.getmembers(plugin_module, inspect.isclass) for (_, c) in clsmembers: # Only add classes that are a sub class of Plugin, # but NOT Plugin itself if issubclass(c, Plugin) & (c is not Plugin): logger.info( f'Found plugin class: {c.__module__}.{c.__name__}') self.plugins.append(c()) # Now that we have looked at all the modules in the current package, # start looking recursively for additional modules in sub packages all_current_paths = [] if isinstance(imported_package.__path__, str): all_current_paths.append(imported_package.__path__) else: all_current_paths.extend([x for x in imported_package.__path__]) for pkg_path in all_current_paths: if pkg_path not in self.seen_paths: self.seen_paths.append(pkg_path) # Get all sub directory of the current package path directory child_pkgs = [ p for p in os.listdir(pkg_path) if os.path.isdir(os.path.join(pkg_path, p)) ] # For each sub directory, # apply the walk_package method recursively for child_pkg in child_pkgs: self.walk_package(package + '.' + child_pkg)
def apply_all_plugins_on_value(self, event, logger, *args, **kwargs): """Apply all of the plugins on the argument supplied to this function """ if self._disable: logger.info('Plugin manager is disable') return False result = False for plugin in self.plugins: if not plugin.name: logger.info( f'Dispatching event {event} to {plugin.description}') result = plugin.perform_operation(logger, *args, **kwargs) elif event == plugin.name: logger.info( f'Dispatching event {event} to {plugin.description}') result = plugin.perform_operation(logger, *args, **kwargs) return result
def __init__(self): super(ThreadPool, self).__init__() self.setExpiryTimeout(3000) logger.info('Init Threadpool done.')
def execution(self, function, *args, **kwargs): logger.info('Got a work.') worker = Runnable(function, *args, **kwargs) self.start(worker, 1)