Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HUD #773

Merged
merged 18 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions _caster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
main Caster module
Created on Jun 29, 2014
'''

import logging
import importlib
from castervoice.lib.ctrl.dependencies import DependencyMan # requires nothing
DependencyMan().initialize()

from castervoice.lib import settings # requires DependencyMan to be initialized
settings.initialize()
from dragonfly import get_engine, get_current_engine
from castervoice.lib import control
from castervoice.lib import settings
from castervoice.lib import printer
from castervoice.lib.ctrl.configure_engine import EngineConfigEarly, EngineConfigLate
from castervoice.lib.ctrl.dependencies import DependencyMan
from castervoice.lib.ctrl.updatecheck import UpdateChecker
from castervoice.asynch import hud_support

from castervoice.lib.ctrl.updatecheck import UpdateChecker # requires settings/dependencies
UpdateChecker().initialize()
printer.out("@ - Starting {} with `{}` Engine -\n".format(settings.SOFTWARE_NAME, get_engine().name))

from castervoice.lib.ctrl.configure_engine import EngineConfigEarly, EngineConfigLate
DependencyMan().initialize() # requires nothing
settings.initialize()
UpdateChecker().initialize() # requires settings/dependencies
EngineConfigEarly() # requires settings/dependencies

_NEXUS = None

from castervoice.lib import printer
from castervoice.lib import control

if control.nexus() is None: # Initialize Caster State
if control.nexus() is None:
from castervoice.lib.ctrl.mgr.loading.load.content_loader import ContentLoader
from castervoice.lib.ctrl.mgr.loading.load.content_request_generator import ContentRequestGenerator
from castervoice.lib.ctrl.mgr.loading.load.reload_fn_provider import ReloadFunctionProvider
Expand All @@ -32,9 +32,17 @@
_content_loader = ContentLoader(_crg, importlib.import_module, _rp.get_reload_fn(), _sma)
control.init_nexus(_content_loader)
EngineConfigLate() # Requires grammars to be loaded and nexus

if settings.SETTINGS["sikuli"]["enabled"]:
from castervoice.asynch.sikuli import sikuli_controller
sikuli_controller.get_instance().bootstrap_start_server_proxy()

printer.out("\n*- Starting " + settings.SOFTWARE_NAME + " -*")
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
printer.out("\n") # Force update to display text
58 changes: 28 additions & 30 deletions castervoice/asynch/hmc/h_launch.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
from subprocess import Popen
import sys, os
import os
import subprocess
import sys

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]
if BASE_PATH not in sys.path:
sys.path.append(BASE_PATH)
finally:
from castervoice.asynch.hmc.hmc_ask_directory import HomunculusDirectory
from castervoice.asynch.hmc.hmc_recording import HomunculusRecording
from castervoice.asynch.hmc.hmc_confirm import HomunculusConfirm
from castervoice.asynch.hmc.homunculus import Homunculus
from castervoice.lib import settings
'''
To add a new homunculus (pop-up ui window) type:
(1) create the module
(2) and its type and title constants to settings.py
(3) add it to _get_title(), and "if __name__ == '__main__':" in this module
(4) call launch() from this module with its type and any data it needs (data as a single string with no spaces)
'''


def launch(hmc_type, data=None):
from dragonfly import (WaitWindow, FocusWindow, Key)
instructions = _get_instructions(hmc_type)
if data is not None: # and callback!=None:
if data is not None:
instructions.append(data)
Popen(instructions)

subprocess.Popen(instructions)
hmc_title = _get_title(hmc_type)
WaitWindow(title=hmc_title, timeout=5).execute()
FocusWindow(title=hmc_title).execute()
Key("tab").execute()


def _get_instructions(hmc_type):
Expand Down Expand Up @@ -61,17 +51,25 @@ def _get_title(hmc_type):
return default


def main():
# 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.
server = SimpleXMLRPCServer(server_address, logRequests=False, allow_none=True)
app = PySide2.QtWidgets.QApplication(sys.argv)
window = Homunculus(server, sys.argv)
window.show()
exit_code = app.exec_()
server.shutdown()
sys.exit(exit_code)


if __name__ == '__main__':
found_word = None
if len(sys.argv) > 2:
found_word = sys.argv[2]
if sys.argv[1] == settings.QTYPE_DEFAULT:
app = Homunculus(sys.argv[1])
elif sys.argv[1] == settings.QTYPE_RECORDING:
app = HomunculusRecording([settings.QTYPE_RECORDING, found_word])
elif sys.argv[1] == settings.QTYPE_INSTRUCTIONS:
app = Homunculus(sys.argv[1], sys.argv[2])
elif sys.argv[1] == settings.QTYPE_DIRECTORY:
app = HomunculusDirectory(sys.argv[1])
elif sys.argv[1] == settings.QTYPE_CONFIRM:
app = HomunculusConfirm([sys.argv[1], sys.argv[2]])
main()
2 changes: 1 addition & 1 deletion castervoice/asynch/hmc/hmc_ask_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class HomunculusDirectory(Homunculus):
def __init__(self, params):
Homunculus.__init__(self, params[0])
Homunculus.__init__(self, params[0], args=None)
self.title(settings.HOMUNCULUS_VERSION + settings.HMC_TITLE_DIRECTORY)

self.geometry("640x50+" + str(int(self.winfo_screenwidth()/2 - 320)) + "+" +
Expand Down
2 changes: 1 addition & 1 deletion castervoice/asynch/hmc/hmc_confirm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class HomunculusConfirm(Homunculus):
def __init__(self, params):
Homunculus.__init__(self, params[0])
Homunculus.__init__(self, params[0], args=None)
self.title(settings.HOMUNCULUS_VERSION + settings.HMC_TITLE_CONFIRM)

self.geometry("320x50+" + str(int(self.winfo_screenwidth()/2 - 160)) + "+" +
Expand Down
2 changes: 1 addition & 1 deletion castervoice/asynch/hmc/hmc_recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_row(self, cut_off=0):

def __init__(self, params):
self.grid_row = 0
Homunculus.__init__(self, params[0])
Homunculus.__init__(self, params[0], args=None)
self.title(settings.HOMUNCULUS_VERSION + settings.HMC_TITLE_RECORDING)

self.geometry("640x480+" + str(int(self.winfo_screenwidth()/2 - 320)) + "+" +
Expand Down
Loading