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 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_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 """ 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.configuration = Configuration(self) 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(icon='images/logo.png')