def new_scheme_from(self, filename): """ Reimplemented from `CanvasMainWindow.new_scheme_from`. Create and return a new :class:`WidgetsScheme` from `filename`. Return `None` if an error occurs or the user aborts the process. """ log = logging.getLogger(__name__) default_workdir = QSettings().value("output/default-working-directory", os.path.expanduser("~/Oasys"), type=str) default_units = QSettings().value("output/default-units", 1, type=int) try: contents = io.BytesIO(open(filename, "rb").read()) doc = ElementTree.parse(contents) root = doc.getroot() workdir = root.get("working_directory") workunits = root.get("workspace_units") title = root.get("title", "untitled") # First parse the contents into intermediate representation # to catch format errors early (will be re-parsed later). try: readwrite.parse_ows_etree_v_2_0(doc) except Exception: message_critical( self.tr("Could not load an Orange Workflow file"), title=self.tr("Error"), informative_text=self.tr("An unexpected error occurred " "while loading '%s'.") % filename, exc_info=True, parent=self) return None readwrite.parse_ows_etree_v_2_0(doc) except Exception: return None # ensure we have a valid working directory either default or # stored. if not workdir or not os.path.isdir(workdir): new_workdir = QFileDialog.getExistingDirectory( self, "Set working directory for project '%s'" % (title or "untitled"), default_workdir) if new_workdir: workdir = new_workdir else: log.info( "Replacement of not existing Working Directory " "'%s' aborted by user", workdir) message_information( "Working directory not set by user:\n\n" "project load aborted", parent=self) return None else: ret = message_question( "Working directory set to:\n\n" + workdir, "Working Directory", informative_text="Do you want to change it?", buttons=QMessageBox.Yes | QMessageBox.No, default_button=QMessageBox.No, parent=self) if ret == QMessageBox.Yes: new_wd = QFileDialog.getExistingDirectory( self, "Set working directory for project '%s'" % (title or "untitled"), default_workdir) if new_wd: workdir = new_wd if not os.path.isdir(workdir): os.mkdir(workdir) else: log.info( "Replacement of not existing Working Directory " "'%s' aborted by user.", workdir) message_information( "Working directory not set by user:\n\n" "project load aborted", parent=self) return None # now start the actual load with a valid working directory log.info("Changing current work dir to '%s'", workdir) os.chdir(workdir) # ensure we have a valid working directory either default or # stored. if workunits is None: new_units = OptionDialog.get_option( self, "Set user's units for project '%s'" % (title or "untitled"), "Set user's units", ["m", "cm", "mm"], default_units) if not new_units is None: workunits = new_units else: log.info( "Replacement of not existing User's Units " "'%s' aborted by user", "") message_information( "Project units not set by user:\n\n" "project load aborted", parent=self) return None else: workunits = int(workunits) ret = message_question( "User's units set to: " + self.getWorkspaceUnitsLabel(workunits), "User's Units", informative_text="Do you want to change it?", buttons=QMessageBox.Yes | QMessageBox.No, default_button=QMessageBox.No, parent=self) if ret == QMessageBox.Yes: new_units = OptionDialog.get_option( self, "Set user's units for project '%s'" % (title or "untitled"), "Set user's units", ["m", "cm", "mm"], workunits) if not new_units is None: workunits = new_units message_information( "Project new units set by user: "******"\n\nWarning: values relating to the previous units are not converted", parent=self) else: log.info( "Replacement of existing User's Units " "'%s' aborted by user", "") message_information( "Project units not set by user:\n\n" "project load aborted", parent=self) return None new_scheme = widgetsscheme.OASYSWidgetsScheme(parent=self) new_scheme.working_directory = workdir new_scheme.workspace_units = workunits errors = [] contents.seek(0) try: readwrite.scheme_load(new_scheme, contents, error_handler=errors.append) except Exception: message_critical( self.tr("Could not load an Orange Workflow file"), title=self.tr("Error"), informative_text=self.tr("An unexpected error occurred " "while loading '%s'.") % filename, exc_info=True, parent=self) return None if errors: message_warning( self.tr("Errors occurred while loading the workflow."), title=self.tr("Problem"), informative_text=self.tr("There were problems loading some " "of the widgets/links in the " "workflow."), details="\n".join(map(repr, errors)), parent=self) return new_scheme
def new_scheme_from(self, filename): """ Reimplemented from `CanvasMainWindow.new_scheme_from`. Create and return a new :class:`WidgetsScheme` from `filename`. Return `None` if an error occurs or the user aborts the process. """ log = logging.getLogger(__name__) default_workdir = QSettings().value( "output/default-working-directory", os.path.expanduser("~/Oasys"), type=str) contents = io.BytesIO(open(filename, "rb").read()) doc = ElementTree.parse(contents) root = doc.getroot() workdir = root.get("working_directory") title = root.get("title", "untitled") # First parse the contents into intermediate representation # to catch format errors early (will be re-parsed later). try: readwrite.parse_ows_etree_v_2_0(doc) except Exception: message_critical( self.tr("Could not load an Orange Workflow file"), title=self.tr("Error"), informative_text=self.tr("An unexpected error occurred " "while loading '%s'.") % filename, exc_info=True, parent=self) return None # ensure we have a valid working directory either default or # stored. if not workdir or not os.path.isdir(workdir): new_workdir = QFileDialog.getExistingDirectory( self, "Set working directory for project '%s'" % title, default_workdir) if new_workdir: workdir = new_workdir else: log.info("Replacement of not existing Working Directory " "'%s' aborted by user", workdir) message_information( "Working directory not set by user:\n\n" "project load aborted", parent=self) return None else: ret = message_question( "Working directory set to:\n\n" + workdir, "Working Directory", informative_text="Do you want to change it?", buttons=QMessageBox.Yes | QMessageBox.No, default_button=QMessageBox.No, parent=self) if ret == QMessageBox.Yes: new_wd = QFileDialog.getExistingDirectory( self, "Set working directory for project '%s'" % title, default_workdir) if new_wd: workdir = new_wd if not os.path.isdir(workdir): os.mkdir(workdir) else: log.info("Replacement of not existing Working Directory " "'%s' aborted by user.", workdir) message_information( "Working directory not set by user:\n\n" "project load aborted", parent=self) return None # now start the actual load with a valid working directory log.info("Changing current work dir to '%s'", workdir) os.chdir(workdir) new_scheme = widgetsscheme.OASYSWidgetsScheme(parent=self) new_scheme.working_directory = workdir errors = [] contents.seek(0) try: readwrite.scheme_load( new_scheme, contents, error_handler=errors.append) except Exception: message_critical( self.tr("Could not load an Orange Workflow file"), title=self.tr("Error"), informative_text=self.tr("An unexpected error occurred " "while loading '%s'.") % filename, exc_info=True, parent=self) return None if errors: message_warning( self.tr("Errors occurred while loading the workflow."), title=self.tr("Problem"), informative_text=self.tr( "There were problems loading some " "of the widgets/links in the " "workflow." ), details="\n".join(map(repr, errors)), parent=self ) return new_scheme
def __on_installer_finished(self): message = "Please restart OASYS for changes to take effect." message_information(message, parent=self) self.accept()
def __on_installer_finished(self): message_information( "Please restart the application for changes to take effect.", parent=self) self.accept()