Fix snackbar size after sending feedback

This commit is contained in:
Lance Edgar 2023-10-12 12:03:20 -05:00
parent fc2fda7c3a
commit aab3d9498d
4 changed files with 25 additions and 19 deletions

View file

@ -26,18 +26,24 @@ WuttaPOS - custom controls (base class)
import flet as ft
from wuttapos.util import make_button
from wuttapos.util import make_button, show_snackbar
class WuttaControl(ft.UserControl):
def __init__(self, config, *args, **kwargs):
def __init__(self, config, page=None, *args, **kwargs):
self.on_reset = kwargs.pop('on_reset', None)
super().__init__(*args, **kwargs)
self.config = config
self.app = config.get_app()
self.enum = self.app.enum
# TODO: why must we save this aside from self.page ?
# but sometimes self.page gets set to None, so we must..
self.mypage = page
def informed_refresh(self, **kwargs):
pass
@ -47,3 +53,6 @@ class WuttaControl(ft.UserControl):
def reset(self, e=None):
if self.on_reset:
self.on_reset(e=e)
def show_snackbar(self, text, bgcolor='yellow'):
show_snackbar(self.mypage, text, bgcolor=bgcolor)

View file

@ -37,13 +37,11 @@ class WuttaFeedback(WuttaControl):
default_font_size = 20
default_button_height = 60
def __init__(self, config, page=None, *args, **kwargs):
def __init__(self, config, *args, **kwargs):
self.on_send = kwargs.pop('on_send', None)
self.on_cancel = kwargs.pop('on_cancel', None)
super().__init__(config, *args, **kwargs)
# TODO: why must we save this aside from self.page ?
# but sometimes self.page gets set to None, so we must..
self.mypage = page
def build(self):
@ -157,12 +155,7 @@ class WuttaFeedback(WuttaControl):
})
self.dlg.open = False
self.mypage.snack_bar = ft.SnackBar(ft.Text(f"MESSAGE WAS SENT",
color='black',
weight=ft.FontWeight.BOLD),
bgcolor='green',
duration=1500)
self.mypage.snack_bar.open = True
self.show_snackbar("MESSAGE WAS SENT", bgcolor='green')
self.mypage.update()
if self.on_send:

View file

@ -51,3 +51,12 @@ def make_button(text, font_size=24, font_bold=True, font_weight=None, **kwargs):
kwargs.setdefault('border', ft.border.all(1, 'black'))
kwargs.setdefault('border_radius', ft.border_radius.all(5))
return ft.Container(content=text, **kwargs)
def show_snackbar(page, text, bgcolor='yellow'):
page.snack_bar = ft.SnackBar(ft.Text(text, color='black',
size=40,
weight=ft.FontWeight.BOLD),
bgcolor=bgcolor,
duration=1500)
page.snack_bar.open = True

View file

@ -31,7 +31,7 @@ from rattail.files import resource_path
import flet as ft
from wuttapos.controls.header import WuttaHeader
from wuttapos.util import get_pos_batch_handler, make_button
from wuttapos.util import get_pos_batch_handler, make_button, show_snackbar
class WuttaView(ft.View):
@ -88,12 +88,7 @@ class WuttaView(ft.View):
return ft.Image(src=logo, **kwargs)
def show_snackbar(self, text, bgcolor='yellow'):
self.page.snack_bar = ft.SnackBar(ft.Text(text, color='black',
size=40,
weight=ft.FontWeight.BOLD),
bgcolor=bgcolor,
duration=1500)
self.page.snack_bar.open = True
show_snackbar(self.page, text, bgcolor=bgcolor)
class WuttaViewContainer(ft.Container):