Exemplo n.º 1
0
class EntryListWindowPanel(BaseWindowPanel):
    def __init__(self, parent):
        BaseWindowPanel.__init__(self,
                                 parent,
                                 bg_color=Colour.BLACK,
                                 fg_color=Colour.WHITE)

        self._title_label = StaticText(self,
                                       pos=(110, 10),
                                       size=(100, 30),
                                       label=u"Entries")
        self._title_label.SetFont(
            Font(20, FONTFAMILY_DEFAULT, FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL))

        self._back_button = Button(self,
                                   -1,
                                   "< Back",
                                   pos=(10, 10),
                                   size=(70, 30))
        self._back_button.SetBackgroundColour(get_colour(0x333333))
        self._back_button.SetForegroundColour(Colour.WHITE)

        self._delete_button = Button(self,
                                     -1,
                                     "Del",
                                     pos=(240, 10),
                                     size=(70, 30))
        self._delete_button.SetBackgroundColour(Colour.RED)
        self._delete_button.SetForegroundColour(Colour.WHITE)

        self._list_control = ListBox(self, pos=(10, 50), size=(295, 170))
        self._list_control.SetBackgroundColour(Colour.BLACK)
        self._list_control.SetForegroundColour(Colour.WHITE)

        self._items = GlobalStorage.get_storage().get_items()
        self._list_control.SetItems(
            GlobalStorage.get_storage().get_string_list(self._items))

        self.Bind(EVT_BUTTON, self._back_button_click, self._back_button)
        self.Bind(EVT_BUTTON, self._delete_button_click, self._delete_button)

    def _back_button_click(self, e):
        self.GetParent().EndModal(ID_OK)

    def _delete_button_click(self, e):
        sel = self._list_control.GetSelection()
        if sel == NOT_FOUND:
            return
        else:
            item = self._items[sel]
            GlobalStorage.get_storage().delete_item(item.Id)

            self._items = GlobalStorage.get_storage().get_items()
            self._list_control.SetItems(
                GlobalStorage.get_storage().get_string_list(self._items))
Exemplo n.º 2
0
class CategoryInputWindowPanel(BaseWindowPanel):
    EMPTY_ITEM = '<empty>'

    def __init__(self, parent, title, categories):
        BaseWindowPanel.__init__(self,
                                 parent,
                                 bg_color=Colour.BLACK,
                                 fg_color=Colour.WHITE)

        # Title Label
        self._title_label = StaticText(self,
                                       pos=(85, 10),
                                       size=(100, 30),
                                       label=title)
        self._title_label.SetFont(
            Font(20, FONTFAMILY_DEFAULT, FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL))

        # Cancel Button
        self._cancel_button = Button(self,
                                     -1,
                                     "Cancel",
                                     pos=(10, 10),
                                     size=(70, 30))
        self._cancel_button.SetBackgroundColour(Colour.DARK_RED)
        self._cancel_button.SetForegroundColour(Colour.WHITE)

        # Confirm Button
        self._confirm_button = Button(self,
                                      -1,
                                      "OK",
                                      pos=(240, 10),
                                      size=(70, 30))
        self._confirm_button.SetBackgroundColour(Colour.DARK_GREEN)
        self._confirm_button.SetForegroundColour(Colour.WHITE)

        # List Views
        self._list_control = ListBox(self, pos=(10, 50), size=(295, 170))
        self._list_control.SetBackgroundColour(Colour.BLACK)
        self._list_control.SetForegroundColour(Colour.WHITE)
        self._list_control.SetItems([CategoryInputWindowPanel.EMPTY_ITEM] +
                                    categories)

        # Event
        self.Bind(EVT_BUTTON, self._confirm_button_click, self._confirm_button)
        self.Bind(EVT_BUTTON, self._cancel_button_click, self._cancel_button)

    def _cancel_button_click(self, e):
        self.GetParent().EndModal(ID_CANCEL)

    def _confirm_button_click(self, e):
        self.GetParent().EndModal(ID_OK)

    def get_value(self):
        v = self._list_control.GetStringSelection()
        return "" if v == CategoryInputWindowPanel.EMPTY_ITEM else v
