()
| 236 | |
| 237 | |
| 238 | def 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 | |
| 267 | def init_dev_clipboard_clipboard(): |
no outgoing calls
no test coverage detected
searching dependent graphs…