1
0
Fork 0

version 1 maybe?

This commit is contained in:
Raatty 2020-03-01 17:19:59 +13:00
parent 5386b889c4
commit 2d605c85a2
5 changed files with 221 additions and 128 deletions

10
Makefile Normal file
View File

@ -0,0 +1,10 @@
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
DATADIR ?= $(PREFIX)/share
CONFDIR = /etc
install:
sed "s/%DATADIR%/\/usr\/share/" lightdm-mobile-greeter.py > lightdm-mobile-greeter
install -Dm755 lightdm-mobile-greeter -t $(DESTDIR)$(BINDIR)
install -Dm644 style.css interface.ui -t $(DESTDIR)$(DATADIR)/lightdm-mobile-greeter
install -Dm644 lightdm-mobile-greeter.desktop -t $(DESTDIR)$(DATADIR)/xgreeters

105
interface.ui Normal file
View File

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.20"/>
<requires lib="libhandy" version="0.0"/>
<object class="GtkWindow" id="greeter_window">
<signal name="destroy" handler="on_destry"/>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<child>
<object class="GtkBox" id="container">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="prompt_label">
<property name="visible">True</property>
<property name="label">prompt label</property>
</object>
</child>
<child>
<object class="GtkEntry" id="pin_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_frame">False</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="visibility">False</property>
<property name="buffer">entry_buffer</property>
<property name="input_purpose">GTK_INPUT_PURPOSE_PIN</property>
<property name="xalign">0.5</property>
<property name="caps_lock_warning">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
</object>
</child>
<child>
<object class="HdyKeypad">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">fill</property>
<property name="valign">fill</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="only_digits">True</property>
<property name="show_symbols">False</property>
<property name="right_action">delete_btn</property>
<property name="entry">pin_entry</property>
<style>
<class name="keypad"/>
</style>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="label">Login</property>
<signal name="clicked" handler="login_cb"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
</packing>
</child>
</object>
</child>
<child>
<object class="GtkLabel" id="message_label">
<property name="visible">True</property>
<property name="label">message label</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<object class="GtkEntryBuffer" id="entry_buffer" />
<object class="GtkButton" id="delete_btn">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus-on-click">False</property>
<signal name="clicked" handler="backspace"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon_name">edit-clear-symbolic</property>
</object>
</child>
</object>
</interface>

View File

@ -1,128 +0,0 @@
#!/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)
# 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()
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()

72
lightdm-mobile-greeter.py Normal file
View File

@ -0,0 +1,72 @@
#!/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()

34
style.css Normal file
View File

@ -0,0 +1,34 @@
window * {
background: none;
color: greenyellow;
box-shadow: none;
text-decoration: none;
}
window {
background-color: black;
}
button {
border: 0;
background: none;
outline-style: dashed;
margin: 0;
border-width: 2px;
padding: 16px 36px;
}
.keypad button {
padding: 16px 16px;
}
label {
font-weight: bold;
}
button:active {
background-color: greenyellow;
color: black;
}
button:active label {
color: black;
}