コード例 #1
0
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)
コード例 #2
0
ファイル: BadCop.py プロジェクト: SnakesAndLadders/BadCop
class MainDialog(Dialog):
    """
    Main window. Hit a button to profile the system, then another to scan what was plugged in
    """
    def __init__(self):
        """Constructor"""
        Dialog.__init__(self, None, title="Bad Cop", size=Size(500, 100))
        ico = Icon('logo.ico', BITMAP_TYPE_ICO)
        self.SetIcon(ico)
        self.message = StaticText(
            self, label="Click Profile, then insert device and click Test")
        self.profile = Button(self, label="Profile")
        self.test = Button(self, label="Test")
        self.test.Disable()
        self.profile.Bind(EVT_BUTTON, self.profileusb)
        self.test.Bind(EVT_BUTTON, self.testusb)
        self.Bind(EVT_CLOSE, self.onclose)
        main_sizer = BoxSizer(VERTICAL)
        t_sizer = BoxSizer(HORIZONTAL)
        p_sizer = BoxSizer(HORIZONTAL)
        t_sizer.Add(self.message, 0, ALL | CENTER, 5)
        p_sizer.Add(self.profile, 0, ALL | CENTER, 5)
        p_sizer.Add(self.test, 0, ALL | CENTER, 5)
        main_sizer.Add(p_sizer, 0, ALL | CENTER, 5)
        main_sizer.Add(t_sizer, 0, ALL | EXPAND | CENTER, 5)
        self.SetSizer(main_sizer)

    def profileusb(self, other):
        del other
        dev = find(find_all=True)
        devices = []
        for cfg in dev:
            devclass = str(cfg.bDeviceClass)
            product = str(cfg.iProduct)
            vid = hex(cfg.idVendor)
            pid = hex(cfg.idProduct)
            for line in Configuration(find(idVendor=cfg.idVendor)):
                line = str(line)
                linestrip = line.strip()
                linesplit = linestrip.split('\n')
                linesplit = [x.split(':') for x in linesplit]
                lines = []
                for w in linesplit:
                    lines.append([y.strip(' ') for y in w])
                for e in lines:
                    if 'bInterfaceClass' in e[0]:
                        intclass = e[1]
                        devices.append([devclass, product, vid, pid, intclass])
        with open('devices.pkl', 'wb') as f:
            dump(devices, f)
        self.profile.SetLabel("Done!")
        self.profile.Disable()
        self.test.Enable()

    def testusb(self, other):
        del other
        with open('devices.pkl', 'rb') as f:
            benchmark = load(f)
        dev = find(find_all=True)
        devices = []
        for cfg in dev:
            devclass = str(cfg.bDeviceClass)
            product = str(cfg.iProduct)
            vid = hex(cfg.idVendor)
            pid = hex(cfg.idProduct)
            for line in Configuration(find(idVendor=cfg.idVendor)):
                line = str(line)
                linestrip = line.strip()
                linesplit = linestrip.split('\n')
                linesplit = [x.split(':') for x in linesplit]
                lines = []
                for w in linesplit:
                    lines.append([y.strip(' ') for y in w])
                for e in lines:
                    if 'bInterfaceClass' in e[0]:
                        intclass = e[1]
                        devices.append([devclass, product, vid, pid, intclass])
        first_tuple_list = [tuple(lst) for lst in benchmark]
        secnd_tuple_list = [tuple(lst) for lst in devices]
        first_set = set(first_tuple_list)
        secnd_set = set(secnd_tuple_list)
        output = ""
        height = 100
        first = 0
        for devclass, product, vid, pid, usbtype in first_set.symmetric_difference(
                secnd_set):
            if usbtype == "0xa CDC Data":
                devicedesc = "Virtual Data Port (Network)"
            elif usbtype == "0xe0 Wireless Controller":
                devicedesc = "Wireless Internet Or Bluetooth"
            elif usbtype == "0x8 Mass Storage":
                devicedesc = "Data Storage Device"
            elif usbtype == "0x9 Hub":
                devicedesc = "USB Hub"
            elif usbtype == "0x3 Human Interface Device":
                devicedesc = "Keyboard, Mouse, or Other Input Device"
            elif usbtype == "0x2 CDC Communication":
                devicedesc = "Vitual Communications Port (Network)"
            else:
                devicedesc = usbtype + " device "
            if first == 0:
                output += "This appears to be a: \n                     " + devicedesc + " \n"
            else:
                output += "                     " + devicedesc + " \n"
            height = height + 30
            first = 1
        self.SetSize((500, height))
        self.message.SetLabel(output)

    def onclose(self, event):
        del event
        try:
            remove('devices.pkl')
        except:
            print('file missing')
        self.Destroy()
        exit("Application Exited")
コード例 #3
0
ファイル: main_ui.py プロジェクト: 150170410/easyselenium
class MainFrame(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.__browser = None
        self.__tmp_dir = mkdtemp()

        self.SetTitle("Easy Selenium UI")
        self.SetSize((800, 600))

        self.__create_widgets()
        self.Bind(EVT_CLOSE, self.__on_close)

    def __create_widgets(self):
        panel = Panel(self)

        sizer = GridBagSizer(5, 5)
        row = 0
        col = 0
        label = StaticText(panel, label=u'Root folder:')
        sizer.Add(label, pos=(row, col))

        col += 1
        col_width = 4
        self.__txt_root_path = TextCtrl(panel)
        sizer.Add(self.__txt_root_path,
                  pos=(row, col),
                  span=(1, col_width),
                  flag=FLAG_ALL_AND_EXPAND)

        col += col_width
        self.__btn_set_root = Button(panel, label=u'Set root folder')
        self.__btn_set_root.Bind(EVT_BUTTON, self.__set_root_folder)
        sizer.Add(self.__btn_set_root,
                  pos=(row, col),
                  flag=FLAG_ALL_AND_EXPAND)

        row += 1
        col = 0
        label = StaticText(panel, label=u'Url:')
        sizer.Add(label, pos=(row, col))

        col += 1
        self.__txt_url = TextCtrl(
            panel, value=u'https://www.google.com/')  # TODO: remove url
        sizer.Add(self.__txt_url, pos=(row, col), flag=FLAG_ALL_AND_EXPAND)

        col += 1
        label = StaticText(panel, label=u'Browser:')
        sizer.Add(label, pos=(row, col), flag=FLAG_ALL_AND_EXPAND)

        col += 1
        self.__cb_browser = Choice(panel,
                                   choices=Browser.get_supported_browsers())
        self.__cb_browser.Select(0)
        sizer.Add(self.__cb_browser, pos=(row, col), flag=FLAG_ALL_AND_EXPAND)

        col += 1
        self.bth_open_url = Button(panel, label=u'Open url')
        self.bth_open_url.Bind(EVT_BUTTON, self.__open_url)
        sizer.Add(self.bth_open_url, pos=(row, col), flag=FLAG_ALL_AND_EXPAND)

        col += 1
        self.bth_close_url = Button(panel, label=u'Close browser')
        self.bth_close_url.Bind(EVT_BUTTON, self.__close_browser)
        sizer.Add(self.bth_close_url, pos=(row, col), flag=FLAG_ALL_AND_EXPAND)

        row += 1
        col = 0
        tabs = Tabs(panel, [(GeneratorTab, "Generator"), (EditorTab, "Editor"),
                            (TestRunnerTab, "Test runner"),
                            (SelectorFinderTab, "Selector finder")])
        sizer.Add(tabs, pos=(row, col), span=(1, 6), flag=FLAG_ALL_AND_EXPAND)

        sizer.AddGrowableCol(1, 1)
        sizer.AddGrowableRow(2, 1)
        panel.SetSizer(sizer)
        self.Layout()

    def get_root_folder(self):
        text = self.__txt_root_path.GetValue()
        if text and len(text) > 0:
            return text
        else:
            return None

    def __set_root_folder(self, evt):
        dialog = DirDialog(self)
        if dialog.ShowModal() == ID_OK:
            path = dialog.GetPath()
            RootFolder.prepare_folder(path)
            self.__txt_root_path.SetValue(path)

    def __open_url(self, evt):
        url = self.__txt_url.GetValue()
        if StringUtils.is_url_correct(url):
            self.bth_open_url.Disable()

            name = self.get_browser_initials()

            try:
                if self.__browser and self.__browser.get_browser_initials(
                ) != name:
                    self.__browser.quit()
                    self.__browser = Browser(name)
                elif not self.__browser:
                    self.__browser = Browser(name)
            except Exception:
                show_error_dialog(self, traceback.format_exc(),
                                  u'Failed to open browser')
                self.__browser = None

            if self.__browser:
                self.__browser.open(url)
            # TODO: if generator or selector -> load image
            self.bth_open_url.Enable()
        else:
            show_dialog(self, u'Bad url: %s' % url, u'Bad url')

    def __close_browser(self, evt):
        if self.__browser:
            self.__browser.quit()
            self.__browser = None

    def __on_close(self, evt):
        self.__close_browser(evt)

        shutil.rmtree(self.__tmp_dir)
        self.Destroy()

    def get_url(self):
        return self.__txt_url.GetValue()

    def set_url(self, url):
        self.__txt_url.SetValue(url)

    def get_browser(self):
        return self.__browser

    def get_browser_initials(self):
        return self.__cb_browser.GetStringSelection()

    def get_tmp_dir(self):
        return self.__tmp_dir
コード例 #4
0
ファイル: DlgEditClass.py プロジェクト: curiousTauseef/PyUt
class DlgEditClass(DlgEditClassCommon):
    """
    Dialog for the class edits.

    Creating a DlgEditClass object will automatically open a dialog for class
    editing. The PyutClass given in the constructor parameters will be used to fill the
    fields of the dialog, and will be updated when the OK button is clicked.

    Dialogs for methods and fields editing are implemented in different classes and
    created when invoking the _callDlgEditMethod and _callDlgEditField methods.

    Because dialog works on a copy of the PyutClass object, if you cancel the
    dialog any modifications are lost.

    Examples of `DlgEditClass` use are in  `Mediator.py`
    """
    def __init__(self, parent, windowId, pyutClass: PyutClass):
        """

        Args:
            parent:         dialog parent
            windowId:       dialog identity
            pyutClass:      Class modified by dialog
        """
        super().__init__(parent=parent,
                         windowId=windowId,
                         dlgTitle=_("Class Edit"),
                         pyutModel=pyutClass)

        self.logger: Logger = getLogger(__name__)
        lblStereotype: StaticText = StaticText(self, -1, _("Stereotype"))
        self._txtStereotype: TextCtrl = TextCtrl(self,
                                                 ID_TXT_STEREO_TYPE,
                                                 "",
                                                 size=(125, -1))

        self._szrNameStereotype.Add(lblStereotype, 0, ALL, 5)
        self._szrNameStereotype.Add(self._txtStereotype, 1, ALIGN_CENTER)

        # Label Fields
        lblField = StaticText(self, -1, _("Fields :"))

        # ListBox List
        self._lstFieldList = ListBox(self,
                                     ID_LST_FIELD_LIST,
                                     choices=[],
                                     style=LB_SINGLE)
        self.Bind(EVT_LISTBOX, self._evtFieldList, id=ID_LST_FIELD_LIST)
        self.Bind(EVT_LISTBOX_DCLICK,
                  self._evtFieldListDClick,
                  id=ID_LST_FIELD_LIST)

        # Button Add
        self._btnFieldAdd = Button(self, ID_BTN_FIELD_ADD, _("&Add"))
        self.Bind(EVT_BUTTON, self._onFieldAdd, id=ID_BTN_FIELD_ADD)

        # Button Edit
        self._btnFieldEdit = Button(self, ID_BTN_FIELD_EDIT, _("&Edit"))
        self.Bind(EVT_BUTTON, self._onFieldEdit, id=ID_BTN_FIELD_EDIT)

        # Button Remove
        self._btnFieldRemove = Button(self, ID_BTN_FIELD_REMOVE, _("&Remove"))
        self.Bind(EVT_BUTTON, self._onFieldRemove, id=ID_BTN_FIELD_REMOVE)

        # Button Up
        self._btnFieldUp = Button(self, ID_BTN_FIELD_UP, _("&Up"))
        self.Bind(EVT_BUTTON, self._onFieldUp, id=ID_BTN_FIELD_UP)

        # Button Down
        self._btnFieldDown = Button(self, ID_BTN_FIELD_DOWN, _("&Down"))
        self.Bind(EVT_BUTTON, self._onFieldDown, id=ID_BTN_FIELD_DOWN)

        # Sizer for Fields buttons
        szrFieldButtons = BoxSizer(HORIZONTAL)
        szrFieldButtons.Add(self._btnFieldAdd, 0, ALL, 5)
        szrFieldButtons.Add(self._btnFieldEdit, 0, ALL, 5)
        szrFieldButtons.Add(self._btnFieldRemove, 0, ALL, 5)
        szrFieldButtons.Add(self._btnFieldUp, 0, ALL, 5)
        szrFieldButtons.Add(self._btnFieldDown, 0, ALL, 5)

        szrMethodButtons: BoxSizer = self._createMethodsUIArtifacts()
        # Show stereotype checkbox
        self._chkShowStereotype = CheckBox(self, -1, _("Show stereotype"))

        # Show fields checkbox
        self._chkShowFields = CheckBox(self, -1, _("Show fields"))

        # Show methods checkbox
        self._chkShowMethods = CheckBox(self, -1, _("Show methods"))

        # Sizer for display properties
        szrDisplayProperties = BoxSizer(VERTICAL)
        szrDisplayProperties.Add(self._chkShowStereotype, 0, ALL, 5)
        szrDisplayProperties.Add(self._chkShowFields, 0, ALL, 5)
        szrDisplayProperties.Add(self._chkShowMethods, 0, ALL, 5)

        self._szrMain.Add(lblField, 0, ALL, 5)
        self._szrMain.Add(self._lstFieldList, 1, ALL | EXPAND, 5)
        self._szrMain.Add(szrFieldButtons, 0, ALL | ALIGN_CENTER_HORIZONTAL, 5)

        self._szrMain.Add(self._lblMethod, 0, ALL, 5)
        self._szrMain.Add(self._lstMethodList, 1, ALL | EXPAND, 5)
        self._szrMain.Add(szrMethodButtons, 0, ALL | ALIGN_CENTER_HORIZONTAL,
                          5)

        self._szrMain.Add(szrDisplayProperties, 0,
                          ALL | ALIGN_CENTER_HORIZONTAL, 5)
        self._szrMain.Add(
            self._szrButtons, 0, ALL | ALIGN_RIGHT, 5
        )  # wxPython 4.1.0 Vertical alignment flags are ignored in vertical sizers

        # Fill the txt control with class data
        self._fillAllControls()

        # Fix buttons (enable or not)
        self._fixBtnFields()
        self._fixBtnMethod()

        # Set the focus and selection
        self._txtName.SetFocus()
        self._txtName.SetSelection(0, len(self._txtName.GetValue()))

        # Help Pycharm
        self._dlgMethod = cast(Dialog, None)
        self._szrMain.Fit(self)  # subclasses need to do this

        self.Centre()
        self.ShowModal()

    def _callDlgEditField(self, field: PyutField) -> int:
        """
                Dialog for Field editing

        Args:
            field:  Field to be edited

        Returns: return code from dialog
        """
        self._dlgField = DlgEditField(theParent=self,
                                      theWindowId=ID_ANY,
                                      fieldToEdit=field,
                                      theMediator=self._mediator)
        return self._dlgField.ShowModal()

    def _dupParams(self, params):
        """
        Duplicate a list of params, all params are duplicated too.

        @since 1.9
        @author N. Dubois <*****@*****.**>
        """
        dupParams = []
        for i in params:
            param: PyutParam = PyutParam(name=i.getName(),
                                         theParameterType=i.getType(),
                                         defaultValue=i.getDefaultValue())
            dupParams.append(param)
        return dupParams

    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 _fixBtnFields(self):
        """
        Fix buttons of fields list (enable or not).
        """
        selection = self._lstFieldList.GetSelection()
        # Button Edit and Remove
        ans = selection != -1
        self._btnFieldEdit.Enable(ans)
        self._btnFieldRemove.Enable(ans)
        self._btnFieldUp.Enable(selection > 0)
        self._btnFieldDown.Enable(
            ans and selection < self._lstFieldList.GetCount() - 1)

    # noinspection PyUnusedLocal
    def _onFieldAdd(self, event: CommandEvent):
        """
        Add a new field in the list.

        Args:
            event:
        """
        field = PyutField()
        ret = self._callDlgEditField(field)
        if ret == OK:
            self._pyutModelCopy.fields.append(field)
            # Add fields in dialog list
            self._lstFieldList.Append(str(field))

            # 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 _onFieldEdit(self, event: CommandEvent):
        """
        Edit a field.
        """
        selection = self._lstFieldList.GetSelection()
        field = self._pyutModelCopy.fields[selection]
        ret = self._callDlgEditField(field)
        if ret == OK:
            # Modify field in dialog list
            self._lstFieldList.SetString(selection, str(field))
            # 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 _onFieldRemove(self, event: CommandEvent):
        """
        Remove a field from the list.
        """
        # Remove from list control
        selection = self._lstFieldList.GetSelection()
        self._lstFieldList.Delete(selection)

        # Select next
        if self._lstFieldList.GetCount() > 0:
            index = min(selection, self._lstFieldList.GetCount() - 1)
            self._lstFieldList.SetSelection(index)

        # Remove from _pyutModelCopy
        fields = self._pyutModelCopy.fields
        fields.pop(selection)

        # Fix buttons of fields list (enable or not)
        self._fixBtnFields()

        # 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 _onFieldUp(self, event: CommandEvent):
        """
        Move up a field in the list.
        """
        # Move up the field in _pyutModelCopy
        selection = self._lstFieldList.GetSelection()
        fields = self._pyutModelCopy.fields
        field = fields[selection]
        fields.pop(selection)
        fields.insert(selection - 1, field)

        # Move up the field in dialog list
        self._lstFieldList.SetString(selection, str(fields[selection]))
        self._lstFieldList.SetString(selection - 1, str(fields[selection - 1]))
        self._lstFieldList.SetSelection(selection - 1)

        # Fix buttons (enable or not)
        self._fixBtnFields()

        # 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 _onFieldDown(self, event: CommandEvent):
        """
        Move down a field in the list.
        """
        selection = self._lstFieldList.GetSelection()
        fields = self._pyutModelCopy.fields
        field = fields[selection]
        fields.pop(selection)
        fields.insert(selection + 1, field)

        # Move down the field in dialog list
        self._lstFieldList.SetString(selection, str(fields[selection]))
        self._lstFieldList.SetString(selection + 1, str(fields[selection + 1]))
        self._lstFieldList.SetSelection(selection + 1)

        # Fix buttons (enable or not)
        self._fixBtnFields()

        # 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 _evtFieldList(self, event):
        """
        Called when click on Fields list.
        """
        self._fixBtnFields()

    def _evtFieldListDClick(self, event: CommandEvent):
        """
        Called when there is a double-click on Fields list.
        """
        self._onFieldEdit(event)

    def _convertNone(self, theString):
        """
        Return the same string, if string = None, return an empty string.

        Args:
            theString:  The string

        Returns:  The input string or 'None' if it was empty
        """
        if theString is None:
            theString = ""
        return theString

    # noinspection PyUnusedLocal
    def _onOk(self, event: CommandEvent):
        """
        Activated when button OK is clicked.
        """
        strStereotype = self._txtStereotype.GetValue()
        if strStereotype == "":
            self._pyutModel.setStereotype(None)
        else:
            self._pyutModel.setStereotype(getPyutStereotype(strStereotype))
        # Adds all fields in a list
        self._pyutModel.fields = self._pyutModelCopy.fields

        # Update display properties
        self._pyutModel.showFields = self._chkShowFields.GetValue()
        self._pyutModel.showMethods = self._chkShowMethods.GetValue()
        self._pyutModel.setShowStereotype(self._chkShowStereotype.GetValue())

        from org.pyut.PyutPreferences import PyutPreferences
        prefs = PyutPreferences()
        try:
            if prefs["AUTO_RESIZE"]:
                oglClass = self._mediator.getOglClass(self._pyutModel)
                oglClass.autoResize()
        except (ValueError, Exception) as e:
            self.logger.warning(f'{e}')

        fileHandling = self._mediator.getFileHandling()
        project = fileHandling.getCurrentProject()
        if project is not None:
            project.setModified()

        super()._onOk(event)