Exemplo n.º 3
0
    def __init__(self, lstClasses):

        super().__init__(None, ID_ANY, "Classes choice", style=CAPTION | RESIZE_BORDER, size=(400, 500))

        # Create not chosen classes listBox
        self._listBox1 = ListBox(self, ID_ANY, style=LB_EXTENDED | LB_ALWAYS_SB | LB_SORT, size=(320, 400))
        for klass in lstClasses:
            self._listBox1.Append(klass.__name__, klass)

        # Create chosen classes listBox
        self._listBox2 = ListBox(self, ID_ANY, style=LB_EXTENDED | LB_ALWAYS_SB | LB_SORT, size=(320, 400))

        # Create buttons
        btnOk = Button(self, ID_OK, "Ok")
        btnToTheRight = Button(self, ID_BTN_TO_THE_RIGHT, "=>")
        btnToTheLeft  = Button(self, ID_BTN_TO_THE_LEFT,  "<=")

        # Callbacks
        self.Bind(EVT_BUTTON, self._onBtnToTheRight, id=ID_BTN_TO_THE_RIGHT)
        self.Bind(EVT_BUTTON, self._onBtnToTheLeft,  id=ID_BTN_TO_THE_LEFT)

        # Create info label
        lblChoice = StaticText(self, ID_ANY, _("Choose classes to reverse: "))

        # Create buttons sizer
        szrBtn = BoxSizer(VERTICAL)
        szrBtn.Add(btnToTheRight, 0, EXPAND)
        szrBtn.Add(btnToTheLeft,  0, EXPAND)

        # Create lists and buttons sizer
        szrLB = BoxSizer(HORIZONTAL)
        szrLB.Add(self._listBox1,  0, EXPAND)
        szrLB.Add(szrBtn,          0, EXPAND)
        szrLB.Add(self._listBox2,  0, EXPAND)

        # Create sizer
        box = BoxSizer(VERTICAL)
        box.Add(lblChoice, 0, EXPAND)
        box.Add(szrLB,     0, EXPAND)
        box.Add(btnOk,     0, EXPAND)
        box.Fit(self)
        self.SetAutoLayout(True)
        self.SetSizer(box)

        # Show dialog
        self.ShowModal()
        if self.GetReturnCode() == ID_CANCEL:     # abort -> empty right column

            while self._listBox2.GetCount() > 0:
                data = self._listBox2.GetClientData(0)
                name = self._listBox2.GetString(0)
                self._listBox1.Append(name, data)
                self._listBox2.Delete(0)
Exemplo n.º 4
0
    def CreateRightSection(self):
        rightPanel = wx.BoxSizer(orient=wx.VERTICAL)
        label = StaticText(
            self, -1, label="Press on a result to show the card", style=wx.ALIGN_CENTER_HORIZONTAL)
        label.SetBackgroundColour('white')
        label.SetFont(self.APPFONT)
        resultList = ListBox(self)

        # moreText.SetFont(font)
        resultList.SetFont(self.APPFONTSMAL)
        resultList.Bind(wx.EVT_LISTBOX, self.ResultClick)

        self.resultList = resultList

        rightPanel.Add(label, 1, wx.EXPAND, 0)
        rightPanel.Add(resultList, 20, wx.EXPAND, 0)
        rightPanel.SetSizeHints(self)
        return rightPanel
Exemplo n.º 5
0
    def __init__(self, parent, title, categories):
        BaseWindowPanel.__init__(self,
                                 parent,
                                 bg_color=Colour.BLACK,
                                 fg_color=Colour.WHITE)

        # Title Label
        self._title_label = StaticText(self,
                                       pos=(85, 10),
                                       size=(100, 30),
                                       label=title)
        self._title_label.SetFont(
            Font(20, FONTFAMILY_DEFAULT, FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL))

        # Cancel Button
        self._cancel_button = Button(self,
                                     -1,
                                     "Cancel",
                                     pos=(10, 10),
                                     size=(70, 30))
        self._cancel_button.SetBackgroundColour(Colour.DARK_RED)
        self._cancel_button.SetForegroundColour(Colour.WHITE)

        # Confirm Button
        self._confirm_button = Button(self,
                                      -1,
                                      "OK",
                                      pos=(240, 10),
                                      size=(70, 30))
        self._confirm_button.SetBackgroundColour(Colour.DARK_GREEN)
        self._confirm_button.SetForegroundColour(Colour.WHITE)

        # List Views
        self._list_control = ListBox(self, pos=(10, 50), size=(295, 170))
        self._list_control.SetBackgroundColour(Colour.BLACK)
        self._list_control.SetForegroundColour(Colour.WHITE)
        self._list_control.SetItems([CategoryInputWindowPanel.EMPTY_ITEM] +
                                    categories)

        # Event
        self.Bind(EVT_BUTTON, self._confirm_button_click, self._confirm_button)
        self.Bind(EVT_BUTTON, self._cancel_button_click, self._cancel_button)
Exemplo n.º 6
0
    def __init__(self, parent):
        BaseWindowPanel.__init__(self,
                                 parent,
                                 bg_color=Colour.BLACK,
                                 fg_color=Colour.WHITE)

        self._title_label = StaticText(self,
                                       pos=(110, 10),
                                       size=(100, 30),
                                       label=u"Entries")
        self._title_label.SetFont(
            Font(20, FONTFAMILY_DEFAULT, FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL))

        self._back_button = Button(self,
                                   -1,
                                   "< Back",
                                   pos=(10, 10),
                                   size=(70, 30))
        self._back_button.SetBackgroundColour(get_colour(0x333333))
        self._back_button.SetForegroundColour(Colour.WHITE)

        self._delete_button = Button(self,
                                     -1,
                                     "Del",
                                     pos=(240, 10),
                                     size=(70, 30))
        self._delete_button.SetBackgroundColour(Colour.RED)
        self._delete_button.SetForegroundColour(Colour.WHITE)

        self._list_control = ListBox(self, pos=(10, 50), size=(295, 170))
        self._list_control.SetBackgroundColour(Colour.BLACK)
        self._list_control.SetForegroundColour(Colour.WHITE)

        self._items = GlobalStorage.get_storage().get_items()
        self._list_control.SetItems(
            GlobalStorage.get_storage().get_string_list(self._items))

        self.Bind(EVT_BUTTON, self._back_button_click, self._back_button)
        self.Bind(EVT_BUTTON, self._delete_button_click, self._delete_button)
Exemplo n.º 7
0
    def _createIssueSelection(self) -> StaticBoxSizer:

        issueWxID: int = wxNewIdRef()

        self._issueList: ListBox = ListBox(self,
                                           issueWxID,
                                           style=LB_MULTIPLE | LB_OWNERDRAW)

        # noinspection PyUnresolvedReferences
        self._issueList.Enable(False)
        sz = StaticBoxSizer(VERTICAL, self, "Repository Issues")
        sz.Add(self._issueList, BasePanel.PROPORTION_CHANGEABLE, EXPAND)

        return sz
Exemplo n.º 8
0
    def _createTodoTaskList(self) -> StaticBoxSizer:

        taskWxID: int = wxNewIdRef()

        self._taskList: ListBox = ListBox(self,
                                          taskWxID,
                                          style=LB_OWNERDRAW | LB_ALWAYS_SB)
        # noinspection PyUnresolvedReferences
        self._taskList.Enable(False)

        sz = StaticBoxSizer(VERTICAL, self, "Todoist Tasks")
        sz.Add(self._taskList, BasePanel.PROPORTION_CHANGEABLE, EXPAND)

        self._taskList.SetItems(['Empty'])
        return sz
    def update_preview(self, list_obj: wx.ListBox, axes: matplotlib.axes.Axes):
        """
		Update the preview from the given list

		:param list_obj: The list to update the preview for
		:param axes: The preview axes to update
		"""

        axes.clear()
        axes.axis("off")
        selection_string = list_obj.GetStringSelection()
        if selection_string == '':
            return

        axes.scatter(1, 1, s=400, color=selection_string, marker='s')
Exemplo n.º 10
0
    def _createMilestoneSelection(self) -> StaticBoxSizer:

        milestoneSelectionWxId: int = wxNewIdRef()

        self._milestoneList: ListBox = ListBox(self,
                                               milestoneSelectionWxId,
                                               style=LB_SINGLE | LB_OWNERDRAW)

        # noinspection PyUnresolvedReferences
        self._milestoneList.Enable(False)
        sz = StaticBoxSizer(VERTICAL, self, "Repository Milestone Titles")
        sz.Add(self._milestoneList, BasePanel.PROPORTION_CHANGEABLE, EXPAND)

        self.Bind(EVT_LISTBOX, self._onMilestoneSelected,
                  milestoneSelectionWxId)

        return sz
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
    def _createMainContainer(self, szrMethodVisibility: BoxSizer) -> BoxSizer:

        lblParam: StaticText = StaticText(self, ID_ANY, _("Parameters:"))

        self._lstParams: ListBox = ListBox(self,
                                           ID_LST_PARAM_LIST,
                                           choices=[],
                                           style=LB_SINGLE)

        szrParamButtons: BoxSizer = self._createParameterButtonsContainer()
        szrButtons: BoxSizer = self._createDialogButtonsContainer()

        szr3: BoxSizer = BoxSizer(VERTICAL)

        szr3.Add(szrMethodVisibility, 0, ALL, 5)
        szr3.Add(lblParam, WX_SIZER_NOT_CHANGEABLE, ALL, 5)
        szr3.Add(self._lstParams, WX_SIZER_CHANGEABLE, ALL | EXPAND, 5)
        szr3.Add(szrParamButtons, WX_SIZER_NOT_CHANGEABLE,
                 ALL | ALIGN_CENTER_HORIZONTAL, 5)
        szr3.Add(szrButtons, WX_SIZER_NOT_CHANGEABLE, ALL | ALIGN_RIGHT, 5)

        self.Bind(EVT_LISTBOX, self._evtParamList, id=ID_LST_PARAM_LIST)

        return szr3
