[Tutor] Clipboard manager for windows

2006-09-14 Thread János Juhász

Hi Derick,

>So I need a way to hijaak the Ctrl-C and Ctrl-V
shortcuts and have my
>application run in the system tray. I don't need
a gui other than changing
>the context menu (which I believe is done in the
registry) - although, I'd
>probably need to use wxPython for using the system
tray - unless by catching
>the shortcut keys, I can call the program...

I have tested it without hijaak the Ctrl-C and Ctrl-V
It is seem to be easier to set up a shortcut to in-place
filtering
on the current content of the clipboard.

I just have played with the sample you showed:


### text.py My small clipboard coverter ###
import win32clipboard as w 
import win32con
import re

def getText(): 
    w.OpenClipboard() 
    d=w.GetClipboardData(win32con.CF_TEXT)

    w.CloseClipboard() 
    return d 
 
def setText(aType,aString): 
    w.OpenClipboard()
    w.EmptyClipboard()
    w.SetClipboardData(aType,aString) 
    w.CloseClipboard()

def myFilter(text):
    comma = re.compile(',')
    return comma.sub('\t', text)

def myTester(text):
    ### context sensitivity
    return ',' in text
    
text = getText()
if myTester(text):
    setText(win32con.CF_TEXT, myFilter(text))
### My small clipboard coverter ###

I have saved this python script into my devel folder,
created a shortcut on the windows desktop,
set up a shortcut key for it with Ctrl-Alt-T.
When I start this program with the shortcut key, it
simple makes 
the replace in-place on the current content of the
clipboard, 
that can be put into excel after it.

Copy this to the clipboard:
a,b,c,d,e
1,2,3,4,5
run the script
Paste the clipboard to excel
Viola :)

You can make it with wxPython and give the choice
for the
user on the visual surface to choose from more filters.

It also could be interesting, to
make the tab delimited clipboard content from the filenames.
>>> w.OpenClipboard()
>>> w.GetClipboardData(win32con.CF_HDROP)
(u'D:\\devel\\tutor\\data.txt',)
>>> w.CloseClipboard()




Yours sincerely, 
__
János Juhász 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Clipboard manager for windows

2006-09-14 Thread Derick Van Niekerk
Hey,I came accross this explanation of how the windows clipboard can be handled with Python:http://www.bigbold.com/snippets/posts/show/724I want to write myself a simple text filter for pasting csv into excel, pasting syntax highlighted code as html and custom formatting text with regular expressions before pasting it. There are free programs that come close to what I need but the filters aren't as customizable as I'd like - allthough they are more complicated than I need. Take a look at 
http://www.clipmagic.com/ and http://www.snapfiles.com/get/clippy.htmlClippy is the closest to what I need.So I need a way to hijaak the Ctrl-C and Ctrl-V shortcuts and have my application run in the system tray. I don't need a gui other than changing the context menu (which I believe is done in the registry) - although, I'd probably need to use wxPython for using the system tray - unless by catching the shortcut keys, I can call the program...
Any ideas? Anybody ever done something like this?-d-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor