Dia Python Plugins

Dia

Dia is a graph editing software being around for longer than I can remember - as you can very well observe that from this 90's design website. The software itself is pretty good, usable and stable.

I am using it for drawing some interactive documentation that helps defining and debugging an event based state machine.

Until recently, there was an "Plain SVG" export mode next to the Cairo SVG and Standard SVG options when I picked File->Export. That happened to disappear.

Deep dive: python 2 is removed from ubuntu packages and unfortunately it broke the python plugin support.

I did not find any easy way to fix this, so I decided I am going to try to build and compile it my own, maybe I can get it back somehow as I found the python file in the repo.

Install a python plugin

Officially, you can simply create a ~/.dia/python folder, and drop your plugin there. This is what I did, but it did not solve my problem as my distro's version of Dia did not load it even then.

So I built a local version and it started working.

Building

# Checkout
git clone https://gitlab.gnome.org/GNOME/dia.git

# Dependencies on PopOS!22
sudo apt-get install gtk2.0 libgrapudo python3 python3-pip python3-setuptools python3-wheel ninja-buildhene-1.0-dev

pip3 install --user meson

# Actual building
meson build -Dprefix=~/dev/dia/build/install
cd build
ninja install

# Running
~/dev/dia/build/run_with_dia_env ./app/dia

Once loaded, used the export but it was still broken: it missed the text nodes due to a python error. I did not dig into the details, I was yak shaving for much longer than I wanted, so I just fixed the problematic lines diasvg.py@193:

def draw_string (self, text, pos, alignment, color) :
if len(text) < 1 :
return # shouldn'this be done at the higher level
talign = ('start', 'middle', 'end') [alignment]
fweight = 500
self.f.write('<text x="%.3f" y="%.3f" fill="%s" text-anchor="%s" font-size="%.2f" font-weight="%d">\n' \
% (pos.x, pos.y, self._rgb(color), talign, self.font_size, fweight))
self.f.write(self._escape(text))
self.f.write('</text>\n')

Pasted-image-20231201200621.png