def generate_output(self):

        if len(self.plugin_name.text()) == 0:
            QMessageBox.information(self.plugin_maker,
                                    "Please enter plugin name",
                                    "Please enter a plugin name")
            return

        path = str(
            QFileDialog.getExistingDirectory(self.plugin_maker,
                                             "Select Directory"))
        print("PATH", path)

        plugin_name = self.plugin_name
        plugin_type = self.plugin_type.currentText()

        extra_content = dict()

        extra_content["package_name"] = plugin_name.text()
        extra_content["display_name"] = plugin_name.text().title(
        ) + " (Xi-cam PluginMaker)"
        extra_content[
            "plugin_version"] = self.plugin_generator.plugin_version.text()
        extra_content["plugin_file_name"] = "__init__.py"
        extra_content["author_name"] = self.plugin_generator.author_name.text()
        extra_content[
            "author_email"] = self.plugin_generator.author_email.text()
        extra_content["author_url"] = self.plugin_generator.author_url.text()
        extra_content[
            "description"] = self.plugin_generator.description.toPlainText()
        extra_content["keywords"] = self.plugin_generator.keywords.text()

        dep_list = []
        for dep_index in range(self.plugin_generator.dependency_list.count()):
            dep_list.append(
                self.plugin_generator.dependency_list.item(dep_index).text())

        extra_content["dependencies"] = "\n".join(dep_list)

        extra_content[
            "plugin_code"] = self.gui_generator.generate_stream_output()
        extra_content[
            "stages_code"] = self.gui_generator.generate_stream_stages()
        extra_content["yapsy_ext"] = "yapsy-plugin"

        print(extra_content)

        # my_path = os.path.dirname(os.path.realpath(__file__)) + os.path.sep + "cookiecutter-pipproject"
        my_path = "https://github.com/lbl-camera/Xi-cam.templates.GuiPlugin"

        cookiecutter(my_path,
                     no_input=True,
                     overwrite_if_exists=True,
                     output_dir=path,
                     extra_context=extra_content)

        from xicam.plugins import manager

        manager.collectPlugins()
Exemple #2
0
def install(name: str):
    """
    Install a Xi-cam plugin package by querying the Xi-cam package repository with REST.

    Packages are installed into the currently active virtualenv

    Parameters
    ----------
    name : str
        The package name to be installed.
    """
    # TODO: test if installed
    # TODO: check if package is in repo

    # Get install plugin package information from cam-mart repository
    o = requests.get(f'http://cam.lbl.gov:5000/pluginpackages?where={{"name":"{name}"}}')

    # Get the uri from the plugin package information
    uri = parse.urlparse(json.loads(o.content)["_items"][0]["installuri"])

    failure = True

    print("Installing to:", venvs.current_environment)

    # Install from the uri
    if uri.scheme == "pipgit":  # Clones a git repo and installs with pip
        failure = pipmain(
            [
                "install",
                # f'--target={os.path.join(venvs.current_environment,"Lib/site-packages")}',
                "git+https://" + "".join(uri[1:]),
            ]
        )
    elif uri.scheme == "pip":
        failure = pipmain(
            [
                "install",
                # f'--target={os.path.join(venvs.current_environment,"Lib/site-packages")}',
                "".join(uri[1:]),
            ]
        )
    elif uri.scheme == "conda":
        raise NotImplementedError

    if not failure:
        pkg_registry[name] = uri.scheme

    from xicam.plugins import manager

    manager.collectPlugins()
    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 __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}")
Exemple #5
0
    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")

        # Load plugins
        pluginmanager.collectPlugins()

        # Restore Settings
        self._configdialog = ConfigDialog()
        self._configdialog.restore()

        # 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 = DebuggableMenuBar()
        self.setMenuBar(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()

        # 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))

        self.readSettings()
        # Wireup default widgets
        defaultstage["left"].sigOpen.connect(self.open)
        defaultstage["left"].sigOpen.connect(print)
        defaultstage["left"].sigPreview.connect(
            defaultstage["lefttop"].preview)