469,635 Members | 2,083 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,635 developers. It's quick & easy.

Using PythonWin32 to copy text to Windoze Clipboard for Unix-style random .sig rotator?

Can you tell I miss Unix?

I want to write a Python script that, when launched, will choose a
random .sig (from a list of about 30 cool ones I've devised), and store
the .sig text in the Windows Clipboard, so I can then paste it into any
Windows application.

This way, it'll work for Outlook e-mails, Yahoo, Gmail, etc.

Also, could I use Python to programmatically set key combos to do
certain things?

Should I buy the Python on Win32 book? Are all my answers there? Or is
there a good PyWin32 FAQ where all (that I'm interested in with this
particular e-mail) will be revealed?

Spammity-spam, y'all.

Thanks.

Dana

Apr 6 '06 #1
1 1673
da*****@yahoo.com wrote:
Can you tell I miss Unix?
by your early-nineties spelling of Windows ?
I want to write a Python script that, when launched, will choose a
random .sig (from a list of about 30 cool ones I've devised), and store
the .sig text in the Windows Clipboard, so I can then paste it into any
Windows application.


since most Python distributions comes with Tkinter, you can use Tkinter's
clipboard interface. unfortunately (at least for this use case), Tkinter re-
moves things it has added to the clipboard when the program terminates,
so you have to make sure that the program is still running when you need
the text.

here's a fortune generator that keeps posting important stuff to the clip-
board at random intervals:

import Tkinter
import random, time

# get some phrases
import StringIO, sys
stdout = sys.stdout
try:
sys.stdout = StringIO.StringIO()
import this
FORTUNES = sys.stdout.getvalue().split("\n")[2:]
finally:
sys.stdout = stdout

# create an invisible (well, not really) window
root = Tkinter.Tk()
root.withdraw()

def refresh():
fortune = random.choice(FORTUNES)
root.clipboard_clear()
root.clipboard_append(fortune)
root.after(random.randint(100, 1000), refresh)

refresh()

root.mainloop()

(since this will make it impossible to use the clipboard for anything else, you
might wish to use a button instead of a timer to update the clipboard...)

</F>

Apr 6 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Risto Heinonen | last post: by
7 posts views Thread by rihad | last post: by
2 posts views Thread by Hariharan Subramony | last post: by
6 posts views Thread by XmlAdoNewbie | last post: by
3 posts views Thread by Tor Inge Rislaa | last post: by
2 posts views Thread by Keith | last post: by
3 posts views Thread by SAL | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.