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