item screen improved (las version before model revamp)

This commit is contained in:
2026-01-24 17:39:48 +01:00
parent b751e75992
commit 1d5c7b2e49
3 changed files with 83 additions and 31 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

+82 -30
View File
@@ -6,10 +6,14 @@ import datetime
from justgetit.constants import * from justgetit.constants import *
from justgetit.basepage import BasePage from justgetit.basepage import BasePage
class DatabaseList(toga.Box): class DatabaseList(toga.Box):
def __init__(self, id=None, style=None, children=None, **kwargs): def __init__(self, id=None, style=None, children=None, **kwargs):
style.direction = COLUMN style.direction = COLUMN
super().__init__(id, style, children, **kwargs) 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( self.source = ListSource(
accessors=["id", "listofitems_id", "label", "quantity", "unit", 'is_checked', 'is_suggestion', 'category'] 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): def on_row_pressed(self, w):
# self.app.configuration.set_current_listid(w.id) # self.app.configuration.set_current_listid(w.id)
# self.app.goto_next_page_by_name(PAGE_ITEMS) # 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") print("item buttn prtesse")
@@ -28,10 +35,12 @@ class DatabaseList(toga.Box):
def __init__(self, parent_widget): def __init__(self, parent_widget):
print("widget: data-item init") print("widget: data-item init")
self.parent_widget = parent_widget self.parent_widget = parent_widget
super().__init__() super().__init__()
def change(self, item): def change(self, item):
print("widget: data-item change") 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) return super().change(item)
def clear(self): def clear(self):
@@ -40,40 +49,91 @@ class DatabaseList(toga.Box):
def insert(self, index, item): def insert(self, index, item):
print("widget: data-item insert") 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) return super().insert(index, item)
def remove(self, index, item): def remove(self, index, item):
print("widget: data-item remove") print("widget: data-item remove")
return super().remove(index, item) return super().remove(index, item)
def create_row(self, listid, text, openitems, totalitems): class ItemRow(toga.Box):
label = toga.Button( def __init__(self, parent_widget, id, label, is_checked, quantity, unit, **kwargs):
text=text, self.parent_widget = parent_widget
id=listid, style=Pack(
margin_bottom=2, direction=ROW,
style = Pack( background_color="#ccc", # ccc
flex=12,
background_color="white", #white
font_size=15,
),
on_press=self.parent_widget.on_row_pressed
) )
indicator_label = toga.Label( super().__init__(id=id, style=style, children=None, **kwargs)
text = f"{openitems} / {totalitems}",
# 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( style = Pack(
color="blue", margin=4,
margin=8, 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( 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 justify_content=END
) )
) )
right_box.add(quantity_label)
listrow_inner = toga.Box( listrow_inner = toga.Box(
style = Pack( style = Pack(
margin_bottom=1, margin_bottom=1,
@@ -81,18 +141,10 @@ class DatabaseList(toga.Box):
background_color="white", #white background_color="white", #white
) )
) )
listrow_inner.add(label) listrow_inner.add(left_box)
listrow_inner.add(indicator_box) listrow_inner.add(right_box)
listrow_outer = toga.Box( self.add(listrow_inner)
style = Pack(
# flex=1,
background_color="#ccc", # ccc
)
)
listrow_outer.add(listrow_inner)
return(listrow_outer)
class Items(BasePage): class Items(BasePage):