1
0
Fork 0

first working prototype

This commit is contained in:
Raatty 2020-02-20 21:11:22 +13:00
commit ed1388cadb
2 changed files with 133 additions and 0 deletions

128
lightdm-mobile-greeter Executable file
View File

@ -0,0 +1,128 @@
#!/usr/bin/python3
import gi
gi.require_version("Gtk", "3.0")
gi.require_version("Handy", "0.0")
#gi.require_version("LightDM", 0.0)
from gi.repository import Gtk, Handy, LightDM, Gdk
# main window
window = Gtk.Window()
window.connect("destroy", Gtk.main_quit)
display = Gdk.Display.get_default()
monitor = display.get_monitor(0)
screen_size = monitor.get_geometry()
window.set_size_request(screen_size.width, screen_size.height)
# window.set_resizable(False)
# scrollable view
scroll = Gtk.ScrolledWindow(visible=True)
window.add(scroll)
viewport = Gtk.Viewport(visible=True)
scroll.add(viewport)
print("2", file=sys.stderr)
# collomn box
container = Gtk.Box(
visible=True,
can_focus=False,
orientation="vertical",
halign="center",
valign="center",
hexpand=True,
vexpand=True,
spacing=12
)
container.set_size_request(screen_size.width * 0.9, screen_size.height * 0.9)
viewport.add(container)
# entry buffer
entry_buffer = Gtk.EntryBuffer()
# backspace
def backspace(btn):
length = entry_buffer.get_length()
if length <= 0:
# theres no text left to delete
return
text = entry_buffer.get_text()
print(text)
entry_buffer.delete_text(length - 1, 1)
text2 = entry_buffer.get_text()
print(text2)
delete_btn = Gtk.Button(visible=True, can_focus=True, focus_on_click=False)
db_img = Gtk.Image(visible=True, icon_name="edit-clear-symbolic")
delete_btn.add(db_img)
delete_btn.connect("clicked", backspace)
# entry
pin_entry = Gtk.Entry(
visible=True,
can_focus=False,
has_frame=False,
margin_top=12,
margin_bottom=12,
visibility=False,
buffer=entry_buffer,
input_purpose=Gtk.InputPurpose.PIN,
xalign=0.5,
caps_lock_warning=False,
hexpand=True,
vexpand=True,
)
container.add(pin_entry)
# keypad
keypad = Handy.Keypad(
visible=True,
can_focus=False,
halign="fill",
valign="fill",
margin_top=12,
margin_bottom=12,
only_digits=True,
show_symbols=False,
right_action=delete_btn,
entry=pin_entry,
)
container.add(keypad)
# greeter
greeter = LightDM.Greeter()
print("4", file=sys.stderr)
def login_clicked(btn):
# greeter.authenticate("demo")
greeter.respond(pin_entry.get_text())
if greeter.get_is_authenticated():
greeter.start_session_sync(None)
# login button
login_btn = Gtk.Button(label="Login", visible=True)
login_btn.connect("clicked", login_clicked)
container.add(login_btn)
# prompt label
prompt_label = Gtk.Label(visible=True)
container.add(prompt_label)
# message label
message_label = Gtk.Label(visible=True)
container.add(message_label)
greeter.connect(
"authentication-complete",
lambda g: g.get_is_authenticated() and g.start_session_sync(None),
)
greeter.connect("show-message", lambda g, m, pt: message_label.set_text(m))
greeter.connect("show-prompt", lambda g, m, t: prompt_label.set_text(m))
greeter.connect_sync()
greeter.authenticate("demo")
window.show()
window.fullscreen()
Gtk.main()

View File

@ -0,0 +1,5 @@
[Desktop Entry]
Name=Mobile Greeter
Comment=A simple lightdm greeter for mobile
Exec=lightdm-mobile-greeter
Type=Application