A 5K Python Fullscreen Text Editor


After a 5K Java Twitter client and a 5K Javascript TODO list app, the next example 5K App is a wxPython fullscreen text editor. Much like Writeroom and Duncan's JDarkroom (both of which are more fully featured) it lets you edit text files in "distraction-free" fullscreen. Ideal for creative writing or similar where you want to just get on with writing without the distraction of the outside world. So at the risk of invoking the apoplectic rage of Mark Pilgrim a fullscreen text editor seemed quite feasible in 5K of Python. In fact after using my self-extracting script code I actually had to add more features as I was way below budget!

Check out the video below or download 5KEdit for yourself.



Features:

  • Fullscreen text editing
  • Open/Save files
  • Undo/Redo
  • Retro looks
  • Resizable fonts
  • Configurable colours
  • Word count
  • Goto line number dialog
  • Find text dialog
  • Help page listing commands
  • About box

It's actually a bit more feature-full than I'd thought it would be. Part of this was that wxPython's wx.StyledTextCtrl and wxPython in general provided quite a lot of what I needed (e.g. undo/redo) out of the box. Plus the self-extracting script technique really did a good job of shrinking the code down - allowing me to add more.

To run 5KEdit your need Python (2.4+) and wxPython (2.8+) installed. If you are running OS X Leopard you already have those installed, so you can simple switch to a terminal and run that 5KEdit script using the command:

pythonw 5KEdit.pyw

Make sure you run that from the directory 5KEdit.pyw is in. On a Windows system you may find that you can simply double-click on the .pyw file to run it. There's a small repaint bug under Windows when you change colors, but it's not a show stopper.

Here are the vital statistics:

  • 17284 bytes/485 lines of original source-code
  • 13767 bytes/379 lines of stripped source-code
  • 5069 bytes of compressed/packed final version

As you can see the final version is less than a third the size of the original source code. A large part of this is due to the compression, but to help push it a bit further the source was also "stripped". Blank-lines and comments were removed and the indentation was changed from my usual 4 spaces to a single space. The stripping doesn't make a huge contribution, but without it the final version would be 5421 bytes in size. So for 400 bytes or so it's probably worth it. Plus it means that you don't have to worry about leaving yourself comments or spacing out your code nicely.