Skip to content

Instantly share code, notes, and snippets.

@alexboche
Last active February 25, 2019 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexboche/5f62080c6be94038bcf12d00e08c1241 to your computer and use it in GitHub Desktop.
Save alexboche/5f62080c6be94038bcf12d00e08c1241 to your computer and use it in GitHub Desktop.
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