1
0
Fork 0
lightdm-mobile-greeter/lightdm-mobile-greeter.py

95 lines
3.2 KiB
Python
Raw Permalink Normal View History

2020-03-01 17:19:59 +13:00
#!/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")
2020-04-17 15:52:01 +12:00
self.de_select = builder.get_object("de_select")
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, visible=True)
self.de_select.add(vbox)
2020-03-01 17:19:59 +13:00
self.greeter.connect_sync()
self.conf = Config()
self.greeter.authenticate(self.conf.user)
2020-04-17 15:52:01 +12:00
self.session = self.greeter.get_default_session_hint()
sessions = iter([(s.get_name(), s.get_key()) for s in LightDM.get_sessions()])
name, key = sessions.__next__()
first = Gtk.RadioButton.new_with_label(None, name)
first.connect("toggled", self.session_change, key)
vbox.add(first)
for name, key in sessions:
rb = Gtk.RadioButton.new_with_label_from_widget(first, name)
rb.connect("toggled", self.session_change, key)
vbox.add(rb)
if self.session == key:
rb.set_active(True)
vbox.show_all()
def session_change(self, rb, key):
self.session = key
2020-03-01 17:19:59 +13:00
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():
2020-04-17 15:52:01 +12:00
greeter.start_session_sync(self.session)
2020-03-01 17:19:59 +13:00
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)
2020-04-17 15:52:01 +12:00
def de_popover(self, settings_btn):
self.de_select.popup()
2020-03-01 17:19:59 +13:00
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()