dictation-toolbox / dragonfly

Speech recognition framework allowing powerful Python-based scripting and extension of Dragon NaturallySpeaking (DNS), Windows Speech Recognition (WSR), Kaldi and CMU Pocket Sphinx
GNU Lesser General Public License v3.0
388 stars 75 forks source link

Raise a timeout exception under clipboard context manager #390

Closed gkuegler closed 2 months ago

gkuegler commented 3 months ago

Currently, when using the context manager, there's no indication if the clipboard timed out when waiting for a change.

This change makes it so I could write the following and be (mostly) certain my text made it to the clipboard:

with clipboard.synchronized_changes(timeout=2, raise_exception_on_timeout=True):
    Key("c-c").execute()

This makes it simple to write rules that rely on getting the user's highlighted text and subsequently stop the action if not text was captured.

drmfinlay commented 3 months ago

Hello @gkuegler,

Thank you for opening this pull request.

You're right, it does make sense to inform the caller somehow if the clipboard wasn't changed. The name of this method implies that synchronising clipboard changes is ensured. If changes are not synchronised, my opinion is that an exception should always occur.

On Fri, 16 Aug 2024 14:26:01 -0700 George Kuegler @.***> wrote:

Currently, when using the context manager, there's no indication if the clipboard timed out when waiting for a change.

This change makes it so I could write the following and be (mostly) certain my text made it to the clipboard:

with clipboard.synchronized_changes(timeout=2, raise_exception_on_timeout=True):
    Key("c-c").execute()

This makes it simple to write rules that rely on getting the user's highlighted text and subsequently stop the action if not text was captured. You can view, comment on, or merge this pull request online at:

https://github.com/dictation-toolbox/dragonfly/pull/390

-- Commit Summary --

  • Optionally raise a timeout exception when waiting for the clipboard to change times out under context manager.

-- File Changes --

M dragonfly/windows/win32_clipboard.py (7)

-- Patch Links --

https://github.com/dictation-toolbox/dragonfly/pull/390.patch https://github.com/dictation-toolbox/dragonfly/pull/390.diff

-- Reply to this email directly or view it on GitHub: https://github.com/dictation-toolbox/dragonfly/pull/390 You are receiving this because you are subscribed to this thread.

Message ID: @.***>

drmfinlay commented 2 months ago

I'll publish this change in version 0.36.0. Thanks again.

gkuegler commented 2 months ago

Thanks! Did you want me to change the default behavior to throw an exception?

drmfinlay commented 2 months ago

There's no need. I changed that prior to merging. All done. :+1: