Dynamic copy/paste using DDE with Python on Windows

Anders M Eriksson anders.eriksson at morateknikutveckling.se
Wed Oct 16 06:20:53 EDT 2002


On Mon, 14 Oct 2002 11:48:57 +0200, Eric Brunel
<eric.brunel at pragmadev.com> wrote:

>Hi all,
>
>We'd like to add to a Windows application the possibility to make dynamic 
>copy/paste: the user selects something in the application, pastes it 
>elsewhere (e.g. Word...), and whenever the source is modified, the changes 
>are automatically forwarded to the copy.
>
>AFAIK, the way to do that on Windows is DDE. But I can't find anywhere a 
>simple sample code showing how to do that.
>
Hmmm... AFAIK is Windows using the clipboard for sharing text, images,
etc. with other programs using Cut/Copy/Paste

The following are typical Clipboard features in Windows Applications: 
Cut: Moves the selected data from the source to the Clipboard. The
data is removed from the source. Any data resident on the Clipboard is
replaced by the new data. The typical shortcut key is: Ctrl+X. 

Copy: Copies the selected data from the source to the Clipboard. The
data isn’t removed from the source. Any data resident on the Clipboard
is replaced by the new data. The typical shortcut key is: Ctrl+C. 

Paste: Moves the data from the Clipboard to the destination. The data
isn’t removed from the Clipboard and can be pasted to another
destination. The typical shortcut key is: Ctrl+V.


>To understand exactly what's going on in DDE, I'd like to do something 
>really simple, for example having a single text file available via a DDE 
>server: I would run the server, paste the text file as a DDE object in Word 
>for example, and then everytime the text file changes, I want the changes 
>forwarded to Word automatically. So no need for fancy GUI, or whatever: 
>just a plain simple command line DDE server and nothing else.
>

In win32extension of Python you have a module dde that lets you handle
dde both as a server and as a client. There are very little
documentation but since dde is a windows api you can use MSDN for
documentation. 

If I understand you correctly you want to create a DDE server that can
distribute text documents via the clipboard.

You will then need to create a server 'myServer', that has a topic
'copy' and then execute this topic from a dde client. meServer will
then read the document and put it on the ClipBoard and you can now use
paste in Word to insert the document into your Word document.

You will of cause need to create a Word VBA script that is the dde
client and calls meServer for the document.

If I get some free time during the weekend I could try to create such
a sample ...

Hope that this will help you in some way

// Anders
-- 
English isn't my first or second language, 
so errors or anything that you find offending is not there on 
purpose it's just due to the translation.



More information about the Python-list mailing list