Show keyboard on login page
also do *not* show feedback button on login page
This commit is contained in:
parent
0676a9ef4c
commit
ced1d37edd
|
@ -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/>.
|
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(
|
self.dlg = ft.AlertDialog(
|
||||||
title=ft.Text(title),
|
title=ft.Text(title),
|
||||||
content=ft.Container(
|
content=ft.Container(
|
||||||
|
@ -132,8 +138,7 @@ WuttaPOS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
ft.Divider(),
|
ft.Divider(),
|
||||||
ft.Text(license),
|
ft.Text(license),
|
||||||
ft.Container(
|
ft.Container(
|
||||||
content=WuttaFeedback(self.config, page=self.page,
|
content=feedback,
|
||||||
on_send=self.reset, on_cancel=self.reset),
|
|
||||||
alignment=ft.alignment.center,
|
alignment=ft.alignment.center,
|
||||||
expand=True,
|
expand=True,
|
||||||
),
|
),
|
||||||
|
|
|
@ -27,6 +27,7 @@ WuttaPOS - login view
|
||||||
import flet as ft
|
import flet as ft
|
||||||
|
|
||||||
from .base import WuttaView
|
from .base import WuttaView
|
||||||
|
from wuttapos.controls.keyboard import WuttaKeyboard
|
||||||
|
|
||||||
|
|
||||||
class LoginView(WuttaView):
|
class LoginView(WuttaView):
|
||||||
|
@ -41,10 +42,14 @@ class LoginView(WuttaView):
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# track which login input has focus
|
||||||
|
self.focused = None
|
||||||
|
|
||||||
def build_controls(self):
|
def build_controls(self):
|
||||||
|
title = self.app.get_title()
|
||||||
controls = [
|
controls = [
|
||||||
ft.Row(
|
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,
|
alignment=ft.MainAxisAlignment.CENTER,
|
||||||
),
|
),
|
||||||
ft.Row(),
|
ft.Row(),
|
||||||
|
@ -52,39 +57,53 @@ class LoginView(WuttaView):
|
||||||
ft.Row(),
|
ft.Row(),
|
||||||
]
|
]
|
||||||
|
|
||||||
if self.show_username:
|
form_fields = []
|
||||||
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,
|
|
||||||
),
|
|
||||||
])
|
|
||||||
|
|
||||||
self.password = ft.TextField(label="Password", width=200, password=True,
|
self.password = ft.TextField(label="Password", width=200, password=True,
|
||||||
on_submit=self.password_submit,
|
on_submit=self.password_submit,
|
||||||
|
on_focus=self.password_focus,
|
||||||
autofocus=not self.show_username)
|
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([
|
controls.extend([
|
||||||
ft.Row(
|
ft.Row(
|
||||||
[self.password],
|
controls=form_fields + [
|
||||||
alignment=ft.MainAxisAlignment.CENTER,
|
ft.Container(content=ft.Text("Login", size=20,
|
||||||
),
|
weight=ft.FontWeight.BOLD),
|
||||||
ft.Row(
|
height=60,
|
||||||
[
|
width=60 * 2.5,
|
||||||
ft.FilledButton("Login", on_click=self.attempt_login),
|
alignment=ft.alignment.center,
|
||||||
ft.ElevatedButton("Clear", on_click=self.clear_login),
|
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,
|
alignment=ft.MainAxisAlignment.CENTER,
|
||||||
),
|
),
|
||||||
ft.Row(),
|
ft.Row(),
|
||||||
ft.Row(
|
ft.Row(),
|
||||||
[ft.Text("TODO: should have on-screen keyboard (at least 10-key pad?) "
|
ft.Row(),
|
||||||
"for use with login etc.", italic=True)],
|
WuttaKeyboard(self.config, on_keypress=self.keypress,
|
||||||
alignment=ft.MainAxisAlignment.CENTER,
|
on_long_backspace=self.long_backspace),
|
||||||
),
|
|
||||||
])
|
])
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
@ -94,13 +113,40 @@ class LoginView(WuttaView):
|
||||||
alignment=ft.MainAxisAlignment.CENTER),
|
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:
|
if self.username.value:
|
||||||
self.password.focus()
|
self.password.focus()
|
||||||
else:
|
else:
|
||||||
self.username.focus()
|
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:
|
if self.password.value:
|
||||||
self.attempt_login()
|
self.attempt_login()
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue