fix: add backward compatibility for Flet 0.19.0

this is needed until more dust settles, for sake of testing.  Flet
0.19.0 was the main version used for initial dev (iirc) and while the
app now runs "fine" (and presumably would prefer) the latest Flet
0.23.2, the global error handler does *not* work there yet..

see also https://github.com/flet-dev/flet/issues/3615
This commit is contained in:
Lance Edgar 2024-07-07 13:52:47 -05:00
parent 4eb9442fce
commit f3ab4f859d
2 changed files with 34 additions and 5 deletions

View file

@ -169,7 +169,10 @@ def main(page: ft.Page):
threading.excepthook = thread_exc_hook
page.title = f"WuttaPOS v{wuttapos.__version__}"
page.window.full_screen = True
if hasattr(page, 'window'):
page.window.full_screen = True
else:
page.window_full_screen = True
# global defaults for button/text styles etc.
page.data = {
@ -179,7 +182,10 @@ def main(page: ft.Page):
def clean_exit():
# TODO: this doesn't do anything interesting now, but it could
page.window.destroy()
if hasattr(page, 'window'):
page.window.destroy()
else:
page.window_destroy()
def keyboard(e):
# exit on ctrl+Q
@ -194,8 +200,12 @@ def main(page: ft.Page):
clean_exit()
# cf. https://flet.dev/docs/controls/page/#window_destroy
page.window.prevent_close = True
page.window.on_event = window_event
if hasattr(page, 'window'):
page.window.prevent_close = True
page.window.on_event = window_event
else:
page.window_prevent_close = True
page.window_on_event = window_event
# TODO: probably these should be auto-loaded from spec
from wuttapos.views.pos import POSView
@ -227,6 +237,11 @@ def main(page: ft.Page):
elif page.route == '/login':
page.views.append(LoginView(config, '/login'))
if hasattr(page, 'window'):
page.window.full_screen = True
else:
page.window_full_screen = True
page.update()
# TODO: this was in example docs but not sure what it's for?

View file

@ -25,6 +25,8 @@ WuttaPOS - timestamp control
"""
import asyncio
import threading
import time
import flet as ft
@ -43,7 +45,13 @@ class WuttaTimestamp(ft.Text):
def did_mount(self):
self.running = True
self.page.run_task(self.update_display)
if hasattr(self.page, 'run_task'):
self.page.run_task(self.update_display)
else:
# nb. daemonized thread should be stopped when app exits
# cf. https://docs.python.org/3/library/threading.html#thread-objects
thread = threading.Thread(target=self.update_display_blocking, daemon=True)
thread.start()
def will_unmount(self):
self.running = False
@ -56,3 +64,9 @@ class WuttaTimestamp(ft.Text):
self.value = self.render_time(self.app.localtime())
self.update()
await asyncio.sleep(0.5)
def update_display_blocking(self):
while self.running:
self.value = self.render_time(self.app.localtime())
self.update()
time.sleep(0.5)