mirror of
https://github.com/boltgolt/howdy.git
synced 2024-09-19 09:51:19 +02:00
Gtk ui now works within rubberstamps
This commit is contained in:
parent
b04ffe5bd8
commit
f16dbe478f
5 changed files with 48 additions and 13 deletions
|
@ -134,10 +134,10 @@ class StickyWindow(gtk.Window):
|
|||
if comm:
|
||||
# Parse a message
|
||||
if comm[0] == "M":
|
||||
message = comm[2:]
|
||||
message = comm[2:].strip()
|
||||
# Parse subtext
|
||||
if comm[0] == "S":
|
||||
subtext = comm[2:]
|
||||
subtext = comm[2:].strip()
|
||||
|
||||
# Redraw the ui
|
||||
self.queue_draw()
|
||||
|
|
|
@ -17,6 +17,7 @@ import configparser
|
|||
import dlib
|
||||
import cv2
|
||||
import datetime
|
||||
import atexit
|
||||
import subprocess
|
||||
import snapshot
|
||||
import numpy as np
|
||||
|
@ -26,7 +27,7 @@ from recorders.video_capture import VideoCapture
|
|||
from i18n import _
|
||||
|
||||
|
||||
def exit(code):
|
||||
def exit(code=None):
|
||||
"""Exit while closeing howdy-gtk properly"""
|
||||
global gtk_proc
|
||||
|
||||
|
@ -35,6 +36,7 @@ def exit(code):
|
|||
gtk_proc.terminate()
|
||||
|
||||
# Exit compare
|
||||
if code is not None:
|
||||
sys.exit(code)
|
||||
|
||||
|
||||
|
@ -82,15 +84,15 @@ def send_to_ui(type, message):
|
|||
global gtk_proc
|
||||
|
||||
# Only execute of the proccess started
|
||||
if 'gtk_proc' in globals():
|
||||
if "gtk_proc" in globals():
|
||||
# Format message so the ui can parse it
|
||||
message = type + "=" + message + " \n"
|
||||
|
||||
# Try to send the message to the auth ui, but it's okay if that fails
|
||||
try:
|
||||
gtk_proc.stdin.write(bytearray(message.encode("ascii")))
|
||||
gtk_proc.stdin.write(bytearray(message.encode("utf-8")))
|
||||
gtk_proc.stdin.flush()
|
||||
except IOError as err:
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
|
||||
|
@ -122,10 +124,11 @@ face_detector = None
|
|||
pose_predictor = None
|
||||
face_encoder = None
|
||||
|
||||
# Start the auth ui
|
||||
# Start the auth ui, register it to be always be closed on exit
|
||||
try:
|
||||
gtk_proc = subprocess.Popen(["howdy-gtk", "--start-auth-ui"], stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
except FileNotFoundError as err:
|
||||
atexit.register(exit)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
# Write to the stdin to redraw ui
|
||||
|
@ -337,7 +340,13 @@ while True:
|
|||
# Run rubberstamps if enabled
|
||||
if config.getboolean("rubberstamps", "enabled", fallback=False):
|
||||
import rubberstamps
|
||||
rubberstamps.execute(config, {
|
||||
|
||||
send_to_ui("S", "")
|
||||
|
||||
if "gtk_proc" not in vars():
|
||||
gtk_proc = None
|
||||
|
||||
rubberstamps.execute(config, gtk_proc, {
|
||||
"video_capture": video_capture,
|
||||
"face_detector": face_detector,
|
||||
"pose_predictor": pose_predictor,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
Download and unpack `dlib` data files from https://github.com/davisking/dlib-models repository:
|
||||
```shell
|
||||
|
||||
```
|
||||
shell
|
||||
wget https://github.com/davisking/dlib-models/raw/master/dlib_face_recognition_resnet_model_v1.dat.bz2
|
||||
wget https://github.com/davisking/dlib-models/raw/master/mmod_human_face_detector.dat.bz2
|
||||
wget https://github.com/davisking/dlib-models/raw/master/shape_predictor_5_face_landmarks.dat.bz2
|
||||
|
|
|
@ -6,14 +6,36 @@ from importlib.machinery import SourceFileLoader
|
|||
|
||||
|
||||
class RubberStamp:
|
||||
UI_TEXT = "ui_text"
|
||||
UI_SUBTEXT = "ui_subtext"
|
||||
|
||||
def create_shorthands(self):
|
||||
self.video_capture = self.opencv["video_capture"]
|
||||
self.face_detector = self.opencv["face_detector"]
|
||||
self.pose_predictor = self.opencv["pose_predictor"]
|
||||
self.clahe = self.opencv["clahe"]
|
||||
|
||||
def set_ui_text(self, text, type=None):
|
||||
typedec = "M"
|
||||
|
||||
def execute(config, opencv):
|
||||
if type == self.UI_SUBTEXT:
|
||||
typedec = "S"
|
||||
|
||||
return self.send_ui_raw(typedec + "=" + text)
|
||||
|
||||
def send_ui_raw(self, command):
|
||||
if self.config.getboolean("debug", "verbose_stamps", fallback=False):
|
||||
print("Sending command to howdy-gtk:")
|
||||
print(" " + command)
|
||||
|
||||
command += " \n"
|
||||
|
||||
if self.gtk_proc:
|
||||
self.gtk_proc.stdin.write(bytearray(command.encode("utf-8")))
|
||||
self.gtk_proc.stdin.flush()
|
||||
|
||||
|
||||
def execute(config, gtk_proc, opencv):
|
||||
verbose = config.getboolean("debug", "verbose_stamps", fallback=False)
|
||||
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||
installed_stamps = []
|
||||
|
@ -56,8 +78,8 @@ def execute(config, opencv):
|
|||
|
||||
instance = constructor()
|
||||
instance.config = config
|
||||
instance.gtk_proc = gtk_proc
|
||||
instance.opencv = opencv
|
||||
print(regex_result.group(3))
|
||||
|
||||
instance.options = {
|
||||
"timeout": int(re.sub("[a-zA-Z]", "", regex_result.group(2))),
|
||||
|
|
|
@ -9,6 +9,8 @@ class nod(RubberStamp):
|
|||
self.options["min_directions"] = 3
|
||||
|
||||
def run(self):
|
||||
self.set_ui_text("Authorised, nod to confirm", self.UI_TEXT)
|
||||
|
||||
last_reldist = -1
|
||||
last_nosepoint = {"x": -1, "y": -1}
|
||||
recorded_nods = {"x": [], "y": []}
|
||||
|
|
Loading…
Reference in a new issue