コード例 #1
0
    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()
コード例 #2
0
ファイル: filemanager.py プロジェクト: dieterv/gaphor
    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."""

        self.logger.info('Loading file')
        self.logger.debug('Path is %s' % filename)

        main_window = self.main_window

        queue = Queue()
        status_window = StatusWindow(_('Loading...'),\
                                     _('Loading model from %s') % filename,\
                                     parent=main_window.window,\
                                     queue=queue)

        loader = storage.load_generator(filename, self.element_factory)
        worker = GIdleThread(loader, queue)

        worker.start()
        worker.wait()
        
        if worker.error:
            self.logger.error('Error loading file: ', exc_info=worker.exc_info)
            #self.logger.error(worker.error)

        self.filename = filename

        status_window.destroy()
コード例 #3
0
    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 and len(filename)):
            return

        self.verify_orphans()

        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 Exception as e:
            error_handler(
                message=gettext("Unable to save model “{filename}”.").format(
                    filename=filename
                ),
                secondary_message=error_message(e),
                window=self.main_window.window,
            )
            raise
        finally:
            status_window.destroy()
コード例 #4
0
    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, self.modeling_language
            )
            worker = GIdleThread(loader, queue)

            worker.start()
            worker.wait()

            if worker.error:
                worker.reraise()

            self.filename = filename
            self.event_manager.handle(FileLoaded(self, filename))
        except Exception:
            error_handler(
                message=gettext("Unable to open model “{filename}”.").format(
                    filename=filename
                ),
                secondary_message=gettext(
                    "This file does not contain a valid Gaphor model."
                ),
                window=self.main_window.window,
            )
            raise
        finally:
            status_window.destroy()
コード例 #5
0
ファイル: filemanager.py プロジェクト: amolenaar/gaphor
    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()
コード例 #6
0
ファイル: filemanager.py プロジェクト: weizx208/gaphor
    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()
コード例 #7
0
ファイル: filemanager.py プロジェクト: paulopperman/gaphor
    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()
コード例 #8
0
ファイル: filemanager.py プロジェクト: amolenaar/gaphor
    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()
コード例 #9
0
    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()
コード例 #10
0
ファイル: filemanager.py プロジェクト: dieterv/gaphor
    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."""
        
        self.logger.info('Saving file')
        self.logger.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)

        out = open(filename, 'w')

        saver = storage.save_generator(XMLWriter(out), self.element_factory)
        worker = GIdleThread(saver, queue)
        worker.start()
        worker.wait()
        
        if worker.error:
            self.logger.error('Error saving file')
            self.logger.error(worker.error)
        
        out.close()
        status_window.destroy()
        self.filename = filename