Skip to content

Commit ea12d04

Browse files
committedAug 22, 2019
refs dictation-toolbox#385, resolve content_loader/nexus circular import
1 parent 29a2bd9 commit ea12d04

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed
 

‎_caster.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,34 @@
33
main Caster module
44
Created on Jun 29, 2014
55
'''
6+
import datetime
7+
8+
from castervoice.lib.ctrl.mgr.loading.load.content_loader import ContentLoader
9+
from castervoice.lib.ctrl.mgr.loading.load.content_request_generator import ContentRequestGenerator
610

711
import logging
812
logging.basicConfig()
913
from dragonfly import get_engine
10-
11-
1214
from castervoice.lib.ctrl.dependencies import DependencyMan # requires nothing
13-
1415
DependencyMan().initialize()
15-
1616
_NEXUS = None
1717
from castervoice.lib import settings # requires toml
1818
if settings.SYSTEM_INFORMATION["platform"] != "win32":
1919
raise SystemError("Your platform is not currently supported by Caster.")
2020
settings.WSR = __name__ == "__main__"
21-
from castervoice.lib.ccr.standard import SymbolSpecs
21+
2222
if settings.WSR:
2323
from castervoice.lib.ccr.standard import SymbolSpecs
2424
SymbolSpecs.set_cancel_word("escape")
2525
from castervoice.lib import control
26+
27+
_crg = ContentRequestGenerator()
28+
_content_loader = ContentLoader(_crg)
29+
control.init_nexus(_content_loader)
30+
2631
_NEXUS = control.nexus()
2732

2833
from castervoice.asynch.sikuli import sikuli_controller
29-
3034
if not globals().has_key('profile_switch_occurred'):
3135
# Load user rules
3236
_NEXUS.process_user_content()
@@ -37,11 +41,8 @@
3741
reload(sikulixx)
3842
else:
3943
profile_switch_occurred = None
40-
4144
if settings.SETTINGS["sikuli"]["enabled"]:
4245
sikuli_controller.get_instance().bootstrap_start_server_proxy()
43-
4446
print("\n*- Starting " + settings.SOFTWARE_NAME + " -*")
45-
4647
if settings.WSR:
4748
get_engine().recognize_forever()

‎castervoice/apps/griddouglas.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from castervoice.asynch.mouse import grids
77
import win32api, win32con
88

9+
from castervoice.lib.ccr.standard import SymbolSpecs
910
from castervoice.lib.ctrl.mgr.rule_details import RuleDetails
1011
from castervoice.lib.merge.additions import IntegerRefST
1112
from castervoice.lib.merge.mergerule import MergeRule

‎castervoice/apps/gridrainbow.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import win32api, win32con
77

88
from castervoice.lib import control, settings
9+
from castervoice.lib.ccr.standard import SymbolSpecs
910
from castervoice.lib.ctrl.mgr.rule_details import RuleDetails
1011
from castervoice.lib.merge.additions import IntegerRefST
1112
from castervoice.lib.merge.mergerule import MergeRule

‎castervoice/lib/control.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
_NEXUS = None
2+
print(" HERE IMPORTING NEXUS ... ")
3+
4+
def init_nexus(content_loader):
5+
global _NEXUS
6+
from castervoice.lib.ctrl.nexus import Nexus
7+
_NEXUS = Nexus(content_loader)
28

39

410
def nexus():
5-
global _NEXUS
6-
if _NEXUS is None:
7-
from castervoice.lib.ctrl.nexus import Nexus
8-
_NEXUS = Nexus()
911
return _NEXUS

‎castervoice/lib/ctrl/mgr/grammar_manager.py

+4
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ def initialize(self):
7777
return
7878

7979
for rcn in self._config.get_active_rule_class_names():
80+
print("initialize:rcn: " + rcn)
8081
is_ccr = self._managed_rules[rcn].declared_ccrtype is not None
8182
if is_ccr and not self._ccr_toggle.is_active():
8283
continue
84+
print("initialize:rcn:activate: " + rcn)
8385
self._activate_rule(rcn, True)
8486

8587
self._initial_activations_complete = True
@@ -163,6 +165,8 @@ def _activate_rule(self, class_name, active):
163165
active_mrs = [self._managed_rules[rcn] for rcn in active_rule_class_names]
164166
active_ccr_mrs = [mr for mr in active_mrs if mr.details.declared_ccrtype is not None]
165167

168+
print("_activate_rule: " + str(len(active_ccr_mrs)))
169+
166170
'''
167171
The merge may result in 1 to n+1 rules where n is the number of ccr app rules
168172
which are in the active rules list.

‎castervoice/lib/ctrl/mgr/loading/load/content_loader.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
import importlib
23
import traceback
34
from sys import modules as MODULES
@@ -88,11 +89,13 @@ def _process_requests(self, requests):
8889
result = []
8990

9091
for request in requests:
92+
print("log {} {} {}".format(1, datetime.datetime.today(), request.module_name))
9193
if request.directory not in path:
9294
path.append(request.directory)
9395
content_item = self.idem_import_module(request.module_name, request.content_type)
9496
if content_item is not None:
9597
result.append(content_item)
98+
print("log {} {} {}".format(2, datetime.datetime.today(), request.module_name))
9699

97100
return result
98101

‎castervoice/lib/ctrl/nexus.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import datetime
2+
13
from castervoice.lib.ctrl.grammar_container import GrammarContainer
24
from castervoice.lib.ctrl.mgr.ccr_toggle import CCRToggle
35
from castervoice.lib.ctrl.mgr.grammar_activator import GrammarActivator
@@ -34,14 +36,15 @@
3436

3537

3638
class Nexus:
37-
def __init__(self):
39+
def __init__(self, content_loader):
3840
"""
3941
The Nexus is the 'glue code' of Caster. It is where the things reside which
4042
manage global state. It is also an access point to those things for other
4143
things which need them. This access should be limited.
4244
"""
4345

4446
'''CasterState is used for impl of the asynchronous actions'''
47+
4548
self.state = CasterState()
4649

4750
'''rpc class for interacting with Caster UI elements via xmlrpclib'''
@@ -68,8 +71,7 @@ def __init__(self):
6871

6972
'''unified loading mechanism for [rules, transformers, hooks]
7073
from [caster starter locations, user dir]'''
71-
crg = ContentRequestGenerator()
72-
self._content_loader = ContentLoader(crg)
74+
self._content_loader = content_loader
7375

7476
'''mapping rule maker: like the ccrmerger, but doesn't merge and isn't ccr'''
7577
mapping_rule_maker = MappingRuleMaker(transformers_runner, smrc)

0 commit comments

Comments
 (0)