Example #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
Example #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))
Example #3
0
class TestPanel(BaseWindowPanel):
    def __init__(self, parent):
        BaseWindowPanel.__init__(self,
                                 parent,
                                 bg_color=Colour.BLACK,
                                 fg_color=Colour.WHITE)

        self._caption_label = StaticText(self,
                                         pos=(70, 5),
                                         size=(20, 0),
                                         label=u"This month, we spent")
        self._caption_label.SetFont(
            Font(13, FONTFAMILY_DEFAULT, FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL))

        self._display = LEDNumberCtrl(self,
                                      pos=(0, 30),
                                      size=(320, 90),
                                      style=LED_ALIGN_RIGHT)
        self._display.SetValue("0.00")

        self._date_display = LEDNumberCtrl(self,
                                           pos=(110, 150),
                                           size=(210, 40),
                                           style=LED_ALIGN_RIGHT)
        self._date_display.SetValue("--.--.--")

        self._clock_display = LEDNumberCtrl(self,
                                            pos=(110, 190),
                                            size=(210, 50),
                                            style=LED_ALIGN_RIGHT)
        self._clock_display.SetValue("--.--.--")

        self.open_button = Button(self,
                                  -1,
                                  "Add",
                                  pos=(10, 125),
                                  size=(70, 35))
        self.open_button.SetBackgroundColour(Colour.DARK_GREEN)
        self.open_button.SetForegroundColour(Colour.WHITE)

        self.list_button = Button(self,
                                  -1,
                                  "List",
                                  pos=(10, 160),
                                  size=(70, 35))
        self.list_button.SetBackgroundColour(get_colour(0x333333))
        self.list_button.SetForegroundColour(Colour.WHITE)

        self.close_button = Button(self,
                                   -1,
                                   "Close",
                                   pos=(10, 195),
                                   size=(70, 35))
        self.close_button.SetBackgroundColour(Colour.DARK_RED)
        self.close_button.SetForegroundColour(Colour.WHITE)

        self._timer = Timer(self)
        self._timer.Start(100)
        self.Bind(EVT_TIMER, self.on_clock_update, self._timer)

    def set_display(self, value):
        """
        :param float value:
        """
        self._display.SetValue("{:.2f}".format(value))

    def on_clock_update(self, e):
        self._clock_display.SetValue(datetime.now().strftime("%H:%M:%S"))
        self._date_display.SetValue(datetime.now().strftime("%d-%m-%Y"))
Example #4
0
class NumberInputWindowPanel(BaseWindowPanel):
    def __init__(self, parent):
        BaseWindowPanel.__init__(self,
                                 parent,
                                 bg_color=Colour.BLACK,
                                 fg_color=Colour.WHITE)

        self._display = LEDNumberCtrl(self,
                                      pos=(0, 0),
                                      size=(320, 70),
                                      style=LED_ALIGN_RIGHT)
        self._display.SetValue("0.00")

        self.keypad_7 = Button(self, -1, "7", size=(50, 50), pos=(5, 80))
        self.keypad_8 = Button(self, -1, "8", size=(50, 50), pos=(60, 80))
        self.keypad_9 = Button(self, -1, "9", size=(50, 50), pos=(115, 80))

        self.keypad_4 = Button(self, -1, "4", size=(50, 50), pos=(5, 130))
        self.keypad_5 = Button(self, -1, "5", size=(50, 50), pos=(60, 130))
        self.keypad_6 = Button(self, -1, "6", size=(50, 50), pos=(115, 130))

        self.keypad_1 = Button(self, -1, "1", size=(50, 50), pos=(5, 180))
        self.keypad_2 = Button(self, -1, "2", size=(50, 50), pos=(60, 180))
        self.keypad_3 = Button(self, -1, "3", size=(50, 50), pos=(115, 180))

        self.keypad_del = Button(self, -1, "<<", size=(50, 50), pos=(170, 80))
        self.keypad_0 = Button(self, -1, "00", size=(50, 50), pos=(170, 130))
        self.keypad_00 = Button(self, -1, "0", size=(50, 50), pos=(170, 180))

        self.keypad_cancel = Button(self,
                                    -1,
                                    "X",
                                    size=(75, 50),
                                    pos=(230, 80))
        self.keypad_confirm = Button(self,
                                     -1,
                                     "OK",
                                     size=(75, 100),
                                     pos=(230, 130))

        f = Font(20, FONTFAMILY_DEFAULT, FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL)

        for b in [
                self.keypad_0, self.keypad_1, self.keypad_2, self.keypad_3,
                self.keypad_4, self.keypad_5, self.keypad_6, self.keypad_7,
                self.keypad_8, self.keypad_9, self.keypad_00
        ]:  # type: Button
            b.SetBackgroundColour(get_colour(0x333333))
            b.SetForegroundColour(Colour.WHITE)
            b.SetFont(f)

        self.keypad_del.SetBackgroundColour(Colour.DARK_RED)
        self.keypad_del.SetForegroundColour(Colour.WHITE)
        self.keypad_del.SetFont(f)

        self.keypad_cancel.SetBackgroundColour(Colour.DARK_RED)
        self.keypad_cancel.SetForegroundColour(Colour.WHITE)
        self.keypad_cancel.SetFont(f)

        self.keypad_confirm.SetBackgroundColour(Colour.DARK_GREEN)
        self.keypad_confirm.SetForegroundColour(Colour.WHITE)
        self.keypad_confirm.SetFont(f)

        self._value = 0
        self._result_confirm = False

        self.set_value(0.00)

    def get_result(self):
        return self.get_value() if self._result_confirm else None

    def get_value(self):
        return float("{:.2f}".format(self._value))

    def set_value(self, value):
        self._value = value
        self._update_value()

    def add_value(self, value):
        v = int(value)
        val = self._value * 10

        if v == 0 and value == "00":
            val = val * 10
        else:
            val += (v * 0.01)

        if val > NumberInputWindow.MAX_VALUE:
            return

        self._value = val
        self._update_value()

    def delete_value(self, it=1):
        for i in range(it):
            v = float("{:.2f}".format(self._value)) * 100
            v -= (v % 10)  # Remove last digit
            self.set_value(v / 1000)

    def _update_value(self):
        self._display.SetValue("{:0.2f}".format(self._value))

    def on_input_callback(self, e):
        """
        :param CommandEvent e:
        :return:
        """
        o = e.GetEventObject()
        self.add_value(o.GetLabel())

    def on_delete(self, e):
        self.delete_value()

    def on_confirm(self, e):
        self._result_confirm = True
        # self.GetParent().Close()

    def on_cancel(self, e):
        # self.GetParent().Close()
        pass

    # @Override
    def Show(self, show=True):
        self._result_confirm = False
        super(NumberInputWindowPanel, self).Show(show)
        self.set_value(0)