Exemplo n.º 13
0
class DlgAskWhichClassesToReverse(Dialog):

    def __init__(self, lstClasses):

        super().__init__(None, ID_ANY, "Classes choice", style=CAPTION | RESIZE_BORDER, size=(400, 500))

        # Create not chosen classes listBox
        self._listBox1 = ListBox(self, ID_ANY, style=LB_EXTENDED | LB_ALWAYS_SB | LB_SORT, size=(320, 400))
        for klass in lstClasses:
            self._listBox1.Append(klass.__name__, klass)

        # Create chosen classes listBox
        self._listBox2 = ListBox(self, ID_ANY, style=LB_EXTENDED | LB_ALWAYS_SB | LB_SORT, size=(320, 400))

        # Create buttons
        btnOk = Button(self, ID_OK, "Ok")
        btnToTheRight = Button(self, ID_BTN_TO_THE_RIGHT, "=>")
        btnToTheLeft  = Button(self, ID_BTN_TO_THE_LEFT,  "<=")

        # Callbacks
        self.Bind(EVT_BUTTON, self._onBtnToTheRight, id=ID_BTN_TO_THE_RIGHT)
        self.Bind(EVT_BUTTON, self._onBtnToTheLeft,  id=ID_BTN_TO_THE_LEFT)

        # Create info label
        lblChoice = StaticText(self, ID_ANY, _("Choose classes to reverse: "))

        # Create buttons sizer
        szrBtn = BoxSizer(VERTICAL)
        szrBtn.Add(btnToTheRight, 0, EXPAND)
        szrBtn.Add(btnToTheLeft,  0, EXPAND)

        # Create lists and buttons sizer
        szrLB = BoxSizer(HORIZONTAL)
        szrLB.Add(self._listBox1,  0, EXPAND)
        szrLB.Add(szrBtn,          0, EXPAND)
        szrLB.Add(self._listBox2,  0, EXPAND)

        # Create sizer
        box = BoxSizer(VERTICAL)
        box.Add(lblChoice, 0, EXPAND)
        box.Add(szrLB,     0, EXPAND)
        box.Add(btnOk,     0, EXPAND)
        box.Fit(self)
        self.SetAutoLayout(True)
        self.SetSizer(box)

        # Show dialog
        self.ShowModal()
        if self.GetReturnCode() == ID_CANCEL:     # abort -> empty right column

            while self._listBox2.GetCount() > 0:
                data = self._listBox2.GetClientData(0)
                name = self._listBox2.GetString(0)
                self._listBox1.Append(name, data)
                self._listBox2.Delete(0)

    def getChosenClasses(self):
        """
        Return the classes chosen by the user
        """
        ret = []
        for el in range(self._listBox2.GetCount()):
            ret.append(self._listBox2.GetClientData(el))
        return ret

    # noinspection PyUnusedLocal
    def _onBtnToTheRight(self, event: CommandEvent):
        """
        Callback for the "=>" button
        """
        lst = list(self._listBox1.GetSelections())
        lst.sort()
        lst.reverse()
        for i in lst:
            data = self._listBox1.GetClientData(i)
            name = self._listBox1.GetString(i)
            self._listBox2.Append(name, data)
            self._listBox1.Delete(i)

    # noinspection PyUnusedLocal
    def _onBtnToTheLeft(self, event: CommandEvent):
        """
        Callback for the "<=" button
        """
        lst = list(self._listBox2.GetSelections())
        lst.sort()
        lst.reverse()
        for i in lst:
            data = self._listBox2.GetClientData(i)
            name = self._listBox2.GetString(i)
            self._listBox1.Append(name, data)
            self._listBox2.Delete(i)
Exemplo n.º 14
0
    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()
Exemplo n.º 15
0
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)