def __init__(self, parent=None): QMenu.__init__(self, parent) self.options = {} system_tray_menu = [ (self.START, lambda: agent_manager("start")), (self.STOP, lambda: agent_manager("stop")), (self.RESTART, lambda: agent_manager("restart")), ] # First the version self.addAction(self.ABOUT.format(get_version())).setEnabled(False) self.addSeparator() for name, action in system_tray_menu: self.add_option(name, action) # enable or disable mac login if Platform.is_mac(): self.add_option(self.MAC_LOGIN.format(self.enable_or_disable_mac()), lambda: self.enable_or_disable_login()) elif Platform.is_windows(): self.add_option(self.FLARE, lambda: thread.start_new_thread(windows_flare, ())) # And finally the exit self.add_option(self.EXIT, lambda: sys.exit(0)) self.connect(self, SIGNAL("aboutToShow()"), lambda: self.update_options())
def __init__(self, parent=None): QMenu.__init__(self, parent) self.options = {} system_tray_menu = [ (self.START, lambda: agent_manager("start")), (self.STOP, lambda: agent_manager("stop")), (self.RESTART, lambda: agent_manager("restart")), ] # First the version self.addAction(self.ABOUT.format(get_version())).setEnabled(False) self.addSeparator() for name, action in system_tray_menu: self.add_option(name, action) # enable or disable mac login if Platform.is_mac(): self.add_option( self.MAC_LOGIN.format(self.enable_or_disable_mac()), lambda: self.enable_or_disable_login()) # And finally the exit self.add_option(self.EXIT, lambda: sys.exit(0)) self.connect(self, SIGNAL("aboutToShow()"), lambda: self.update_options())
def __init__(self): QMainWindow.__init__(self) self.setWindowIcon(get_icon(os.path.join(APP_RESOURCES, 'icons', 'python.png'))) self.setupUi(self) # Redirect output to GUI's QTextEdit sys.stdout = OutLog(self.outputTextEdit, sys.stdout) sys.stderr = OutLog(self.outputTextEdit, sys.stderr, QColor(255,0,0) ) settings = QSettings() size = settings.value("MainWindow/Size", QVariant(QSize(600, 500))).toSize() self.resize(size) position = settings.value("MainWindow/Position", QVariant(QPoint(0, 0))).toPoint() self.move(position) self.restoreState( settings.value("MainWindow/State").toByteArray()) self.logger = Logger('Zupport.GUIloader') self.logger.debugging = settings.value("Logging/debugging").toBool() # Set up a ZupportManager to deal with the plugins self.manager = Manager(self) self.plugins = {} # Set up the extents menu self.extent = ExtentContainer() self.menuExtent = QMenu("Extent") resolutions = self.extent.resolutions self.extenactiongroup = QActionGroup(self.menuExtent) noneaction = QAction("None", self.menuExtent) self.extenactiongroup.addAction(noneaction) self.menuExtent.addAction(noneaction) for resolution in resolutions: resolution_text = str(resolution) submenu = self.menuExtent.addMenu(resolution_text) self.menuExtent.addMenu(submenu) for area in self.extent.get_names(resolution): subaction = QAction(str(area) + ": %s" % resolution_text, submenu) subaction.setCheckable(True) self.extenactiongroup.addAction(subaction) submenu.addAction(subaction) noneaction.isChecked() self.menuSettings.addMenu(self.menuExtent) self.actionDebugging_messages.setChecked(self.logger.debugging) self.setWindowTitle("Zupport GUI") self.load_tools() self.toolTreeWidget.itemSelectionChanged.connect(self.update_ui) self.actionDebugging_messages.toggled.connect(self._set_debugging) self.menuExtent.triggered.connect(self.update_ui) self.actionLoad_tool.triggered.connect(self.show_tool_gui) self.toolTreeWidget.doubleClicked.connect(self.show_tool_gui)
def __init__(self, settings, parent=None): QMenu.__init__(self, parent) self.options = {} for name, action in settings: menu_action = self.addAction(name) self.connect(menu_action, SIGNAL("triggered()"), action) self.options[name] = menu_action
def __init__(self, settings, parent=None,): QMenu.__init__(self, parent) self.options = {} for name, action in settings: menu_action = self.addAction(name) self.connect(menu_action, SIGNAL('triggered()'), action) self.options[name] = menu_action
def __init__(self, parent=None, ): QMenu.__init__(self, parent) self.options = {} for name, action in SYSTEM_TRAY_MENU: menu_action = self.addAction(name) self.connect(menu_action, SIGNAL('triggered()'), action) self.options[name] = menu_action self.connect(self, SIGNAL("aboutToShow()"), lambda: self.update_options())
def __init__(self, imanager): QObject.__init__(self) self._plmanager = None self._cpmanager = None self._immanager = imanager self._algorithms = [] self._algolist = dict() self._menu = QMenu(_("Algorithms")) self.init_plugin_manager() self.get_actions() self.get_widgets() self._databases = dict() pass
def get_context_menu(self, plot=None): """ Return widget context menu -- built using active tools """ if plot is None: plot = self.get_plot() menu = QMenu(plot) self.update_tools_status(plot) for tool in self.tools: tool.setup_context_menu(menu, plot) return menu
class MainWindow(QMainWindow, Ui_MainWindow): '''Mainwindow for initial loading of different plugins. ''' def __init__(self): QMainWindow.__init__(self) self.setWindowIcon(get_icon(os.path.join(APP_RESOURCES, 'icons', 'python.png'))) self.setupUi(self) # Redirect output to GUI's QTextEdit sys.stdout = OutLog(self.outputTextEdit, sys.stdout) sys.stderr = OutLog(self.outputTextEdit, sys.stderr, QColor(255,0,0) ) settings = QSettings() size = settings.value("MainWindow/Size", QVariant(QSize(600, 500))).toSize() self.resize(size) position = settings.value("MainWindow/Position", QVariant(QPoint(0, 0))).toPoint() self.move(position) self.restoreState( settings.value("MainWindow/State").toByteArray()) self.logger = Logger('Zupport.GUIloader') self.logger.debugging = settings.value("Logging/debugging").toBool() # Set up a ZupportManager to deal with the plugins self.manager = Manager(self) self.plugins = {} # Set up the extents menu self.extent = ExtentContainer() self.menuExtent = QMenu("Extent") resolutions = self.extent.resolutions self.extenactiongroup = QActionGroup(self.menuExtent) noneaction = QAction("None", self.menuExtent) self.extenactiongroup.addAction(noneaction) self.menuExtent.addAction(noneaction) for resolution in resolutions: resolution_text = str(resolution) submenu = self.menuExtent.addMenu(resolution_text) self.menuExtent.addMenu(submenu) for area in self.extent.get_names(resolution): subaction = QAction(str(area) + ": %s" % resolution_text, submenu) subaction.setCheckable(True) self.extenactiongroup.addAction(subaction) submenu.addAction(subaction) noneaction.isChecked() self.menuSettings.addMenu(self.menuExtent) self.actionDebugging_messages.setChecked(self.logger.debugging) self.setWindowTitle("Zupport GUI") self.load_tools() self.toolTreeWidget.itemSelectionChanged.connect(self.update_ui) self.actionDebugging_messages.toggled.connect(self._set_debugging) self.menuExtent.triggered.connect(self.update_ui) self.actionLoad_tool.triggered.connect(self.show_tool_gui) self.toolTreeWidget.doubleClicked.connect(self.show_tool_gui) def closeEvent(self, event): settings = QSettings() settings.setValue("Logging/debugging", self.logger.debugging) settings.setValue("MainWindow/Size", QVariant(self.size())) settings.setValue("MainWindow/Position", QVariant(self.pos())) settings.setValue("MainWindow/State", QVariant(self.saveState())) def load_tools(self): plugins = self.manager.plugins for name, plugin in plugins.iteritems(): item = QTreeWidgetItem(QStringList(name.capitalize())) tool_items = [] for tool_name in plugin.tool_names(): tool_items.append(QTreeWidgetItem(QStringList(tool_name))) item.addChildren(tool_items) self.toolTreeWidget.addTopLevelItem(item) item.setExpanded(True) self.statusbar.showMessage("Succesfully loaded %s plugins" % len(plugins), 4000) def show_tool_gui(self): selected_tool = self.toolListWidget.currentItem() toolname = str(selected_tool.text()) parameters = self.manager.plugins[toolname] # Check if extent is available extent = self.extenactiongroup.checkedAction() if extent: extent = str(extent.text()) # Extent is a String of the form "area: resolution" area, resolution = extent.split(':') resolution = int(resolution) self.extent.resolution = resolution # This is a list of coordinates coordinates = self.extent.get_extent(area) # Create a string for the GUI coord_text = ', '.join([str(coord) for coord in coordinates]) self.manager.plugins[toolname].set_parameter_value('extent', coord_text) dataset = ToolLoader(toolname, parameters) if dataset.edit(): self.logger.debug('User pressed OK, proceeding to execution') self.manager.plugins[toolname] = dataset.get_parameters() # Run the tool if self.actionArcGIS.isChecked(): backend = 'arcgis' else: backend = 'osgeo' else: self.logger.debug('User pressed cancel') return self.manager.executetool(toolname, backend) def update_ui(self): if self.toolTreeWidget.currentItem(): self.actionLoad_tool.setEnabled(True) selected_tool = str(self.toolTreeWidget.currentItem().text(0)) help_text = self.manager.plugins[selected_tool].help self.helpTextEdit.setText(help_text) extent = self.extenactiongroup.checkedAction() if extent: self.extentLabel.setText("Current extent: %s" % extent.text()) @Slot() def on_actionAbout_triggered(self): QMessageBox.about(self, "About Zupport GUI", """<b>Zupport GUI</b> v %s <p>Copyright © 2011 Joona Lehtomaki <*****@*****.**>. All rights reserved. <p>Support zools for Zonation related pre- and post-processing operations.</p> <p>Python %s - Qt %s - PySide %s on %s</p>""" % ( __version__, platform.python_version(), QT_VERSION, PYQT_VERSION, platform.system())) @Slot() def on_actionOpen_log_triggered(self): logfile = os.path.join(USER_DATA_DIR, 'zupport.log') if os.path.exists(logfile): import webbrowser webbrowser.open(logfile) self.logger.debug('Opened log file %s' % logfile) else: msg = "Zupport log file cannot be found in default location %s" % os.path.dirname(logfile) self.logger.debug(msg) QMessageBox.warning(self, "File not found", msg, buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton) def _set_debugging(self, toggle): self.logger.debugging = toggle
class AlgorithmsManager(QObject): def __init__(self, imanager): QObject.__init__(self) self._plmanager = None self._cpmanager = None self._immanager = imanager self._algorithms = [] self._algolist = dict() self._menu = QMenu(_("Algorithms")) self.init_plugin_manager() self.get_actions() self.get_widgets() self._databases = dict() pass def databases_list(self): return self._databases.keys() def database_settings(self, name, settings_type): return self._databases.get(name) def algorithms_menu(self): return self._menu def algorithms_settings(self): return self._algorithms def algorithms_list(self): return self._algolist.keys() def get_actions(self): for plugin_info in self._plmanager.getAllPlugins(): if plugin_info.is_activated: actions = plugin_info.plugin_object.get_algorithms_actions( self._menu) for action in actions: if action and isinstance(action, QAction): self._menu.addAction(action) if action and isinstance(action, QMenu): self._menu.addMenu(action) algo_list = plugin_info.plugin_object.get_algorithms_list() for algo in algo_list: self._algolist[algo] = plugin_info.plugin_object def get_widgets(self): for plugin_info in self._plmanager.getAllPlugins(): if plugin_info.is_activated: widgets = plugin_info.plugin_object.get_interfaces() if widgets: for widget in widgets: if widget: self._algorithms.append(widget) def algosettings(self, name): plugin = self._algolist.get(name) if plugin is not None: return plugin.settings(name) return None def apply_algorithm(self, name, settings=dict()): plugin = self._algolist.get(name) if plugin is not None: return plugin.apply(name, settings) return None def init_plugin_manager(self): # Configuring plugin locator plugin_locator = PluginFileLocator() plugin_locator.setPluginPlaces(PLUGIN_PLACES) # Initializing plugin manager... # categories_filter={"Default": IPlugin, "Custom": ICustomPlugin}, self._plmanager = PluginManager( categories_filter={"Default": IAlgorithmPlugin}, plugin_locator=plugin_locator) # decorate plugin manager with configurable feature self._cpmanager = ConfigurablePluginManager( decorated_manager=self._plmanager) # create parser for config file config_parser = ConfigParser() # set config file location config_parser.read(get_config_file_path()) # set parser to configurable decorator self._cpmanager.setConfigParser( configparser_instance=config_parser, config_change_trigger=config_change_trigger) # plugin_manager.collectPlugins() # configurable_plugin_manager.loadPlugins() self._cpmanager.collectPlugins() self.plugins_info() for plugin_info in self._plmanager.getAllPlugins(): if plugin_info.is_activated: plugin_info.plugin_object.set_image_manager(self._immanager) def plugins_info(self): # Output of various information and activation of each plugin for plugin_info in self._plmanager.getAllPlugins(): print "Loading plugin '%s' ..." % plugin_info.name # configurable_plugin_manager.activatePluginByName(plugin_info.name) print " name : %s" % plugin_info.name print " path : %s" % plugin_info.path print " version : %s" % plugin_info.version print " author : %s" % plugin_info.author print " copyright : %s" % plugin_info.copyright print " website : %s" % plugin_info.website print " description : %s" % plugin_info.description print " details : %s" % plugin_info.details print " is Activated : %s" % plugin_info.is_activated print " categories : %s" % plugin_info.categories print " plugin object : %s" % plugin_info.plugin_object print " error : %s" % plugin_info.error