MCPcopy
hub / github.com/asweigart/pyperclip / init_klipper_clipboard

Function init_klipper_clipboard

src/pyperclip/__init__.py:238–264  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

236
237
238def init_klipper_clipboard():
239 def copy_klipper(text):
240 text = _PYTHON_STR_TYPE(text) # Converts non-str values to str.
241 p = subprocess.Popen(
242 ['qdbus', 'org.kde.klipper', '/klipper', 'setClipboardContents',
243 text.encode(ENCODING)],
244 stdin=subprocess.PIPE, close_fds=True)
245 p.communicate(input=None)
246
247 def paste_klipper():
248 p = subprocess.Popen(
249 ['qdbus', 'org.kde.klipper', '/klipper', 'getClipboardContents'],
250 stdout=subprocess.PIPE, close_fds=True)
251 stdout, stderr = p.communicate()
252
253 # Workaround for https://bugs.kde.org/show_bug.cgi?id=342874
254 # TODO: https://github.com/asweigart/pyperclip/issues/43
255 clipboardContents = stdout.decode(ENCODING)
256 # even if blank, Klipper will append a newline at the end
257 assert len(clipboardContents) > 0
258 # make sure that newline is there
259 assert clipboardContents.endswith('\n')
260 if clipboardContents.endswith('\n'):
261 clipboardContents = clipboardContents[:-1]
262 return clipboardContents
263
264 return copy_klipper, paste_klipper
265
266
267def init_dev_clipboard_clipboard():

Callers 2

TestKlipperClass · 0.90
determine_clipboardFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…