Posts about pyqt (old posts, page 2)

2009-10-23 23:27

24-hour app #1: Die Schere, a video editor

I have long known that application development is an arduous process. I have also long suspected one of the reasons it's arduous is the developer. I should be more specific, I am one of the reasons.

That's because I don't know what I am doing, and I don't mean that in the "I am a lame programmer" sense (even if that's also true somewhat), but in the sense that I literally don't know what the app should look like, or what its feature set should be.

So, I have decided to embark on a series of experiments I will call 24-hour apps.

Here are the rules:

  • I shall create a neat application, stable, useful, usable and decent-looking.
  • I shall do it in no more than 24 hours. After that time, it should be at least good enough for a preview release, if not a beta.
  • Those 24 hours can be split in two or three sessions
  • Time spent doing icons, docs, etc, counts.
  • All development shall be public (I am using github)
  • I must have a use for the resulting application, and it should be at least an adequate solution for that problem.

So, what's the first project? I call it Die Schere (The Scissors in german) and it's a video editor.

It's not a kdenlive replacement, it's just the video editor I wish I had when I needed to glue a piece of one video with a piece of another.

In the old, pre-digital world, that was done using a cutter and scotch tape. I want Die Schere to be as useful and comprehensible as that was, but useful for clumsy people like myself.

Here is a video after today's session, which lasted 8 hours:

The basic functions are there, even if lots of work is still needed.

  • You can load clips to work with them
  • You can cut clips (like using a cutter!)
  • You can choose the cut points interactively or by editing a time
  • You can arrange them (like using scotch tape!)
  • You can generate the output video

As a backend it's using mencoder, but there's no reason it shouldn't work with ffmpeg or melt if someone writes 20 lines of code.

2009-10-02 22:58

Bookrest: the stylesheet editor in action

As usual, a video showing it:

The current status is that the infrastructure required for the stylesheet editor is in place:

  • I figured out how to turn the StyleSheet object back into a JSON stylesheet.
  • The changes are done and merged back into the same file.
  • There is UI for 3 of the 6 required pieces. The missing ones are text styles, embedded fonts, and config options (like, break subsections to odd pages)
  • The UI for the whole app is pretty rough, I am in full make-it-functional mode right now. It will be rethought later on.

2009-09-28 11:24

Bookrest: it was meant to be a stylesheet editor.

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.

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-21 10:17

Yak Shavings for september 21, 2009

yak shaving
(idiomatic) Any apparently useless activity which, by allowing you to overcome intermediate difficulties, allows you to solve a larger problem.

And boy, are my yaks hairy!

I started trying to do a rst2pdf stylesheet editor (see here).

One thing lead to another, and I have now at least three interesting mini-projects because of it.

Here's today's: abuse pygments to use it as a generic syntax highlighter in a Qt interface.

Why pygments? Because it's the only reStructured Text highlighter I found. That's probably because reSt is pretty damn hard to highlight!

AFAIK, this is the first time anyone has managed to use pygments for this, in an editable window. And there are good reasons for that:

  • It's pure python, so maybe you expect it to be too slow
  • It doesn't do partial or progressive lexing, so you need to lex the whole thing (again, maybe you expect it to be too slow)
  • It has a file-oriented API, it generates a file with all the formatting in it, and for this kind of thing we need to access stuff in the middle of the data.

So, of course, it turns out it works pretty well, as you can see in this video:

Lesson learned: computers are fast nowadays.

Here's the code for with extensive comments.

You can just run it and get the same demo you saw on the video (minus the typing ;-)

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.

Contents © 2000-2018 Roberto Alsina