LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-22-2005, 03:02 PM   #1
carl.waldbieser
Member
 
Registered: Jun 2005
Location: Pennsylvania
Distribution: Kubuntu
Posts: 197

Rep: Reputation: 32
Python DCOP (KDE) and binary data


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.

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert a float to its binary or hex representation in Python? zero79 Programming 1 09-01-2005 10:19 AM
How to convert a float to its binary or hex representation in Python? zero79 Linux - Software 1 08-29-2005 09:30 PM
manipulate dcop data for File commandS? carl0ski Programming 2 07-02-2005 08:46 PM
Python and binary files The_Nerd Programming 2 08-27-2004 02:48 PM
kde startup DCOP error Ideas ?? bzflag_f+ Linux - Newbie 1 06-20-2004 01:38 AM


All times are GMT -5. The time now is 04:04 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration