Skip to content

Commit

Permalink
refs dictation-toolbox#385, dictation-toolbox#54: resolve odd stack f…
Browse files Browse the repository at this point in the history
…rame index error
  • Loading branch information
synkarius committed Nov 1, 2019
1 parent 4c62fff commit 1cf2381
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion castervoice/lib/ccr/core/nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from castervoice.lib.merge.additions import IntegerRefST
from castervoice.lib.merge.mergerule import MergeRule
from castervoice.lib.merge.state.actions import AsynchronousAction, ContextSeeker
from castervoice.lib.merge.state.actions2 import UntilCancelled
from castervoice.lib.merge.state.actions2 import UntilCancelled, NullAction
from castervoice.lib.merge.state.short import S, L, R

_tpd = text_punc_dict()
Expand All @@ -35,6 +35,7 @@ class Navigation(MergeRule):
mapping = {
# "periodic" repeats whatever comes next at 1-second intervals until "terminate"
# or "escape" (or your SymbolSpecs.CANCEL) is spoken or 100 tries occur

"periodic":
ContextSeeker(forward=[
L(
Expand Down
14 changes: 10 additions & 4 deletions castervoice/lib/ctrl/mgr/rule_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ def __init__(self, name=None, executable=None, title=None, grammar_name=None,
self.watch_exclusion = watch_exclusion

# Python black magic to determine which file to track:
frame = inspect.stack()[1]
stack = inspect.stack(0)
self._filepath = RuleDetails._calculate_filepath_from_frame(stack, 1)

@staticmethod
def _calculate_filepath_from_frame(stack, index):
frame = stack[index]
module = inspect.getmodule(frame[0])
self._filepath = module.__file__.replace("\\", "/")
if self._filepath.endswith("pyc"):
self._filepath = self._filepath[:-1]
filepath = module.__file__.replace("\\", "/")
if filepath.endswith("pyc"):
filepath = filepath[:-1]
return filepath

def get_filepath(self):
return self._filepath

0 comments on commit 1cf2381

Please sign in to comment.