Show keyboard on login page

also do *not* show feedback button on login page
This commit is contained in:
Lance Edgar 2023-09-26 12:16:44 -05:00
parent 0676a9ef4c
commit ced1d37edd
2 changed files with 78 additions and 27 deletions

View file

@ -121,6 +121,12 @@ You should have received a copy of the GNU General Public License along with
WuttaPOS. If not, see <http://www.gnu.org/licenses/>.
"""
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 <http://www.gnu.org/licenses/>.
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,
),

View file

@ -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: