def __initCtrl(self): """ Initialize the controls. """ # IDs [self.__editorID] = PyutUtils.assignID(1) sizer = BoxSizer(VERTICAL) self.__lblEditor = StaticText(self, -1, _("Editor")) self.__txtEditor = TextCtrl(self, -1, size=(100, 20)) sizer.Add(self.__lblEditor, 0, ALL, DlgFastEditOptions.GAP) sizer.Add(self.__txtEditor, 0, ALL, DlgFastEditOptions.GAP) hs = BoxSizer(HORIZONTAL) btnOk = Button(self, ID_OK, _("&OK")) hs.Add(btnOk, 0, ALL, DlgFastEditOptions.GAP) sizer.Add(hs, 0, CENTER) self.SetAutoLayout(True) self.SetSizer(sizer) sizer.Fit(self) sizer.SetSizeHints(self) btnOk.SetDefault() self.Bind(EVT_TEXT, self.__OnText, id=self.__editorID) self.__setValues() self.Center() self.__changed: bool = False
def __init__(self, parent, ID, pyutUseCase): """ Constructor. @since 1.0 @author Philippe Waelti <*****@*****.**> """ super().__init__(parent, ID, _("Use Case Edit"), style=RESIZE_BORDER | CAPTION) # Associated PyutUseCase self._pyutUseCase = pyutUseCase self.SetAutoLayout(True) self._text = self._pyutUseCase.getName() self._returnAction = -1 # describe how the user exited the dialog box label = StaticText(self, -1, _("Use case text")) self._txtCtrl = TextCtrl(self, TXT_USECASE, self._text, size=(400, 180), style=TE_MULTILINE) self._txtCtrl.SetFocus() # text events self.Bind(EVT_TEXT, self._onTxtChange, id=TXT_USECASE) btnOk = Button(self, OK, _("&Ok")) btnOk.SetDefault() btnCancel = Button(self, CANCEL, _("&Cancel")) self.Bind(EVT_BUTTON, self._onCmdOk, id=OK) self.Bind(EVT_BUTTON, self._onCmdCancel, id=CANCEL) szrButtons = BoxSizer(HORIZONTAL) szrButtons.Add(btnOk, 0, RIGHT, 10) szrButtons.Add(btnCancel, 0, ALL) szrMain = BoxSizer(VERTICAL) szrMain.Add(label, 0, BOTTOM, 5) szrMain.Add(self._txtCtrl, 1, EXPAND | BOTTOM, 10) szrMain.Add(szrButtons, 0, ALIGN_CENTER_HORIZONTAL) # Border szrBorder = BoxSizer(VERTICAL) szrBorder.Add(szrMain, 1, EXPAND | ALL, 10) self.SetSizer(szrBorder) szrBorder.Fit(self) self.Centre() self.ShowModal()
def __init__(self, parent, ID, pyutLink: PyutLink): """ """ super().__init__(parent, ID, _("Link Edit"), style=RESIZE_BORDER | CAPTION) self.logger: Logger = getLogger(__name__) # Associated PyutLink self._pyutLink: PyutLink = pyutLink self._relationship = self._pyutLink.getName() self._aRoleInB = "" self._bRoleInA = "" # self._cardinalityA = self._pyutLink.getSourceCardinality() # self._cardinalityB = self._pyutLink.getDestinationCardinality() self._cardinalityA = self._pyutLink.sourceCardinality self._cardinalityB = self._pyutLink.destinationCardinality self._returnAction = CANCEL # #describe how user exited dialog box # labels lblCardA = StaticText(self, -1, _("Cardinality"), style=ALIGN_LEFT) lblRela = StaticText(self, -1, _("Relationship"), style=ALIGN_CENTRE) lblCardB = StaticText(self, -1, _("Cardinality"), style=ALIGN_RIGHT) lblA = StaticText(self, -1, "A", style=ALIGN_LEFT) self._lblArrow = StaticText(self, -1, "", style=ALIGN_CENTRE) self.updateLblArrow() lblB = StaticText(self, -1, "B", style=ALIGN_RIGHT) lblAinB = StaticText(self, -1, _("A's role in B"), style=ALIGN_LEFT) lblBinA = StaticText(self, -1, _("B's role in A"), style=ALIGN_RIGHT) # text self._txtCardinalityA = TextCtrl(self, TXT_CARDINALITY_A, "", size=Size(50, 20)) self._txtRelationship = TextCtrl(self, TXT_RELATIONSHIP, "", size=Size(100, 20)) self._txtCardinalityB = TextCtrl(self, TXT_CARDINALITY_B, "", size=Size(50, 20)) self._txtARoleB = TextCtrl(self, A_ROLE_IN_B, "") self._txtBRoleA = TextCtrl(self, B_ROLE_IN_A, "") self.setValues(self._relationship, self._aRoleInB, self._bRoleInA, self._cardinalityA, self._cardinalityB) self._txtARoleB.Enable(False) self._txtBRoleA.Enable(False) # text events self.Bind(EVT_TEXT, self._onTxtCardinalityAChange, id=TXT_CARDINALITY_A) self.Bind(EVT_TEXT, self._onTxtCardinalityBChange, id=TXT_CARDINALITY_B) self.Bind(EVT_TEXT, self._onTxtRelationshipChange, id=TXT_RELATIONSHIP) self.Bind(EVT_TEXT, self._onTxtARoleBChange, id=A_ROLE_IN_B) self.Bind(EVT_TEXT, self._onTxtBRoleAChange, id=B_ROLE_IN_A) # Ok/Cancel btnOk = Button(self, OK, _("&Ok")) btnCancel = Button(self, CANCEL, _("&Cancel")) btnRemove = Button(self, BTN_REMOVE, _("&Remove")) btnOk.SetDefault() # button events self.Bind(EVT_BUTTON, self._onCmdOk, id=OK) self.Bind(EVT_BUTTON, self._onCmdCancel, id=CANCEL) self.Bind(EVT_BUTTON, self._onRemove, id=BTN_REMOVE) szr1 = FlexGridSizer(cols=3, hgap=30, vgap=5) szr1.AddMany([(lblCardA, 0, ALIGN_LEFT), (lblRela, 0, ALIGN_CENTER_HORIZONTAL), (lblCardB, 0, ALIGN_RIGHT), (self._txtCardinalityA, 0, ALIGN_LEFT), (self._txtRelationship, 0, ALIGN_CENTER_HORIZONTAL), (self._txtCardinalityB, 0, ALIGN_RIGHT)]) szr1.AddGrowableCol(0) szr1.AddGrowableCol(1) szr1.AddGrowableCol(2) szr2 = BoxSizer(HORIZONTAL) szr2.Add(lblA, 1, GROW | RIGHT, 10) szr2.Add(self._lblArrow, 1, GROW, 10) szr2.Add(lblB, 1, GROW) # szr3 : # lblAinB, lblBinA # self._txtARoleB, self._txtBRoleA szr3 = FlexGridSizer(cols=2, hgap=30, vgap=5) szr3.AddMany([(lblAinB, 0), (lblBinA, 0, ALIGN_RIGHT), (self._txtARoleB, 0), (self._txtBRoleA, 0, ALIGN_RIGHT | BOTTOM, 20)]) szr3.AddGrowableCol(0) szr3.AddGrowableCol(1) # szr4 : # btnRemove, btnOk, btnCancel szr4 = BoxSizer(HORIZONTAL) szr4.Add(btnRemove, 0, RIGHT, 10) szr4.Add(btnOk, 0, RIGHT, 10) szr4.Add(btnCancel, 0) # szr5 : # szr1 # szr2 # szr3 # szr4 szr5 = BoxSizer(VERTICAL) szr5.Add(szr1, 0, GROW | ALL, 10) szr5.Add(szr2, 0, GROW | ALL, 10) szr5.Add(szr3, 0, GROW | ALL, 10) szr5.Add(szr4, 0, ALIGN_RIGHT | ALL, 10) self.SetSizer(szr5) self.SetAutoLayout(True) szr5.Fit(self)
class DlgEditClassCommon(Dialog): clsLogger: Logger = getLogger(__name__) def __init__(self, parent, windowId, dlgTitle: str, pyutModel: CommonClassType): super().__init__(parent, windowId, dlgTitle, style=RESIZE_BORDER | CAPTION) self._parent = parent # TODO Do I really need to stash this from org.pyut.general.Mediator import Mediator self.logger: Logger = DlgEditClassCommon.clsLogger self._pyutModel: CommonClassType = pyutModel self._pyutModelCopy: CommonClassType = deepcopy(pyutModel) self._mediator: Mediator = Mediator() self.SetAutoLayout(True) if isinstance(pyutModel, PyutClass): lbl: str = _('Class Name') else: lbl: str = _('Interface Name') lblName: StaticText = StaticText(self, ID_ANY, lbl) self._txtName: TextCtrl = TextCtrl(self, ID_TEXT_NAME, "", size=(125, -1)) # Name and Stereotype sizer self._szrNameStereotype: BoxSizer = BoxSizer(HORIZONTAL) self._szrNameStereotype.Add(lblName, 0, ALL | ALIGN_CENTER, 5) self._szrNameStereotype.Add(self._txtName, 1, ALIGN_CENTER) self._szrButtons: BoxSizer = self.createButtonContainer() self._szrMain: BoxSizer = BoxSizer(VERTICAL) self._szrMain.Add(self._szrNameStereotype, 0, ALL | ALIGN_CENTER_HORIZONTAL, 5) self.SetSizer(self._szrMain) def createButtonContainer(self) -> BoxSizer: """ Create Ok, Cancel and description buttons Returns: The container """ # Buttons OK, cancel and description self._btnOk = Button(self, ID_BTN_OK, _("&Ok")) self.Bind(EVT_BUTTON, self._onOk, id=ID_BTN_OK) self._btnOk.SetDefault() self._btnCancel = Button(self, ID_BTN_CANCEL, _("&Cancel")) self.Bind(EVT_BUTTON, self._onCancel, id=ID_BTN_CANCEL) self._btnDescription = Button(self, ID_BTN_DESCRIPTION, _("&Description...")) self.Bind(EVT_BUTTON, self._onDescription, id=ID_BTN_DESCRIPTION) szrButtons: BoxSizer = BoxSizer(HORIZONTAL) szrButtons.Add(self._btnDescription, 0, ALL, 5) szrButtons.Add(self._btnOk, 0, ALL, 5) szrButtons.Add(self._btnCancel, 0, ALL, 5) return szrButtons def _createMethodsUIArtifacts(self) -> BoxSizer: self._lblMethod = StaticText(self, ID_ANY, _("Methods:")) self._lstMethodList: ListBox = ListBox(self, ID_LST_METHOD_LIST, choices=[], style=LB_SINGLE) self.Bind(EVT_LISTBOX, self._evtMethodList, id=ID_LST_METHOD_LIST) self.Bind(EVT_LISTBOX_DCLICK, self._evtMethodListDClick, id=ID_LST_METHOD_LIST) # Button Add self._btnMethodAdd = Button(self, ID_BTN_METHOD_ADD, _("A&dd")) self.Bind(EVT_BUTTON, self._onMethodAdd, id=ID_BTN_METHOD_ADD) # Button Edit self._btnMethodEdit = Button(self, ID_BTN_METHOD_EDIT, _("Ed&it")) self.Bind(EVT_BUTTON, self._onMethodEdit, id=ID_BTN_METHOD_EDIT) # Button Remove self._btnMethodRemove = Button(self, ID_BTN_METHOD_REMOVE, _("Re&move")) self.Bind(EVT_BUTTON, self._onMethodRemove, id=ID_BTN_METHOD_REMOVE) # Button Up self._btnMethodUp = Button(self, ID_BTN_METHOD_UP, _("U&p")) self.Bind(EVT_BUTTON, self._onMethodUp, id=ID_BTN_METHOD_UP) # Button Down self._btnMethodDown = Button(self, ID_BTN_METHOD_DOWN, _("Do&wn")) self.Bind(EVT_BUTTON, self._onMethodDown, id=ID_BTN_METHOD_DOWN) # Sizer for Methods buttons szrMethodButtons: BoxSizer = BoxSizer(HORIZONTAL) szrMethodButtons.Add(self._btnMethodAdd, 0, ALL, 5) szrMethodButtons.Add(self._btnMethodEdit, 0, ALL, 5) szrMethodButtons.Add(self._btnMethodRemove, 0, ALL, 5) szrMethodButtons.Add(self._btnMethodUp, 0, ALL, 5) szrMethodButtons.Add(self._btnMethodDown, 0, ALL, 5) return szrMethodButtons def _fillMethodList(self): for method in self._pyutModelCopy.methods: self._lstMethodList.Append(method.getString()) # noinspection PyUnusedLocal def _onDescription(self, event: CommandEvent): """ Called when the class description button is pressed. Args: event: """ dlg = DlgEditComment(self, ID_ANY, self._pyutModelCopy) dlg.Destroy() # Tell window that its data has been modified fileHandling = self._mediator.getFileHandling() project = fileHandling.getCurrentProject() if project is not None: project.setModified() # noinspection PyUnusedLocal def _evtMethodList(self, event: CommandEvent): """ Called when there is a click on Methods list. """ self._fixBtnMethod() def _evtMethodListDClick(self, event: CommandEvent): """ Called when click on Methods list. """ self._onMethodEdit(event) # noinspection PyUnusedLocal def _onMethodEdit(self, event: CommandEvent): """ Edit a method. """ selection = self._lstMethodList.GetSelection() method = self._pyutModelCopy.methods[selection] ret = self._invokeEditMethodDialog(method) if ret == OK: # Modify method in dialog list self._lstMethodList.SetString(selection, method.getString()) # Tell window that its data has been modified fileHandling = self._mediator.getFileHandling() project = fileHandling.getCurrentProject() if project is not None: project.setModified() # noinspection PyUnusedLocal def _onMethodAdd(self, event: CommandEvent): """ Add a new method in the list. Args: event: """ # Add fields in PyutClass copy object method: PyutMethod = PyutMethod(PyutMethod.DEFAULT_METHOD_NAME) ret = self._invokeEditMethodDialog(method) if ret == OK: self._pyutModelCopy.methods.append(method) # Add fields in dialog list self._lstMethodList.Append(method.getString()) # Tell window that its data has been modified fileHandling = self._mediator.getFileHandling() project = fileHandling.getCurrentProject() if project is not None: project.setModified() # noinspection PyUnusedLocal def _onMethodDown(self, event): """ Move down a method in the list. """ selection = self._lstMethodList.GetSelection() methods = self._pyutModelCopy.methods method = methods[selection] methods.pop(selection) methods.insert(selection + 1, method) # Move up the method in dialog list self._lstMethodList.SetString(selection, methods[selection].getString()) self._lstMethodList.SetString(selection + 1, methods[selection + 1].getString()) self._lstMethodList.SetSelection(selection + 1) # Fix buttons (enable or not) self._fixBtnMethod() # Tell window that its data has been modified fileHandling = self._mediator.getFileHandling() project = fileHandling.getCurrentProject() if project is not None: project.setModified() # noinspection PyUnusedLocal def _onMethodRemove(self, event: CommandEvent): """ Remove a field from the list. """ selection = self._lstMethodList.GetSelection() self._lstMethodList.Delete(selection) # Select next if self._lstMethodList.GetCount() > 0: index = min(selection, self._lstMethodList.GetCount() - 1) self._lstMethodList.SetSelection(index) # Remove from _pyutModelCopy methods = self._pyutModelCopy.methods methods.pop(selection) # Fix buttons of methods list (enable or not) self._fixBtnMethod() # Tell window that its data has been modified fileHandling = self._mediator.getFileHandling() project = fileHandling.getCurrentProject() if project is not None: project.setModified() # noinspection PyUnusedLocal def _onMethodUp(self, event: CommandEvent): """ Move up a method in the list. """ selection = self._lstMethodList.GetSelection() methods = self._pyutModelCopy.methods method = methods[selection] methods.pop(selection) methods.insert(selection - 1, method) # Move up the method in dialog list self._lstMethodList.SetString(selection, methods[selection].getString()) self._lstMethodList.SetString(selection - 1, methods[selection - 1].getString()) self._lstMethodList.SetSelection(selection - 1) # Fix buttons (enable or not) self._fixBtnMethod() # Tell window that its data has been modified fileHandling = self._mediator.getFileHandling() project = fileHandling.getCurrentProject() if project is not None: project.setModified() def _fixBtnMethod(self): """ Fix buttons of Method list (enable or not). """ selection = self._lstMethodList.GetSelection() # Button Edit and Remove enabled: bool = selection != -1 self._btnMethodEdit.Enable(enabled) self._btnMethodRemove.Enable(enabled) self._btnMethodUp.Enable(selection > 0) self._btnMethodDown.Enable( enabled and selection < self._lstMethodList.GetCount() - 1) def _invokeEditMethodDialog(self, methodToEdit: PyutMethod) -> int: """ Create and invoke the dialog for Method editing. Args: methodToEdit: Method to be edited Returns: The return code from dialog """ self.logger.info(f'method to edit: {methodToEdit}') self._dlgMethod: DlgEditMethod = DlgEditMethod( theParent=self, theWindowId=ID_ANY, methodToEdit=methodToEdit, theMediator=self._mediator) return self._dlgMethod.ShowModal() # noinspection PyUnusedLocal def _onOk(self, event: CommandEvent): """ Called when the Ok button is pressed Args: event: """ self._pyutModel.setName(self._txtName.GetValue()) self._pyutModel.methods = self._pyutModelCopy.methods self._pyutModel.description = self._pyutModelCopy.description self._returnAction = OK # This is probably obsolete event.Skip(skip=True) self.SetReturnCode(OK) self.EndModal(OK) # noinspection PyUnusedLocal def _onCancel(self, event: CommandEvent): self._returnAction = CANCEL # This is probably obsolete self.SetReturnCode(CANCEL) self.EndModal(CANCEL)