def load(self, filename): """Load the Gaphor model from the supplied file name. A status window displays the loading progress. The load generator updates the progress queue. The loader is passed to a GIdleThread which executes the load generator. If loading is successful, the filename is set.""" queue = Queue() status_window = StatusWindow( gettext("Loading..."), gettext("Loading model from {filename}").format(filename=filename), parent=self.main_window.window, queue=queue, ) try: loader = storage.load_generator(filename.encode("utf-8"), self.element_factory) worker = GIdleThread(loader, queue) worker.start() worker.wait() if worker.error: worker.reraise() self.filename = filename self.event_manager.handle(FileLoaded(self, filename)) except (QueueEmpty, QueueFull): error_handler(message=gettext( "Error while loading model from file {filename}").format( filename=filename)) raise finally: status_window.destroy()
def load(self, filename): """Load the Gaphor model from the supplied file name. A status window displays the loading progress. The load generator updates the progress queue. The loader is passed to a GIdleThread which executes the load generator. If loading is successful, the filename is set.""" log.info("Loading file") log.debug("Path is %s" % filename) queue = Queue() try: main_window = self.main_window status_window = StatusWindow( _("Loading..."), _("Loading model from %s") % filename, parent=main_window.window, queue=queue, ) except component.interfaces.ComponentLookupError: status_window = None try: loader = storage.load_generator( filename.encode("utf-8"), self.element_factory ) worker = GIdleThread(loader, queue) worker.start() worker.wait() if worker.error: worker.reraise() self.filename = filename except: error_handler( message=_("Error while loading model from file %s") % filename ) raise finally: if status_window is not None: status_window.destroy()
def save(self, filename): """Save the current UML model to the specified file name. Before writing the model file, this will verify that there are no orphan references. It will also verify that the filename has the correct extension. A status window is displayed while the GIdleThread is executed. This thread actually saves the model.""" log.info("Saving file") log.debug("File name is %s" % filename) if not filename or not len(filename): return self.verify_orphans() filename = self.verify_filename(filename) main_window = self.main_window queue = Queue() status_window = StatusWindow( _("Saving..."), _("Saving model to %s") % filename, parent=main_window.window, queue=queue, ) try: with open(filename.encode("utf-8"), "w") as out: saver = storage.save_generator(XMLWriter(out), self.element_factory) worker = GIdleThread(saver, queue) worker.start() worker.wait() if worker.error: worker.reraise() self.filename = filename except: error_handler(message=_("Error while saving model to file %s") % filename) raise finally: status_window.destroy()
def save(self, filename): """Save the current UML model to the specified file name. Before writing the model file, this will verify that there are no orphan references. It will also verify that the filename has the correct extension. A status window is displayed while the GIdleThread is executed. This thread actually saves the model.""" if not filename or not len(filename): return self.verify_orphans() filename = self.verify_filename(filename) main_window = self.main_window queue = Queue() status_window = StatusWindow( gettext("Saving..."), gettext("Saving model to {filename}").format(filename=filename), parent=main_window.window, queue=queue, ) try: with open(filename.encode("utf-8"), "w") as out: saver = storage.save_generator(XMLWriter(out), self.element_factory) worker = GIdleThread(saver, queue) worker.start() worker.wait() if worker.error: worker.reraise() self.filename = filename self.event_manager.handle(FileSaved(self, filename)) except (OSError, QueueEmpty, QueueFull): error_handler(message=gettext( "Error while saving model to file {filename}").format( filename=filename)) raise finally: status_window.destroy()
def load(self, filename): """Load the Gaphor model from the supplied file name. A status window displays the loading progress. The load generator updates the progress queue. The loader is passed to a GIdleThread which executes the load generator. If loading is successful, the filename is set.""" queue = Queue() status_window: Optional[StatusWindow] try: main_window = self.main_window status_window = StatusWindow( _("Loading..."), _("Loading model from %s") % filename, parent=main_window.window, queue=queue, ) except: log.warning("Could not create status window, proceding without.") status_window = None try: loader = storage.load_generator(filename.encode("utf-8"), self.element_factory) worker = GIdleThread(loader, queue) worker.start() worker.wait() if worker.error: worker.reraise() self.filename = filename except: error_handler(message=_("Error while loading model from file %s") % filename) raise finally: if status_window is not None: status_window.destroy()