Last active
February 25, 2019 07:21
-
-
Save alexboche/5f62080c6be94038bcf12d00e08c1241 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dragonfly import (Grammar, AppContext, Dictation, Key, Text, Repeat, Choice, Function, ActionBase, ActionError) | |
class MultiAppContext(AppContext): | |
# ---------------------------------------------------------------------- | |
# Initialization methods. | |
def __init__(self, relevant_apps=None, title=None, exclude=False): | |
AppContext.__init__(self) | |
if relevant_apps is None: | |
self._relevant_apps = None | |
else: | |
self._relevant_apps = set(relevant_apps) | |
self._title = title | |
self._exclude = bool(exclude) | |
self._str = "%s, %s, %s" % (self._relevant_apps, self._title, | |
self._exclude) | |
# ---------------------------------------------------------------------- | |
# Matching methods. | |
def matches(self, executable, title, handle): | |
executable = executable.lower() | |
if not self._relevant_apps: | |
# If no apps are relevant, then all apps will match. | |
if self._log_match: | |
self._log_match.debug("%s: Match." % self) | |
return True | |
for app in self._relevant_apps: | |
if app.lower() in executable: | |
if self._log_match: | |
self._log_match.debug("%s: Match." % self) | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment