0
0
Fork 0
mirror of https://github.com/boltgolt/howdy.git synced 2024-09-19 09:51:19 +02:00
This commit is contained in:
boltgolt 2020-12-03 13:08:37 +01:00
parent 2c28c94353
commit 11eaccbdfb
No known key found for this signature in database
GPG key ID: BECEC9937E1AAE26
3 changed files with 141 additions and 96 deletions

View file

@ -9,5 +9,5 @@ Vcs-Git: https://github.com/boltgolt/howdy
Package: howdy-gtk
Homepage: https://github.com/boltgolt/howdy
Architecture: all
Depends: ${misc:Depends}, curl|wget, python3, python3-pip, python3-dev, python-gtk2, cmake
Depends: ${misc:Depends}, curl|wget, python3, python3-pip, python3-dev, python-gtk2, python-gtk2-dev, cmake
Description: Optional UI package for Howdy, written in Gtk

View file

@ -20,14 +20,18 @@ from gi.repository import GObject as gobject
windowWidth = 400
windowHeight = 100
# Set default messages to show in the popup
message = "Starting up... "
subtext = ""
class StickyWindow(gtk.Window):
def __init__(self):
"""Initialize the sticky window"""
# Make the class a GTK window
gtk.Window.__init__(self)
# Set the title of the window
self.set_title("Howdy Authentication UI")
# Set a bunch of options to make the window stick and be on top of everything
@ -44,84 +48,115 @@ class StickyWindow(gtk.Window):
self.set_type_hint(gdk.WindowTypeHint.NOTIFICATION)
self.set_decorated(False)
# Draw
# Listen for a window redraw
self.connect("draw", self.draw)
# Listen for a force close or click event and exit
self.connect("destroy", self.exit)
self.connect("button-press-event", self.exit)
# Create a GDK drawing, restricts the window size
darea = gtk.DrawingArea()
darea.set_size_request(windowWidth, windowHeight)
self.add(darea)
screen = self.get_screen()
# Get the default screen
screen = gdk.Screen.get_default()
visual = screen.get_rgba_visual()
if visual and screen.is_composited():
self.set_visual(visual)
# TODO: handle more than 1 screen
# Move the window to the center top of the default window, where a webcam usually is
self.move((screen.get_width() / 2) - (windowWidth / 2), 0)
# Show window and force a resize again
self.show_all()
self.resize(windowWidth, windowHeight)
gobject.timeout_add(100, self.test)
print("init")
# Add a timeout to catch input passed from compare.py
gobject.timeout_add(100, self.catch_stdin)
# Start GTK main loop
gtk.main()
def draw(self, widget, ctx):
"""Draw the UI"""
# Change cursor to the kill icon
self.get_window().set_cursor(gdk.Cursor(gdk.CursorType.PIRATE))
ctx.set_source_rgba(0, 0, 0, .9)
# Draw a semi transparent background
ctx.set_source_rgba(0, 0, 0, .7)
ctx.set_operator(cairo.OPERATOR_SOURCE)
ctx.paint()
ctx.set_operator(cairo.OPERATOR_OVER)
dir = os.path.dirname(os.path.abspath(__file__))
# Get absolute or relative logo path
path = "/usr/lib/howdy-gtk/logo.png"
if not os.access(path, os.R_OK):
path = "./logo.png"
image_surface = cairo.ImageSurface.create_from_png("/usr/lib/howdy-gtk/logo.png")
# Create image and calculate scale size based on image size
image_surface = cairo.ImageSurface.create_from_png(path)
ratio = float(windowHeight - 20) / float(image_surface.get_height())
# Position and draw the logo
ctx.translate(15, 10)
ctx.scale(ratio, ratio)
ctx.set_source_surface(image_surface)
ctx.paint()
ctx.set_source_rgba(255, 255, 255, .9)
ctx.set_font_size(80)
# Calculate main message positioning, as the text is heigher if there's a subtext
if subtext:
ctx.move_to(380, 145)
else:
ctx.move_to(380, 170)
# Draw the main message
ctx.set_source_rgba(255, 255, 255, .9)
ctx.set_font_size(80)
ctx.select_font_face("Arial", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
ctx.show_text(message)
# Draw the subtext if there is one
if subtext:
ctx.move_to(380, 210)
ctx.set_source_rgba(230, 230, 230, .8)
ctx.set_font_size(40)
ctx.move_to(380, 210)
ctx.select_font_face("Arial", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
ctx.show_text(subtext)
def exit(self, widget, context):
gtk.main_quit()
def test(self):
def catch_stdin(self):
"""Catch input from stdin and redraw"""
global message, subtext
# Wait for a line on stdin
comm = sys.stdin.readline()[:-1]
# If the line is not empty
if comm:
# Parse a message
if comm[0] == "M":
message = comm[2:]
# Parse subtext
if comm[0] == "S":
subtext = comm[2:]
# Redraw the ui
self.queue_draw()
gobject.timeout_add(100, self.test)
# Fire this function again in 10ms, as we're waiting on IO in readline anyway
gobject.timeout_add(10, self.catch_stdin)
def exit(self, widget, context):
"""Cleanly exit"""
gtk.main_quit()
# Make sure we quit on a SIGINT
signal.signal(signal.SIGINT, signal.SIG_DFL)
# Open the GTK window
window = StickyWindow()

View file

@ -28,7 +28,11 @@ def exit(code):
"""Exit while closeing howdy-gtk properly"""
global gtk_proc
# Exit the auth ui process if there is one
if 'gtk_proc' in globals():
gtk_proc.terminate()
# Exit compare
sys.exit(code)
@ -75,6 +79,8 @@ def send_to_ui(type, message):
"""Send message to the auth ui"""
global gtk_proc
# Only execute of the proccess started
if 'gtk_proc' in globals():
# Format message so the ui can parse it
message = type + "=" + message + " \n"
@ -115,7 +121,11 @@ pose_predictor = None
face_encoder = None
# Start the auth ui
gtk_proc = subprocess.Popen(["howdy-gtk-auth"], stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
try:
gtk_proc = subprocess.Popen(["python3", "-u", "../howdy-gtk/src/authsticky.py"], stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except FileNotFoundError as err:
pass
# Write to the stdin to redraw ui
send_to_ui("M", "Starting up...")