Closed kendonB closed 4 years ago
This was on Ubuntu 20.04 with the latest pip dragonfly and python3
Thanks for opening this issue. This is not really a bug with ContextAction
, but with your default
argument. I'm guessing this is what you wanted to do:
from dragonfly import ContextAction, BringApp, AppContext, Key, Text, Pause, Function
def bring_and_pause(app):
BringApp("firefox").execute()
Pause("300").execute()
ContextAction(default=Function(lambda: bring_and_pause("firefox")), actions=[
(AppContext("firefox"), Key("c-l") + Text("Hello!"))
]).execute()
So, bring_and_pause()
had already run before your ContextAction
had been initialised. You could also do something like this instead, with the same ContextAction
part:
def bring_and_pause(app):
return BringApp(app) + Pause("300")
This should be much clearer in any case. I will add some type checking into ContextAction
so that it rejects "actions" that do not inherit from the ActionBase
class. That way you will get an error running your original code when bring_and_pause()
returns None
:-)
awesome! thanks so much
Agree that a useful error message would be best for this case.
No worries. I will add some type checking code soon and release the changes in the next version.
example.py
Then run
python example.py