items screen POC

This commit is contained in:
2026-01-13 21:20:36 +01:00
parent 65bb3c7b2d
commit b751e75992
5 changed files with 223 additions and 43 deletions
+6
View File
@@ -7,6 +7,7 @@ from justgetit.register import Register
from justgetit.configuration import Configuration from justgetit.configuration import Configuration
from justgetit.providekey import ProvideKey from justgetit.providekey import ProvideKey
from justgetit.lists import Lists from justgetit.lists import Lists
from justgetit.items import Items
from justgetit.backend import BackEnd from justgetit.backend import BackEnd
from justgetit.localdata import LocalData from justgetit.localdata import LocalData
@@ -15,6 +16,7 @@ class JustEatIt(toga.App):
register_screen = toga.Box() register_screen = toga.Box()
providekey_screen = toga.Box() providekey_screen = toga.Box()
lists_screen = toga.Box() lists_screen = toga.Box()
items_screen = toga.Box()
backend = None backend = None
configuration = None configuration = None
last_screen_width = -1 last_screen_width = -1
@@ -32,6 +34,8 @@ class JustEatIt(toga.App):
self.set_page(self.login_screen) self.set_page(self.login_screen)
elif destination == PAGE_LISTS: elif destination == PAGE_LISTS:
self.set_page(self.lists_screen) self.set_page(self.lists_screen)
elif destination == PAGE_ITEMS:
self.set_page(self.items_screen)
def startup(self): def startup(self):
self.configuration = Configuration(self) self.configuration = Configuration(self)
@@ -42,9 +46,11 @@ class JustEatIt(toga.App):
self.register_screen = Register() self.register_screen = Register()
self.providekey_screen = ProvideKey() self.providekey_screen = ProvideKey()
self.lists_screen = Lists(self.localdata.lists) self.lists_screen = Lists(self.localdata.lists)
self.items_screen = Items(self.localdata.items)
self.backend = BackEnd(self) self.backend = BackEnd(self)
self.localdata.lists.data_widget = self.lists_screen.data_widget.source self.localdata.lists.data_widget = self.lists_screen.data_widget.source
self.localdata.items.data_widget = self.items_screen.data_widget.source
self.main_window = toga.MainWindow(title=self.formal_name) self.main_window = toga.MainWindow(title=self.formal_name)
+11
View File
@@ -11,6 +11,7 @@ class Configuration():
- user: the user as a dict - user: the user as a dict
- userlang: the users language - userlang: the users language
- lastlogin_date: date of last sucessful login - lastlogin_date: date of last sucessful login
- current_listid; the id of the last viewed list
""" """
loaded = False loaded = False
data = {} data = {}
@@ -82,3 +83,13 @@ class Configuration():
print() print()
result = self.data['user']['id'] result = self.data['user']['id']
return result return result
def set_current_listid(self, lid):
self.data['current_listid'] = lid
def get_current_listid(self):
if 'current_listid' in self.data:
return self.data['current_listid']
return 0
+164
View File
@@ -0,0 +1,164 @@
import toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW, END, START, CENTER, HIDDEN, JUSTIFY
from toga.sources import ListSource, Listener
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.source = ListSource(
accessors=["id", "listofitems_id", "label", "quantity", "unit", 'is_checked', 'is_suggestion', 'category']
)
self.source.add_listener(DatabaseList.DataListener(self))
def on_row_pressed(self, w):
# self.app.configuration.set_current_listid(w.id)
# self.app.goto_next_page_by_name(PAGE_ITEMS)
print("item buttn prtesse")
class DataListener(Listener):
# listen to the database
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")
return super().change(item)
def clear(self):
print("widget: data-item clear")
return super().clear()
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))
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
)
indicator_label = toga.Label(
text = f"{openitems} / {totalitems}",
style = Pack(
color="blue",
margin=8,
)
)
indicator_box = toga.Box(
children=[indicator_label],
style = Pack(
flex=2,
justify_content=END
)
)
listrow_inner = toga.Box(
style = Pack(
margin_bottom=1,
flex=1,
background_color="white", #white
)
)
listrow_inner.add(label)
listrow_inner.add(indicator_box)
listrow_outer = toga.Box(
style = Pack(
# flex=1,
background_color="#ccc", # ccc
)
)
listrow_outer.add(listrow_inner)
return(listrow_outer)
class Items(BasePage):
def __init__(self, datasource, *args, **kwargs):
"""
This page allows you to enter the aplication key
The aplication-key is kept until a month after the app is last used
:param self: register-screen
:param navigate_to: function to call if we want to switch screens
:param args: args for super
:param kwargs: kwars for super
"""
# set button and image
self.first_menu_button_icon = 'edit3'
self.first_menu_button_callback = self.edit_button_pressed
self.second_menu_button_icon = 'logout'
self.second_menu_button_callback = self.logout_button_pressed
self.datasource = datasource
super().__init__(*args, **kwargs)
# here the list of lists
self.data_widget = DatabaseList(
style=Pack(
margin_bottom=10,
# background_color="white",
),
)
scrollarea = toga.ScrollContainer(
content=self.data_widget,
style=Pack(
flex=1,
margin=10,
),
horizontal=False
)
# at the bottom of the list: edit-button
save_button = toga.Button(
icon=toga.Icon("images/edit"),
style=Pack(
width=50,
margin=10,
),
on_press=self.edit_button_pressed)
save_button_box= toga.Column(
children=[save_button],
style=Pack(
flex=1,
align_items=START,
margin=20
)
)
# wrapping up the windows elements
self.content_box.add(scrollarea)
# self.content_box.add(save_button_box)
def on_show(self):
super().on_show()
self.datasource.reload()
def edit_button_pressed(self):
self.app.goto_next_page_by_name(PAGE_ADDITEMS)
+25 -21
View File
@@ -12,10 +12,14 @@ class DatabaseList(toga.Box):
super().__init__(id, style, children, **kwargs) super().__init__(id, style, children, **kwargs)
self.source = ListSource( self.source = ListSource(
accessors=["id", "owner_user_id", "name", "is_active"] accessors=["id", "owner_user_id", "name", "is_active", "pending", 'total']
) )
self.source.add_listener(DatabaseList.DataListener(self)) self.source.add_listener(DatabaseList.DataListener(self))
def on_row_pressed(self, w):
print("goto list")
self.app.configuration.set_current_listid(int(w.id))
self.app.goto_next_page_by_name(PAGE_ITEMS)
class DataListener(Listener): class DataListener(Listener):
# listen to the database # listen to the database
@@ -34,36 +38,38 @@ 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.name,"3", "20")) self.parent_widget.add(self.create_row(item.id, item.name, item.pending, item.total))
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, text, openitems, totalitems): def create_row(self, listid, text, openitems, totalitems):
label = toga.Button( label = toga.Button(
text=text, text=text,
id=listid,
margin_bottom=2, margin_bottom=2,
style = Pack( style = Pack(
# margin_bottom=2, # scrollig doesnt work, bug?, replaced by margin_bottom in Button flex=12,
# width=250,
flex=15,
background_color="white", #white background_color="white", #white
font_size=15 font_size=15,
) ),
on_press=self.parent_widget.on_row_pressed
) )
spacer = toga.Box( indicator_label = toga.Label(
style = Pack(
flex=1
)
)
indicator = toga.Label(
text = f"{openitems} / {totalitems}", text = f"{openitems} / {totalitems}",
style = Pack( style = Pack(
color="blue", color="blue",
margin=8, margin=8,
flex=2
)
)
indicator_box = toga.Box(
children=[indicator_label],
style = Pack(
flex=2,
justify_content=END
) )
) )
listrow_inner = toga.Box( listrow_inner = toga.Box(
@@ -74,8 +80,7 @@ class DatabaseList(toga.Box):
) )
) )
listrow_inner.add(label) listrow_inner.add(label)
listrow_inner.add(spacer) listrow_inner.add(indicator_box)
listrow_inner.add(indicator)
listrow_outer = toga.Box( listrow_outer = toga.Box(
style = Pack( style = Pack(
@@ -88,6 +93,8 @@ class DatabaseList(toga.Box):
return(listrow_outer) return(listrow_outer)
class Lists(BasePage): class Lists(BasePage):
def __init__(self, datasource, *args, **kwargs): def __init__(self, datasource, *args, **kwargs):
@@ -153,9 +160,6 @@ class Lists(BasePage):
super().on_show() super().on_show()
self.datasource.reload() self.datasource.reload()
def edit_button_pressed(self): def edit_button_pressed(self):
self.app.goto_next_page_by_name(PAGE_EDITLISTS) self.app.goto_next_page_by_name(PAGE_EDITLISTS)
+16 -21
View File
@@ -17,36 +17,31 @@ class ListsData():
for item in result['data']: for item in result['data']:
self.data_widget.append(item) self.data_widget.append(item)
class ItemsData():
def __init__(self, app):
self.app = app
self.data_widget = None
def reload(self):
print("reload items")
current_userid = self.app.configuration.get_userid()
current_listid = self.app.configuration.get_current_listid()
if current_listid > 0:
parameters = {}
parameters['listid'] = current_listid
result = self.app.backend.postwait('load_items', parameters)
for item in result['data']:
self.data_widget.append(item)
class List():
id = 0
updated_at = None
owner_user_id = 0
name = ''
is_active = True
class Item():
id = 0
updated_at = None
listofitems_id = 0
label = ''
quantity = 0
unit = ''
label_alt1 = ''
label_alt2 = ''
is_checked = False
is_suggestion = False
category = ''
class LocalData(): class LocalData():
def __init__(self, app): def __init__(self, app):
self.app = app self.app = app
self.curent_userid = 0 self.curent_userid = 0
self.current_listid = 0 self.current_listid = 0
self.lists = ListsData(app) self.lists = ListsData(app)
self.items = ItemsData(app)
def set_user(self, userid): def set_user(self, userid):
if userid != self.curent_userid: if userid != self.curent_userid: