def server_proxy_timer_fn(): utilities.report("Attempting Caster-Sikuli connection [...]") try: start_server_proxy() control.nexus().timer.remove_callback(server_proxy_timer_fn) except Exception: pass
def start_server_proxy(): global server_proxy server_proxy = control.nexus().comm.get_com("sikuli") fns = server_proxy.list_functions() if len(fns) > 0: generate_commands(fns) utilities.report("Caster-Sikuli server started successfully.")
def process_set(data): '''''' word=data["word"] pronunciation=data["pronunciation"] if pronunciation=="": pronunciation=None word_info=data["word_info"] #missingno import natlink result=0 if pronunciation==None: result=natlink.addWord(word, word_info) if result==0 and data["force"]==1: process_delete(data) result=natlink.addWord(word, word_info) else: result=natlink.addWord(word, word_info, str(pronunciation)) if result==0 and data["force"]==1: process_delete(data) result=natlink.addWord(word, word_info, str(pronunciation)) if result==1: utilities.report("word added successfully: "+word, False) else: utilities.report("word add failed: "+word, False)
def add_vocab(): engine = dragonfly.get_engine() if engine.name != "natlink": utilities.report( "feature unavailable in your speech recognition engine", speak=True) return # attempts to get what was highlighted first highlighted = context.read_selected_without_altering_clipboard(True) # change the following regex to accept alphabetical only disallow = "^[A-Za-z]*$" selected = None if highlighted[0] == 0 and highlighted[1] != "": if not re.match(disallow, highlighted[1]): utilities.report("only used for single words", speak=True) return selected = highlighted[1] try: h_launch.launch(settings.QTYPE_SET, process_set, selected) except Exception: utilities.simple_log(False)
def process_set(data): '''''' word = data["word"] pronunciation = data["pronunciation"] if pronunciation == "": pronunciation = None word_info = data["word_info"] #missingno import natlink result = 0 if pronunciation == None: result = natlink.addWord(word, word_info) if result == 0 and data["force"] == 1: process_delete(data) result = natlink.addWord(word, word_info) else: result = natlink.addWord(word, word_info, str(pronunciation)) if result == 0 and data["force"] == 1: process_delete(data) result = natlink.addWord(word, word_info, str(pronunciation)) if result == 1: utilities.report("word added successfully: " + word, False) else: utilities.report("word add failed: " + word, False)
def attempt_focus(): for win in Window.get_all_windows(): w=win found_match=True if title!=None: found_match=title in w.title if found_match and executable!=None: found_match=executable in w.executable if found_match: try: # this is still broken win32gui.SetWindowPos(w.handle,win32con.HWND_NOTOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE + win32con.SWP_NOSIZE) win32gui.SetWindowPos(w.handle,win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE + win32con.SWP_NOSIZE) win32gui.SetWindowPos(w.handle,win32con.HWND_NOTOPMOST, 0, 0, 0, 0, win32con.SWP_SHOWWINDOW + win32con.SWP_NOMOVE + win32con.SWP_NOSIZE) Key("alt").execute() time.sleep(0.5) win32gui.SetForegroundWindow(w.handle) w.set_foreground() except Exception: utilities.report("Unable to set focus:\ntitle: "+w.title+"\nexe: "+w.executable) break # do not assume that it worked success = SuperFocusWindow.focus_was_success(title, executable) if not success: if title!=None: print "title failure: ", title, w.title if executable!=None: print "executable failure: ", executable, w.executable, executable in w.executable return success
def pita(textnv): global OLD_ACTIVE_WINDOW_TITLE, ACTIVE_FILE_PATH filename, folders, title = utilities.get_window_title_info() active_has_changed = OLD_ACTIVE_WINDOW_TITLE != title # check to see if the active file has changed; if not, skip this step if active_has_changed: OLD_ACTIVE_WINDOW_TITLE = title ACTIVE_FILE_PATH = scanner.guess_file_based_on_window_title(filename, folders) if filename == None: utilities.report("pita: filename pattern not found in window title") return if ACTIVE_FILE_PATH[0] != None: global CHOICES CHOICES = selector.get_similar_symbol_name(str(textnv), scanner.DATA["directories"][ACTIVE_FILE_PATH[0]][ACTIVE_FILE_PATH[1]]["names"]) try: if settings.SETTINGS["miscellaneous"]["status_window_enabled"]: display = "" counter = 1 for result in CHOICES: if counter>1: display+="\n" display+=str(counter)+" "+result[1] counter+=1 control.nexus().intermediary.hint(display) except Exception: utilities.simple_log()
def wait_for_death(title, timeout=5): t = 0.0 inc = 0.1 while t < timeout: if not utilities.window_exists(None, title): break t += inc time.sleep(inc) if t >= timeout: utilities.report("wait_for_death()" + " timed out (" + title + ")")
def _merge_node_compatible_check(node_rule): global current_combined_rule_ccr for spec in node_rule.master_node.all_possibilities(): if spec in current_combined_rule_ccr._mapping.keys(): utilities.report("The spec '"+spec+"' from the "+node_rule.master_node.text \ + " node is incompatible with one of the following CCR modules: " \ + ", ".join([x for x in settings.SETTINGS["ccr"]["modes"] if settings.SETTINGS["ccr"]["modes"][x]]) \ + " --disabling "+node_rule.master_node.text +" node") node_rule.master_node.active = False return
def pita_list_provider(): filename, folders, title = utilities.get_window_title_info() active_file_path = scanner.guess_file_based_on_window_title(filename, folders) if filename == None: utilities.report("pita: filename pattern not found in window title") return [] if active_file_path[0] != None: return scanner.DATA["directories"][active_file_path[0]][active_file_path[1]]["names"] else: return []
def pita_list_provider(): filename, folders, title = utilities.get_window_title_info() active_file_path = scanner.guess_file_based_on_window_title( filename, folders) if filename == None: utilities.report("pita: filename pattern not found in window title") return [] if active_file_path[0] != None: return scanner.DATA["directories"][active_file_path[0]][ active_file_path[1]]["names"] else: return []
def get_chain_alias_spec(): global MESSAGE_SPLITTER result=None copy_worked=False for i in range(0, 10): result=context.read_selected_without_altering_clipboard(True) if result[0]==0: copy_worked=True break if copy_worked==True: h_launch.launch(settings.QTYPE_INSTRUCTIONS, chain_alias, "Enter_spec_for_command|" + MESSAGE_SPLITTER.join(result[1].split())) else: utilities.report("copy failed")
def get_chain_alias_spec(): global MESSAGE_SPLITTER result = None copy_worked = False for i in range(0, 10): result = context.read_selected_without_altering_clipboard(True) if result[0] == 0: copy_worked = True break if copy_worked == True: h_launch.launch( settings.QTYPE_INSTRUCTIONS, chain_alias, "Enter_spec_for_command|" + MESSAGE_SPLITTER.join(result[1].split())) else: utilities.report("copy failed")
def pita(textnv): global OLD_ACTIVE_WINDOW_TITLE, ACTIVE_FILE_PATH filename, folders, title = utilities.get_window_title_info() active_has_changed = OLD_ACTIVE_WINDOW_TITLE != title # check to see if the active file has changed; if not, skip this step if active_has_changed: OLD_ACTIVE_WINDOW_TITLE = title ACTIVE_FILE_PATH = scanner.guess_file_based_on_window_title(filename, folders) if filename == None: utilities.report("pita: filename pattern not found in window title") return if ACTIVE_FILE_PATH[0] != None: result = selector.get_similar_symbol_name(str(textnv), scanner.DATA["directories"][ACTIVE_FILE_PATH[0]][ACTIVE_FILE_PATH[1]]["names"]) # print "fuzzy match: ", str(textnv), "->", result Text(result)._execute()
def attempt_focus(): for win in Window.get_all_windows(): w = win found_match = True if title != None: found_match = title in w.title if found_match and executable != None: found_match = executable in w.executable if found_match: try: # this is still broken win32gui.SetWindowPos( w.handle, win32con.HWND_NOTOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE + win32con.SWP_NOSIZE) win32gui.SetWindowPos( w.handle, win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE + win32con.SWP_NOSIZE) win32gui.SetWindowPos( w.handle, win32con.HWND_NOTOPMOST, 0, 0, 0, 0, win32con.SWP_SHOWWINDOW + win32con.SWP_NOMOVE + win32con.SWP_NOSIZE) Key("alt").execute() time.sleep(0.5) win32gui.SetForegroundWindow(w.handle) w.set_foreground() except Exception: utilities.report("Unable to set focus:\ntitle: " + w.title + "\nexe: " + w.executable) break # do not assume that it worked success = SuperFocusWindow.focus_was_success(title, executable) if not success: if title != None: print "title failure: ", title, w.title if executable != None: print "executable failure: ", executable, w.executable, executable in w.executable return success
def add_vocab(): engine=dragonfly.get_engine() if engine.name!="natlink": utilities.report("feature unavailable in your speech recognition engine", speak=True) return # attempts to get what was highlighted first highlighted=context.read_selected_without_altering_clipboard(True) # change the following regex to accept alphabetical only disallow="^[A-Za-z]*$" selected=None if highlighted[0]==0 and highlighted[1]!="": if not re.match(disallow, highlighted[1]): utilities.report("only used for single words", speak=True) return selected=highlighted[1] try: h_launch.launch(settings.QTYPE_SET, process_set, selected) except Exception: utilities.simple_log(False)
def resume(self): utilities.report("T: " + str(self.remaining) + " m") control.nexus().timer.add_callback(self.tick, self.minute)
def change_monitor(): if settings.SETTINGS["miscellaneous"]["sikuli_enabled"]: Playback([(["monitor", "select"], 0.0)]).execute() else: utilities.report("This command requires SikuliX to be enabled in the settings file")
] defaults = {"n": 1, "nnv": 1, "text": "", "volume_mode": "setsysvolume", "enable":-1 } grammar = Grammar('general') grammar.add_rule(MainRule()) grammar.load() def unload(): global grammar if grammar: grammar.unload() grammar = None ccr.unload() sikuli.unload() if settings.SETTINGS["miscellaneous"]["status_window_enabled"]: utilities.report("\nWARNING: Status Window is an experimental feature, and there is a known freezing glitch with it.\n") utilities.report("*- Starting " + settings.SOFTWARE_NAME + " -*") if __name__ == "__main__": import pythoncom print "Windows Speech Recognition is garbage; it is " \ +"recommended that you not run Caster this way. " \ + "" while True: pythoncom.PumpWaitingMessages() # @UndefinedVariable time.sleep(.1)
def send_message(self, msg): if settings.SETTINGS["miscellaneous"]["status_window_enabled"]: control.nexus().intermediary.text(msg) else: utilities.report(msg)
def update(name, value): # settings try: control.nexus().node_rule_active(name, value) ccr.set_active() ccr.refresh() except Exception: utilities.simple_log() _mapping={} for node in [# register nodes here in order to get them into ccr css.getCSSNode() ]: if node.spec.lower() in settings.SETTINGS["ccr"]["modes"]: utilities.report("CCR naming conflict found between: config"+node.spec+".txt and " \ +node.spec+".py, favoring CCR module, ignoring "+node.spec+".py" \ +" (Please delete config"+node.spec+".txt) and remove "+node.spec \ +" from the settings.json file to change this.") continue if node.spec in settings.SETTINGS["nodes"] and settings.SETTINGS["nodes"][node.spec]: node.active = True control.nexus().add_node_rule(NodeRule(node, None, control.nexus().intermediary, False)) _mapping["enable "+node.spec]=Function(update, name=node.spec, value=True) _mapping["disable "+node.spec]=Function(update, name=node.spec, value=False) if len(_mapping)>0: grammar = Grammar("NodeActivation") grammar.add_rule(MappingRule(mapping=_mapping, name="NodeActivation")) grammar.load() def unload():
def text(self, message): if settings.SETTINGS["miscellaneous"]["status_window_enabled"]: self.communicator.get_com("status").text(message) else: utilities.report(message)
def update(name, value): # settings try: control.nexus().node_rule_active(name, value) ccr.set_active() ccr.refresh() except Exception: utilities.simple_log() _mapping={} for node in [# register nodes here in order to get them into ccr css.getCSSNode() ]: if node.text in settings.SETTINGS["ccr"]["modes"]: utilities.report("CCR naming conflict found between: config"+node.text+".txt and " \ +node.text+".py, favoring CCR module, ignoring "+node.text+".py" \ +" (Please delete config"+node.text+".txt) and remove "+node.text \ +" from the settings.json file to change this.") continue if node.text in settings.SETTINGS["nodes"] and settings.SETTINGS["nodes"][node.text]: node.active = True control.nexus().add_node_rule(NodeRule(node, None, control.nexus().intermediary, False)) _mapping["enable "+node.text]=Function(update, name=node.text, value=True) _mapping["disable "+node.text]=Function(update, name=node.text, value=False) if len(_mapping)>0: grammar = Grammar("NodeActivation") grammar.add_rule(MappingRule(mapping=_mapping, name="NodeActivation")) grammar.load() def unload():
def tick(self): # one time increment passes self.remaining -= 1 self.save_settings() if self.remaining <= 0: winsound.PlaySound(settings.SETTINGS["paths"]["ALARM_SOUND_PATH"], winsound.SND_FILENAME) utilities.report("T: " + str(self.remaining) + " m")
def stop(self): self.active = False self.save_settings() utilities.report("ending dispel") control.nexus().timer.remove_callback(self.tick)