예제 #1
0
    def onFileInsertProject(self, event: CommandEvent):
        """
        Insert a project into this one

        Args:
            event:
        """
        PyutUtils.displayWarning(_("The project insert is experimental, "
                                   "use it at your own risk.\n"
                                   "You risk a shapes ID duplicate with "
                                   "unexpected results !"), parent=self)

        if (self._treeNotebookHandler.getCurrentProject()) is None:
            PyutUtils.displayError(_("No project to insert this file into !"))
            return

        # Ask which project to insert
        defaultDirectory: str    = self._currentDirectoryHandler.currentDirectory

        dlg = FileDialog(self._parent, _("Choose a project"), defaultDirectory, "", "*.put", FD_OPEN)
        if dlg.ShowModal() != ID_OK:
            dlg.Destroy()
            return False
        self._currentDirectoryHandler.currentDirectory = dlg.GetPath()
        filename = dlg.GetPath()
        dlg.Destroy()

        self.logger.warning(f'inserting file: {filename}')

        # Insert the specified files
        try:
            self._treeNotebookHandler.insertFile(filename)
        except (ValueError, Exception) as e:
            PyutUtils.displayError(_(f"An error occurred while loading the project!  {e}"))
def getFilePath(wildcard, title):
    app = App(None)
    style = FD_OPEN | FD_FILE_MUST_EXIST
    dialog = FileDialog(None, title, wildcard=wildcard, style=style)
    if dialog.ShowModal() == ID_OK:
        path = dialog.GetPath()
    else:
        path = None
    dialog.Destroy()
    return path
예제 #3
0
    def loadFile(self, filename: str = ""):
        """
        Load the specified filename;  This is externally available so that
        we can open a file from the command line

        Args:
            filename: Its name
        """
        # Make a list to be compatible with multi-files loading
        fileNames = [filename]

        currentDir: str    = self._mediator.getCurrentDir()

        # TODO This is bad practice to do something different based on input
        if filename == "":
            dlg = FileDialog(self._parent, _("Choose a file"), currentDir, "", "*.put", FD_OPEN | FD_MULTIPLE)

            if dlg.ShowModal() != ID_OK:
                dlg.Destroy()
                return False

            fileNames = dlg.GetPaths()
            self._currentDirectoryHandler.currentDirectory = fileNames[0]

            dlg.Destroy()

        self.logger.info(f"loading file(s) {filename}")

        # Open the specified files
        for filename in fileNames:
            try:
                if self._treeNotebookHandler.openFile(filename):
                    # Add to last opened files list
                    self._preferences.addNewLastOpenedFilesEntry(filename)
                    self.setLastOpenedFilesItems()
                    self._mediator.updateTitle()
            except (ValueError, Exception) as e:
                PyutUtils.displayError(_("An error occurred while loading the project !"))
                self.logger.error(f'{e}')
예제 #4
0
    def _loadFile(self, filename=""):
        """
        Load the specified filename

        Args:
            filename: Its name
        """
        # Make a list to be compatible with multi-files loading
        fileNames = [filename]

        # Ask which filename to load ?
        if filename == "":
            dlg = FileDialog(self, _("Choose a file"), self._lastDir, "",
                             "*.put", FD_OPEN | FD_MULTIPLE)

            if dlg.ShowModal() != ID_OK:
                dlg.Destroy()
                return False
            self.updateCurrentDir(dlg.GetPath())
            fileNames = dlg.GetPaths()
            dlg.Destroy()

        self.logger.info(f"loading file(s) {filename}")

        # Open the specified files
        for filename in fileNames:
            try:
                if self._mainFileHandlingUI.openFile(filename):
                    # Add to last opened files list
                    self._prefs.addNewLastOpenedFilesEntry(filename)
                    self.__setLastOpenedFilesItems()
                    self._ctrl.updateTitle()
            except (ValueError, Exception) as e:
                PyutUtils.displayError(
                    _("An error occurred while loading the project !"),
                    parent=self)
                self.logger.error(f'{e}')
