def _execute(self, data=None):
        executable = self.executable
        title = self.title
        index = self.index
        if data and isinstance(data, dict):
            if executable: executable = (executable % data).lower()
            if title: title = (title % data).lower()
            if index: index = (index % data).lower()

        index = int(index) if index else 0

        # Get the first matching window and bring it to the foreground.
        windows = Window.get_matching_windows(executable, title)
        if self.filter_func:
            windows = [
                window for window in windows if self.filter_func(window)
            ]
        if windows and (index < len(windows)):
            window = windows[index]
            if self.focus_only:
                window.set_focus()
            else:
                window.set_foreground()
        else:
            raise ActionError("Failed to find window (%s)." % self._str)
Esempio n. 2
0
 def emit(self, record):
     # Brings status window to the forefront upon error
     if (settings.SETTINGS["miscellaneous"]["status_window_foreground_on_error"]):
          # The window title is unique to Natlink
         if (get_engine()._name == 'natlink'):
             windows = Window.get_matching_windows(None, "Messages from Python Macros V")
         if windows:
             windows[0].set_foreground()
Esempio n. 3
0
def show_window():
    title = None
    if get_engine()._name == 'natlink':
        import natlinkstatus  # pylint: disable=import-error
        status = natlinkstatus.NatlinkStatus()
        if status.NatlinkIsEnabled() == 1:
            if six.PY2:
                title = "Messages from Python Macros"
            else:
                title = "Messages from Natlink"
        else:
            title = "Caster: Status Window"
    if get_engine()._name != 'natlink':
        title = "Caster: Status Window"
    windows = Window.get_matching_windows(title=title)
    if windows:
        windows[0].set_foreground()
Esempio n. 4
0
    def _focus_window_after_starting(self, pid):
        timeout = 1.0
        exe = self._args[0]

        # Wait for the window to appear for N seconds.
        action = WaitWindow(executable=exe, timeout=timeout)
        if action.execute():
            # Bring the window to the foreground.
            Window.get_foreground().set_foreground()

        # The application window wasn't focused, so try to focus it.
        else:
            target = pid
            start = time.time()
            while time.time() - start < timeout:
                found = False
                for window in Window.get_matching_windows(exe):
                    if target is None or window.pid == target:
                        window.set_foreground()
                        found = True
                        break
                if found:
                    break
Esempio n. 5
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