An ultrasimple clipboard application that expects to find a French word on the clipboard and sends it for translation.
Put a shortcut to the script in a Win2K toolbar, or on the desktop if you want to use a keyboard shortcut. Then just highlight the word or phrase to be translated, copy it to the clipboard, then launch the script.
What Objects are Involved
- wxTheClipboard - access to the clipboard
- wxDataFormat - specification of the type of data that must be available on the clipboard
- wxTextDataObject - place to store clipboard contents
- wxMessageDialog - for displaying diagnostics
ShellExecute - for requesting translation
This is the place to list anything such as
- Optional packages that might be required,
- Links to other pages with additional techniques that go well with this one
- Limitations of this technique (such as "Drag and drop only seems to work with other wxPython codes).
- Additional reading on this subject
- Concerns you have about areas of this technique you don't fully understand.
1 import wx 2 from win32api import ShellExecute 3 4 if wx.TheClipboard.Open(): 5 if wx.TheClipboard.IsSupported(wxDataFormat(wxDF_TEXT)): 6 data = wx.TextDataObject() 7 wx.TheClipboard.GetData(data) 8 text = data.GetText().strip() 9 wx.TheClipboard.Close() 10 if not text: 11 wx.MessageDialog(None,"No French word specified") 12 else: 13 wx.MessageDialog(None,"Can't open clipboard") 14 15 ShellExecute(0, None, 'http://wordreference.com/fr/en/translation.asp?fren=%s' % text, None, 'c:/', 0)
Unfortunately depends on the MS Windows API. - email@example.com