73 lines
2.3 KiB
Python
73 lines
2.3 KiB
Python
|
#!/usr/bin/python3
|
||
|
import gi
|
||
|
from gi.repository import Gtk, Gdk, Handy, LightDM
|
||
|
import json
|
||
|
|
||
|
|
||
|
class Config:
|
||
|
def __init__(self):
|
||
|
with open("/etc/lightdm_mobile_greeter.json") as f:
|
||
|
j = json.load(f)
|
||
|
self.user = j["user"]
|
||
|
|
||
|
|
||
|
class Handler:
|
||
|
def __init__(self, builder: Gtk.Builder):
|
||
|
self.pin_entry = builder.get_object("entry_buffer")
|
||
|
self.greeter = LightDM.Greeter()
|
||
|
self.greeter.connect("authentication-complete", self.auth_complete)
|
||
|
self.greeter.connect("show-message", self.show_msg)
|
||
|
self.greeter.connect("show-prompt", self.show_prompt)
|
||
|
self.pmpt_label = builder.get_object("prompt_label")
|
||
|
self.msg_label = builder.get_object("message_label")
|
||
|
self.greeter.connect_sync()
|
||
|
self.conf = Config()
|
||
|
self.greeter.authenticate(self.conf.user)
|
||
|
|
||
|
def on_destry(self, window):
|
||
|
Gtk.main_quit()
|
||
|
|
||
|
def login_cb(self, login_btn):
|
||
|
self.greeter.respond(self.pin_entry.get_text())
|
||
|
self.pin_entry.set_text("", 0)
|
||
|
|
||
|
def backspace(self, del_btn):
|
||
|
length = self.pin_entry.get_length()
|
||
|
if length <= 0:
|
||
|
return
|
||
|
self.pin_entry.delete_text(length - 1, 1)
|
||
|
|
||
|
def auth_complete(self, greeter):
|
||
|
if greeter.get_is_authenticated():
|
||
|
greeter.start_session_sync(None)
|
||
|
else:
|
||
|
greeter.authenticate(self.conf.user)
|
||
|
|
||
|
def show_msg(self, greeter, text, type):
|
||
|
self.msg_label.set_text(text)
|
||
|
|
||
|
def show_prompt(self, greeter, text, type):
|
||
|
self.pmpt_label.set_text(text)
|
||
|
|
||
|
|
||
|
Handy.Keypad()
|
||
|
builder: Gtk.Builder = Gtk.Builder.new_from_file(
|
||
|
"%DATADIR%/lightdm-mobile-greeter/interface.ui"
|
||
|
)
|
||
|
handler = Handler(builder)
|
||
|
builder.connect_signals(handler)
|
||
|
window: Gtk.Window = builder.get_object("greeter_window")
|
||
|
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)
|
||
|
container = builder.get_object("container")
|
||
|
container.set_size_request(screen_size.width * 0.8, screen_size.height * 0.8)
|
||
|
style: Gtk.CssProvider = Gtk.CssProvider()
|
||
|
style.load_from_path("%DATADIR%/lightdm-mobile-greeter/style.css")
|
||
|
Gtk.StyleContext.add_provider_for_screen(
|
||
|
Gdk.Screen.get_default(), style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
|
||
|
)
|
||
|
window.show()
|
||
|
Gtk.main()
|