예제 #1
0
    def _askForDirectoryExport(self, preferredDefaultPath: str = None):
        """
        Called by plugin to ask for an output directory
        """
        if preferredDefaultPath is None:
            defaultPath: str = self._ctrl.getCurrentDir()
        else:
            defaultPath = preferredDefaultPath

        dirDialog = DirDialog(self._umlFrame,
                              "Choose a destination directory",
                              defaultPath=defaultPath)
        if dirDialog.ShowModal() == ID_CANCEL:
            dirDialog.Destroy()
            return ""
        else:
            directory = dirDialog.GetPath()
            self._ctrl.setCurrentDir(directory)
            dirDialog.Destroy()
            return directory
예제 #2
0
def get_path():
    app = App(None)
    style = FD_SAVE
    dialog = DirDialog(None, "Save to...", "", DD_DEFAULT_STYLE | DD_DIR_MUST_EXIST)
    if dialog.ShowModal() == ID_OK:
        path = dialog.GetPath()
    else:
        path = ""
        print("No directory selected, saving to current directory.")
    dialog.Destroy()
    return path
예제 #3
0
    def doAction(self, umlObjects: List[OglClass],
                 selectedObjects: List[OglClass], umlFrame: UmlFrame):
        """

        Args:
            umlObjects:         list of the uml objects of the diagram
            selectedObjects:    list of the selected objects
            umlFrame:           The diagram frame
        """
        if umlFrame is None:
            self.displayNoUmlFrame()
            return

        ctrl = getMediator()
        project = ctrl.getFileHandling().getProjectFromFrame(umlFrame)
        if project.getCodePath() == "":
            dlg = DirDialog(None, _("Choose the root directory for the code"),
                            getcwd())
            if dlg.ShowModal() == ID_OK:
                codeDir = dlg.GetPath()
                self.logger.info(f"Chosen directory is {codeDir}")
                umlFrame.setCodePath(codeDir)
                dlg.Destroy()
            else:
                return
        oglClasses = [x for x in selectedObjects if isinstance(x, OglClass)]
        if len(oglClasses) == 0:
            self.logger.info("Nothing selected")
            return
        oldDir = getcwd()
        chdir(project.getCodePath())
        sysPath.append(getcwd())

        # plug = IoPython(None, None)
        plug = IoPython(cast(OglObject, None), cast(UmlFrame, None))
        normalDir = getcwd()
        for oglClass in oglClasses:
            pyutClass = oglClass.getPyutObject()
            filename = pyutClass.getFilename()
            if filename == "":
                dlg = FileDialog(None, _("Choose the file for this UML class"),
                                 project.getCodePath(), "", "*.py", FD_OPEN)
                if dlg.ShowModal() != ID_OK:
                    dlg.Destroy()
                    continue
                filename = dlg.GetPaths()[0]
                self.logger.info(f"Chosen filename is {filename}")
                pyutClass.setFilename(filename)
                dlg.Destroy()
            modulename = filename[:-3]  # remove ".py"
            try:
                # normalDir = getcwd()
                path, name = osPath.split(osPath.abspath(modulename))
                chdir(path)
                module = __import__(name)
                importlib.reload(module)
                chdir(normalDir)
            except ImportError as ie:
                self.logger.error(
                    f"Error while trying to import module '{str(modulename)}' --- '{ie}'"
                )
                chdir(normalDir)
                continue
            orgClass = module.__dict__[pyutClass.getName()]
            plug.getPyutClass(orgClass, filename, pyutClass)
            oglClass.autoResize()
        chdir(oldDir)