Keypad Patch for Stani’s Python Editor (SPE)

Although I haven’t been lucky enough lately to get to do any Python programming at work or in my spare time, I still end up tweaking the occasional file or fixing a bug here and there—And hope springs eternal for what the future may hold. A friend pointed out that he wanted to find a better Python editor, and brought Stani’s Python Editor (or SPE) to my attention, which wasn’t even on my radar a year ago but seems very promising now that I’ve had a chance to look.

While it’s still beta code—I wouldn’t spend more than a few minutes working in it without saving my work—its features are none the less impressive; it’s definitely lighter weight than jEdit, much more Python-focused, and has some very nice integrations to boot (most notably the shell, automatic UML diagramming and on-the-fly PyDoc HTML page generation). While SPE is very Python-focused, making it a poor choice for editing anything but Python files, it has the same strength as jEdit—that is, it will run on all Python-supporting platforms (including Windows, OSX, and Linux) but without the weight of a JRE or the somewhat slow startup performance associated with Java applications.

That was when I hit the show-stopper bug: SPE had no numeric keypad support. That is to say, the numbers worked fine, but the arrow keys, Home, End, Page Up, etc. all did not work at all; in fact they rendered Unicode characters to the screen (and produced Unicode errors in the application as well). Yuck. I chatted briefly with Stani himself via his blog, but to no avail—which is when I took matters into my own hands.

Fortunately the fix was ridiculously easy; I just had to add some keyboard mappings to the sm/wxp/stc.py file and now I have perfect keypad support, just the way I like it. I also learned a little about keyboard mappings in wxPython, which means I can customise other SPE keystrokes to do my bidding too—when I’m feeling a little more ambitious.

Without further ado, here is my patch file for sm/wxp/stc.py:

*** stc.py      Tue Sep 18 19:45:04 2007
--- stc-patched.py     Wed Sep 19 01:17:49 2007
*************** class PythonBaseSTC(wx_stc.StyledTextCtr
*** 75,80 ****
--- 75,94 ----
          self.CmdKeyAssign(ord('B'), wx_stc.STC_SCMOD_CTRL, wx_stc.STC_CMD_ZOOMIN)
          self.CmdKeyAssign(ord('N'), wx_stc.STC_SCMOD_CTRL, wx_stc.STC_CMD_ZOOMOUT)

+         #KEYPAD DEFINITIONS
+         self.CmdKeyAssign(wx.WXK_NUMPAD_UP, 0, wx_stc.STC_CMD_LINEUP)
+         self.CmdKeyAssign(wx.WXK_NUMPAD_DOWN, 0, wx_stc.STC_CMD_LINEDOWN)
+         self.CmdKeyAssign(wx.WXK_NUMPAD_LEFT, 0, wx_stc.STC_CMD_CHARLEFT)
+         self.CmdKeyAssign(wx.WXK_NUMPAD_RIGHT, 0, wx_stc.STC_CMD_CHARRIGHT)
+         self.CmdKeyAssign(wx.WXK_NUMPAD_HOME, 0, wx_stc.STC_CMD_HOME)
+         self.CmdKeyAssign(wx.WXK_NUMPAD_END, 0, wx_stc.STC_CMD_LINEEND)
+         self.CmdKeyAssign(wx.WXK_NUMPAD_HOME, wx_stc.STC_SCMOD_CTRL, wx_stc.STC_CMD_DOCUMENTSTART)
+         self.CmdKeyAssign(wx.WXK_NUMPAD_END, wx_stc.STC_SCMOD_CTRL, wx_stc.STC_CMD_DOCUMENTEND)
+         self.CmdKeyAssign(wx.WXK_NUMPAD_PAGEUP, 0, wx_stc.STC_CMD_PAGEUP)
+         self.CmdKeyAssign(wx.WXK_NUMPAD_PAGEDOWN, 0, wx_stc.STC_CMD_PAGEDOWN)
+         self.CmdKeyAssign(wx.WXK_NUMPAD_INSERT, 0, wx_stc.STC_CMD_EDITTOGGLEOVERTYPE)
+         self.CmdKeyAssign(wx.WXK_NUMPAD_DELETE, 0, wx_stc.STC_CMD_CLEAR)
+
          #PYTHON
          self.SetLexer(wx_stc.STC_LEX_PYTHON)
          keywords=keyword.kwlist

I have submitted the patch directly to SPE’s project hosted at Berlios.

Great job, Stani, and keep up the good work. I’ll try to scrape up some cash for a donation to keep development moving in the next month or two.

Leave a Reply