Add the "About" dialog and move feedback button there
This commit is contained in:
parent
bdae602289
commit
0676a9ef4c
|
@ -30,9 +30,14 @@ import flet as ft
|
||||||
class WuttaControl(ft.UserControl):
|
class WuttaControl(ft.UserControl):
|
||||||
|
|
||||||
def __init__(self, config, *args, **kwargs):
|
def __init__(self, config, *args, **kwargs):
|
||||||
|
self.on_reset = kwargs.pop('on_reset', None)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.config = config
|
self.config = config
|
||||||
self.app = config.get_app()
|
self.app = config.get_app()
|
||||||
|
|
||||||
def informed_refresh(self, **kwargs):
|
def informed_refresh(self, **kwargs):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def reset(self, e=None):
|
||||||
|
if self.on_reset:
|
||||||
|
self.on_reset(e=e)
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
WuttaPOS - feedback control
|
WuttaPOS - feedback control
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
import flet as ft
|
import flet as ft
|
||||||
|
|
||||||
from .base import WuttaControl
|
from .base import WuttaControl
|
||||||
|
@ -35,10 +37,13 @@ class WuttaFeedback(WuttaControl):
|
||||||
default_font_size = 20
|
default_font_size = 20
|
||||||
default_button_height = 60
|
default_button_height = 60
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, config, page=None, *args, **kwargs):
|
||||||
self.on_send = kwargs.pop('on_send', None)
|
self.on_send = kwargs.pop('on_send', None)
|
||||||
self.on_cancel = kwargs.pop('on_cancel', None)
|
self.on_cancel = kwargs.pop('on_cancel', None)
|
||||||
super().__init__(*args, **kwargs)
|
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):
|
def build(self):
|
||||||
|
|
||||||
|
@ -107,9 +112,15 @@ class WuttaFeedback(WuttaControl):
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
self.page.dialog = self.dlg
|
if self.mypage.dialog and self.mypage.dialog.open and self.mypage.dialog is not self.dlg:
|
||||||
|
self.mypage.dialog.open = False
|
||||||
|
self.mypage.update()
|
||||||
|
# cf. https://github.com/flet-dev/flet/issues/1670
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
self.mypage.dialog = self.dlg
|
||||||
self.dlg.open = True
|
self.dlg.open = True
|
||||||
self.page.update()
|
self.mypage.update()
|
||||||
|
|
||||||
def keypress(self, key):
|
def keypress(self, key):
|
||||||
if key == '⏎':
|
if key == '⏎':
|
||||||
|
@ -120,7 +131,10 @@ class WuttaFeedback(WuttaControl):
|
||||||
self.message.value += key
|
self.message.value += key
|
||||||
|
|
||||||
self.message.focus()
|
self.message.focus()
|
||||||
self.update()
|
|
||||||
|
# TODO: why is keypress happening with no page?
|
||||||
|
if self.page:
|
||||||
|
self.update()
|
||||||
|
|
||||||
def long_backspace(self):
|
def long_backspace(self):
|
||||||
self.message.value = self.message.value[:-10]
|
self.message.value = self.message.value[:-10]
|
||||||
|
@ -129,7 +143,7 @@ class WuttaFeedback(WuttaControl):
|
||||||
|
|
||||||
def cancel(self, e):
|
def cancel(self, e):
|
||||||
self.dlg.open = False
|
self.dlg.open = False
|
||||||
self.page.update()
|
self.mypage.update()
|
||||||
|
|
||||||
if self.on_cancel:
|
if self.on_cancel:
|
||||||
self.on_cancel(e)
|
self.on_cancel(e)
|
||||||
|
@ -138,22 +152,22 @@ class WuttaFeedback(WuttaControl):
|
||||||
if self.message.value:
|
if self.message.value:
|
||||||
|
|
||||||
self.app.send_email('pos_feedback', data={
|
self.app.send_email('pos_feedback', data={
|
||||||
'user_name': self.page.session.get('user_display'),
|
'user_name': self.mypage.session.get('user_display'),
|
||||||
'message': self.message.value,
|
'message': self.message.value,
|
||||||
})
|
})
|
||||||
|
|
||||||
self.dlg.open = False
|
self.dlg.open = False
|
||||||
self.page.snack_bar = ft.SnackBar(ft.Text(f"MESSAGE WAS SENT",
|
self.mypage.snack_bar = ft.SnackBar(ft.Text(f"MESSAGE WAS SENT",
|
||||||
color='black',
|
color='black',
|
||||||
weight=ft.FontWeight.BOLD),
|
weight=ft.FontWeight.BOLD),
|
||||||
bgcolor='green',
|
bgcolor='green',
|
||||||
duration=1500)
|
duration=1500)
|
||||||
self.page.snack_bar.open = True
|
self.mypage.snack_bar.open = True
|
||||||
self.page.update()
|
self.mypage.update()
|
||||||
|
|
||||||
if self.on_send:
|
if self.on_send:
|
||||||
self.on_send()
|
self.on_send()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.message.focus()
|
self.message.focus()
|
||||||
self.page.update()
|
self.mypage.update()
|
||||||
|
|
|
@ -24,10 +24,14 @@
|
||||||
WuttaPOS - header control
|
WuttaPOS - header control
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import rattail
|
||||||
|
|
||||||
import flet as ft
|
import flet as ft
|
||||||
|
|
||||||
|
import wuttapos
|
||||||
from .base import WuttaControl
|
from .base import WuttaControl
|
||||||
from .timestamp import WuttaTimestamp
|
from .timestamp import WuttaTimestamp
|
||||||
|
from .feedback import WuttaFeedback
|
||||||
|
|
||||||
|
|
||||||
class WuttaHeader(WuttaControl):
|
class WuttaHeader(WuttaControl):
|
||||||
|
@ -36,8 +40,9 @@ class WuttaHeader(WuttaControl):
|
||||||
self.txn_display = ft.Text("Txn: N", weight=ft.FontWeight.BOLD, size=20)
|
self.txn_display = ft.Text("Txn: N", weight=ft.FontWeight.BOLD, size=20)
|
||||||
self.cust_display = ft.Text("Cust: N", weight=ft.FontWeight.BOLD, size=20)
|
self.cust_display = ft.Text("Cust: N", weight=ft.FontWeight.BOLD, size=20)
|
||||||
self.user_display = ft.Text("User: N", weight=ft.FontWeight.BOLD, size=20)
|
self.user_display = ft.Text("User: N", weight=ft.FontWeight.BOLD, size=20)
|
||||||
self.logout_button = ft.FilledButton("Logout", on_click=self.logout_click, visible=False)
|
self.logout_button = ft.OutlinedButton("Logout", on_click=self.logout_click, visible=False)
|
||||||
self.logout_divider = ft.VerticalDivider(visible=False)
|
self.logout_divider = ft.VerticalDivider(visible=False)
|
||||||
|
self.title_button = ft.FilledButton(self.app.get_title(), on_click=self.title_click)
|
||||||
|
|
||||||
controls = [
|
controls = [
|
||||||
self.txn_display,
|
self.txn_display,
|
||||||
|
@ -50,7 +55,7 @@ class WuttaHeader(WuttaControl):
|
||||||
ft.VerticalDivider(),
|
ft.VerticalDivider(),
|
||||||
self.logout_button,
|
self.logout_button,
|
||||||
self.logout_divider,
|
self.logout_divider,
|
||||||
ft.Text(f"WuttaPOS", weight=ft.FontWeight.BOLD, size=20),
|
self.title_button,
|
||||||
]
|
]
|
||||||
|
|
||||||
return ft.Row(controls)
|
return ft.Row(controls)
|
||||||
|
@ -94,3 +99,71 @@ class WuttaHeader(WuttaControl):
|
||||||
|
|
||||||
self.page.session.clear()
|
self.page.session.clear()
|
||||||
self.page.go('/login')
|
self.page.go('/login')
|
||||||
|
|
||||||
|
def title_click(self, e):
|
||||||
|
title = self.app.get_title()
|
||||||
|
|
||||||
|
license = """\
|
||||||
|
WuttaPOS -- Pythonic Point of Sale System
|
||||||
|
Copyright © 2023 Lance Edgar
|
||||||
|
|
||||||
|
WuttaPOS is free software: you can redistribute it and/or modify it under the
|
||||||
|
terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation, either version 3 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
WuttaPOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
WuttaPOS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.dlg = ft.AlertDialog(
|
||||||
|
title=ft.Text(title),
|
||||||
|
content=ft.Container(
|
||||||
|
content=ft.Column(
|
||||||
|
[
|
||||||
|
ft.Divider(),
|
||||||
|
ft.Text(f"{title} v{wuttapos.__version__}"),
|
||||||
|
ft.Text(f"rattail v{rattail.__version__}"),
|
||||||
|
ft.Divider(),
|
||||||
|
ft.Text(license),
|
||||||
|
ft.Container(
|
||||||
|
content=WuttaFeedback(self.config, page=self.page,
|
||||||
|
on_send=self.reset, on_cancel=self.reset),
|
||||||
|
alignment=ft.alignment.center,
|
||||||
|
expand=True,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
expand=True,
|
||||||
|
),
|
||||||
|
height=600,
|
||||||
|
),
|
||||||
|
actions=[
|
||||||
|
ft.Row(
|
||||||
|
[
|
||||||
|
ft.Container(content=ft.Text("Close", size=20,
|
||||||
|
weight=ft.FontWeight.BOLD),
|
||||||
|
height=60,
|
||||||
|
width=60 * 2.5,
|
||||||
|
alignment=ft.alignment.center,
|
||||||
|
border=ft.border.all(1, 'black'),
|
||||||
|
border_radius=ft.border_radius.all(5),
|
||||||
|
on_click=self.close_dlg),
|
||||||
|
],
|
||||||
|
alignment=ft.MainAxisAlignment.CENTER,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
self.page.dialog = self.dlg
|
||||||
|
self.dlg.open = True
|
||||||
|
self.page.update()
|
||||||
|
|
||||||
|
def close_dlg(self, e):
|
||||||
|
self.dlg.open = False
|
||||||
|
self.reset()
|
||||||
|
self.page.update()
|
||||||
|
|
|
@ -53,9 +53,12 @@ class WuttaView(ft.View):
|
||||||
return [self.build_header()]
|
return [self.build_header()]
|
||||||
|
|
||||||
def build_header(self):
|
def build_header(self):
|
||||||
self.header = WuttaHeader(self.config)
|
self.header = WuttaHeader(self.config, on_reset=self.reset)
|
||||||
return self.header
|
return self.header
|
||||||
|
|
||||||
|
def reset(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class WuttaViewContainer(ft.Container):
|
class WuttaViewContainer(ft.Container):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -32,7 +32,6 @@ import flet as ft
|
||||||
|
|
||||||
from .base import WuttaView
|
from .base import WuttaView
|
||||||
from wuttapos.controls.custlookup import WuttaCustomerLookup
|
from wuttapos.controls.custlookup import WuttaCustomerLookup
|
||||||
from wuttapos.controls.feedback import WuttaFeedback
|
|
||||||
from wuttapos.util import get_pos_batch_handler
|
from wuttapos.util import get_pos_batch_handler
|
||||||
|
|
||||||
|
|
||||||
|
@ -641,7 +640,6 @@ class POSView(WuttaView):
|
||||||
|
|
||||||
ft.Row(
|
ft.Row(
|
||||||
[
|
[
|
||||||
WuttaFeedback(self.config, on_send=self.reset, on_cancel=self.reset),
|
|
||||||
ft.Row(
|
ft.Row(
|
||||||
[
|
[
|
||||||
self.set_quantity,
|
self.set_quantity,
|
||||||
|
|
Loading…
Reference in a new issue