Files
JustGetIt/src/justgetit/app.py
T

79 lines
2.5 KiB
Python
Raw Normal View History

2026-01-06 22:56:13 +01:00
import toga
from toga.style.pack import COLUMN, ROW, CENTER, START, END
from toga.style import Pack
from justgetit.constants import *
from justgetit.login import Login
from justgetit.register import Register
from justgetit.configuration import Configuration
from justgetit.providekey import ProvideKey
from justgetit.lists import Lists
2026-01-06 22:56:13 +01:00
class JustEatIt(toga.App):
login_screen = toga.Box()
register_screen = toga.Box()
providekey_screen = toga.Box()
lists_screen = toga.Box()
configuration = None
last_screen_width = SCREENWIDTH
2026-01-06 22:56:13 +01:00
def goto_next_page_by_name(self, destination):
2026-01-06 22:56:13 +01:00
"""
ask app to activate a next page, id of the page is in the id of the widget
:param widget: the widget that called this function
"""
if destination == PAGE_REGISTER:
self.set_page(self.register_screen)
elif destination == PAGE_LOGIN:
self.set_page(self.login_screen)
elif destination == PAGE_LISTS:
self.set_page(self.lists_screen)
2026-01-06 22:56:13 +01:00
def startup(self):
self.configuration = Configuration(self)
self.login_screen = Login()
self.register_screen = Register()
self.providekey_screen = ProvideKey()
self.lists_screen = Lists()
2026-01-06 22:56:13 +01:00
self.main_window = toga.MainWindow(title=self.formal_name)
# here comes the startup logic.
# check if there is a valid APP-KEY
# check if there is va alid user and user has been logged in recently
if self.configuration.has_valid_app_key():
if self.configuration.user_is_logged_in():
self.set_page(self.lists_screen)
else:
self.set_page(self.login_screen)
else:
self.set_page(self.providekey_screen)
2026-01-06 22:56:13 +01:00
self.main_window.show()
# Initial layout clamp
self.on_resize(self.main_window)
def set_page(self, page):
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
2026-01-06 22:56:13 +01:00
if width < SCREENWIDTH:
# Phone-like: fill available width
elf.last_screen_width = width
else:
self.last_screen_width = SCREENWIDTH
# set actie screen to the corre ct width
self.main_window.content.set_screen_width(self.last_screen_width)
2026-01-06 22:56:13 +01:00
def on_exit(self):
self.configuration.save()
return super().on_exit()
2026-01-06 22:56:13 +01:00
def main():
return JustEatIt(icon='images/logo.png')