def showMenu(self, pos): self.menu = QMenu() # Add all resource plugins self.actions = {} from xicam.plugins import manager as pluginmanager for plugin in pluginmanager.getPluginsOfCategory("CatalogPlugin") + pluginmanager.getPluginsOfCategory( "DataResourcePlugin"): self.actions[plugin.plugin_object.name] = QAction(plugin.plugin_object.name) self.actions[plugin.plugin_object.name].triggered.connect(partial(self._addBrowser, plugin)) self.menu.addAction(self.actions[plugin.plugin_object.name]) self.menu.popup(pos)
def load_header(uris: List[Union[str, Path]] = None, uuid: str = None): """ Load a document object, either from a file source or a databroker source, by uuid. If loading from a filename, the file will be registered in databroker. Parameters ---------- uris uuid Returns ------- NonDBHeader """ from xicam.plugins import manager as pluginmanager # must be a late import # ext = Path(filename).suffix[1:] # for cls, extensions in extension_map.items(): # if ext in extensions: handlercandidates = [] ext = Path(uris[0]).suffix for plugin in pluginmanager.getPluginsOfCategory('DataHandlerPlugin'): if ext in plugin.plugin_object.DEFAULT_EXTENTIONS: handlercandidates.append(plugin) if not handlercandidates: return NonDBHeader({}, [], [], {}) # try: return NonDBHeader(**handlercandidates[0].plugin_object.ingest(uris))
def __init__(self, workflowview: QAbstractItemView): super(WorkflowWidget, self).__init__() self.view = workflowview self.toolbar = QToolBar() addfunctionmenu = QToolButton() functionmenu = QMenu() for plugin in pluginmanager.getPluginsOfCategory('ProcessingPlugin'): functionmenu.addAction( plugin.name, partial(self.addProcess, plugin.plugin_object, autoconnectall=True)) addfunctionmenu.setMenu(functionmenu) addfunctionmenu.setIcon(QIcon(path('icons/addfunction.png'))) addfunctionmenu.setText('Add Function') addfunctionmenu.setPopupMode(QToolButton.InstantPopup) self.toolbar.addWidget(addfunctionmenu) # self.toolbar.addAction(QIcon(path('icons/up.png')), 'Move Up') # self.toolbar.addAction(QIcon(path('icons/down.png')), 'Move Down') self.toolbar.addAction(QIcon(path('icons/folder.png')), 'Load Workflow') self.toolbar.addAction(QIcon(path('icons/trash.png')), 'Clear Workflow') v = QVBoxLayout() v.addWidget(self.view) v.addWidget(self.toolbar) v.setContentsMargins(0, 0, 0, 0) self.setLayout(v)
def __init__(self): # # Enforce global style within the console # with open('xicam/gui/style.stylesheet', 'r') as f: # style = f.read() # style = (qdarkstyle.load_stylesheet() + style) # Setup the kernel self.kernel_manager = QtInProcessKernelManager() self.kernel_manager.start_kernel() kernel = self.kernel_manager.kernel kernel.gui = 'qt' # Push Xi-cam variables into the kernel kernel.shell.push({ plugin.name: plugin for plugin in pluginmanager.getPluginsOfCategory("GUIPlugin") + pluginmanager.getPluginsOfCategory("EZPlugin") }) # Observe plugin changes pluginmanager.attach(self.pluginsChanged) # Continue kernel setuppluginmanager.getPluginsOfCategory("GUIPlugin") self.kernel_client = self.kernel_manager.client() threads.invoke_in_main_thread(self.kernel_client.start_channels) # Setup console widget def stop(): self.kernel_client.stop_channels() self.kernel_manager.shutdown_kernel() control = RichJupyterWidget() control.kernel_manager = self.kernel_manager threads.invoke_in_main_thread(setattr, control, "kernel_client", self.kernel_client) control.exit_requested.connect(stop) # control.style_sheet = style control.syntax_style = u'monokai' control.set_default_style(colors='Linux') # Setup layout self.stages = {'Terminal': GUILayout(control)} # Save for later self.kernel = kernel super(IPythonPlugin, self).__init__()
def load_header(uris: List[Union[str, Path]] = None, uuid: str = None): """ Load a document object, either from a file source or a databroker source, by uuid. If loading from a filename, the file will be registered in databroker. Parameters ---------- uris uuid Returns ------- NonDBHeader """ from xicam.plugins import manager as pluginmanager # must be a late import # ext = Path(filename).suffix[1:] # for cls, extensions in extension_map.items(): # if ext in extensions: # First try to see if we have a databroker ingestor, then fall-back to Xi-cam DataHandlers ingestor = None filename = str(Path(uris[0])) mimetype = None try: mimetype = detect_mimetype(filename) except UnknownFileType as e: msg.logMessage(f"{e}", msg.WARNING) else: msg.logMessage(f'Mimetype detected: {mimetype}') try: ingestor = choose_ingestor(filename, mimetype) except NoIngestor as e: warn(f"{e}. Falling-back to DataHandlers") else: msg.logMessage(f'Ingestor selected: {ingestor}') if ingestor: document = list(ingestor(uris)) uid = document[0][1]["uid"] catalog = BlueskyInMemoryCatalog() # TODO -- change upsert signature to put start and stop as kwargs # TODO -- ask about more convenient way to get a BlueskyRun from a document generator catalog.upsert(document[0][1], document[-1][1], ingestor, [uris], {}) return catalog[uid] handlercandidates = [] ext = Path(uris[0]).suffix for plugin in pluginmanager.getPluginsOfCategory("DataHandlerPlugin"): if ext in plugin.DEFAULT_EXTENTIONS: handlercandidates.append(plugin) if not handlercandidates: return NonDBHeader({}, [], [], {}) # try: msg.logMessage(f'Handler selected: {handlercandidates[0]}') return NonDBHeader(**handlercandidates[0].ingest(uris))
def createIcons(self): self.contentsModel.clear() for pluginInfo in pluginmanager.getPluginsOfCategory("SettingsPlugin"): item = QStandardItem(pluginInfo.plugin_object.icon, pluginInfo.plugin_object.name()) item.widget = pluginInfo.plugin_object.widget item.setTextAlignment(Qt.AlignHCenter) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) item.setSizeHint(QSize(136, 80)) self.contentsModel.appendRow(item)
def __call__(self, pluginname, internaldata): from xicam.plugins import manager as pluginmanager # if pluginmanager hasn't collected plugins yet, then do it if not pluginmanager.loadcomplete and not pluginmanager.loading: pluginmanager.collectPlugins() # look for the plugin matching the saved name and re-instance it for plugin in pluginmanager.getPluginsOfCategory("ProcessingPlugin"): if plugin.__name__ == pluginname: p = plugin() p.__dict__ = internaldata return p pluginlist = "\n\t".join( [plugin.__name__ for plugin in pluginmanager.getPluginsOfCategory("ProcessingPlugin")] ) raise ValueError(f"No plugin found with name {pluginname} in list of plugins:{pluginlist}")
def restore(self): try: for pluginInfo in pluginmanager.getPluginsOfCategory( 'SettingsPlugin'): pluginInfo.plugin_object.restore(QSettings().value( pluginInfo.name)) except (AttributeError, TypeError, SystemError): # No settings saved pass self.apply()
def _build_nodes(self): self._nodes = [] for plugin in pluginmanager.getPluginsOfCategory("GUIPlugin"): node = Node(plugin, plugin.plugin_object.name) for name, stage in plugin.plugin_object.stages.items(): node.children.append( self._build_subnodes(name, stage, parent=node)) self._nodes.append(node)
def showMenu(self, pos): self.menu = QMenu() # Add all resource plugins self.actions = {} for plugin in pluginmanager.getPluginsOfCategory('DataResourcePlugin'): self.actions[plugin.name] = QAction(plugin.name) self.actions[plugin.name].triggered.connect( partial(self._addBrowser, plugin)) self.menu.addAction(self.actions[plugin.name]) self.menu.popup(pos)
def showGUIPlugins(self): plugins = pluginmanager.getPluginsOfCategory('GUIPlugin') # TODO: test deactivated plugins names = [ plugin.name for plugin in plugins if hasattr(plugin, 'is_activated') and ( plugin.is_activated or True) ] self.fadeOut(callback=partial(self.mkButtons, names=names, callback=self.showStages), distance=20)
def populateFunctionMenu(self): self.functionmenu.clear() sortingDict = {} for plugin in pluginmanager.getPluginsOfCategory("ProcessingPlugin"): typeOfProcessingPlugin = plugin.plugin_object.getCategory() if not typeOfProcessingPlugin in sortingDict.keys(): sortingDict[typeOfProcessingPlugin] = [] sortingDict[typeOfProcessingPlugin].append(plugin) for key in sortingDict.keys(): self.functionmenu.addSeparator() self.functionmenu.addAction(key) self.functionmenu.addSeparator() for plugin in sortingDict[key]: self.functionmenu.addAction(plugin.name, partial(self.addProcess, plugin.plugin_object, autoconnectall=True))
def __call__(self, pluginname, internaldata): from xicam.plugins import manager as pluginmanager # if pluginmanager hasn't collected plugins yet, then do it if not pluginmanager.loadcomplete: pluginmanager.collectPlugins() # look for the plugin matching the saved name and re-instance it for plugin in pluginmanager.getPluginsOfCategory('ProcessingPlugin'): if plugin.plugin_object.__name__ == pluginname: p = plugin.plugin_object() p.__dict__ = internaldata return p raise ValueError(f'No plugin found with name {pluginname}')
def __init__(self, workflowview: QAbstractItemView): super(WorkflowWidget, self).__init__() self.view = workflowview self.toolbar = QToolBar() addfunctionmenu = QToolButton() functionmenu = QMenu() sortingDict = {} for plugin in pluginmanager.getPluginsOfCategory("ProcessingPlugin"): typeOfProcessingPlugin = plugin.plugin_object.getCategory() if not typeOfProcessingPlugin in sortingDict.keys(): sortingDict[typeOfProcessingPlugin] = [] sortingDict[typeOfProcessingPlugin].append(plugin) for key in sortingDict.keys(): functionmenu.addSeparator() functionmenu.addAction(key) functionmenu.addSeparator() for plugin in sortingDict[key]: functionmenu.addAction( plugin.name, partial(self.addProcess, plugin.plugin_object, autoconnectall=True)) addfunctionmenu.setMenu(functionmenu) addfunctionmenu.setIcon(QIcon(path("icons/addfunction.png"))) addfunctionmenu.setText("Add Function") addfunctionmenu.setPopupMode(QToolButton.InstantPopup) self.toolbar.addWidget(addfunctionmenu) # self.toolbar.addAction(QIcon(path('icons/up.png')), 'Move Up') # self.toolbar.addAction(QIcon(path('icons/down.png')), 'Move Down') self.toolbar.addAction(QIcon(path("icons/folder.png")), "Load Workflow") self.toolbar.addAction(QIcon(path("icons/trash.png")), "Delete Operation", self.deleteProcess) v = QVBoxLayout() v.addWidget(self.view) v.addWidget(self.toolbar) v.setContentsMargins(0, 0, 0, 0) self.setLayout(v)
def __init__(self): super(AstropyQSpectraFit, self).__init__() self.model.limits = {plugin.name: plugin.plugin_object for plugin in pluginmanager.getPluginsOfCategory('Fittable1DModelPlugin')} self.model.value = list(self.model.limits.values())[0]
def apply(self): for pluginInfo in pluginmanager.getPluginsOfCategory('SettingsPlugin'): QSettings().setValue(pluginInfo.name, pluginInfo.plugin_object.save())
def setGUIPlugin(self, i: int): self.currentGUIPlugin = pluginmanager.getPluginsOfCategory( 'GUIPlugin')[i]
def __init__(self): super(XicamMainWindow, self).__init__() # Set icon self.setWindowIcon(QIcon(QPixmap(str(path('icons/xicam.gif'))))) # Set size and position self.setGeometry(0, 0, 1000, 600) frameGm = self.frameGeometry() screen = QApplication.desktop().screenNumber( QApplication.desktop().cursor().pos()) centerPoint = QApplication.desktop().screenGeometry(screen).center() frameGm.moveCenter(centerPoint) self.move(frameGm.topLeft()) # Init child widgets to None self.topwidget = self.leftwidget = self.rightwidget = self.bottomwidget = self.lefttopwidget = \ self.righttopwidget = self.leftbottomwidget = self.rightbottomwidget = None # Setup appearance self.setWindowTitle('Xi-cam') # Restore Settings ConfigDialog().restore() # Load plugins pluginmanager.collectPlugins() # Setup center/toolbar/statusbar/progressbar self.pluginmodewidget = pluginModeWidget() self.pluginmodewidget.sigSetStage.connect(self.setStage) self.pluginmodewidget.sigSetGUIPlugin.connect(self.setGUIPlugin) self.addToolBar(self.pluginmodewidget) self.setStatusBar(QStatusBar(self)) msg.progressbar = QProgressBar(self) msg.progressbar.hide() msg.statusbar = self.statusBar() self.statusBar().addPermanentWidget(msg.progressbar) self.setCentralWidget(QStackedWidget()) # NOTE: CentralWidgets are force-deleted when replaced, even if the object is still referenced; # To avoid this, a QStackedWidget is used for the central widget. # Setup menubar menubar = self.menuBar() file = QMenu('&File', parent=menubar) menubar.addMenu(file) file.addAction('Se&ttings', self.showSettings, shortcut=QKeySequence(Qt.CTRL + Qt.ALT + Qt.Key_S)) file.addAction('E&xit', self.close) help = QMenu('&Help', parent=menubar) menubar.addMenu(help) # Initialize layout with first plugin self._currentGUIPlugin = None self.build_layout() if pluginmanager.getPluginsOfCategory("GUIPlugin"): # self._currentGUIPlugin = pluginmanager.getPluginsOfCategory("GUIPlugin")[0] self.populate_layout() # Make F key bindings fkeys = [ Qt.Key_F1, Qt.Key_F2, Qt.Key_F3, Qt.Key_F4, Qt.Key_F5, Qt.Key_F6, Qt.Key_F7, Qt.Key_F8, Qt.Key_F9, Qt.Key_F10, Qt.Key_F11, Qt.Key_F12 ] self.Fshortcuts = [QShortcut(QKeySequence(key), self) for key in fkeys] for i in range(12): self.Fshortcuts[i].activated.connect(partial(self.setStage, i)) # Wireup default widgets defaultstage['left'].sigOpen.connect(self.open) defaultstage['left'].sigOpen.connect(print) defaultstage['left'].sigPreview.connect( defaultstage['lefttop'].preview_header)
def apply(self): for pluginInfo in pluginmanager.getPluginsOfCategory("SettingsPlugin"): pluginInfo.plugin_object.save()
def restore(self): for pluginInfo in pluginmanager.getPluginsOfCategory("SettingsPlugin"): pluginInfo.plugin_object.restore() self.apply()
def pluginsChanged(self): self.kernel.shell.push({ plugin.name: plugin for plugin in pluginmanager.getPluginsOfCategory("GUIPlugin") + pluginmanager.getPluginsOfCategory("EZPlugin") })