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:
parent
4eb9442fce
commit
f3ab4f859d
|
@ -169,7 +169,10 @@ def main(page: ft.Page):
|
||||||
threading.excepthook = thread_exc_hook
|
threading.excepthook = thread_exc_hook
|
||||||
|
|
||||||
page.title = f"WuttaPOS v{wuttapos.__version__}"
|
page.title = f"WuttaPOS v{wuttapos.__version__}"
|
||||||
|
if hasattr(page, 'window'):
|
||||||
page.window.full_screen = True
|
page.window.full_screen = True
|
||||||
|
else:
|
||||||
|
page.window_full_screen = True
|
||||||
|
|
||||||
# global defaults for button/text styles etc.
|
# global defaults for button/text styles etc.
|
||||||
page.data = {
|
page.data = {
|
||||||
|
@ -179,7 +182,10 @@ def main(page: ft.Page):
|
||||||
|
|
||||||
def clean_exit():
|
def clean_exit():
|
||||||
# TODO: this doesn't do anything interesting now, but it could
|
# TODO: this doesn't do anything interesting now, but it could
|
||||||
|
if hasattr(page, 'window'):
|
||||||
page.window.destroy()
|
page.window.destroy()
|
||||||
|
else:
|
||||||
|
page.window_destroy()
|
||||||
|
|
||||||
def keyboard(e):
|
def keyboard(e):
|
||||||
# exit on ctrl+Q
|
# exit on ctrl+Q
|
||||||
|
@ -194,8 +200,12 @@ def main(page: ft.Page):
|
||||||
clean_exit()
|
clean_exit()
|
||||||
|
|
||||||
# cf. https://flet.dev/docs/controls/page/#window_destroy
|
# cf. https://flet.dev/docs/controls/page/#window_destroy
|
||||||
|
if hasattr(page, 'window'):
|
||||||
page.window.prevent_close = True
|
page.window.prevent_close = True
|
||||||
page.window.on_event = window_event
|
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
|
# TODO: probably these should be auto-loaded from spec
|
||||||
from wuttapos.views.pos import POSView
|
from wuttapos.views.pos import POSView
|
||||||
|
@ -227,6 +237,11 @@ def main(page: ft.Page):
|
||||||
elif page.route == '/login':
|
elif page.route == '/login':
|
||||||
page.views.append(LoginView(config, '/login'))
|
page.views.append(LoginView(config, '/login'))
|
||||||
|
|
||||||
|
if hasattr(page, 'window'):
|
||||||
|
page.window.full_screen = True
|
||||||
|
else:
|
||||||
|
page.window_full_screen = True
|
||||||
|
|
||||||
page.update()
|
page.update()
|
||||||
|
|
||||||
# TODO: this was in example docs but not sure what it's for?
|
# TODO: this was in example docs but not sure what it's for?
|
||||||
|
|
|
@ -25,6 +25,8 @@ WuttaPOS - timestamp control
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
import flet as ft
|
import flet as ft
|
||||||
|
|
||||||
|
@ -43,7 +45,13 @@ class WuttaTimestamp(ft.Text):
|
||||||
|
|
||||||
def did_mount(self):
|
def did_mount(self):
|
||||||
self.running = True
|
self.running = True
|
||||||
|
if hasattr(self.page, 'run_task'):
|
||||||
self.page.run_task(self.update_display)
|
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):
|
def will_unmount(self):
|
||||||
self.running = False
|
self.running = False
|
||||||
|
@ -56,3 +64,9 @@ class WuttaTimestamp(ft.Text):
|
||||||
self.value = self.render_time(self.app.localtime())
|
self.value = self.render_time(self.app.localtime())
|
||||||
self.update()
|
self.update()
|
||||||
await asyncio.sleep(0.5)
|
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)
|
||||||
|
|
Loading…
Reference in a new issue