added scrolling widget for lists

This commit is contained in:
2026-01-10 16:08:21 +01:00
parent e3672c4b14
commit c4b5cac768
9 changed files with 137 additions and 70 deletions
+8 -7
View File
@@ -16,7 +16,7 @@ class JustEatIt(toga.App):
lists_screen = toga.Box()
backend = None
configuration = None
last_screen_width = SCREENWIDTH
last_screen_width = -1
def goto_next_page_by_name(self, destination):
@@ -59,18 +59,19 @@ class JustEatIt(toga.App):
self.on_resize(self.main_window)
def set_page(self, page):
page.set_screen_width(self.last_screen_width)
if self.last_screen_width > 0:
page.set_screen_width(self.last_screen_width)
self.main_window.content = page
def on_resize(self, widget, **kwargs):
width = self.main_window.size.width
if width < SCREENWIDTH:
# Phone-like: fill available width
self.last_screen_width = width
if width >= TABLET_WIDTH:
self.last_screen_width = MAX_NONMOBILE_SCREENWIDTH
else:
self.last_screen_width = SCREENWIDTH
# set actie screen to the corre ct width
self.last_screen_width = -1
# set current screen to the correct width
self.main_window.content.set_screen_width(self.last_screen_width)
def on_exit(self):
+10 -3
View File
@@ -62,8 +62,10 @@ class BasePage(toga.Box):
style=Pack(
direction=COLUMN,
align_items=CENTER,
justify_content=END,
margin=24
justify_content=START,
margin=24,
flex=1,
background_color="yellow"
)
)
@@ -131,10 +133,15 @@ class BasePage(toga.Box):
:param self: this screen
:param w: width
"""
self.content_box.style.width = w
if w>0:
self.content_box.style.width = w
async def display_warning(self, message):
self.warningtext.text = message
self.warning_box = self.warningline_outer
await asyncio.sleep(5)
self.warning_box = self.warning_placeholder
def logout_button_pressed(self, widget):
self.app.configuration.logout_user()
self.app.goto_next_page_by_name(PAGE_LOGIN)
+2
View File
@@ -37,6 +37,7 @@ class Configuration():
def has_valid_app_key(self):
return True
if 'appkey' in self.data:
print("found app key {self.data['appkey']}")
today = datetime.date.today()
@@ -52,6 +53,7 @@ class Configuration():
self.save()
def user_is_logged_in(self):
return True
if 'username' in self.data:
print("found user {self.data['username']}")
today = datetime.date.today()
+3 -2
View File
@@ -1,5 +1,6 @@
SCREENWIDTH = 400
# SCREENHEIGHT = 680
MAX_NONMOBILE_SCREENWIDTH = 400
MOBILE_PLATFORMS = ['ios', 'android']
TABLET_WIDTH = 600
PAGE_LOGIN = 'login'
PAGE_REGISTER = 'register'
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

+90 -56
View File
@@ -4,86 +4,120 @@ from toga.style.pack import COLUMN, ROW, END, START, CENTER, HIDDEN, JUSTIFY
# from justgetit.constants import SCREENHEIGHT, SCREENWIDTH
import asyncio
from justgetit.constants import *
import httpx
from justgetit.basepage import BasePage
class Lists(toga.Box):
dialog_txt = ""
class Lists(BasePage):
def __init__(self, *args, **kwargs):
"""
Docstring for __init__
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
super().__init__(*args, **kwargs)
# menu bar with register button
register_button = toga.Button(
icon=toga.Icon("images/logout"),
id="login",
style=Pack(margin=5),
on_press=self.logout_button_pressed)
menu_bar_inner = toga.Box(
children = [register_button],
# here the list of lists
listholder = toga.Column(
style=Pack(
background_color="#efefef",
justify_content=END,
flex=1),
margin_bottom=10,
background_color="#aaa",
)
)
menu_bar = toga.Row(
children = [menu_bar_inner]
scrollarea = toga.ScrollContainer(
content=listholder,
style=Pack(
flex=1,
margin=10,
),
horizontal=False
)
# line ast the bottom of the menubar
liner=toga.Box(style=Pack(flex=1, height = 2, background_color="#ddd"))
# body of the screen with image 2 edit fielfds and ok button
# Title icon
my_image = toga.Image("images/key.png")
title = toga.ImageView(my_image, style=Pack(
for i in range(30):
listholder.add(self.create_row("Supermarkt",f"{i}","30"))
# at the bottom of the list: edit-button
save_button = toga.Button(
icon=toga.Icon("images/edit"),
style=Pack(
width=50,
margin_bottom=20
))
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 = toga.Box(
children=[
title,
self.content_box.add(scrollarea)
# self.content_box.add(save_button_box)
# self.helpbox
def edit_button_pressed(self):
self.app.goto_next_page_by_name(PAGE_EDITLISTS)
],
style=Pack(
direction=COLUMN,
align_items=CENTER,
justify_content=END,
margin=24
def create_row(self, text, open, total):
label = toga.Button(
text=text,
margin_bottom=2,
style = Pack(
# margin_bottom=2, # scrollig doesnt work, bug?, replaced by margin_bottom in Button
width=250,
background_color="white",
font_size=15
)
)
# bringing the 3 parts together
self.add(menu_bar)
self.add(liner)
self.add(self.content_box)
self.style=Pack(
direction=COLUMN,
flex=1,
align_items=CENTER,
spacer = toga.Box(
style = Pack(
flex=1
)
)
indicator = toga.Label(
text = f"{open} / {total}",
style = Pack(
color="blue",
margin=8
)
)
listrow_inner = toga.Box(
style = Pack(
margin_bottom=1,
flex=1,
background_color="white",
)
)
listrow_inner.add(label)
listrow_inner.add(spacer)
listrow_inner.add(indicator)
def set_screen_width(self, w):
"""
mainscreen is calling this for setting proper screen width, upon start and on-resize
listrow_outer = toga.Box(
style = Pack(
flex=1,
background_color="#ccc",
)
)
listrow_outer.add(listrow_inner)
:param self: this screen
:param w: width
"""
self.content_box.style.width = w
def logout_button_pressed(self, widget):
self.app.configuration.logout_user()
self.app.goto_next_page_by_name(PAGE_LOGIN)
return(listrow_outer)
+22
View File
@@ -0,0 +1,22 @@
class ListItems():
id = 0
updated_at = None
owner_user_id = 0
name = ''
is_active = True
class Item():
id = 0
updated_at = db.Column(db.TIMESTAMP, default=datetime.now(), onupdate=datetime.now(), nullable=False)
listofitems_id = db.Column(db.Integer, nullable=False)
label = db.Column(db.String(40), nullable=False)
quantity = db.Column(db.Integer, default=0)
unit = db.Column(db.String(10))
label_alt1 = db.Column(db.String(40))
label_alt2 = db.Column(db.String(40))
is_checked = db.Column(db.Boolean, default=False)
is_suggestion = db.Column(db.Boolean, default=False)
category = db.Column(db.String(20))