Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Clipboard read\write retry attempts on failure #665

Merged
merged 1 commit into from
Aug 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 42 additions & 29 deletions castervoice/lib/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dragonfly import AppContext, Pause

from castervoice.lib import utilities, settings
from castervoice.lib.actions import Key
from castervoice.lib.actions import Key
from castervoice.lib.clipboard import Clipboard

# Override dragonfly.AppContext with aenea.ProxyAppContext if the 'use_aenea'
Expand Down Expand Up @@ -110,27 +110,33 @@ def read_selected_without_altering_clipboard(same_is_okay=False, pause_time="0")
(1, None) - indicates no change
(2, None) - indicates clipboard error
'''

time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/
1000.) # time for previous keypress to execute
cb = Clipboard(from_system=True)
temporary = None
prior_content = None
try:

prior_content = Clipboard.get_system_text()
Clipboard.set_system_text("")

Key("c-c").execute()
Pause(pause_time).execute()
time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/
1000.) # time for keypress to execute
temporary = Clipboard.get_system_text()
cb.copy_to_system()

except Exception:
utilities.simple_log(False)
return 2, None
max_tries = 20

for i in range(0, max_tries):
failure = False
try:
prior_content = Clipboard.get_system_text()
Clipboard.set_system_text("")
Key("c-c").execute()
Pause(pause_time).execute()
time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/
1000.) # time for keypress to execute
temporary = Clipboard.get_system_text()
cb.copy_to_system()
except Exception:
print("Clipboard Read Attempts " + str(i)) # Debugging
failure = True
utilities.simple_log(False)
if i is max_tries:
return 2, None
if not failure:
break
if prior_content == temporary and not same_is_okay:
return 1, None
return 0, temporary
Expand All @@ -144,18 +150,25 @@ def paste_string_without_altering_clipboard(content, pause_time="1"):
time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/
1000.) # time for previous keypress to execute
cb = Clipboard(from_system=True)

try:
Clipboard.set_system_text(unicode(content))
Pause(pause_time).execute()
Key("c-v").execute()
time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/
1000.) # time for keypress to execute
cb.copy_to_system()

except Exception:
utilities.simple_log(False)
return False
max_tries = 20

for i in range(0, max_tries):
failure = False
try:
Clipboard.set_system_text(unicode(content))
Pause(pause_time).execute()
Key("c-v").execute()
time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/
1000.) # time for keypress to execute
cb.copy_to_system()
except Exception:
print("Clipboard Write Attempts " + str(i)) # Debugging
failure = True
utilities.simple_log(False)
if i is max_tries:
return False
if not failure:
break
return True


Expand Down