base app with app-key, registration, login, logout

This commit is contained in:
2026-01-09 13:36:21 +01:00
parent e316001fa7
commit 362a83b2e3
13 changed files with 602 additions and 160 deletions
+52 -13
View File
@@ -1,40 +1,79 @@
import toga
from toga.style.pack import COLUMN, ROW, CENTER, START, END
from toga.style import Pack
import requests
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
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
def goto_next_page(self, widget):
def goto_next_page_by_name(self, destination):
"""
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
"""
print(f"action 6 {widget.id}")
if widget.id == 'register':
self.main_window.content = self.register_screen
elif widget.id =='login':
self.main_window.content = self.login_screen
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)
def startup(self):
self.login_screen = Login(navigate_to=self.goto_next_page)
self.register_screen = Register(navigate_to=self.goto_next_page)
self.configuration = Configuration(self)
self.main_window = toga.MainWindow(title=self.formal_name, size=(SCREENWIDTH, SCREENHEIGHT))
self.main_window.content = self.register_screen
self.login_screen = Login()
self.register_screen = Register()
self.providekey_screen = ProvideKey()
self.lists_screen = Lists()
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)
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
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)
def on_exit(self):
self.configuration.save()
return super().on_exit()
def main():
return JustEatIt()
return JustEatIt(icon='images/logo.png')