[Tutor] clipboard questions

Che M pine508 at hotmail.com
Mon Jan 26 19:23:00 CET 2009

> To: tutor at python.org
> From: alan.gauld at btinternet.com
> Date: Mon, 26 Jan 2009 10:13:15 +0000
> Subject: Re: [Tutor] clipboard questions
> "Che M"  wrote
>> I'm curious about how to interact with the contents of the clipboard
>> effectively and have a couple of questions...
>> 1) Is there one cross-platform way to read the clipboard,
> In a generic sense no. But if the cut n paste is within a single
> application then yes, you can use a cross platform GUI framework.
> That will work across OS versions. Where it gets messy is if you
> want to paste from the generic OS clipboard into your application
> and different frameworks vary in how well they handle that.

Ahh, yes, that's a problem, because I am interested in using the
clipboard for cross-application cut/copy/paste, in fact from/to my
apps to any apps on any platform.  (One to all; all to one).  

>> 2) I would like to be able to copy formatting (bold, italics,
>> bullets,
>> hyperlinks, etc.) into the clipboard and then have Python have
>> access
>> to the text content and its formatting
> Thats even more tricky because not all clipboards will capture
> formatting codes in their original form. Some require special
> commands/events. It may also depend on the application that
> you are copying from. For example consider a MacOS web
> browser. Do you want to copy the underlying HTML formatting
> tags? Or the display PDF codes which are used by the Aqua
> graphics system used by the browser to actually display the
> output?

I would like to copy whatever makes the most sense for that 
context, similarly to how Word can accept a lot of different
formatting one could copy from, say, the web, and have it show
up in a similar way in the document.  Bold, italics, colors,
underline, paragraph breaks, bullets, fonts, font-size, alignment,
etc., such that it looks the same in both windows.  Ideally,
images, too.

>> In other words your display mechanism will need to be able
> to display whatever the clipboard passes. And your applucatin
> will need to be able to extract the data from it (eg parse PDF
> or RTF etc)

Right.  OK.

> Cut n paste between apps is non trivial even on a single OS
> and within a single framework. But if you have mixed environments
> it can get really messy in my experience! If it's all within a single
> framework then its not so bad.

I thought that was probably the reality, and I find that too bad.
Easy inter-app communication is a great thing, and I can't help but 
wish there was some built-in module in Python to help with this (I know,
I know, I'm being greedy, there are already so many great modules!)
in this most complete way that I am hoping for.  There is, e.g., a
very nice rich text control in wxPython, but for a few years now it
has been bereft of rich text input/output, including cut/copy/paste
or open/save, and so it sort of isolates the widget from inter-use 
with Word or OpenOffice.org, AbiWord, etc., though it can save as 
HTML.  I don't know C++, so I feel I cannot be helpful on adding 
this (wanted) functionality to the wxWidget itself, but was wondering if, while
the actual widget was still waiting for that enhancement (which
may or may not ever come, it depends on if someone takes it on), I 
could maybe take a misguided scratch at making some kind of pure 
Python go-between that could read out the clipboard and paste it 
into the richtextctrl and tell the control how to handle the formatting, 
and then vice-versa.  

Maybe there is a way to start to do this with HTML at least; 
Phillip Piper made this code for that purpose, here:


Although I don't understand this statement by him, "It would be nice 
to have this as a data object in wxPython, but that
doesn't support 
the necessary clipboard system calls
(RegisterClipboardFormat is 
essential)."  What does he mean by necessary clipboard system calls?
Note, this will not of course copy Word formatting codes, so there is
no Word --> Python pasting, though he claims there is Python --> Word
pasting (of HTML I guess).

All this makes me think this is probably beyond what I can reasonably
accomplish at this point in my understanding.  

Thanks for the insight.

> Alan G
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

Windows Live™: E-mail. Chat. Share. Get more ways to connect. 

More information about the Tutor mailing list