Update in-progress login screen with input widgets
This commit is contained in:
parent
382f31fcb6
commit
9100da53f9
@ -18,11 +18,21 @@ import fswait
|
|||||||
import panel
|
import panel
|
||||||
from panel import PanelWindow, FillWidget, VolumeWidget, NetworkWidget, DateWidget, ClockWidget, RestartMenuWidget, LabelWidget
|
from panel import PanelWindow, FillWidget, VolumeWidget, NetworkWidget, DateWidget, ClockWidget, RestartMenuWidget, LabelWidget
|
||||||
|
|
||||||
from input_box import TextInputWindow
|
from input_box import InputBox
|
||||||
from dialog import DialogWindow
|
from dialog import DialogWindow
|
||||||
|
|
||||||
import yutani_mainloop
|
import yutani_mainloop
|
||||||
|
|
||||||
|
def rounded_rectangle(ctx,x,y,w,h,r):
|
||||||
|
degrees = math.pi / 180
|
||||||
|
ctx.new_sub_path()
|
||||||
|
|
||||||
|
ctx.arc(x + w - r, y + r, r, -90 * degrees, 0 * degrees)
|
||||||
|
ctx.arc(x + w - r, y + h - r, r, 0 * degrees, 90 * degrees)
|
||||||
|
ctx.arc(x + r, y + h - r, r, 90 * degrees, 180 * degrees)
|
||||||
|
ctx.arc(x + r, y + r, r, 180 * degrees, 270 * degrees)
|
||||||
|
ctx.close_path()
|
||||||
|
|
||||||
class LoginWindow(yutani.Window):
|
class LoginWindow(yutani.Window):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -33,6 +43,11 @@ class LoginWindow(yutani.Window):
|
|||||||
self.move(0,0)
|
self.move(0,0)
|
||||||
self.set_stack(yutani.WindowStackOrder.ZORDER_BOTTOM)
|
self.set_stack(yutani.WindowStackOrder.ZORDER_BOTTOM)
|
||||||
|
|
||||||
|
self.font = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF, 11, 0xFFFFFFFF)
|
||||||
|
self.font.set_shadow((0xFF000000, 2, 1, 1, 3.0))
|
||||||
|
self.tr = text_region.TextRegion(0,0,200,30,font=self.font)
|
||||||
|
self.tr.set_text(f"ToaruOS {os.uname().release}")
|
||||||
|
|
||||||
self.load_wallpaper()
|
self.load_wallpaper()
|
||||||
|
|
||||||
def load_wallpaper(self):
|
def load_wallpaper(self):
|
||||||
@ -75,12 +90,19 @@ class LoginWindow(yutani.Window):
|
|||||||
surface = self.get_cairo_surface()
|
surface = self.get_cairo_surface()
|
||||||
ctx = cairo.Context(surface)
|
ctx = cairo.Context(surface)
|
||||||
|
|
||||||
# Clear
|
# Paint blurred wallpaper
|
||||||
ctx.set_source_surface(self.wallpaper)
|
ctx.set_source_surface(self.wallpaper)
|
||||||
ctx.paint()
|
ctx.paint()
|
||||||
|
|
||||||
|
self.tr.move(10,self.height-24)
|
||||||
|
self.tr.draw(self)
|
||||||
|
|
||||||
self.flip()
|
self.flip()
|
||||||
|
|
||||||
|
def focus_changed(self, msg):
|
||||||
|
if msg.focused:
|
||||||
|
yutani.yutani_ctx.focus_window(prompts.wid)
|
||||||
|
|
||||||
def finish_resize(self, msg):
|
def finish_resize(self, msg):
|
||||||
"""Accept a resize."""
|
"""Accept a resize."""
|
||||||
self.resize_accept(msg.width, msg.height)
|
self.resize_accept(msg.width, msg.height)
|
||||||
@ -94,6 +116,118 @@ class LoginWindow(yutani.Window):
|
|||||||
def keyboard_event(self, msg):
|
def keyboard_event(self, msg):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class InputWindow(yutani.Window):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
_w = yutani.yutani_ctx._ptr.contents.display_width
|
||||||
|
_h = yutani.yutani_ctx._ptr.contents.display_height
|
||||||
|
|
||||||
|
self.logo = cairo.ImageSurface.create_from_png('/usr/share/logo_login.png')
|
||||||
|
|
||||||
|
super(InputWindow, self).__init__(272, self.logo.get_height() + 110 + 50, doublebuffer=True)
|
||||||
|
self.update_position(_w,_h)
|
||||||
|
|
||||||
|
self.username = InputBox(placeholder="Username",width=180)
|
||||||
|
self.password = InputBox(password=True,placeholder="Password",width=180)
|
||||||
|
self.focused_widget = None
|
||||||
|
|
||||||
|
self.username.tab_handler = self.focus_password
|
||||||
|
self.password.tab_handler = self.focus_username
|
||||||
|
|
||||||
|
self.username.submit = self.password_or_go
|
||||||
|
self.password.submit = self.go
|
||||||
|
|
||||||
|
self.error_font = toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF, 11, 0xFFFF0000)
|
||||||
|
self.error_font.set_shadow((0xFF000000, 2, 0, 0, 3.0))
|
||||||
|
self.error_tr = text_region.TextRegion(0,0,self.width,20,font=self.error_font)
|
||||||
|
self.error_tr.set_alignment(2)
|
||||||
|
|
||||||
|
self.error = None
|
||||||
|
|
||||||
|
def focus_changed(self, msg):
|
||||||
|
if not msg.focused:
|
||||||
|
self.username.focus_leave()
|
||||||
|
self.password.focus_leave()
|
||||||
|
|
||||||
|
def update_position(self, w, h):
|
||||||
|
self.move(int((w - self.width)/2),int((h - self.height)/2))
|
||||||
|
|
||||||
|
def draw(self):
|
||||||
|
surface = self.get_cairo_surface()
|
||||||
|
ctx = cairo.Context(surface)
|
||||||
|
|
||||||
|
# Clear
|
||||||
|
ctx.set_operator(cairo.OPERATOR_SOURCE)
|
||||||
|
ctx.rectangle(0,0,self.width,self.height)
|
||||||
|
ctx.set_source_rgba(0,0,0,0)
|
||||||
|
ctx.fill()
|
||||||
|
|
||||||
|
ctx.set_operator(cairo.OPERATOR_OVER)
|
||||||
|
|
||||||
|
ctx.set_source_surface(self.logo, (self.width - self.logo.get_width())/2, 0)
|
||||||
|
ctx.paint()
|
||||||
|
|
||||||
|
base = self.height - 110
|
||||||
|
|
||||||
|
rounded_rectangle(ctx, 0, base, self.width, 110, 4)
|
||||||
|
ctx.set_source_rgba(0,0,0,0.5)
|
||||||
|
ctx.fill()
|
||||||
|
|
||||||
|
if self.error:
|
||||||
|
self.error_tr.move(0,base+8)
|
||||||
|
self.error_tr.set_text(self.error)
|
||||||
|
self.error_tr.draw(self)
|
||||||
|
|
||||||
|
ctx.save()
|
||||||
|
ctx.translate(46,base + 30)
|
||||||
|
self.username.draw(self,ctx)
|
||||||
|
ctx.restore()
|
||||||
|
|
||||||
|
ctx.save()
|
||||||
|
ctx.translate(46,base + 60)
|
||||||
|
self.password.draw(self,ctx)
|
||||||
|
ctx.restore()
|
||||||
|
|
||||||
|
self.flip()
|
||||||
|
|
||||||
|
def keyboard_event(self, msg):
|
||||||
|
if self.focused_widget:
|
||||||
|
self.focused_widget.keyboard_event(msg)
|
||||||
|
else:
|
||||||
|
self.focus_username()
|
||||||
|
self.focused_widget.keyboard_event(msg)
|
||||||
|
|
||||||
|
def focus_password(self):
|
||||||
|
self.username.focus_leave()
|
||||||
|
self.password.focus_enter()
|
||||||
|
self.focused_widget = self.password
|
||||||
|
self.draw()
|
||||||
|
|
||||||
|
def focus_username(self):
|
||||||
|
self.password.focus_leave()
|
||||||
|
self.username.focus_enter()
|
||||||
|
self.focused_widget = self.username
|
||||||
|
self.draw()
|
||||||
|
|
||||||
|
def password_or_go(self):
|
||||||
|
if self.password.text:
|
||||||
|
self.go()
|
||||||
|
else:
|
||||||
|
self.focus_password()
|
||||||
|
|
||||||
|
def go(self):
|
||||||
|
print(f"Your username is {self.username.text} and your password is {self.password.text}")
|
||||||
|
|
||||||
|
def mouse_event(self, msg):
|
||||||
|
if self.username.mouse_event(msg):
|
||||||
|
self.focus_username()
|
||||||
|
elif self.password.mouse_event(msg):
|
||||||
|
self.focus_password()
|
||||||
|
elif msg.command == yutani.MouseEvent.CLICK:
|
||||||
|
self.password.focus_leave()
|
||||||
|
self.username.focus_leave()
|
||||||
|
self.focused_widget = None
|
||||||
|
|
||||||
def maybe_animate():
|
def maybe_animate():
|
||||||
tick = int(time.time())
|
tick = int(time.time())
|
||||||
if tick != panel.current_time:
|
if tick != panel.current_time:
|
||||||
@ -113,6 +247,9 @@ if __name__ == '__main__':
|
|||||||
window = LoginWindow()
|
window = LoginWindow()
|
||||||
window.draw()
|
window.draw()
|
||||||
|
|
||||||
|
prompts = InputWindow()
|
||||||
|
prompts.draw()
|
||||||
|
|
||||||
def restart_callback():
|
def restart_callback():
|
||||||
def confirm():
|
def confirm():
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
@ -125,11 +262,6 @@ if __name__ == '__main__':
|
|||||||
panel_window = PanelWindow(widgets)
|
panel_window = PanelWindow(widgets)
|
||||||
panel_window.draw()
|
panel_window.draw()
|
||||||
|
|
||||||
def input_callback(input_window):
|
|
||||||
print(input_window.tr.text)
|
|
||||||
input_window.close()
|
|
||||||
TextInputWindow(d,"Username?","star",text="テスト",callback=input_callback)
|
|
||||||
|
|
||||||
fds = [yutani.yutani_ctx]
|
fds = [yutani.yutani_ctx]
|
||||||
while 1:
|
while 1:
|
||||||
# Poll for events.
|
# Poll for events.
|
||||||
@ -141,6 +273,7 @@ if __name__ == '__main__':
|
|||||||
if msg.type == yutani.Message.MSG_WELCOME:
|
if msg.type == yutani.Message.MSG_WELCOME:
|
||||||
panel_window.resize(msg.display_width, panel_window.height)
|
panel_window.resize(msg.display_width, panel_window.height)
|
||||||
window.resize(msg.display_width, msg.display_height)
|
window.resize(msg.display_width, msg.display_height)
|
||||||
|
prompts.update_position(msg.display_width, msg.display_height)
|
||||||
else:
|
else:
|
||||||
if not yutani_mainloop.handle_event(msg):
|
if not yutani_mainloop.handle_event(msg):
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
Loading…
Reference in New Issue
Block a user