Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bvancil committed Jan 10, 2025
1 parent b1a027f commit 6f77b17
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 28 deletions.
9 changes: 6 additions & 3 deletions _caster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
main Caster module
Created on Jun 29, 2014
'''

import logging
import importlib
from dragonfly import get_engine, get_current_engine
from castervoice.lib import control
Expand Down Expand Up @@ -37,8 +37,11 @@
from castervoice.asynch.sikuli import sikuli_controller
sikuli_controller.get_instance().bootstrap_start_server_proxy()

if get_current_engine().name != "text":
hud_support.start_hud()
try:
if get_current_engine().name != "text":
hud_support.start_hud()
except ImportError:
pass # HUD is not available

dh = printer.get_delegating_handler()
dh.register_handler(hud_support.HudPrintMessageHandler()) # After hud starts
Expand Down
12 changes: 8 additions & 4 deletions castervoice/asynch/hmc/h_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import subprocess
import sys

from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCServer # pylint: disable=no-name-in-module

try: # Style C -- may be imported into Caster, or externally
BASE_PATH = os.path.realpath(__file__).rsplit(os.path.sep + "castervoice", 1)[0]
Expand Down Expand Up @@ -52,9 +52,13 @@ def _get_title(hmc_type):


def main():
import PySide2.QtWidgets
from castervoice.asynch.hmc.homunculus import Homunculus
from castervoice.lib.merge.communication import Communicator
# TODO: Remove this try wrapper when CI server supports Qt
try:
import PySide2.QtWidgets
from castervoice.asynch.hmc.homunculus import Homunculus
from castervoice.lib.merge.communication import Communicator
except ImportError:
sys.exit(0)
server_address = (Communicator.LOCALHOST, Communicator().com_registry["hmc"])
# Enabled by default logging causes RPC to malfunction when the GUI runs on
# pythonw. Explicitly disable logging for the XML server.
Expand Down
23 changes: 18 additions & 5 deletions castervoice/asynch/hmc/homunculus.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import os
import sys
import threading

from xmlrpc.server import SimpleXMLRPCServer
from tkinter import Label, Text
import tkinter as tk
import dragonfly

import signal, os
from threading import Timer
# TODO: Remove this try wrapper when CI server supports Qt
try:
import PySide2.QtCore
from PySide2.QtWidgets import QApplication
from PySide2.QtWidgets import QCheckBox
from PySide2.QtWidgets import QDialog
from PySide2.QtWidgets import QFileDialog
from PySide2.QtWidgets import QFormLayout
from PySide2.QtWidgets import QLabel
from PySide2.QtWidgets import QLineEdit
from PySide2.QtWidgets import QScrollArea
from PySide2.QtWidgets import QTextEdit
from PySide2.QtWidgets import QVBoxLayout
from PySide2.QtWidgets import QWidget
except ImportError:
sys.exit(0)

try: # Style C -- may be imported into Caster, or externally
BASE_PATH = os.path.realpath(__file__).rsplit(os.path.sep + "castervoice", 1)[0]
Expand Down
20 changes: 9 additions & 11 deletions castervoice/asynch/hud_support.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys, subprocess, json

from dragonfly import CompoundRule, MappingRule, get_current_engine, Function
from dragonfly import CompoundRule, MappingRule, get_current_engine

from pathlib import Path

Expand All @@ -11,7 +11,8 @@
finally:
from castervoice.lib import settings

from castervoice.lib import printer, control, utilities
from castervoice.lib import printer
from castervoice.lib import control
from castervoice.lib.rules_collection import get_instance

def start_hud():
Expand Down Expand Up @@ -45,8 +46,6 @@ def clear_hud():
hud.clear_hud()
except Exception as e:
printer.out("Unable to clear hud. Hud not available. \n{}".format(e))
# clear cmd output if hud unavailable
Function(utilities.clear_log).execute()


def show_rules():
Expand Down Expand Up @@ -105,27 +104,26 @@ class HudPrintMessageHandler(printer.BaseMessageHandler):
def __init__(self):
super(HudPrintMessageHandler, self).__init__()
self.hud = control.nexus().comm.get_com("hud")
self.is_hud_active = False
self.exception = False
try:
if get_current_engine().name != "text":
self.hud.ping() # HUD running?
self.is_hud_active = True
except Exception as e:
self.is_hud_active = False
self.exception = True
printer.out("Hud not available. \n{}".format(e))

def handle_message(self, items):
if self.is_hud_active is True:
if self.exception is False:
# The timeout with the hud can interfere with the dragonfly speech recognition loop.
# This appears as a stutter in recognition.
# This stutter only happens to end user once, while self.hud.ping() is executing.
# is_hud_active is False if the hud is not available/text engine
# Exceptions are tracked so this stutter only happens to end user once.
# Make exception if the hud is not available/python 2/text engine
# TODO: handle raising exception gracefully
try:
self.hud.send("\n".join([str(m) for m in items]))
except Exception as e:
# If an exception, print is managed by SimplePrintMessageHandler
self.is_hud_active = False
self.exception = True
printer.out("Hud not available. \n{}".format(e))
raise("") # pylint: disable=raising-bad-type
else:
Expand Down
1 change: 1 addition & 0 deletions castervoice/lib/ctrl/configure_engine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
from dragonfly import get_current_engine, register_recognition_callback, RecognitionObserver
from castervoice.lib.ctrl.mgr.engine_manager import EngineModesManager
from castervoice.lib import settings
from castervoice.lib import printer

Expand Down
10 changes: 5 additions & 5 deletions castervoice/rules/core/utility_rules/caster_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class CasterRule(MappingRule):
R(Function(lambda: control.nexus().set_ccr_active(True))),
"disable (c c r|ccr)":
R(Function(lambda: control.nexus().set_ccr_active(False))),
"show caster hud":
"show hud":
R(Function(show_hud), rdescript="Show the HUD window"),
"hide caster hud":
"hide hud":
R(Function(hide_hud), rdescript="Hide the HUD window"),
"show caster rules":
"show rules":
R(Function(show_rules), rdescript="Open HUD frame with the list of active rules"),
"hide caster rules":
"hide rules":
R(Function(hide_rules), rdescript="Hide the list of active rules"),
"clear caster hud":
"clear hud":
R(Function(clear_hud), rdescript="Clear output the HUD window"),
}

Expand Down

0 comments on commit 6f77b17

Please sign in to comment.