Thank you for your donations!   Download the book!   Public source code repository   Join the group!

Python-in-the-room

... more like an elephant, tbh. One thing I somehow forgot try to postpone as much as possible is inevitable switch over to Python 3, which is starting to become a default system-level Python for Linux distros (e.g. current Fedora), and Python 2 relegated to running legacy code.

Switch from Python 2 to 3 isn't all that problematic, especially if you won't be maintaining backward compatibility, which I won't. What really is holding me down is dependencies, namely GTK+ 2. With switch over to Python 3, pygtk was abandoned, and a new bindings, PyGObject, were written. Oki, changed imports a bit, shuffled some stuff around, not a big deal, bindings mostly just expose whatever is behind them.

GTK team with its' switch from version 2 to 3 changed things a little bit, most looks like small enough. They also decided to drop (most? all? of) their off-screen drawing support, namely gdk.Drawable, with no obvious, easy-to-use replacement. I'm guessing, this is done because GTK+ is mostly used to draw GiMP,  and GUI in general, i.e. user interaction stuff.

Real issue is that most other drawing libraries are nowhere near capabilities provided by GTK+. I don't actually use all that much, filled and outlined polygons and circles, polylines, all with basic styles (colors, width), text with some styles (colors, font name, size), but all of these are a must for a scaled, generated image. While Rust + image + imageproc comes close, it still doesn't have e.g. width parameter to draw_line_segment(), which, as I said, is a must.

One possibility would be to write support ticket for imageproc devs, which, depending on their priorities, free time, ... might be done anywhere in between very soon and never. I won't be contributing to imageproc with patches, nor trying to make bigger-and-better fork out of it, as I have enough of things to do to my own book.

So, in the end it might be that Python 3 + PIL Pillow is the way to go. Since I last checked they added very much appreciated (and needed!) changes: "Added line width parameter to rectangle and ellipse-based shapes", and some niceties which weren't available in GTK+: "Text stroking". Sometimes, waiting being patient pays off.

No comments:

Post a Comment