I have been experimenting with the python-dcop bindings for use with KDE. I created some simple scripts that let me pipe textual data to an from the KDE clipboard (klipper).
klipin shell script
Code:
#!/bin/bash
##################################################
# A simple shell script that works in conjunction with
# the KDE DCOP server to let you pipe text to the
# klipboard.
#
# example:
#
# $cat file | klipin
#
##################################################
dcop klipper klipper setClipboardContents "$(cat)"
klipout shell script
Code:
#!/usr/bin/python
#########################################################
# A simple python script that allows you to redirect the
# klipboard contents as though it were standard output.
#
# examples:
#
# klipout | grep xyzzy
# klipout > out.txt
#
#########################################################
# NOTE: Originally, I wrote this as a one-line shell
# script:
#
# dcop klipper klipper getClipboardContents
#
# , but the QString return value was coming back without
# embedded newlines, so piping the result to grep and
# such was pretty much useless. This python version of
# the script is almost as simple, but it does require
# that the python-dcop package is installed.
#
#########################################################
import pydcop
if __name__ == "__main__":
klipper = pydcop.DCOPObject("klipper", "klipper")
print klipper.getClipboardContents()
I am having problems sending binary data to the klipboard using this, technique, though. I tried the following:
Code:
>>> import pydcop
>>> klipper = pydcop.DCOPObject("klipper", "klipper")
>>> f = file("smile.png", "rb")
>>> data = f.read()
>>> f.close()
>>> klipper.setClipboardContents(data)
However, when I view the clipboard contents, it appears to have only a few bytes (up to the first zero-byte, I think) and displays the contents as textual data rather than an image.
Does anyone have any idea what might be going on here? I have tried searching for documentation on python-dcop but haven't been having much success with the results. Any links, etc. would be appreciated.
Thanks.