diff --git a/src/justgetit/app.py b/src/justgetit/app.py index 183a412..99e1f93 100644 --- a/src/justgetit/app.py +++ b/src/justgetit/app.py @@ -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): @@ -58,19 +58,20 @@ class JustEatIt(toga.App): # Initial layout clamp self.on_resize(self.main_window) - def set_page(self, page): - page.set_screen_width(self.last_screen_width) + def set_page(self, page): + 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): diff --git a/src/justgetit/basepage.py b/src/justgetit/basepage.py index 0d4e912..5721041 100644 --- a/src/justgetit/basepage.py +++ b/src/justgetit/basepage.py @@ -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 \ No newline at end of file + 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) \ No newline at end of file diff --git a/src/justgetit/configuration.py b/src/justgetit/configuration.py index 5f50efd..6e88dd7 100644 --- a/src/justgetit/configuration.py +++ b/src/justgetit/configuration.py @@ -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() diff --git a/src/justgetit/constants.py b/src/justgetit/constants.py index 74e593a..3d10596 100644 --- a/src/justgetit/constants.py +++ b/src/justgetit/constants.py @@ -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' diff --git a/src/justgetit/images/edit.png b/src/justgetit/images/edit.png new file mode 100644 index 0000000..8b71678 Binary files /dev/null and b/src/justgetit/images/edit.png differ diff --git a/src/justgetit/images/edit2.png b/src/justgetit/images/edit2.png new file mode 100644 index 0000000..dd2bd38 Binary files /dev/null and b/src/justgetit/images/edit2.png differ diff --git a/src/justgetit/images/edit3.png b/src/justgetit/images/edit3.png new file mode 100644 index 0000000..b188704 Binary files /dev/null and b/src/justgetit/images/edit3.png differ diff --git a/src/justgetit/lists.py b/src/justgetit/lists.py index 3e4f4b6..9fd1955 100644 --- a/src/justgetit/lists.py +++ b/src/justgetit/lists.py @@ -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 - - :param self: this screen - :param w: width - """ - self.content_box.style.width = w + listrow_outer = toga.Box( + style = Pack( + flex=1, + background_color="#ccc", + ) + ) + listrow_outer.add(listrow_inner) - def logout_button_pressed(self, widget): - self.app.configuration.logout_user() - self.app.goto_next_page_by_name(PAGE_LOGIN) \ No newline at end of file + return(listrow_outer) \ No newline at end of file diff --git a/src/justgetit/localmodel.py b/src/justgetit/localmodel.py new file mode 100644 index 0000000..8294e7f --- /dev/null +++ b/src/justgetit/localmodel.py @@ -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)) \ No newline at end of file