-
Notifications
You must be signed in to change notification settings - Fork 121
/
clipboard.py
56 lines (48 loc) · 2.04 KB
/
clipboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from castervoice.lib import settings, printer
Clipboard = None
try:
from dragonfly import Clipboard as DragonflyClipboard
# Use DragonflyClipboard as Clipboard.
Clipboard = DragonflyClipboard
except:
printer.out("dragonfly.Clipboard failed to import.")
def _is_aenea_available():
try:
import aenea
return True
except ImportError:
print("Unable to import aenea, dragonfly.Clipboard will be used "
"instead.")
return False
# Use a subclass of dragonfly's clipboard class instead if the 'use_aenea'
# setting is set to true. This will allow commands like 'stoosh' to work
# properly server-side if the RPC functions are available.
if settings.settings(["miscellaneous", "use_aenea"]) and _is_aenea_available():
# pylint: disable=import-error
import aenea
from jsonrpclib import ProtocolError
class Clipboard(DragonflyClipboard): # pylint: disable=function-redefined
@classmethod
def get_system_text(cls):
# Get the server's clipboard content if possible and update this
# system's clipboard.
try:
server_text = aenea.communications.server.paste()
DragonflyClipboard.set_system_text(server_text)
return server_text
except ProtocolError as e:
print("ProtocolError caught when calling server.paste(): %s"
% e)
print("Only getting local clipboard content.")
return DragonflyClipboard.get_system_text()
@classmethod
def set_system_text(cls, content):
# Set the server's clipboard content if possible.
try:
aenea.communications.server.copy(content)
except ProtocolError as e:
print("ProtocolError caught when calling server.copy(): %s"
% e)
print("Only setting local clipboard content.")
# Set this system's clipboard content.
DragonflyClipboard.set_system_text(content)