Tiny and simple webserver for Basico

While developing the Dashboard module I had problems to display charts generated with Pygal. Charts can only be saved as SVG format (they can be saved as PNG files but I haven’t found any portable library to use easily in Windows).

The first solution I came up with was to create an HTML file and then point to the SVG file but WebKit doesn’t allow to do that if you aren’t using a Webserver (it is all about security policies).

So the next step was to implement a tiny webserver based on Python 3 core standard library. After a few research looking for simple implementations I found one very simple. At first, it worked but then Basico became unstable:

– After stopping Basico, the next execution returns errors due to the webserver isn’t stopped successfully and the port remains binded.
– Another issue: you can’t run the webserver and GTK application in the same thread because then the application freezes.

After a little bit more of research I was able to rewrite the module to overcome these problems and keep the compatibility in both platforms, Linux and Windows.

Finally, I was able to load my webpage from my tiny and simple webserver and embed it into my GTK application using WebKit:

The code used to do this:

The HTML code:

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *