Combining Jupyterlab, QtAgg, Matplotlib and PyQt

For a variety of reasons I have recently started to study options to write PyQt applications which are directly started from a Python3 notebook in Jupyterlab and are displayed on the Linux desktop.

Without blocking further code execution in other notebook cells and without compromising interactivity both of the notebook and the Qt windows.

Due to the support of QtAgg you do not need any blocking “app.exec_()” statements. You just construct your PyQt windows (with Qt-widgets and integrated Matplotlib figures) and afterward show them on your Linux desktop.

In addition it is rather easy to move activities, objects, methods to background threads controlled by QThread-objects. Worker objects in such threads can communicate with Qt windows and widgets in the foreground via signals, which end up in a thread-safe and serialized way in the Qt event-loop in the main thread. From there they are picked up and handled by callbacks.

I found this a fascinating way on a Linux system with a KDE desktop to use Python in Jupyterlab to create full-fledged Qt-applications and run them under the control of Jupyterlab.

People who are interested find more information in the sister-blog

See the posts

Using PyQt with QtAgg in Jupyterlab – I – a first simple example
Using PyQt with QtAgg in Jupyterlab – II – excursion on threads, signals and events
Using PyQt with QtAgg in Jupyterlab – III – a simple pattern for background threads
Using PyQt with QtAgg in Jupyterlab – IV – simple PyQt and MPL application with background worker and receiver threads


Upgrade of PCs and laptops from Opensuse Leap 15.4 to 15.5

The last days I have upgraded multiple PC- and laptop-systems from Leap 15.4 to Leap 15.5. This was one of the smoothest upgrades ever. Despite Nvidia cards, Optimus etc.

In contrast to upgrades in the last years I just kept all special repositories (Nvidia, Packman, Graphics, Security, Print, etc.) active during the upgrade. This worked perfectly.

Suse’s prime-select on an Optimus system just continued working.

To better support Rocca mice on my PC I eliminated old drivers from Rocca and instead used “piper” to set the buttons. My Rocca EMP is basically also well supported by the generic Linux USB mouse driver.

The older I get the more it becomes true:

Linux just works. Why someone uses Windows remains a big mystery to me …

One of the next tasks is to upgrade server systems.

WordPress, MathML, Latex – vertical space between (aligned) formulas

This is only a small tip regarding the vertical spacing of formulas/equations in WordPress plugins which understand the LaTex notation. As e.g. the plugin “MathML Block”.

Very often when you align formulas with the
\begin{align} equ 1 \\ equ 2 \end{align}
commands the vertical arrangement of the equations may appear sub-optimal: The equations get very close in vertical direction.

Especially when you work with complex formulas that have some significant vertical extensions the vertical distance between adjacent equations often becomes too small in my opinion.

As I am not an experienced user of neither Latex nor MathML I always fiddled around with some invisible \phantom{} creation in the lower formulas which gave me sufficient extra vertical space. But this is a tiresome approach. As I learned some days ago from a tex-related stackexchange post there is a much simpler recipe:

The line-break symbol “\\” can be extended like “\\[6pt]“. This will give you exactly the vertical separation you want to get. For details see the following link:

add vertical space between equations” at from an author LaRiFaRi.

I think this simple trick is worth spreading as it saves so much time!