def _execute_events(self, events): """ Send keyboard events. If instance was initialized with *autofmt* True, then this method will mimic a word recognition and analyze its formatting so as to autoformat the text's spacing and capitalization before sending it as keyboard events. """ if self._autofmt: # Mimic a word, select and copy it to retrieve capitalization. get_engine().mimic("test") Key("cs-left, c-c/5").execute() word = Clipboard.get_text() # Inspect formatting of the mimicked word. index = word.find("test") if index == -1: index = word.find("Test") capitalize = True if index == -1: self._log.error("Failed to autoformat.") return False else: capitalize = False # Capitalize given text if necessary. text = self._spec if capitalize: text = text[0].capitalize() + text[1:] # Reconstruct autoformatted output and convert it # to keyboard events. prefix = word[:index] suffix = word[index + 4 :] events = self._parse_spec(prefix + text + suffix) # Send keyboard events. self._keyboard.send_keyboard_events(events) return True
def _execute_events(self, events): """ Send keyboard events. If instance was initialized with *autofmt* True, then this method will mimic a word recognition and analyze its formatting so as to autoformat the text's spacing and capitalization before sending it as keyboard events. """ if self._autofmt: # Mimic a word, select and copy it to retrieve capitalization. get_engine().mimic("test") Key("cs-left, c-c/5").execute() word = Clipboard.get_text() # Inspect formatting of the mimicked word. index = word.find("test") if index == -1: index = word.find("Test") capitalize = True if index == -1: self._log.error("Failed to autoformat.") return False else: capitalize = False # Capitalize given text if necessary. text = self._spec if capitalize: text = text[0].capitalize() + text[1:] # Reconstruct autoformatted output and convert it # to keyboard events. prefix = word[:index] suffix = word[index + 4:] events = self._parse_spec(prefix + text + suffix) # Send keyboard events. self._keyboard.send_keyboard_events(events) return True
from dragonfly.engines.engine import get_engine from dragonfly import ActionBase engine = get_engine() class Say(ActionBase): def __init__(self, text): ActionBase.__init__(self) self.__text = text def _execute(self, data): global engine say(self.__text) return True def say(text): engine.speak(text)
except ImportError, e: raise GrammarError("Failed to load number module %r for language %r" % (module_name, language)) # Make the newly imported language-dependent Integer and Digits # classes available in this module's global namespace. global Integer; Integer = module.Integer global Digits; Digits = module.Digits # Import and set up the Number class. from dragonfly.grammar.number_base import Number as _Number _Number._element_type = IntegerRef global Number; Number = _Number # Said that the reference classes. IntegerRef._element_type = Integer DigitsRef._element_type = Digits NumberRef._element_type = Number #--------------------------------------------------------------------------- # Load number classes for current language. try: import dragonfly.engines.engine as _engine load_language(_engine.get_engine().language) except Exception, e: from dragonfly.log import get_log as _get_log _log =_get_log("") _log.error("Failed to load language-specific number module: %s" % e)