diff --git a/core/modes/modes.py b/core/modes/modes.py index 33625f2013..b141a36854 100644 --- a/core/modes/modes.py +++ b/core/modes/modes.py @@ -1,6 +1,8 @@ -from talon import Module, actions, app, speech_system +from talon import Context, Module, actions, app, speech_system mod = Module() +ctx_sleep = Context() +ctx_awake = Context() modes = { "admin": "enable extra administration commands terminal (docker, etc)", @@ -12,6 +14,26 @@ for key, value in modes.items(): mod.mode(key, value) +ctx_sleep.matches = r""" +mode: sleep +""" + +ctx_awake.matches = r""" +not mode: sleep +""" + + +@ctx_sleep.action_class("speech") +class ActionsSleepMode: + def disable(): + actions.app.notify("Talon is already asleep") + + +@ctx_awake.action_class("speech") +class ActionsAwakeMode: + def enable(): + actions.app.notify("Talon is already awake") + @mod.action_class class Actions: diff --git a/core/modes/to_sleep_mode.talon b/core/modes/modes_dragon.talon similarity index 91% rename from core/modes/to_sleep_mode.talon rename to core/modes/modes_dragon.talon index 8fbfcf4b08..c05a518108 100644 --- a/core/modes/to_sleep_mode.talon +++ b/core/modes/modes_dragon.talon @@ -1,7 +1,7 @@ -mode: command -mode: dictation +mode: sleep +not mode: sleep +speech.engine: dragon - - # The optional afterwards allows these to match even if you say arbitrary text # after this command, without having to wait for the speech timeout. @@ -13,6 +13,8 @@ mode: dictation # sleep and ignore "hey bob". Note that subtitles will show "sleep all hey bob", # because it's part of the rule definition, but "hey bob" will be ignored, because # we don't do anything with the in the body of the command. +^talon sleep []$: speech.disable() +^talon wake []$: speech.enable() ^sleep all []$: user.switcher_hide_running() @@ -22,5 +24,3 @@ mode: dictation user.mouse_sleep() speech.disable() user.engine_sleep() - -^talon sleep []$: speech.disable() diff --git a/core/modes/modes_not_dragon.talon b/core/modes/modes_not_dragon.talon new file mode 100644 index 0000000000..c7a6c0604d --- /dev/null +++ b/core/modes/modes_not_dragon.talon @@ -0,0 +1,41 @@ +mode: sleep +not mode: sleep +not speech.engine: dragon +- +# The optional afterwards allows these to match even if you say arbitrary text +# after this command, without having to wait for the speech timeout. + +# This is handy because you often need to put Talon asleep in order to immediately +# talk to humans, and it's annoying to have to say "sleep all", wait for the timeout, +# and then resume your conversation. + +# With this, you can say "sleep all hey bob" and Talon will immediately go to +# sleep and ignore "hey bob". Note that subtitles will show "sleep all hey bob", +# because it's part of the rule definition, but "hey bob" will be ignored, because +# we don't do anything with the in the body of the command. + +^talon wake []$: speech.enable() + +# We define this *only* if the speech engine isn't Dragon, because if you're using Dragon, +# "wake up" is used to specifically control Dragon, and not affect Talon. +# +# It's a useful and well known command, though, so if you're using any other speech +# engine, this controls Talon. +^(wake up)+$: speech.enable() + +# We define this *only* if the speech engine isn't Dragon, because if you're using Dragon, +# "go to sleep" is used to specifically control Dragon, and not affect Talon. +# +# It's a useful and well known command, though, so if you're using any other speech +# engine, this controls Talon. +^go to sleep []$: speech.disable() +^talon sleep []$: speech.disable() + +^sleep all []$: + user.switcher_hide_running() + user.history_disable() + user.homophones_hide() + user.help_hide() + user.mouse_sleep() + speech.disable() + user.engine_sleep() diff --git a/core/modes/sleep_mode.talon b/core/modes/sleep_mode.talon index 695ba1fd5f..64a879cea3 100644 --- a/core/modes/sleep_mode.talon +++ b/core/modes/sleep_mode.talon @@ -34,5 +34,3 @@ settings(): user.mouse_wake() user.history_enable() user.talon_mode() - -^(talon wake)+$: speech.enable() diff --git a/core/modes/sleep_mode_not_dragon.talon b/core/modes/sleep_mode_not_dragon.talon deleted file mode 100644 index a4b305c975..0000000000 --- a/core/modes/sleep_mode_not_dragon.talon +++ /dev/null @@ -1,9 +0,0 @@ -mode: sleep -not speech.engine: dragon -- -# We define this *only* if the speech engine isn't Dragon, because if you're using Dragon, -# "wake up" is used to specifically control Dragon, and not affect Talon. -# -# It's a useful and well known command, though, so if you're using any other speech -# engine, this controls Talon. -^(wake up)+$: speech.enable() diff --git a/core/modes/to_sleep_mode_not_dragon.talon b/core/modes/to_sleep_mode_not_dragon.talon deleted file mode 100644 index a412853e92..0000000000 --- a/core/modes/to_sleep_mode_not_dragon.talon +++ /dev/null @@ -1,12 +0,0 @@ -mode: command -mode: dictation -not speech.engine: dragon -- -# We define this *only* if the speech engine isn't Dragon, because if you're using Dragon, -# "go to sleep" is used to specifically control Dragon, and not affect Talon. -# -# It's a useful and well known command, though, so if you're using any other speech -# engine, this controls Talon. -# -# For a note about the optional , see to_sleep_mode.talon. -^go to sleep []$: speech.disable()