def get_window_by_title(title=None): # returns 0 if nothing found Matches = Window.get_matching_windows(title=title) if Matches: return Matches[0].handle else: return 0
def focus_mousegrid(gridtitle): ''' Loops over active windows for MouseGrid window titles. Issue #171 When MouseGrid window titles found focuses MouseGrid overly. ''' if sys.platform.startswith('win'): # May not be needed for Linux/Mac OS - testing required try: for i in range(9): matches = Window.get_matching_windows(title=gridtitle, executable="python") if not matches: Pause("50").execute() else: break if matches: for handle in matches: handle.set_foreground() break else: printer.out( "`Title: `{}` no matching windows found".format(gridtitle)) except Exception as e: printer.out("Error focusing MouseGrid: {}".format(e)) else: pass
def disconnect(self): """ Disconnect from natlink. """ # Unload all grammars from the engine so that Dragon doesn't keep # recognizing them. for grammar in self.grammars: grammar.unload() # Close the the waitForSpeech() dialog box if it is active. from dragonfly import Window target_title = "Natlink / Python Subsystem" for window in Window.get_matching_windows(title=target_title): if window.is_visible: try: window.close() except pywintypes.error: pass break # Stop the special timer thread if it is running. if self._timer_thread: self._timer_thread.stop() self._timer_thread = None # Finally disconnect from natlink. self.natlink.natDisconnect()
def _process_recognition(self, node, extras): # Find a notepad window, set it as the target window and move it. # Display a warning if no notepad window was found. notepad_windows = Window.get_matching_windows(executable="notepad", title="notepad") if not notepad_windows: print("Could not find a notepad window to move.") return self.window_movement.target_window = notepad_windows[0] self.move_target_window(extras)
def window_exists(windowname=None, executable=None): if Window.get_matching_windows(title=windowname, executable=executable): return True else: return False