Archive for December, 2006
My wxPython 2.7.x Upgrade From 2.6.x
I’m not sure exactly why I did it. I decided to install wxPython 2.7.x on my WinXP development environment. Several things to note about the changes:
- py2exe will start throwing errors (although the latest and greatest is supposed to fix it) about gdiplus.dll not being found. The solution is to use the
--dll-exclude gdiplus.dlloption to prevent getting the error message. This also means that you need to make sure that the Win2K machines that you deploy to already have the Win2K gdiplus.dll already installed or that you distribute an appropriate version with your code. I’m still needing to test this out. - I had a text control (a search field) for which I was looking for the ENTER key (via Bind on wx.EVT_KeyUp) so that I could launch an action immediately when the user pressed enter (after filling the search field). In wxPython 2.7, the behavior (at least in windows) is to now advance to the next field (like a TAB key was pressed) on using the ENTER key in a single line text control. The solution is fairly simple: just include
style=wx.TE_PROCESS_ENTERin your init parameters for the text control and the control can start getting the ENTER keys again. - I also had registered the ESCAPE key as a hot key for a button (a cancel button) on a form. In 2.6.x, it worked fine. In 2.7.x, the escape key seems to be unavailable as a hot key for a control. Instead, I registered a handler for a CHAR_HOOK event for the whole form and look for the escape there. This has the disadvantage that you sometimes can get several events for the same key press. But at least you can get it. The code in the __init for the form looks something like this:
self.Bind(wx.EVT_CHAR_HOOK,self._onKey)
Then later on, we define self._onKey something like this:
def _onKey(self,evt): if evt.GetKeyCode() in [wx.WXK_ESCAPE]: self.handler.handleCancelButton(evt) else: evt.Skip()
- I am now having an issue with a StaticBoxSizer not properly expanding to fill its space. I am still researching this issue but it clearly is related to the upgrade since it was working correctly before.
Technorati Tags: python, wxpython, py2exe
Python and win32: Bring a Window to Front or Top
Oh joy! I had the need to bring a window (other than my own program) to the front or top, even if it was minimized. So after looking around for awhile, I pieced together several different things and managed to accomplish what I needed with the following code:
import win32api import win32con import win32gui def windowEnumerationHandler(hwnd, resultList): '''Pass to win32gui.EnumWindows() to generate list of window handle, window text tuples.''' resultList.append((hwnd, win32gui.GetWindowText(hwnd))) def bringToFront(windowText): topWindows = [] win32gui.EnumWindows(windowEnumerationHandler, topWindows) print len(topWindows) for i in topWindows: if i[1] and windowText.lower() in i[1].lower(): print i[1] win32gui.ShowWindow(i[0],5) win32gui.SetForegroundWindow(i[0])
The important stuff here is the callback function and the win32 calls. Also note that it appears that we need both the ShowWindow call and the SetForegroundWindow call. The ShowWindow handles minimized windows and the SetForegroundWindow call pulls it it to the top. I’ll be the first to admit this isn’t really good code. There are other ways of getting window handles. This just happens to be the method that I got to work.
1 commentThe SW Journal and My Shattered Dream
I was very nearly ready to release my Python-based Snowy Woods Journal application. It’s a simple application. It allows you to keep a personal journal. It’s wxPython-based so it enjoys some cross-platform goodness. It uses SQLite for storage so it’s pretty tight on the storage side of things. I also have support for tagging and text based searches.
I also am missing some things that would be nice like storing rich text (in a non-RTF way), export templates (although it does support a basic text export) and storing links to web-sites. I’d also like to find an elegant way to handle encryption without totally breaking the search functionality.
But aside from the encryption issue, I’ve found what is surely a better program for accomplishing what my little Snowy Woods app hoped to do: TiddlyWiki. And really TiddlyWiki does so much more.
In my own words, TiddlyWiki is wiki software written entirely using JavaScript embedded in an html file. It’s capable of updating itself on most any modern browser. So what you have is a wiki stored entirely inside a single html file that can update itself and can be run on almost any computer with a modern browser. Furthermore, the author has made the system pluggable so new features can be added. It takes a bit of adjusting to get the hang of it, but it really is an amazing JavaScript accomplishment and for what I would use it for, I suspect that it might do just as well or better than my journal program. Plus, I could use it on far more computers. So just like my goal with my journal app, TiddlyWiki works perfectly from a little USB drive. Oh, and when it saves, it also makes a backup copy. But of course unlike most programs, the backup essentially includes the source code as well as the data.
If there’s one complaint I have, it’s that it does store everything in the one file. There’s something that makes me nervous when my data and source code all live together in the same file. It violates every rule of common-sense abstraction I like to follow. But in the end, it still is a brilliant program that has to have many scratching their heads wondering why they hadn’t thought of it first.
As for Snowy Woods Journal, I guess I’ll try to finish up a few things on it and go ahead and release it here on the site. But without me using it, I don’t see that I’ll making many improvements or changes there. The only brightspot I can see is that the app layout as a whole might work fairly well for a blog editor that I have been planning (PumpkinSeed) to go along with the Pumpkinvine Blog System.
Technorati Tags: pumpkinvine, pumpkinseed, TiddlyWiki, Snowy Woods Journal, python, java script, wxpython
powered by performancing firefox
2 comments