Skip to content

Commit

Permalink
Merge branch 'fix_unimacro_basics' of github.com:dougransom/unimacro …
Browse files Browse the repository at this point in the history
…into fix_unimacro_basics
  • Loading branch information
dougransom committed Oct 18, 2022
2 parents 2e36c5c + f743728 commit 879c93d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/unimacro/BrowseGrammarApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def on_size (self, params):
self.LayoutControls(w, h)

def LayoutControls(self, w, h):
d=w/4
d=int(w/4)
self.Tree.MoveWindow((0,0,d,h))
self.Syntax.MoveWindow((d,0,w,h))

Expand Down Expand Up @@ -314,7 +314,7 @@ def FillList(self):
numCols = len(self.colHeadings)
index = 0
for col in self.colHeadings:
## change second variable to int, QH, 23092922::
## change second variable to int, QH, 23092022::
itemDetails = (LVCFMT_LEFT, int(width*colw[index]), col, 0)
print(f'index: {index}, itemDetails: {itemDetails}')
self.Syntax.InsertColumn(index, itemDetails)
Expand Down Expand Up @@ -579,8 +579,8 @@ def CreateBrowseDialog():
if Exclusive: Name='Exclusive Grammars (Active Rules)'
elif All: Name='All Grammars'
else: Name='Active Grammars'
# dlg=GrammarDialog(Name,GramHierList(Grammars,Start))
dlg=TrainGrammarDialog(Name,GramHierList(Grammars,Start))
dlg=GrammarDialog(Name,GramHierList(Grammars,Start))
# dlg=TrainGrammarDialog(Name,GramHierList(Grammars,Start))
return dlg


Expand Down
Empty file.
31 changes: 9 additions & 22 deletions src/unimacro/UnimacroGrammars/_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ class ThisGrammar(ancestor):
# include only if searchinothertask is True (via .ini file) (enable search commands = T)
searchRule = "<searchinothertask> exported = search ({taskcount}|{application}) | <before> search ({taskcount}|{application});"

def _prog_infonit__(self):
def __init__(self):
"""start the inifile and add to grammar if needed the searchRule
"""
ancestor.__init__(self)
self.startInifile()
#print 'enableSearchCommands: %s'% self.enableSearchCommands
if self.enableSearchCommands:
self.gramSpec.append(self.searchRule)
ancestor.__init__(self)
self.gramSpec += '\n' + self.searchRule
_name = self.getName()


Expand Down Expand Up @@ -1126,7 +1126,12 @@ def cancelMode(self):


# standard stuff Joel (adapted for possible empty gramSpec, QH, unimacro)

# print(f'_task grammar, __name__: {__name__}')
thisGrammar = ThisGrammar()
if thisGrammar.gramSpec:
thisGrammar.initialize()
else:
thisGrammar = None

def unload():
#pylint:disable = W0603
Expand All @@ -1142,21 +1147,3 @@ def changeCallback(Type,Args):
if thisGrammar:
thisGrammar.cancelMode()

if __name__ == "__main__":
natlink.natConnect()
try:
thisGrammar = ThisGrammar()
thisGrammar.startInifile() #modName = '_tasks')
thisGrammar.initialize()
Words = ['task', 'three']
# print(f'natbj.loadedGrammars: {natbj.loadedGrammars}')
thisGrammar.rule_taskswitch(Words)
# natlink.recognitionMimic(["task", "three"])
finally:
natlink.natDisconnect()
else:
thisGrammar = ThisGrammar()
if thisGrammar.gramSpec:
thisGrammar.initialize()
else:
thisGrammar = None
2 changes: 1 addition & 1 deletion src/unimacro/natlinkutilsbj.py
Original file line number Diff line number Diff line change
Expand Up @@ -2239,7 +2239,7 @@ def startInifile(self, modName=None):
self.checkForChanges = 1
self.openedInifile = 0
self.ignore = None
modName = modName or self.__module__
modName = modName or self.__module__.rsplit('.', maxsplit=1)[-1]
# baseDir = status.getUnimacroDirectory()
userDir = status.getUnimacroUserDirectory()

Expand Down
35 changes: 35 additions & 0 deletions tests/test_grammar_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pylint:disable=E1101
from pathlib import Path
import pytest
import natlink
from unimacro.UnimacroGrammars._tasks import ThisGrammar
from natlinkcore import natlinkstatus
status = natlinkstatus.NatlinkStatus

thisDir = Path(__file__).parent

def mock_unimacro_user_dir(_self):
mock_folder= thisDir / "mock_unimacro_userdir"
if not mock_folder.is_dir():
mock_folder.mkdir()
return str(mock_folder)

def test_gototask(monkeypatch):
"""see if (with debugging) coming into a grammar works
"""
monkeypatch.setattr(status, "getUnimacroUserDirectory", mock_unimacro_user_dir)

natlink.natConnect()
try:
thisGrammar = ThisGrammar()
thisGrammar.startInifile() #modName = '_tasks')
thisGrammar.initialize()
Words = ['task', 'three']
# print(f'natbj.loadedGrammars: {natbj.loadedGrammars}')
thisGrammar.rule_taskswitch(Words)
# natlink.recognitionMimic(["task", "three"])
finally:
natlink.natDisconnect()

if __name__ == "__main__":
pytest.main(['test_gototask'])

0 comments on commit 879c93d

Please sign in to comment.