From ced1d37edd00a244b2113f013bb7f5b90849c6a6 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 26 Sep 2023 12:16:44 -0500 Subject: [PATCH] Show keyboard on login page also do *not* show feedback button on login page --- wuttapos/controls/header.py | 9 +++- wuttapos/views/login.py | 96 +++++++++++++++++++++++++++---------- 2 files changed, 78 insertions(+), 27 deletions(-) diff --git a/wuttapos/controls/header.py b/wuttapos/controls/header.py index e053c75..e84a47b 100644 --- a/wuttapos/controls/header.py +++ b/wuttapos/controls/header.py @@ -121,6 +121,12 @@ You should have received a copy of the GNU General Public License along with WuttaPOS. If not, see . """ + if self.page.session.get('user_uuid'): + feedback = WuttaFeedback(self.config, page=self.page, + on_send=self.reset, on_cancel=self.reset) + else: + feedback = ft.Text() # no display + self.dlg = ft.AlertDialog( title=ft.Text(title), content=ft.Container( @@ -132,8 +138,7 @@ WuttaPOS. If not, see . ft.Divider(), ft.Text(license), ft.Container( - content=WuttaFeedback(self.config, page=self.page, - on_send=self.reset, on_cancel=self.reset), + content=feedback, alignment=ft.alignment.center, expand=True, ), diff --git a/wuttapos/views/login.py b/wuttapos/views/login.py index 47ef9f2..9bc7e75 100644 --- a/wuttapos/views/login.py +++ b/wuttapos/views/login.py @@ -27,6 +27,7 @@ WuttaPOS - login view import flet as ft from .base import WuttaView +from wuttapos.controls.keyboard import WuttaKeyboard class LoginView(WuttaView): @@ -41,10 +42,14 @@ class LoginView(WuttaView): super().__init__(*args, **kwargs) + # track which login input has focus + self.focused = None + def build_controls(self): + title = self.app.get_title() controls = [ ft.Row( - [ft.Text(value="Welcome to WuttaPOS", weight=ft.FontWeight.BOLD, size=28)], + [ft.Text(value=f"Welcome to {title}", weight=ft.FontWeight.BOLD, size=28)], alignment=ft.MainAxisAlignment.CENTER, ), ft.Row(), @@ -52,39 +57,53 @@ class LoginView(WuttaView): ft.Row(), ] - if self.show_username: - self.username = ft.TextField(label="Login", width=200, - on_submit=self.username_submit, - autofocus=True) - controls.extend([ - ft.Row( - [self.username], - alignment=ft.MainAxisAlignment.CENTER, - ), - ]) + form_fields = [] self.password = ft.TextField(label="Password", width=200, password=True, on_submit=self.password_submit, + on_focus=self.password_focus, autofocus=not self.show_username) + self.focused = self.password + + if self.show_username: + self.username = ft.TextField(label="Login", width=200, + on_submit=self.username_submit, + on_focus=self.username_focus, + autofocus=True) + form_fields.append(self.username) + self.focused = self.username + + form_fields.append(self.password) controls.extend([ ft.Row( - [self.password], - alignment=ft.MainAxisAlignment.CENTER, - ), - ft.Row( - [ - ft.FilledButton("Login", on_click=self.attempt_login), - ft.ElevatedButton("Clear", on_click=self.clear_login), + controls=form_fields + [ + ft.Container(content=ft.Text("Login", 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), + bgcolor='blue', + on_click=self.attempt_login), + + ft.Container(content=ft.Text("Clear", 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.clear_login), ], alignment=ft.MainAxisAlignment.CENTER, ), ft.Row(), - ft.Row( - [ft.Text("TODO: should have on-screen keyboard (at least 10-key pad?) " - "for use with login etc.", italic=True)], - alignment=ft.MainAxisAlignment.CENTER, - ), + ft.Row(), + ft.Row(), + WuttaKeyboard(self.config, on_keypress=self.keypress, + on_long_backspace=self.long_backspace), ]) return [ @@ -94,13 +113,40 @@ class LoginView(WuttaView): alignment=ft.MainAxisAlignment.CENTER), ] - def username_submit(self, e): + def keypress(self, key): + assert self.focused + if key == '⏎': + if self.focused is self.username: + self.username_submit() + else: + self.password_submit() + elif key == '⌫': + self.focused.value = self.focused.value[:-1] + else: + self.focused.value += key + + self.focused.focus() + self.update() + + def long_backspace(self): + assert self.focused + self.focused.value = '' + self.focused.focus() + self.update() + + def username_focus(self, e): + self.focused = self.username + + def username_submit(self, e=None): if self.username.value: self.password.focus() else: self.username.focus() - def password_submit(self, e): + def password_focus(self, e): + self.focused = self.password + + def password_submit(self, e=None): if self.password.value: self.attempt_login() else: