Writing an editor is reinventing the wheel. I know that. I tell myself Marave is a fine wheel, with distinct features, and I think that is true, but, if you are reinventing the wheel, there's no need to reinvent the axle and the spoke, too.
So, I refactored the stuff that I think a text editor must provide into a nice library, so the next time someone must invent a wheel, he can use Marave's neat spokes and axles:
So, introducing Editor, the most-obviously named class ever! It's a text editing widget for PyQt with extra features, which you can use as a drop-in replacement for a QTextEdit or QPlainTextEdit.
Right now, it lives inside Marave's SVN but it may even move out someday.
Here are its features:
-
Syntax highlighting
And I don't mean "in theory", like QTextEdit and company do! Editor can highlight a bunch of languages, because it uses GNU source highlight via Lorenzo Bettini's Source Highlight Qt.
-
Spell checking
If you have PyEnchant installed and the right dictionaries, it will do online spellchecking.
-
Search and Search+Replace widgets
The Editor class can give you nice widgets for search or search and replace already hooked with the editor widget, so you can add them to your app's UI easily.
-
new/open/save/saveas methods:
Don't implement opening/saving, etc yourself! That's always the same code!
Hopefully this will be helpful for someone else :-)