In my original post about it I was referring to Bookrest as a stylesheet editor for rst2pdf, because that's what I wanted, a way to test style changes and see what they did.
Of course, one thing lead to another and it's starting to look more like a word processor than anything else, but ... well, how about a stylesheet editor?
Sure, you can use the "Style" tab, and edit at will, but that's not exactly fun for everyone.
So, let's work on one. Here's the video of the current status:
Of course, this is about 1/20th of the stylesheet editor, but at least the dialog is there, and most of the remaining work is wiring dialogs, which is quick using designer.
Yes, the program known so far as "my rst2pdf editor/previewer application" is now called Bookrest.
What's a bookrest? It's a thing you put a book on.
Why Bookrest? I hope someday people will have books open in bookrest. Plus, it ends with "rest", which is the preferred abbreviation for reStructured Text.
And what's the outline view? It's a clickable tree with the outline of the document, of course.
As usual, let's go to the video:
The background rendering was done using python's awesome multiprocessing module.
I am in the middle of that honeymoon you get starting a new app. Every new feature seems tobe just 50 lines of code away, there is no legacy code (in fact, you are creating that legacy code), and you learn new tricks all the time.
So, I did a new feature today.
A day or two ago, my editor started showing a yellow bar highlighting the current line.
But then I though... wouldn't it be more useful to have a similar bar following you in the PDF?
That way, when you are on a given line, you can immediately see where you are in the output. Neat, right?
Here is a video showing it:
Sadly it's not perfect, and probably never will be because of docutils limitations, but it's pretty nice!
(idiomatic) Any apparently useless activity which, by allowing you to overcome intermediate difficulties, allows you to solve a larger problem.
This yak is starting to look better.
For my second pile of yak shavings: turning QPlainTextEdit into a decent editing widget for programmers.
As work advanced in my rst2pdf editor (BTW: need a name!), it became obvious that the piece of the UI the user will use most is just a couple of plain text editors.
Qt comes with a widget for that, of course, called QPlainTextEdit. However, it's a very, very bad widget for programmers.
Here's the least I wanted:
Syntax highlighting for two languages: restructured text and javascript. This yak is already shaved.
Line numbers
Current line highlight
Error highlight when it makes sense (like, in the stylesheet)
One way to achieve this would be to dump QPlainTextEdit and use QSciScintilla which is the basis for the code editor in eric and (another version) in scite.
However, I experienced a bad bug in QSciScintilla, where I can't type accented characters! Without that, (decent) spanish is impossible, and the bug seems to be at least two years old, so... no go.
So, did I get those features? I say yes!
Here is the video (yes, I am getting addicted to making these, since qt-recordmydesktop makes them so easy ;-):
The basis for this is the Code Editor example that comes with Qt itself, plus a bit of my own handywork.
First, I ported Code Editor from C++ to Python, which was very simple and took a few minutes. That takes care of points 2 and 3.
Then, the syntax highlight was plugged in, which was point 1.
Then, how about realtime javascript validation? Easy using simplejson! Just make sure to run this whenever you want validation (I do it on every keystroke).
Replace self.ui.style.toPlainText with whatever your widget is called, of course:
defvalidateStyle(self):style=unicode(self.ui.style.toPlainText())#no point in validating an empty stringifnotstyle.strip():returnpos=Nonetry:json.loads(style)exceptValueError,e:s=str(e)printsifs=='No JSON object could be decoded':pos=0elifs.startswith('Expecting '):pos=int(s.split(' ')[-1][:-1])else:print'UNKNOWN ERROR'# This makes a red bar appear in the line# containing position posself.ui.style.highlightError(pos)
highlightError(pos) simply stores pos in the Code Editor, which will draw a red bar in that line, the same way it highlights the current line.