Posts about qt (old posts, page 2)

2009-09-25 14:35

It shall be called Bookrest, and it has an outline view.

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.

2009-09-23 18:43

rst2pdf previewer: a new feature

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!

2009-09-22 13:33

More fun with rst2pdf, poppler and PyQt

First: I really, really need a name for this thing. I am tired of saying "my rst2pdf previewer/editor app".

Now, here's a video of how it looks nowadays after all the yak shaving (sorry about my english, I write lots of it, but never speak it):

As you can see, the basic app is fairly complete, even if it lacks all the amenities that would make someone use it (like, search? save? ;-).

It has one big problem, though: I can't publish it yet.

Why? Because I need to use poppler from PyQt, and the code I found to do it has no license (see the code).

I am trying to contact the author (Rajeev J Sebastian), so there should be news soon!

As soon as that's cleared, the PDF widget is a whole post by itself, because it's pretty neat, if I may say so myself.

UPDATE: the binding is now under MIT license, thanks to Rajeev Sebastian!

2009-09-22 04:01

Yak Shavings for September 22, 2009

yak shaving
(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:

  1. Syntax highlighting for two languages: restructured text and javascript. This yak is already shaved.
  2. Line numbers
  3. Current line highlight
  4. 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 with whatever your widget is called, of course:

def validateStyle(self):
    #no point in validating an empty string
    if not style.strip():
    except ValueError, e:
        print s
        if s == 'No JSON object could be decoded':
        elif s.startswith('Expecting '):
            pos=int(s.split(' ')[-1][:-1])
            print 'UNKNOWN ERROR'

    # This makes a red bar appear in the line
    # containing position 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.

And that's it. Here is the code for

2009-09-19 14:49

Having a little fun with poppler, PyQt and rst2pdf

Inspired by a post by André Roberge I wanted to see if rst2pdf was too slow to be used for real-time previews in a restructured text editor.

It would also be very useful, for example, as a way to test stylesheet changes, making rst2pdf much more useful in general.

And after a couple of hours of gentle hacking, you know... it doesn't suck at all. I implemented the (still very primitive) PDF viewer using a python/poppler/Qt binding I found via google, the UI is PyQt.

Here's the video:

A note: the video was recorded using qt-recordmydesktop and that program is awesome. It was trivial to do.

I expect this will not be good enough when long documents are processed, but the rst2pdf manual (about 25 pages) renders in 5 seconds.

2009-04-12 10:32

PyQt by Example (Session 4) in spanish! (and some thanks)

Thanks to Leonardo De Luca, session 4 is now available in spanish

Also, thanks to:

  • ZeD who pointed out a bug in session 2 and wrote a sphinx config file (works very well!)
  • Emanuele Rampichini who pointed out a bug (which I have not fixed yet)
  • Simon Edwards who posted about this series in his blog and pointed out some differences if you want to use PyKDE instead of PyQt.

2009-03-17 21:10

Translations coming

The spanish translations of most sessions of "PyQt by Example" are almost done, thanks to several volunteers.

Tomorrow I will upload at least one.

If anyone wants to translate them to other languages, I will be happy to include those too.

2009-03-16 10:02

Qt 4.5

Doing a routine update in my desktop, I was surprised to see Qt 4.5 is now in extra! Way to go Arch!

I had a bad start, because all fonts were broken, but after running fc-cache -fv as root and my user it looks ok again.

In fact, it fixes a bug that has been annoying me for a year.

Performance seems to be snappier. That may be a bit subjective, but things like the animations in krunner now are really quick and smooth while before they were jumpy.

And... I can try to make flash work in uRSSus! Yay!

UPDATE: it just started working:


Contents © 2000-2019 Roberto Alsina