def doAction(self, umlObjects: List[OglObject], selectedObjects: List[OglClass], umlFrame: UmlFrame): """ Args: umlObjects: list of the uml objects of the diagram selectedObjects: list of the selected objects umlFrame: the frame of the diagram """ if len(selectedObjects) != 1: dlg: MessageDialog = MessageDialog( None, _("You must select at most a single class"), _("Warning"), OK | ICON_EXCLAMATION) dlg.ShowModal() dlg.Destroy() return oglClass: OglClass = selectedObjects[0] if isinstance(oglClass, OglClass) is False: dlg = MessageDialog(None, _('Must be a UML Class'), _('Bad Selection'), OK | ICON_ERROR | CENTER) dlg.ShowModal() dlg.Destroy() return filename: str = ToFastEdit.FAST_EDIT_TEMP_FILE self._writeTempTextFileForEditor(filename, oglClass) self._launchAppropriateEditor(filename) self._readTheModifiedTextFile(filename, oglClass) self._setProjectModified() self._cleanupTempFile()
def OnDropFiles(self, x, y, filenames): for name in filenames: try: file = open(name, 'r') text = file.read() self.window.WriteText(text) file.close() except IOError, error: dlg = MessageDialog(None, 'Error open file\n' + str(error)) dlg.ShowModal() except UnicodeDecodeError, error: dlg = MessageDialog(None, 'Non ascii file\n' + str(error)) dlg.ShowModal()
def ask_and_overwrite(self): backupDir = self.backupDir.GetValue() savePath = self.saveDir.GetValue() if not (isdir(backupDir) and bool(savePath)): with MessageDialog(self.master, "Set paths up!", "Error") as dlg: dlg.ShowModal() return False repo = Repo(backupDir) if repo.is_dirty(): with MessageDialog(self.master, "Backup repository '%s' is dirty" % backupDir, "Error") as dlg: dlg.ShowModal() return False active_branch = repo.active_branch try: c = active_branch.commit except Exception as e: hint = "" try: if active_branch.name == "master": hint = "Is backup empty?" except: pass with MessageDialog(self.master, str(e) + "\n" + hint, "Error") as dlg: dlg.ShowModal() return False label = commit_time_str(c) + " | " + c.message dlg = MessageDialog(self.master, "Do you want to overwrite save data with current version?\n\n" + "SHA1: %s\n\n%s\n\n" % (c.hexsha, label) + "Files in save directory will be overwritten!", "Confirmation is required", YES_NO ) switch = dlg.ShowModal() == ID_YES dlg.Destroy() if not switch: return False self._switch_to(c) return True
def displayNoSelectedUmlObjects(self): booBoo: MessageDialog = MessageDialog( parent=None, message='No selected UML objects', caption='Try Again!', style=OK | ICON_ERROR) booBoo.ShowModal()
def displayNothingSelected(): booBoo: MessageDialog = MessageDialog( parent=None, message='Please select some frame objects', caption='Try Again!', style=OK | ICON_ERROR) booBoo.ShowModal()
def removeDocument(self, document, confirmation=True): """ Remove a given document from the project. Args: document: PyutDocument to remove from this project confirmation: If `True` ask for confirmation """ frame = document.getFrame() if confirmation: self._mediator.getFileHandling().showFrame(frame) dlg = MessageDialog(self._mediator.getUmlFrame(), _("Are you sure to remove the document ?"), _("Remove a document from a project"), YES_NO) if dlg.ShowModal() == ID_NO: dlg.Destroy() return dlg.Destroy() # Remove references fileHandling = self._mediator.getFileHandling() fileHandling.removeAllReferencesToUmlFrame(frame) document.removeFromTree() # Remove document from documents list self._documents.remove(document)
def onClose(self, event): dialog = MessageDialog(self, "Close app?", "Confirm Exit", OK | CANCEL | ICON_QUESTION) result = dialog.ShowModal() dialog.Destroy() if result == ID_OK: self.Destroy()
def _onCreateTaskClicked(self, event: CommandEvent): dlg: ProgressDialog = self.__setupProgressDialog() ci: CloneInformation = self._cloneInformation adapter: AbstractTodoistAdapter = self._todoistAdapter try: adapter.createTasks(info=ci, progressCb=self.__adapterCallback) self._progressDlg.Destroy() except AdapterAuthenticationError as e: self._progressDlg.Destroy() self.__handleAuthenticationError(event) except (TaskCreationError, NoteCreationError) as tce: self._progressDlg.Destroy() errorHandler: ErrorHandler = ErrorHandler() if errorHandler.isErrorHandled(tce.errorCode) is True: errorHandler.handleError(tce.message, tce.errorCode) else: booBoo: MessageDialog = MessageDialog( parent=None, message=tce.message, caption='Task Creation Error!', style=OK | ICON_ERROR) booBoo.ShowModal()
def __OnCheckBox(self, event: CommandEvent): """ """ self.__changed = True eventID: int = event.GetId() val: bool = event.IsChecked() if eventID == self.__autoResizeID: self._prefs.autoResizeShapesOnEdit = val elif eventID == self.__showParamsID: self._mediator.showParams(val) self._prefs.showParameters = val elif eventID == self.__maximizeID: self._prefs.fullScreen = val elif eventID == self.__showTipsID: self._prefs.showTipsOnStartup = val elif eventID == self.__toolBarIconSizeID: if val is True: self._prefs.toolBarIconSize = ToolBarIconSize.SIZE_32 else: self._prefs.toolBarIconSize = ToolBarIconSize.SIZE_16 dlg: MessageDialog = MessageDialog(self, _("Icons will change size on next restart"), _("Warning"), OK | ICON_EXCLAMATION) dlg.ShowModal() dlg.Destroy() else: self.clsLogger.warning(f'Unknown combo box ID: {eventID}')
def ignore_dirty_state(prompt=None): """Checks if dirty state can be abandoned""" with MessageDialog(None, "%sContinue?" % prompt, 'Confirm overwrite', YES_NO | ICON_QUESTION) as dialog: if ID_YES == dialog.ShowModal(): return True return False
def doAction(self, umlObjects: List[OglObject], selectedObjects: List[OglObject], umlFrame: UmlFrame): """ Args: umlObjects: list of the uml objects of the diagram selectedObjects: list of the selected objects umlFrame: the frame of the diagram """ if len(selectedObjects) != 1: dlg = MessageDialog(None, _("You must select at most a single class"), _("Warning"), OK | ICON_EXCLAMATION) dlg.ShowModal() dlg.Destroy() return filename: str = ToFastEdit.FAST_EDIT_TEMP_FILE file: TextIO = open(filename, "w") self.write(selectedObjects[0], file) file.close() if sysPlatform == PyutConstants.THE_GREAT_MAC_PLATFORM: osSystem(f'open -W -a {self._editor} {filename}') else: osSystem(f'{self._editor} {filename}') file = open(filename, "r") self.read(selectedObjects[0], file) file.close() self._setProjectModified() self._cleanupTempFile()
def _fillAllControls(self): """ Fill all controls with _pyutModelCopy data. """ # Fill Class name self._txtName.SetValue(self._pyutModelCopy.getName()) # Fill Stereotype stereotype = self._pyutModelCopy.getStereotype() if stereotype is None: strStereotype = "" else: strStereotype = stereotype.getName() self._txtStereotype.SetValue(strStereotype) # Fill the list controls try: for el in self._pyutModelCopy.fields: self.logger.debug(f'field: {el}') self._lstFieldList.Append(str(el)) self._fillMethodList() except (ValueError, Exception) as e: eMsg: str = _(f"Error: {e}") dlg = MessageDialog(self, eMsg, OK | ICON_ERROR) dlg.ShowModal() dlg.Destroy() # Fill display properties self._chkShowFields.SetValue(self._pyutModelCopy.showFields) self._chkShowMethods.SetValue(self._pyutModelCopy.showMethods) self._chkShowStereotype.SetValue( self._pyutModelCopy.getShowStereotype())
def __OnCheckBox(self, event: CommandEvent): """ """ self.__changed = True eventID = event.GetId() val = event.IsChecked() if eventID == self.__autoResizeID: self.__prefs[PyutPreferences.AUTO_RESIZE_SHAPE_ON_EDIT] = val elif eventID == self.__showParamsID: self.__ctrl.showParams(val) self.__prefs[PyutPreferences.SHOW_PARAMETERS] = val elif eventID == self.__maximizeID: self.__prefs[PyutPreferences.FULL_SCREEN] = val elif eventID == self.__showTipsID: self.__prefs[PyutPreferences.SHOW_TIPS_ON_STARTUP] = val elif eventID == self.__centerDiagramID: self.__prefs.centerAppOnStartup = val self.__setPositionControls() dlg = MessageDialog( self, _("You must restart Pyut for position changes"), _("Warning"), OK | ICON_EXCLAMATION) dlg.ShowModal() dlg.Destroy() else: self.logger.warning(f'Unknown combo box ID: {eventID}')
def closeCurrentProject(self): """ Close the current project Returns: True if everything is ok """ if self._currentProject is None and self._currentFrame is not None: self._currentProject = self.getProjectFromFrame(self._currentFrame) if self._currentProject is None: PyutUtils.displayError(_("No frame to close !"), _("Error...")) return False # Display warning if we are in scripting mode if self._mediator.isInScriptMode(): self.logger.warning( "WARNING : in script mode, the non-saved projects are closed without warning" ) # Close the file if self._currentProject.getModified( ) is True and not self._mediator.isInScriptMode(): frame = self._currentProject.getFrames()[0] frame.SetFocus() self.showFrame(frame) dlg = MessageDialog( self.__parent, _("Your project has not been saved. " "Would you like to save it ?"), _("Save changes ?"), YES_NO | ICON_QUESTION) if dlg.ShowModal() == ID_YES: if self.saveFile() is False: return False # Remove the frame in the notebook if not self._mediator.isInScriptMode(): pages = list(range(self.__notebook.GetPageCount())) pages.reverse() for i in pages: pageFrame = self.__notebook.GetPage(i) if pageFrame in self._currentProject.getFrames(): self.__notebook.DeletePage(i) self._currentProject.removeFromTree() self._projects.remove(self._currentProject) self.logger.debug(f'{self._currentProject.getFilename()=}') self._currentProject = None self._currentFrame = None nbrProjects: int = len(self._projects) self.logger.debug(f'{nbrProjects=}') if nbrProjects > 0: self.__updateTreeNotebookIfPossible(project=self._projects[0]) self._mediator.updateTitle() return True
def Function(self): contents = 'Copyright (c) 2021 ryoTd0112' with MessageDialog(None, contents, caption='About', style=DEFAULT_DIALOG_STYLE | ICON_NONE) as dialog: if dialog.ShowModal() == ID_CANCEL: return
def _on_about(self, _): dlg = MessageDialog(self, "Monitors save directory and backs up" " changes to backup directory. Backup directory is under Git" " version control system.\n" "\n" "Author(s):\n" "Vasiliy (real) Efimov\n", "About") dlg.ShowModal() dlg.Destroy()
def newWarning(self, msg, title=None, parent=None): if title is None: title = _("WARNING...") try: dlg = MessageDialog(parent, msg, title, OK | ICON_EXCLAMATION | CENTRE) dlg.ShowModal() dlg.Destroy() except (ValueError, Exception) as e: self.logger.error(f'newWarning: {e}')
def _informUserOfOptions(self, errorMessage): msg: str = ( f'Error: "{errorMessage}" ' f'This error can usually be handled by deleting the ' f'Todoist cache. However, you have that preference turned off ' f'Turn the preference on and retry your operation') msgDlg: MessageDialog = MessageDialog(parent=None, message=msg, caption='Information', style=OK | ICON_INFORMATION) msgDlg.ShowModal() msgDlg.Destroy()
def onClose(self) -> bool: """ Close all files Returns: True if everything is ok """ # Display warning if we are in scripting mode if self._mediator.isInScriptMode(): self.logger.warning( "WARNING : in script mode, the non-saved projects are closed without warning" ) # Close projects and ask for unsaved but modified projects if not self._mediator.isInScriptMode(): for project in self._projects: if project.getModified() is True: frames = project.getFrames() if len(frames) > 0: frame = frames[0] frame.SetFocus() wxYield() self.showFrame(frame) dlg = MessageDialog( self.__parent, _("Your diagram has not been saved! Would you like to save it?" ), _("Save changes?"), YES_NO | ICON_QUESTION) if dlg.ShowModal() == ID_YES: # save if self.saveFile() is False: return False dlg.Destroy() from org.pyut.ui.frame.PyutApplicationFrame import PyutApplicationFrame # Prevent recursion import problem from org.pyut.ui.Mediator import Mediator # dereference all self.__notebook.DeleteAllPages() self.__notebook = None self.__parent = cast(PyutApplicationFrame, None) self._projects = cast(List[PyutProject], None) self._mediator = cast(Mediator, None) self._currentProject = cast(PyutProject, None) self._currentFrame = cast(UmlDiagramsFrame, None) self.__splitter = None self.__projectTree = None self.__splitter = None return True
def _on_switch(self, _): backupDir = self.backupDir.GetValue() if not isdir(backupDir): return with BackupSelector(self.master, backupDir) as dlg: res = dlg.ShowModal() if res != ID_OK: return target = dlg.target try: self._switch_to(target) except BaseException as e: with MessageDialog(self.master, str(e), "Error") as dlg: dlg.ShowModal()
def Destroy(self): if self.changed: dlg = MessageDialog(self, "編集した内容を保存しますか?", "終了", style=YES | NO | CANCEL) stat = dlg.ShowModal() if stat == ID_YES: self.Save() elif stat == ID_CANCEL: dlg.Destroy() return False dlg.Destroy() self.application.ExitMainLoop() return True
def _doRemedialAction(self): msg: str = ( f'You opted to allow us to clean up certain types of errors by ' f'removing the Todoist cache. ' f'I am just double confirming you want to do this?') msgDlg: MessageDialog = MessageDialog(parent=None, message=msg, caption='Question', style=YES | NO | NO_DEFAULT | ICON_QUESTION) answer: int = msgDlg.ShowModal() msgDlg.Destroy() if answer == ID_YES: self.__removeTodoistCache()
def __OnSizeChange(self, event: SpinEvent): self.__changed = True eventId: int = event.GetId() newValue: int = event.GetInt() if eventId == self.__scAppWidthID: self.__prefs.startupWidth = newValue elif eventId == self.__scAppHeightID: self.__prefs.startupHeight = newValue else: self.logger.error(f'Unknown onSizeChange event id: {eventId}') dlg = MessageDialog(self, _("You must restart Pyut for size changes"), _("Warning"), OK | ICON_EXCLAMATION) dlg.ShowModal() dlg.Destroy()
def __removeTodoistCache(self): homeDir: str = getenv('HOME') directoryToDelete: str = osPath.join( homeDir, ErrorHandler.TODOIST_CACHE_DIRECTORY_NAME) rmtree(directoryToDelete) msgDlg: MessageDialog = MessageDialog( parent=None, message='Now quit and restart PyGitIssueClone', caption='Restart', style=OK | ICON_INFORMATION) msgDlg.ShowModal() msgDlg.Destroy()
def __OnLanguageChange(self, event: CommandEvent): newLanguage: str = event.GetString() actualLanguage: str = self.__prefs[PyutPreferences.I18N] if actualLanguage not in Lang.LANGUAGES or newLanguage != Lang.LANGUAGES[ actualLanguage][0]: # Search the key corresponding to the newLanguage for i in list(Lang.LANGUAGES.items()): if newLanguage == i[1][0]: # Write the key in preferences file self.__prefs[PyutPreferences.I18N] = i[0] dlg = MessageDialog( self, _("You must restart Pyut for language changes"), _("Warning"), OK | ICON_EXCLAMATION) dlg.ShowModal() dlg.Destroy()
def Open(self, e=None): if self.changed: dlg = MessageDialog(self, "編集中の内容を保存して既存ファイルを開きますか?", "確認", style=OK | CANCEL) if dlg.ShowModal() == ID_OK: self.Save() dlg.Destroy() file = FileSelector("開くファイルを選択", expanduser('~'), "", "*.wnf") if not file: return self.File = file with open(self.File, encoding='utf-8') as f: self.editor.SetValue(f.read()) self.SetTitle(f"{BASETITLE} - {basename(self.File)}") self.changed = False
def _on_commit_selected(self, e): c = e.commit dlg = MessageDialog(self, "Do you want to switch to that version?\n\n" + "SHA1: %s\n\n%s\n\n" % (c.backed.hexsha, c.label) + "Files in both save and backup directories will be overwritten!", "Confirmation is required", YES_NO ) switch = dlg.ShowModal() == ID_YES dlg.Destroy() if not switch: return self.target = c.backed self.EndModal(ID_OK)
def copy_account(self, event): if TheClipboard.IsOpened() or TheClipboard.Open(): TheClipboard.Clear() sel_row = self.m_dataViewListCtrl1.GetSelectedRow() if sel_row == NOT_FOUND: return addr = self.m_dataViewListCtrl1.GetTextValue(sel_row, 1) TheClipboard.SetData(TextDataObject(addr)) TheClipboard.Flush() TheClipboard.Close() copied_modal = MessageDialog( self, f"Account address {addr}\nwas copied in the clipboard", "Copied", STAY_ON_TOP | CENTER, DefaultPosition, ) copied_modal.ShowModal()
def newFatalError(self, msg, title=None, parent=None): from org.pyut.errorcontroller.ErrorManager import ErrorManager # Avoid cyclical dependency if title is None: title = _("An error occurred...") errMsg: str = msg + "\n\n" errorInfo: str = ErrorManager.getErrorInfo() if errorInfo is not None: errMsg = f'{errMsg}{ErrorManager.getErrorInfo()}' try: dlg = MessageDialog(parent, errMsg, title, OK | ICON_ERROR | CENTRE) dlg.ShowModal() dlg.Destroy() except (ValueError, Exception) as e: self.logger.error(f'newFatalError: {e}')
def onClose(self) -> bool: """ Close all files Returns: True if everything is ok """ # Display warning if we are in scripting mode if self._mediator.isInScriptMode(): print("WARNING : in script mode, the non-saved projects are closed without warning") # Close projects and ask for unsaved but modified projects if not self._mediator.isInScriptMode(): for project in self._projects: if project.getModified() is True: frames = project.getFrames() if len(frames) > 0: frame = frames[0] frame.SetFocus() wxYield() # if self._ctrl is not None: # self._ctrl.registerUMLFrame(frame) self.showFrame(frame) dlg = MessageDialog(self.__parent, _("Your diagram has not been saved! Would you like to save it ?"), _("Save changes ?"), YES_NO | ICON_QUESTION) if dlg.ShowModal() == ID_YES: # save if self.saveFile() is False: return False dlg.Destroy() # dereference all self.__parent = None self._mediator = None self.__splitter = None self.__projectTree = None self.__notebook.DeleteAllPages() self.__notebook = None self.__splitter = None self._projects = None self._currentProject = None self._currentFrame = None