Esempio n. 1
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
Esempio n. 2
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))