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

Discussion in 'Python' started by dananrg@yahoo.com, Apr 6, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. Re: Using PythonWin32 to copy text to Windoze Clipboard forUnix-stylerandom .sig rotator?

    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>
     
    Fredrik Lundh, Apr 6, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. F. GEIGER

    [PythonWin32] TLB's for mere mortals?

    F. GEIGER, May 3, 2004, in forum: Python
    Replies:
    0
    Views:
    328
    F. GEIGER
    May 3, 2004
  2. Replies:
    0
    Views:
    281
  3. matchstick86

    sig : process vs. process(sig)

    matchstick86, Oct 12, 2009, in forum: VHDL
    Replies:
    1
    Views:
    574
    power_hf2005
    Oct 13, 2009
  4. Mahsha

    Clipboard - Copy Image To Clipboard

    Mahsha, Jun 1, 2009, in forum: Javascript
    Replies:
    1
    Views:
    627
    Thomas 'PointedEars' Lahn
    Jun 1, 2009
  5. Mahsha

    Clipboard - Copy Text To Clipboard

    Mahsha, Jun 1, 2009, in forum: Javascript
    Replies:
    3
    Views:
    673
    Thomas 'PointedEars' Lahn
    Jun 1, 2009
Loading...

Share This Page