Esempio n. 1
0
    def get_parameters_helper(self):
        """
        Helper method to launch get_parameters_from_script on a thread so that it isn't run on the GUI thread, since
        it may be slow (when initializing pyimagej).
        """
        # Reset previously parsed parameters
        self.clear_script_parameters()

        global stop_progress_thread
        stop_progress_thread = False

        progress_gauge = Gauge(Window.FindFocus(), -1, size=(100, -1))
        progress_gauge.Show(True)

        parse_param_thread = Thread(target=self.get_parameters_from_script, name="Parse Parameters Thread", daemon=True)
        parse_param_thread.start()

        while True:
            # Wait for get_parameters_from_script to finish
            progress_gauge.Pulse()
            time.sleep(0.025)
            if stop_progress_thread:
                progress_gauge.Show(False)
                break

        if not self.initialization_failed:
            self.parsed_params = True
Esempio n. 2
0
    def save(self, project):
        """
        Aave diagram in XML file.

        @param project

        @author Deve Roux
        @modified Laurent Burgbacher <*****@*****.**> : add version support
        @modified C.Dutoit 20021122 : added document container tag
        """
        dlg:    Dialog   = Dialog(None, -1, "Saving...", style=STAY_ON_TOP | ICON_INFORMATION | RESIZE_BORDER, size=Size(207, 70))
        xmlDoc: Document = Document()
        try:
            # xmlDoc: Document  = Document()
            top     = xmlDoc.createElement("PyutProject")
            top.setAttribute('version', str(self._this_version))
            top.setAttribute('CodePath', project.getCodePath())

            xmlDoc.appendChild(top)

            # dlg   = Dialog(None, -1, "Saving...", style=STAY_ON_TOP | ICON_INFORMATION | RESIZE_BORDER, size=Size(207, 70))
            gauge = Gauge(dlg, -1, 100, pos=Point(2, 5), size=Size(200, 30))
            dlg.Show(True)

            # Save all documents in the project
            for document in project.getDocuments():
                documentNode = xmlDoc.createElement("PyutDocument")
                documentNode.setAttribute('type', PyutConstants.diagramTypeAsString(document.getType()))
                top.appendChild(documentNode)

                oglObjects = document.getFrame().getUmlObjects()
                for i in range(len(oglObjects)):
                    gauge.SetValue(i * 100 / len(oglObjects))
                    oglObject = oglObjects[i]
                    if isinstance(oglObject, OglClass):
                        documentNode.appendChild(self._OglClass2xml(oglObject, xmlDoc))
                    elif isinstance(oglObject, OglNote):
                        documentNode.appendChild(self._OglNote2xml(oglObject, xmlDoc))
                    elif isinstance(oglObject, OglActor):
                        documentNode.appendChild(self._OglActor2xml(oglObject, xmlDoc))
                    elif isinstance(oglObject, OglUseCase):
                        documentNode.appendChild(self._OglUseCase2xml(oglObject, xmlDoc))
                    elif isinstance(oglObject, OglLink):
                        documentNode.appendChild(self._OglLink2xml(oglObject, xmlDoc))
                    elif isinstance(oglObject, OglSDInstance):
                        documentNode.appendChild(self._OglSDInstance2xml(oglObject, xmlDoc))
                    elif isinstance(oglObject, OglSDMessage):
                        documentNode.appendChild(self._OglSDMessage2xml(oglObject, xmlDoc))
        except (ValueError, Exception) as e:
            try:
                dlg.Destroy()
                self.logger.error(f'{e}')
            except (ValueError, Exception) as e:
                self.logger.error(f'{e}')
            PyutUtils.displayError(_("Can't save file"))
            return xmlDoc

        dlg.Destroy()

        return xmlDoc
Esempio n. 3
0
def gauge(element, instance: wx.Gauge) -> wx.Object:
    props = element['props']
    set_basic_props(instance, props)
    if props.get('range'):
        instance.SetRange(props['range'])
    if props.get('pulse', False):
        instance.Pulse()
    return instance
Esempio n. 4
0
    def __init__(self, parent, title, text):
        Dialog.__init__(self, parent, title=title, style=CAPTION | STAY_ON_TOP)
        sizer = BoxSizer(VERTICAL)

        self.label = StaticText(self, label=text)
        sizer.Add(self.label, flag=FLAG_ALL_AND_EXPAND)

        self.gauge = Gauge(self, style=GA_SMOOTH | GA_HORIZONTAL)
        sizer.Add(self.gauge, flag=FLAG_ALL_AND_EXPAND)

        self.close_event = Event()

        def show_progress():
            while not self.close_event.is_set():
                sleep(0.05)
                self.gauge.Pulse()
            self.EndModal(ID_OK)

        self.SetSizerAndFit(sizer)

        run_in_separate_thread(show_progress)
Esempio n. 5
0
    def __setupProgressDialog(self):

        self._dlgGauge = Dialog(None,
                                ID_ANY,
                                "Loading...",
                                style=STAY_ON_TOP | ICON_INFORMATION
                                | RESIZE_BORDER,
                                size=Size(250, 70))
        self._gauge: Gauge = Gauge(self._dlgGauge,
                                   ID_ANY,
                                   5,
                                   pos=Point(2, 5),
                                   size=Size(200, 30))
        self._dlgGauge.Show(True)
        wxYield()
Esempio n. 6
0
    def save(self, project: PyutProject) -> Document:
        """
        Save diagram in XML file.

        Args:
            project:  The project to write as XML

        Returns:
            A minidom XML Document
        """
        assert project is not None, 'Oops someone sent me a bad project'

        dlg: Dialog = Dialog(None,
                             ID_ANY,
                             "Saving...",
                             style=STAY_ON_TOP | ICON_INFORMATION
                             | RESIZE_BORDER,
                             size=Size(207, 70))
        xmlDoc: Document = Document()
        try:
            top = xmlDoc.createElement(PyutXmlConstants.TOP_LEVEL_ELEMENT)
            top.setAttribute(PyutXmlConstants.ATTR_VERSION,
                             str(PyutXml.VERSION))
            codePath: str = project.getCodePath()
            if codePath is None:
                top.setAttribute(PyutXmlConstants.ATTR_CODE_PATH, '')
            else:
                top.setAttribute(PyutXmlConstants.ATTR_CODE_PATH, codePath)

            xmlDoc.appendChild(top)

            gauge = Gauge(dlg,
                          ID_ANY,
                          100,
                          pos=Point(2, 5),
                          size=Size(200, 30))
            dlg.Show(True)
            wxYield()

            toPyutXml: OglToMiniDomV10 = OglToMiniDomV10()
            # Save all documents in the project
            for pyutDocument in project.getDocuments():

                document: PyutDocument = cast(PyutDocument, pyutDocument)
                documentNode: Element = self.__pyutDocumentToPyutXml(
                    xmlDoc=xmlDoc, pyutDocument=document)

                top.appendChild(documentNode)

                from org.pyut.ui.UmlFrame import UmlObjects

                oglObjects: UmlObjects = document.getFrame().getUmlObjects()
                for i in range(len(oglObjects)):
                    gauge.SetValue(i * 100 / len(oglObjects))
                    wxYield()
                    oglObject = oglObjects[i]
                    if isinstance(oglObject, OglClass):
                        classElement: Element = toPyutXml.oglClassToXml(
                            oglObject, xmlDoc)
                        documentNode.appendChild(classElement)
                    elif isinstance(oglObject, OglInterface2):
                        classElement = toPyutXml.oglInterface2ToXml(
                            oglObject, xmlDoc)
                        documentNode.appendChild(classElement)
                    elif isinstance(oglObject, OglNote):
                        noteElement: Element = toPyutXml.oglNoteToXml(
                            oglObject, xmlDoc)
                        documentNode.appendChild(noteElement)
                    elif isinstance(oglObject, OglText):
                        textElement: Element = toPyutXml.oglTextToXml(
                            oglObject, xmlDoc)
                        documentNode.appendChild(textElement)
                    elif isinstance(oglObject, OglActor):
                        actorElement: Element = toPyutXml.oglActorToXml(
                            oglObject, xmlDoc)
                        documentNode.appendChild(actorElement)
                    elif isinstance(oglObject, OglUseCase):
                        useCaseElement: Element = toPyutXml.oglUseCaseToXml(
                            oglObject, xmlDoc)
                        documentNode.appendChild(useCaseElement)
                    elif isinstance(oglObject, OglSDInstance):
                        sdInstanceElement: Element = toPyutXml.oglSDInstanceToXml(
                            oglObject, xmlDoc)
                        documentNode.appendChild(sdInstanceElement)
                    elif isinstance(oglObject, OglSDMessage):
                        sdMessageElement: Element = toPyutXml.oglSDMessageToXml(
                            oglObject, xmlDoc)
                        documentNode.appendChild(sdMessageElement)
                    # OglLink comes last because OglSDInstance is a subclass of OglLink
                    # Now I know why OglLink used to double inherit from LineShape, ShapeEventHandler
                    # I changed it to inherit from OglLink directly
                    elif isinstance(oglObject, OglLink):
                        linkElement: Element = toPyutXml.oglLinkToXml(
                            oglObject, xmlDoc)
                        documentNode.appendChild(linkElement)
                    else:
                        self.logger.warning(
                            f'Unhandled OGL Object: {oglObject}')
        except (ValueError, Exception) as e:
            try:
                dlg.Destroy()
                self.logger.error(f'{e}')
            except (ValueError, Exception) as e:
                self.logger.error(f'{e}')
            PyutUtils.displayError(_("Can't save file"))
            return xmlDoc

        dlg.Destroy()

        return xmlDoc
Esempio n. 7
0
    def save(self, project: PyutProject) -> Document:
        """
        Save diagram in XML file.

        Args:
            project:  The project to write as XML

        Returns:
            A minidom XML Document
        """
        dlg:    Dialog   = Dialog(None, -1, "Saving...", style=STAY_ON_TOP | ICON_INFORMATION | RESIZE_BORDER, size=Size(207, 70))
        xmlDoc: Document = Document()
        try:
            # xmlDoc: Document  = Document()
            top     = xmlDoc.createElement(PyutXmlConstants.TOP_LEVEL_ELEMENT)
            top.setAttribute(PyutXmlConstants.ATTR_VERSION, str(PyutXml.VERSION))
            codePath: str = project.getCodePath()
            if codePath is None:
                top.setAttribute('CodePath', '')
            else:
                top.setAttribute('CodePath', codePath)

            xmlDoc.appendChild(top)

            gauge = Gauge(dlg, -1, 100, pos=Point(2, 5), size=Size(200, 30))
            dlg.Show(True)
            wxYield()

            toPyutXml: OglToMiniDom = OglToMiniDom()
            # Save all documents in the project
            for document in project.getDocuments():

                document: PyutDocument = cast(PyutDocument, document)

                documentNode = xmlDoc.createElement(PyutXmlConstants.ELEMENT_DOCUMENT)

                docType: str = document.getType().__str__()

                documentNode.setAttribute(PyutXmlConstants.ATTR_TYPE, docType)
                documentNode.setAttribute(PyutXmlConstants.ATTR_TITLE, document.title)
                top.appendChild(documentNode)

                oglObjects: List[OglObject] = document.getFrame().getUmlObjects()
                for i in range(len(oglObjects)):
                    gauge.SetValue(i * 100 / len(oglObjects))
                    wxYield()
                    oglObject = oglObjects[i]
                    if isinstance(oglObject, OglClass):
                        # documentNode.appendChild(self._OglClass2xml(oglObject, xmlDoc))
                        classElement: Element = toPyutXml.oglClassToXml(oglObject, xmlDoc)
                        documentNode.appendChild(classElement)
                    elif isinstance(oglObject, OglNote):
                        # documentNode.appendChild(self._OglNote2xml(oglObject, xmlDoc))
                        noteElement: Element = toPyutXml.oglNoteToXml(oglObject, xmlDoc)
                        documentNode.appendChild(noteElement)
                    elif isinstance(oglObject, OglActor):
                        # documentNode.appendChild(self._OglActor2xml(oglObject, xmlDoc))
                        actorElement: Element = toPyutXml.oglActorToXml(oglObject, xmlDoc)
                        documentNode.appendChild(actorElement)
                    elif isinstance(oglObject, OglUseCase):
                        # documentNode.appendChild(self._OglUseCase2xml(oglObject, xmlDoc))
                        useCaseElement: Element = toPyutXml.oglUseCaseToXml(oglObject, xmlDoc)
                        documentNode.appendChild(useCaseElement)
                    elif isinstance(oglObject, OglSDInstance):
                        # documentNode.appendChild(self._OglSDInstance2xml(oglObject, xmlDoc))
                        sdInstanceElement: Element = toPyutXml.oglSDInstanceToXml(oglObject, xmlDoc)
                        documentNode.appendChild(sdInstanceElement)
                    elif isinstance(oglObject, OglSDMessage):
                        # documentNode.appendChild(self._OglSDMessage2xml(oglObject, xmlDoc))
                        sdMessageElement: Element = toPyutXml.oglSDMessageToXml(oglObject, xmlDoc)
                        documentNode.appendChild(sdMessageElement)
                    # OglLink comes last because OglSDInstance is a subclass of OglLink
                    # Now I know why OglLink used to double inherit from LineShape, ShapeEventHandler
                    # I changed it to inherit from OglLink directly
                    elif isinstance(oglObject, OglLink):
                        # documentNode.appendChild(self._OglLink2xml(oglObject, xmlDoc))
                        linkElement: Element = toPyutXml.oglLinkToXml(oglObject, xmlDoc)
                        documentNode.appendChild(linkElement)
        except (ValueError, Exception) as e:
            try:
                dlg.Destroy()
                self.logger.error(f'{e}')
            except (ValueError, Exception) as e:
                self.logger.error(f'{e}')
            PyutUtils.displayError(_("Can't save file"))
            return xmlDoc

        dlg.Destroy()

        return xmlDoc