예제 #5
0
    def _OnMnuFileInsertProject(self, event: CommandEvent):
        """
        Insert a project into this one

        Args:
            event:
        """
        PyutUtils.displayWarning(_("The project insert is experimental, "
                                   "use it at your own risk.\n"
                                   "You risk a shapes ID duplicate with "
                                   "unexpected results !"),
                                 parent=self)

        if (self._mainFileHandlingUI.getCurrentProject()) is None:
            PyutUtils.displayError(_("No project to insert this file into !"),
                                   parent=self)
            return

        # Ask which project to insert
        dlg = FileDialog(self, _("Choose a file"), self._lastDir, "", "*.put",
                         FD_OPEN)
        if dlg.ShowModal() != ID_OK:
            dlg.Destroy()
            return False
        self.updateCurrentDir(dlg.GetPath())
        filename = dlg.GetPath()
        dlg.Destroy()

        print(("inserting file", str(filename)))

        # Insert the specified files
        try:
            self._mainFileHandlingUI.insertFile(filename)
        except (ValueError, Exception) as e:
            PyutUtils.displayError(
                _(f"An error occurred while loading the project!  {e}"),
                parent=self)
예제 #6
0
 def OnAdd(self, event):
     '''
     dialog = AddDialog("Add Option", None)
     if dialog.ShowModal() == wx.ID_OK:
         print dialog.GetOption()
         self.listCtrl.AppendAndEnsureVisible(dialog.GetOption())
     '''
     wildcard = "All Files (*.*) | *.* |" \
                "source (*.py) | *.py |" \
                "Doc Files (*.doc) | *.doc"
     dialog = FileDialog(self, "Attach files", os.getcwd(), "", "*.*", FileDialog.OPEN | FileDialog.MULTIPLE)
     if dialog.ShowModal() == wx.ID_OK:
         
         fullList = dialog.GetPaths()
         self.attachments.copy(fullList)
         for item in self.attachments.GetFilenames():
             self.listCtrl.Append(item)
             
     dialog.Destroy()
예제 #7
0
    def saveFileAs(self):
        """
        Ask for a filename and save the diagram data

        Returns:
            `True` if the save succeeds else `False`
        """
        if self._mediator.isInScriptMode():
            PyutUtils.displayError(_("Save File As is not accessible in script mode !"))
            return

        # Test if no diagram exists
        if self._mediator.getDiagram() is None:
            PyutUtils.displayError(_("No diagram to save !"), _("Error"))
            return

        # Ask for filename
        filenameOK = False
        # TODO revisit this to figure out how to get rid of Pycharm warning 'dlg referenced before assignment'
        # Bad thing is dlg can be either a FileDialog or a MessageDialog
        dlg: DialogType = cast(DialogType, None)
        while not filenameOK:
            dlg = FileDialog(self.__parent,
                             defaultDir=self.__parent.getCurrentDir(),
                             wildcard=_("Pyut file (*.put)|*.put"),
                             style=FD_SAVE | FD_OVERWRITE_PROMPT)

            # Return False if canceled
            if dlg.ShowModal() != ID_OK:
                dlg.Destroy()
                return False

            # Find if a specified filename is already opened
            filename = dlg.GetPath()

            if len([project for project in self._projects if project.getFilename() == filename]) > 0:
                dlg = MessageDialog(self.__parent,
                                    _("Error ! The filename '%s" + "' correspond to a project which is currently opened !" +
                                      " Please choose another filename !") % str(filename),
                                    _("Save change, filename error"), OK | ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()
                return
            filenameOK = True

        project = self._currentProject
        project.setFilename(dlg.GetPath())
        project.saveXmlPyut()

        # Modify notebook text
        for i in range(self.__notebook.GetPageCount()):
            frame = self.__notebook.GetPage(i)
            document = [document for document in project.getDocuments() if document.getFrame() is frame]
            if len(document) > 0:
                document = document[0]
                if frame in project.getFrames():
                    diagramTitle: str = document.getTitle()
                    shortName:    str = self.shortenNotebookPageFileName(diagramTitle)

                    self.__notebook.SetPageText(i, shortName)
            else:
                self.logger.info("Not updating notebook in FileHandling")

        self.__parent.updateCurrentDir(dlg.GetPath())

        project.setModified(False)
        dlg.Destroy()
        return True