def paste_command(): # Add Command Prompt, putty, ...? context = AppContext(executable="console") window = Window.get_foreground() if context.matches(window.executable, window.title, window.handle): return release.execute() Key("c-v/3").execute()
def matches(self, executable, title, handle): if AppContext.matches(self, executable, title, handle): return True # Only check Linux if it is active. if title.find("Oracle VM VirtualBox") != -1 or title.find(" - Chrome Remote Desktop") != -1: remote_title = linux_helper.GetActiveWindowTitle().lower() found = remote_title.find(self._title) != -1 if self._exclude != found: return True return False
def matches(self, executable, title, handle): if AppContext.matches(self, executable, title, handle): return True # Only check Linux if it is active. if title.find("Oracle VM VirtualBox") != -1 or title.find( "<remotedesktop.corp.google.com>") != -1: remote_title = linux_helper.GetActiveWindowTitle().lower() found = any( remote_title.find(match) != -1 for match in self._title) if self._exclude != found: return True return False
class ModeManager(): def __init__(self): self.mode = "normal" self.frequency = 5 self.command_titles = ["sublime", "jupyter", "rstudio", "mingw64", "lyx", "scientific notebook"] self.command_executables = ["code.exe", "kindle.exe"] self.command_contexts = AppContext(title=self.command_titles) | AppContext(self.command_executables) self.timer = get_engine().create_timer(self.check_context, self.frequency) def switch_mode(self, mode="command"): Playback([([mode, "mode", "on"], 0.0)]).execute() self.mode = mode def check_context(self): if natlink.getMicState() == "on": w = Window.get_foreground() should_be_command = self.command_contexts.matches(w.executable, w.title, w.handle) if should_be_command and self.mode == "normal": self.switch_mode("command") elif not should_be_command and self.mode == "command": self.switch_mode("normal") else: pass
class ChromeURLContext(Context): def __init__(self, match=None): Context.__init__(self) self.chrome_context = AppContext("chrome") if isinstance(match, string_types): self._matches = [match.lower()] elif isinstance(match, (list, tuple)): self._matches = [m.lower() for m in match] elif match is None: self._matches = None else: raise TypeError("match argument must be a string or None;" " received %r" % match) def matches(self, executable, title, handle): if not self.chrome_context.matches(executable, title, handle): return False current_url = utilities.chrome_get_url() for match in self._matches: if match not in current_url: return False else: return True