Esempio n. 8
0
    def open(self, dom, project):
        """
        Open a file and create a diagram.
        """
        dlgGauge = None
        umlFrame = None  # avoid Pycharm warning
        try:
            root = dom.getElementsByTagName("PyutProject")[0]
            if root.hasAttribute('version'):
                version = int(root.getAttribute("version"))
            else:
                version = 1
            if version != self._this_version:
                self.logger.error("Wrong version of the file loader")
                eMsg: str = f'This is version {self._this_version} and the file version is {version}'
                self.logger.error(eMsg)
                raise Exception(f'VERSION_ERROR:  {eMsg}')
            project.setCodePath(root.getAttribute("CodePath"))

            # Create and init gauge
            dlgGauge = Dialog(None,
                              -1,
                              "Loading...",
                              style=STAY_ON_TOP | ICON_INFORMATION
                              | RESIZE_BORDER,
                              size=Size(207, 70))
            gauge = Gauge(dlgGauge, -1, 5, pos=Point(2, 5), size=Size(200, 30))
            dlgGauge.Show(True)

            # for all elements il xml file
            dlgGauge.SetTitle("Reading file...")
            gauge.SetValue(1)

            for documentNode in dom.getElementsByTagName("PyutDocument"):

                dicoOglObjects = {}  # format {id/name : oglClass}
                dicoLink = {}  # format [id/name : PyutLink}
                dicoFather = {}  # format {id child oglClass : [id fathers]}

                docType = documentNode.getAttribute("type")  # Python 3 update

                document = project.newDocument(
                    PyutConstants.diagramTypeFromString(docType))
                umlFrame = document.getFrame()

                mediator: Mediator = Mediator()
                mediator.getFileHandling().showFrame(umlFrame)

                self._getOglClasses(
                    documentNode.getElementsByTagName('GraphicClass'),
                    dicoOglObjects, dicoLink, dicoFather, umlFrame)
                self._getOglNotes(
                    documentNode.getElementsByTagName('GraphicNote'),
                    dicoOglObjects, dicoLink, dicoFather, umlFrame)
                self._getOglActors(
                    documentNode.getElementsByTagName('GraphicActor'),
                    dicoOglObjects, dicoLink, dicoFather, umlFrame)
                self._getOglUseCases(
                    documentNode.getElementsByTagName('GraphicUseCase'),
                    dicoOglObjects, dicoLink, dicoFather, umlFrame)
                self._getOglLinks(
                    documentNode.getElementsByTagName("GraphicLink"),
                    dicoOglObjects, dicoLink, dicoFather, umlFrame)
                self._getOglSDInstances(
                    documentNode.getElementsByTagName("GraphicSDInstance"),
                    dicoOglObjects, dicoLink, dicoFather, umlFrame)
                self._getOglSDMessages(
                    documentNode.getElementsByTagName("GraphicSDMessage"),
                    dicoOglObjects, dicoLink, dicoFather, umlFrame)

                # fix the link's destination field
                gauge.SetValue(2)
                dlgGauge.SetTitle("Fixing link's destination...")
                for links in list(dicoLink.values()):
                    for link in links:
                        link[1].setDestination(
                            dicoOglObjects[link[0]].getPyutObject())
                # adding fathers
                dlgGauge.SetTitle("Adding fathers...")
                gauge.SetValue(3)
                for child, fathers in list(dicoFather.items()):
                    for father in fathers:
                        umlFrame.createInheritanceLink(dicoOglObjects[child],
                                                       dicoOglObjects[father])

                # adding links to this OGL object
                dlgGauge.SetTitle("Adding Links...")
                gauge.SetValue(4)
                for src, links in list(dicoLink.items()):
                    for link in links:
                        createdLink = umlFrame.createNewLink(
                            dicoOglObjects[src],
                            dicoOglObjects[link[1].getDestination().getId()])

                        # fix link with the loaded information
                        pyutLink = createdLink.getPyutObject()
                        traversalLink: PyutLink = link[1]
                        pyutLink.setBidir(traversalLink.getBidir())

                        # pyutLink.setDestinationCardinality(link[1].getDestinationCardinality())
                        # pyutLink.setSourceCardinality(link[1].getSrcCard())
                        pyutLink.destinationCardinality = traversalLink.destinationCardinality
                        pyutLink.sourceCardinality = traversalLink.sourceCardinality

                        pyutLink.setName(link[1].getName())
        except (ValueError, Exception) as e:
            if dlgGauge is not None:
                dlgGauge.Destroy()
            PyutUtils.displayError(_(f"Can't load file {e}"))
            umlFrame.Refresh()
            return

        # to draw diagram
        umlFrame.Refresh()
        gauge.SetValue(5)

        if dlgGauge is not None:
            dlgGauge.Destroy()