def welcome_dialog_paged(self): # type: (CanvasMainWindow) -> None """ Show a modal multipaged welcome screen. """ dlg = PagedDialog( self, windowTitle=self.tr("Orange Data Mining"), ) dlg.setWindowModality(Qt.ApplicationModal) dlg.setAttribute(Qt.WA_DeleteOnClose) dlg.layout().setSizeConstraint(QVBoxLayout.SetFixedSize) dlg.setStyleSheet(""" TabView::item:selected { background: rgb(243, 171, 86); } """) main = FancyWelcomeScreen() spec = welcome_screen_specs() if spec.image: background = QImage(spec.image) else: background = QImage("canvas_icons:orange-start-background.png") main.setImage(background) if spec.css: main.setStyleSheet(spec.css) else: main.setStyleSheet( "StartItem { background-color: rgb(123, 164, 214) }") def decorate_icon(icon): return decorate_welcome_icon(icon, "#6dacb2") for i, item in zip(range(3), spec.items): main.setItemText(i, item.text) main.setItemToolTip(i, item.tooltip) main.setItemIcon(i, decorate_icon(QIcon(item.icon))) main.setItemActiveIcon(i, decorate_icon(QIcon(item.active_icon))) main.item(i).setProperty("path", item.path) main.setCurrentIndex(0) main.activated.connect(lambda: openselectedbutton.click()) PageWelcome = dlg.addPage(sc_icon("Welcome.svg"), "Welcome", main) examples_ = examples.workflows(config.default) items = [previewmodel.PreviewItem(path=t.abspath()) for t in examples_] model = previewmodel.PreviewModel(items=items) model.delayedScanUpdate() browser = previewbrowser.PreviewBrowser() browser.setModel(model) PageTemplates = dlg.addPage(sc_icon("Templates.svg"), "Templates", browser) browser.activated.connect(lambda: openselectedbutton.click()) recent = [ previewmodel.PreviewItem(name=item.title, path=item.path) for item in self.recent_schemes ] model = previewmodel.PreviewModel(items=recent) browser = previewbrowser.PreviewBrowser() browser.setModel(model) model.delayedScanUpdate() PageRecent = dlg.addPage(self.recent_action.icon(), "Recent", browser) browser.activated.connect(lambda: openselectedbutton.click()) dlg.setPageEnabled(PageRecent, model.rowCount() > 0) page = SingleLinkPage( image=QImage( resource_path("icons/getting-started-video-tutorials.png")), heading="Getting Started", link=QUrl("https://www.youtube.com/watch?v=3nMcI4Hxm7c"), ) page.setContentsMargins(25, 25, 25, 25) PageGetStarted = dlg.addPage( canvas_icons("YouTube.svg"), "Get Started", page, ) buttons = dlg.buttonBox() buttons.setVisible(True) buttons.setStandardButtons(QDialogButtonBox.Open | QDialogButtonBox.Cancel) # choose the selected workflow button openselectedbutton = buttons.button(QDialogButtonBox.Open) openselectedbutton.setText(self.tr("Open")) openselectedbutton.setToolTip("Open the selected workflow") openselectedbutton.setDefault(True) newbutton = QPushButton("New", toolTip="Create a new workflow") s = QShortcut(QKeySequence.New, newbutton) s.activated.connect(newbutton.click) buttons.addButton(newbutton, QDialogButtonBox.AcceptRole) openexisting = QPushButton("Open Existing\N{HORIZONTAL ELLIPSIS}", toolTip="Open an existing workflow file") s = QShortcut(QKeySequence.Open, dlg) s.activated.connect(openexisting.click) buttons.addButton(openexisting, QDialogButtonBox.AcceptRole) settings = QSettings() show_start_key = "startup/show-welcome-screen" show_start = QCheckBox("Show at startup", checked=settings.value(show_start_key, True, type=bool)) # Abusing ResetRole to push the check box to the left in all button # layouts. buttons.addButton(show_start, QDialogButtonBox.ResetRole) def update_show_at_startup(value): settings.setValue(show_start_key, value) show_start.toggled.connect(update_show_at_startup) def on_page_changed(index): if index == PageWelcome: openselectedbutton.setEnabled(True) elif index == PageTemplates: openselectedbutton.setEnabled(bool(examples)) elif index == PageRecent: openselectedbutton.setEnabled(bool(recent)) elif index == PageGetStarted: openselectedbutton.setEnabled(False) else: openselectedbutton.setEnabled(False) dlg.currentIndexChanged.connect(on_page_changed) def open_example_workflow(path): # open a workflow without filename/directory tracking. wf = self.new_scheme_from(path) if self.is_transient(): window = self else: window = self.create_new_window() window.show() window.raise_() window.activateWindow() window.set_new_scheme(wf) def open_url(url): return QDesktopServices.openUrl(QUrl(url)) def on_clicked(button): current = dlg.currentIndex() path = None open_workflow_file = None if current == PageWelcome: open_workflow_file = open_url elif current == PageTemplates: open_workflow_file = open_example_workflow elif current == PageRecent: open_workflow_file = self.open_scheme_file if button is openselectedbutton and \ current in {PageTemplates, PageRecent}: w = dlg.widget(current) assert isinstance(w, previewbrowser.PreviewBrowser) assert w.currentIndex() != -1 model = w.model() item = model.item(w.currentIndex()) path = item.path() elif button is openselectedbutton and current == PageWelcome: w = dlg.widget(current) assert isinstance(w, FancyWelcomeScreen) assert w.currentIndex() != -1 path = w.item(w.currentIndex()).property("path") if path is not None: open_workflow_file(path) dlg.accept() buttons.clicked.connect(on_clicked) def on_open_existing(): filedlg = self._open_workflow_dialog() filedlg.fileSelected.connect(self.open_scheme_file) filedlg.accepted.connect(dlg.accept) filedlg.exec() openexisting.clicked.connect(on_open_existing) def new_window(): if not self.is_transient(): self.new_workflow_window() dlg.accept() newbutton.clicked.connect(new_window) dlg.show()
def welcome_dialog(self): """ Show a modal welcome dialog for OASYS. Reimplemented from `CanvasMainWindow`. """ dialog = welcomedialog.WelcomeDialog(self) dialog.setWindowTitle(self.tr("Welcome to OASYS")) def new_scheme(): if self.new_scheme() == QDialog.Accepted: dialog.accept() def open_scheme(): if self.open_scheme() == QDialog.Accepted: dialog.accept() def open_recent(): if self.recent_scheme() == QDialog.Accepted: dialog.accept() def tutorial(): import webbrowser webbrowser.open("https://github.com/srio/ShadowOui-Tutorial") #if self.tutorial_scheme() == QDialog.Accepted: # dialog.accept() new_action = \ QAction(self.tr("New"), dialog, toolTip=self.tr("Open a new workflow."), triggered=new_scheme, shortcut=QKeySequence.New, icon=canvasmain.canvas_icons("New.svg") ) open_action = \ QAction(self.tr("Open"), dialog, objectName="welcome-action-open", toolTip=self.tr("Open a workflow."), triggered=open_scheme, shortcut=QKeySequence.Open, icon=canvasmain.canvas_icons("Open.svg") ) recent_action = \ QAction(self.tr("Recent"), dialog, objectName="welcome-recent-action", toolTip=self.tr("Browse and open a recent workflow."), triggered=open_recent, shortcut=QKeySequence(Qt.ControlModifier | \ (Qt.ShiftModifier | Qt.Key_R)), icon=canvasmain.canvas_icons("Recent.svg") ) tutorials_action = \ QAction(self.tr("Tutorial"), dialog, objectName="welcome-tutorial-action", toolTip=self.tr("Browse tutorial workflows."), triggered=tutorial, icon=canvasmain.canvas_icons("Tutorials.svg") ) icon = resource_path("icons/Install.svg") addons_action = \ QAction(self.tr("Add-ons"), dialog, objectName="welcome-addons-action", toolTip=self.tr("Install add-ons"), triggered=self.open_addons, icon=QIcon(icon), ) if self.__updatable: addons_action.setText("Update Now") addons_action.setToolTip("Update or install new add-ons") addons_action.setIcon(QIcon(resource_path("icons/Update.svg"))) mbox = QMessageBox( dialog, icon=QMessageBox.Information, text="{} add-on{} {} a newer version.\n" "Would you like to update now?".format( "One" if self.__updatable == 1 else self.__updatable, "s" if self.__updatable > 1 else "", "has" if self.__updatable == 1 else "have"), standardButtons=QMessageBox.Ok | QMessageBox.No, ) mbox.setWindowFlags(Qt.Sheet | Qt.MSWindowsFixedSizeDialogHint) mbox.setModal(True) dialog.show() mbox.show() mbox.finished.connect(lambda r: self.open_addons() if r == QMessageBox.Ok else None) bottom_row = [ self.get_started_action, tutorials_action, self.documentation_action, addons_action ] self.new_action.triggered.connect(dialog.accept) top_row = [new_action, open_action, recent_action] dialog.addRow(top_row, background="light-grass") dialog.addRow(bottom_row, background="light-orange") # Find and hide the welcome dialogs bottom bar. It contains the # Show at startup" check box and we ALWAYS want the Welcome Dialog # to show. bottombar = dialog.findChild(QWidget, name='bottom-bar') if bottombar is not None: bottombar.hide() status = dialog.exec_() dialog.deleteLater() return status
def welcome_dialog(self): """ Show a modal welcome dialog for OASYS. Reimplemented from `CanvasMainWindow`. """ dialog = welcomedialog.WelcomeDialog(self) dialog.setWindowTitle(self.tr("Welcome to OASYS")) def new_scheme(): if self.new_scheme() == QDialog.Accepted: dialog.accept() def open_scheme(): if self.open_scheme() == QDialog.Accepted: dialog.accept() def open_recent(): if self.recent_scheme() == QDialog.Accepted: dialog.accept() def tutorial(): if self.tutorial_scheme() == QDialog.Accepted: dialog.accept() new_action = \ QAction(self.tr("New"), dialog, toolTip=self.tr("Open a new workflow."), triggered=new_scheme, shortcut=QKeySequence.New, icon=canvasmain.canvas_icons("New.svg") ) open_action = \ QAction(self.tr("Open"), dialog, objectName="welcome-action-open", toolTip=self.tr("Open a workflow."), triggered=open_scheme, shortcut=QKeySequence.Open, icon=canvasmain.canvas_icons("Open.svg") ) recent_action = \ QAction(self.tr("Recent"), dialog, objectName="welcome-recent-action", toolTip=self.tr("Browse and open a recent workflow."), triggered=open_recent, shortcut=QKeySequence(Qt.ControlModifier | \ (Qt.ShiftModifier | Qt.Key_R)), icon=canvasmain.canvas_icons("Recent.svg") ) tutorials_action = \ QAction(self.tr("Tutorial"), dialog, objectName="welcome-tutorial-action", toolTip=self.tr("Browse tutorial workflows."), triggered=tutorial, icon=canvasmain.canvas_icons("Tutorials.svg") ) icon = resource_path("icons/Install.svg") addons_action = \ QAction(self.tr("Add-ons"), dialog, objectName="welcome-addons-action", toolTip=self.tr("Install add-ons"), triggered=self.open_addons, icon=QIcon(icon), ) if self.__updatable: addons_action.setText("Update Now") addons_action.setToolTip("Update or install new add-ons") addons_action.setIcon(QIcon(resource_path("icons/Update.svg"))) mbox = QMessageBox( dialog, icon=QMessageBox.Information, text="{} add-on{} {} a newer version.\n" "Would you like to update now?" .format("One" if self.__updatable == 1 else self.__updatable, "s" if self.__updatable > 1 else "", "has" if self.__updatable == 1 else "have"), standardButtons=QMessageBox.Ok | QMessageBox.No, ) mbox.setWindowFlags(Qt.Sheet | Qt.MSWindowsFixedSizeDialogHint) mbox.setModal(True) dialog.show() mbox.show() mbox.finished.connect( lambda r: self.open_addons() if r == QMessageBox.Ok else None ) bottom_row = [self.get_started_action, tutorials_action, self.documentation_action, addons_action] self.new_action.triggered.connect(dialog.accept) top_row = [new_action, open_action, recent_action] dialog.addRow(top_row, background="light-grass") dialog.addRow(bottom_row, background="light-orange") # Find and hide the welcome dialogs bottom bar. It contains the # Show at startup" check box and we ALWAYS want the Welcome Dialog # to show. bottombar = dialog.findChild(QWidget, name='bottom-bar') if bottombar is not None: bottombar.hide() status = dialog.exec_() dialog.deleteLater() return status
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)
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)