diff --git a/src/justgetit/images/checked.png b/src/justgetit/images/checked.png new file mode 100644 index 0000000..1ed8bb7 Binary files /dev/null and b/src/justgetit/images/checked.png differ diff --git a/src/justgetit/images/unchecked.png b/src/justgetit/images/unchecked.png new file mode 100644 index 0000000..7c7bec1 Binary files /dev/null and b/src/justgetit/images/unchecked.png differ diff --git a/src/justgetit/items.py b/src/justgetit/items.py index 634337a..5c8f75f 100644 --- a/src/justgetit/items.py +++ b/src/justgetit/items.py @@ -6,10 +6,14 @@ import datetime from justgetit.constants import * from justgetit.basepage import BasePage + class DatabaseList(toga.Box): def __init__(self, id=None, style=None, children=None, **kwargs): style.direction = COLUMN super().__init__(id, style, children, **kwargs) + self.rows = {} + self.icon_checked = toga.Icon(path="images/checked") + self.icon_unchecked = toga.Icon(path="images/unchecked") self.source = ListSource( accessors=["id", "listofitems_id", "label", "quantity", "unit", 'is_checked', 'is_suggestion', 'category'] @@ -20,6 +24,9 @@ class DatabaseList(toga.Box): def on_row_pressed(self, w): # self.app.configuration.set_current_listid(w.id) # self.app.goto_next_page_by_name(PAGE_ITEMS) + # the widget may have an id of L_26 or B_26, so remove the _ and make it an int + item = self.source.find({"id": int(w.id.replace("L_","").replace("B_",""))}) + item.is_checked = not item.is_checked print("item buttn prtesse") @@ -28,10 +35,12 @@ class DatabaseList(toga.Box): def __init__(self, parent_widget): print("widget: data-item init") self.parent_widget = parent_widget + super().__init__() def change(self, item): print("widget: data-item change") + self.parent_widget.rows[item.id].checkbox.icon = self.parent_widget.icon_checked if item.is_checked else self.parent_widget.icon_unchecked return super().change(item) def clear(self): @@ -40,40 +49,91 @@ class DatabaseList(toga.Box): def insert(self, index, item): print("widget: data-item insert") - self.parent_widget.add(self.create_row(item.id, item.label, item.quantity, item.unit)) + r = DatabaseList.ItemRow(self.parent_widget, item.id, item.label, item.is_checked, item.quantity, item.unit) + self.parent_widget.add(r) + self.parent_widget.rows[item.id] = r return super().insert(index, item) def remove(self, index, item): print("widget: data-item remove") return super().remove(index, item) - def create_row(self, listid, text, openitems, totalitems): - label = toga.Button( - text=text, - id=listid, - margin_bottom=2, - style = Pack( - flex=12, - background_color="white", #white - font_size=15, - ), - on_press=self.parent_widget.on_row_pressed + class ItemRow(toga.Box): + def __init__(self, parent_widget, id, label, is_checked, quantity, unit, **kwargs): + self.parent_widget = parent_widget + style=Pack( + direction=ROW, + background_color="#ccc", # ccc ) - indicator_label = toga.Label( - text = f"{openitems} / {totalitems}", - style = Pack( - color="blue", - margin=8, + super().__init__(id=id, style=style, children=None, **kwargs) + # checkbox = toga.Switch( + # text = '', + # value = is_checked, + # on_change=self.parent_widget.on_row_pressed, + # style=Pack( + # font_size=12, + # ) + # ) + + # item_label = toga.Label( + # text = label, + # style = Pack( + # margin=4, + # font_size=15 + # ) + # ) + + item_label = toga.Button( + text=label, + id=f"L_{id}", + style = Pack( + margin=4, + font_size=15, + background_color="white" + ), + on_press=self.parent_widget.on_row_pressed, + + ) + + + self.checkbox = toga.Button( + icon=self.parent_widget.icon_checked if is_checked else self.parent_widget.icon_unchecked, + id=f"B_{id}", + # margin_bottom=2, + on_press=self.parent_widget.on_row_pressed, + style=Pack( + background_color="white", ) ) - indicator_box = toga.Box( - children=[indicator_label], + + quantity_label = toga.Label( + text = f"{quantity} {unit}", style = Pack( - flex=2, + color="blue", + margin=5, + font_size=12 + ) + ) + + left_box = toga.Box( + style = Pack( + flex=1, + justify_content=START, + margin=4 + ) + ) + left_box.add(self.checkbox) + left_box.add(item_label) + + right_box = toga.Box( + style = Pack( + flex=1, justify_content=END ) ) + right_box.add(quantity_label) + listrow_inner = toga.Box( style = Pack( margin_bottom=1, @@ -81,18 +141,10 @@ class DatabaseList(toga.Box): background_color="white", #white ) ) - listrow_inner.add(label) - listrow_inner.add(indicator_box) + listrow_inner.add(left_box) + listrow_inner.add(right_box) - listrow_outer = toga.Box( - style = Pack( - # flex=1, - background_color="#ccc", # ccc - ) - ) - listrow_outer.add(listrow_inner) - - return(listrow_outer) + self.add(listrow_inner) class Items(BasePage):