示例#1
0
    def open_addons(self):
        """Open the add-on manager dialog.
        """
        if not hasattr(self, "__f_pypi_addons") or self.__f_pypi_addons is None:
            self.__f_pypi_addons = self.__executor.submit(
                addons.pypi_search,
                oasysconf.addon_pypi_search_spec(),
                timeout=20,
            )

        dlg = addons.AddonManagerDialog(
            self, windowTitle=self.tr("Add-ons"), modal=True)
        dlg.setAttribute(Qt.WA_DeleteOnClose)

        if not hasattr(self, "__addon_items") or self.__addon_items is not None:
            pypi_distributions = self.__f_pypi_addons.result()
            installed = [ep.dist for ep in config.default.addon_entry_points()]
            items = addons.installable_items(pypi_distributions, installed)
            self.__addon_items = items
            dlg.setItems(items)
        else:
            # Use the dialog's own progress dialog
            progress = dlg.progressDialog()
            dlg.show()
            progress.show()
            progress.setLabelText(
                self.tr("Retrieving package list")
            )
            self.__f_pypi_addons.add_done_callback(
                addons.method_queued(self.__on_pypi_search_done, (object,))
            )
            close_dialog = addons.method_queued(dlg.close, ())

            self.__f_pypi_addons.add_done_callback(
                lambda f:
                    close_dialog() if f.exception() else None)

            self.__p_addon_items_available.connect(progress.hide)
            self.__p_addon_items_available.connect(dlg.setItems)

        return dlg.exec_()
示例#2
0
    def open_addons(self):
        """Open the add-on manager dialog.
        """
        if not hasattr(self, "__f_pypi_addons") or self.__f_pypi_addons is None:
            self.__f_pypi_addons = self.__executor.submit(
                addons.pypi_search,
                oasysconf.addon_pypi_search_spec(),
                timeout=20,
            )

        dlg = addons.AddonManagerDialog(
            self, windowTitle=self.tr("Add-ons"), modal=True)
        dlg.setAttribute(Qt.WA_DeleteOnClose)

        if not hasattr(self, "__addon_items") or self.__addon_items is not None:
            pypi_distributions = self.__f_pypi_addons.result()
            installed = [ep.dist for ep in config.default.addon_entry_points()]
            items = addons.installable_items(pypi_distributions, installed)
            self.__addon_items = items
            dlg.setItems(items)
        else:
            # Use the dialog's own progress dialog
            progress = dlg.progressDialog()
            dlg.show()
            progress.show()
            progress.setLabelText(
                self.tr("Retrieving package list")
            )
            self.__f_pypi_addons.add_done_callback(
                addons.method_queued(self.__on_pypi_search_done, (object,))
            )
            close_dialog = addons.method_queued(dlg.close, ())

            self.__f_pypi_addons.add_done_callback(
                lambda f:
                    close_dialog() if f.exception() else None)

            self.__p_addon_items_available.connect(progress.hide)
            self.__p_addon_items_available.connect(dlg.setItems)

        return dlg.exec_()
示例#3
0
    def __init__(self, parent=None, **kwargs):
        super().__init__(parent, **kwargs)
        self.is_main = True
        self.menu_registry = None

        settings = QSettings()
        updateperiod = settings.value("oasys/addon-update-check-period",
                                      defaultValue=1,
                                      type=int)
        try:
            timestamp = os.stat(addons_cache_path()).st_mtime
        except OSError:
            timestamp = 0

        lastdelta = datetime.now() - datetime.fromtimestamp(timestamp)
        self._log = logging.getLogger(__name__)
        self._log.info("Time from last update %s (%s)", lastdelta, timestamp)
        check = updateperiod >= 0 and \
                abs(lastdelta) > timedelta(days=updateperiod)

        self.__executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
        self.__pypi_addons_f = None
        self.__pypi_addons = None
        self.__updatable = 0

        if check:
            f = self.__executor.submit(addons.list_available_versions)
            f.add_done_callback(
                addons.method_queued(self.__set_pypi_addons_f, (object, )))
            self.__pypi_addons_f = f
        else:
            try:
                items = load_pypi_packages()
            except Exception:
                pass
            else:
                self.__set_pypi_addons(items)

        self.automatic_save.connect(self.automatic_save_scheme)

        self.new_action_on_new_window = \
            QAction(self.tr("New on a New Window"), self,
                    objectName="action-new-new-window",
                    toolTip=self.tr("Open a new workflow on a new window."),
                    triggered=self.new_scheme_on_new_window,
                    icon=canvasmain.canvas_icons("New.svg")
                    )

        self.open_action_on_new_window = \
            QAction(self.tr("Open on a New Window"), self,
                    objectName="action-open-new-window",
                    toolTip=self.tr("Open a workflow on a new window."),
                    triggered=self.open_scheme_on_new_window,
                    icon=canvasmain.canvas_icons("Open.svg")
                    )

        file_menu = self.menuBar().children()[-1]

        file_menu.insertAction(file_menu.actions()[2],
                               self.open_action_on_new_window)
        file_menu.insertAction(file_menu.actions()[1],
                               self.new_action_on_new_window)
示例#4
0
    def __init__(self, parent=None, **kwargs):
        super().__init__(parent, **kwargs)
        self.is_main = True
        self.menu_registry = None

        settings = QSettings()
        updateperiod = settings.value(
            "oasys/addon-update-check-period", defaultValue=1, type=int)
        try:
            timestamp = os.stat(addons_cache_path()).st_mtime
        except OSError:
            timestamp = 0

        lastdelta = datetime.now() - datetime.fromtimestamp(timestamp)
        self._log = logging.getLogger(__name__)
        self._log.info("Time from last update %s (%s)", lastdelta, timestamp)
        check = updateperiod >= 0 and \
                abs(lastdelta) > timedelta(days=updateperiod)

        self.__executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
        self.__pypi_addons_f = None
        self.__pypi_addons = None
        self.__updatable = 0

        if check:
            f = self.__executor.submit(
                addons.pypi_search,
                oasysconf.addon_pypi_search_spec(),
                timeout=10
            )
            f.add_done_callback(
                addons.method_queued(self.__set_pypi_addons_f, (object,)))
            self.__pypi_addons_f = f
        else:
            try:
                items = load_pypi_packages()
            except Exception:
                pass
            else:
                self.__set_pypi_addons(items)

        self.automatic_save.connect(self.automatic_save_scheme)

        self.new_action_on_new_window = \
            QAction(self.tr("New on a New Window"), self,
                    objectName="action-new-new-window",
                    toolTip=self.tr("Open a new workflow on a new window."),
                    triggered=self.new_scheme_on_new_window,
                    icon=canvasmain.canvas_icons("New.svg")
                    )

        self.open_action_on_new_window = \
            QAction(self.tr("Open on a New Window"), self,
                    objectName="action-open-new-window",
                    toolTip=self.tr("Open a workflow on a new window."),
                    triggered=self.open_scheme_on_new_window,
                    icon=canvasmain.canvas_icons("Open.svg")
                    )
        if sys.platform == "darwin":
            file_menu = self.menuBar().children()[1]
        else:
            file_menu = self.menuBar().children()[2]

        file_menu.insertAction(file_menu.actions()[2], self.open_action_on_new_window)
        file_menu.insertAction(file_menu.actions()[1], self.new_action_on_new_window)