PyGTK Tab-Completion

PyGTK – EntryCompletion hacked up to give nicer tab-completion (PasteBin.ca) (GitHub)

While working on a batch organizing tool, I found out the hard way that GTK’s EntryCompletion is not meant for people who want speed. (It’s a memory aid, not a speed aid) I also couldn’t just switch to PyQt or wxPython because they all do basically the same thing.

As such, I hacked the GTK auto-complete up a bit so that it behaves more like shell auto-complete. (It doesn’t do anything until you hit Tab. When you do, if there’s one match, it’s completed. If there are multiple matches, it pops open the normal auto-complete list so you can pick one.

Hope this help someone. I know I would have liked to find this in my Google results.

Update: If you’d like to preserve normal tab behaviour when the box is empty, just change line 28 to if event.keyval == KEY_TAB and self.get_text():. Of course, make sure you explain the behaviour and provide some sort of workaround for tabbing when the field isn’t empty. (In my app, pressing enter to submit the contents and clear the field is a perfectly acceptable solution)

CC BY-SA 4.0 PyGTK Tab-Completion by Stephan Sokolow is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

This entry was posted in Geek Stuff. Bookmark the permalink.

1 Response to PyGTK Tab-Completion

  1. Pingback: Recent Links Tagged With "pygtk" - JabberTags

Leave a Reply

Your email address will not be published. Required fields are marked *

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution under the same terms as the associated post.       Also, please be aware that non-constructive comments will have their URL field erased before being approved in order to combat SEO spam.