From aadc5305fef4e9ed90a6808cd3b1ab4857b9163b Mon Sep 17 00:00:00 2001 From: Eric Paulson Date: Tue, 6 Sep 2016 01:40:16 -0700 Subject: [PATCH] add optional target specifiers to BringApp --- dragonfly/actions/action_startapp.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/dragonfly/actions/action_startapp.py b/dragonfly/actions/action_startapp.py index 12e22e5..ad7c23c 100644 --- a/dragonfly/actions/action_startapp.py +++ b/dragonfly/actions/action_startapp.py @@ -38,7 +38,7 @@ BringApp(r"C:\Windows\system32\\notepad.exe").execute() -Note that the path to *notepad.exe* given above might not be correct for +.Note that the path to *notepad.exe* given above might not be correct for your computer, since it depends on the operating system and its configuration. @@ -122,8 +122,10 @@ class BringApp(StartApp): foreground. On the other hand, if no window is found the application is started. - Note that the constructor arguments are identical to those used by - the :class:`StartApp` action class. + In addition to the constructor arguments used by the + :class:`StartApp` action class, it also accepts arguments + specifying an alternate executable and title text to use + when selecting a window to bring to the foreground. """ @@ -136,14 +138,27 @@ def __init__(self, *args, **kwargs): - *cwd* (*str*, default *None*) -- if not *None*, then start the application in this directory + - *target* (*str*, defaults to :class:StartApp` target) -- + if specified, use this as the executable target of + :class:`FocusWindow` + - *title* (*str*, default *None*) -- + if not *None*, use this as the title target of + :class:`FocusWindow` """ + self._target = args[0].lower() + self._title = None + + if "target" in kwargs: + self._target = kwargs.pop("target") + if "title" in kwargs: + self._title = kwargs.pop("title") + StartApp.__init__(self, *args, **kwargs) def _execute(self, data=None): self._log.debug("Bringing app: %r" % (self._args,)) - target = self._args[0].lower() - focus_action = FocusWindow(executable=target) + focus_action = FocusWindow(executable=self._target,title=self._title) # Attempt to focus on an existing window. if not focus_action.execute(): # Failed to focus on an existing window, so start