i am currently trying to write a user interface for one of my NGSolve simulations using PyQt5.
In the attached MWE, the user interface is used to read in a parameter and execute the poisson.py script using the provided parameter via pressing a ‘start script’ button.
The computed result should then be shown in the Netgen Window, such that one can quickly adjust the parameter and view the effect on the result.
This is where things don’t work out yet. The Netgen window is opened and updated only after the GUI window is closed, despite Draw() is called in the successfully executed script.
If a Netgen window is already open, the window is frozen until the UI is terminated.
On top of that, i would like to embed or dock the Netgen window into the PyQt UI, such that the user only has one window to focus on.
Hope that someone with a little bit of experience in PyQt5 and NGSolve can help me out here
Hi Lukas,
Have you had a look at the pyside2/pyqt5 project ngsgui?
I think it is basically what you are looking for. It provides entry points for extension and you can add arbitrary functionality to the gui in your extension.
Best
Christopher
thanks for your response! Looks exactly like what I’m looking for.
Unfortunately I am not very experienced in managing Ubuntu packages and run into some trouble installing it.
NgsGui works on an older version of ipykernel, but I’d like to use Spyder IDE, which requires the latest version of ipykernel . Through the installation i thus get the error message that : ‘ngsgui 0.1.11 requires ipykernel<5, but you’ll have ipykernel 5.3.4 which is incompatible’.
Can you tell me how to resolve this?
Running the demo programs Spyder encounters an unknown internal error.
Since 5.3.4 is the current version, we can replace this requirement with a recent one I think.
I’ll update the setup.py and release a new version to pip
thanks for the fix! It works fine now, except for some smaller issues:
When the ngsgui window starts, the first solution drawn is always corrupted. It shows some weird clipping error:
When i play around with the lighting and clipping settings, it dissappears after a while most times…
I would also like to set the min and max value of the drawn function programatically, is this possible?
In the meantime i tried to find a workaround for the GUI using the VTK output of ngsolve. The field is written as .vtk file via vtk = VTKOutput(…) and calling vtk.Do(). It is then read back in to a PyQt vtk object and integrated in the display:
I attached the example code. In my opinion, this looks really nice and is very convenient for the user. Unfortunately, the vtk output file gets very large, when a more complex mesh is used, and the writing/reading takes a long time. If one could skip that step by converting the NGSolve vtk-object to a PyQt vtk-object this may work much faster.
Maybe someone with a little experince knows if and how this is possible.
Can you send the script creating the clipping error?
Going via vtk is an option, but the ngsolve vtk object doesn’t have anything to do with the python vtk objects provided by pyqt… To bypass the writing you would have to extract the required information manually from the ngsolve objects (for example as numpy arrays) and put it into pyqt… Which is some work I guess and needs some understanding of vtk and ngsolve.
The script creating the clipping error is basically the one i started with (i attached it again). In my console window i get the warning:
libpng warning: bKGD: invalid
But i cant find anything related to ngsgui, all forum entries for this warning relate to *.png files…
Extracting the information manually from the ngsolve vtk object to convert it into pyqt seems too much of a task for me right now, but thanks for confirming
not sure if you read my last posting but i noticed that for the example script i sent, the scene commands (i.e. scene.setShowWireframe(True) ) are also broken. Calling them leads to an error in ngsgui/startup.py:
‘SpyderKernel’ object has no attribute ‘send_spyder_msg’
Im on ipykernel 5.3.4. So maybe still a kernel problem?
It seems like you are trying to use the Spyder integration. Which version of spyder do you use? I think I have tested it with 4.1
I cannot reproduce your flickering as well. Can you send the script that is producing it (you only included some pyqt scripts but they do not use ngsgui. Also do you have the most current versions of the software packages ngsgui and ngsolve? Which versions of python, pyqt,… are you using?
Best
Christopher
Hi Christopher,
my ultimate goal is to use a pyqt GUI to manipulate the output in the NGSgui Window (merging them into one window would be cool but is beyond my abilities). Thats why im using pyqt.
The examples i attached earlier open a pyqt window, that, besides the clipping error, succesfully changes the output in the ngsgui tab in Spyder. Btw you are correct, i am using Spyder 4.1.4 with Python 3.7, NGSolve 6.2.2004 and NGSgui 0.1.13.dev0.
The clipping error already occurs running the following simple poisson example without pyqt. It opens the NGSgui Tab in Spyder and displays the solution, but most of the times it has the clipping error.
Hm I cannot reproduce the clipping error yet…
With the setting of parameters, you are right, this wasn’t working in spyder due to a change in their interface. It is fixed now. Note that to set the colormap you first have to turn autoscale off:
btw. it is possible to add buttons and stuff in the ngsgui, you can hook into it as an add on by installing a python package which provides an entry point for a ngsgui_plugin:
thanks for fixing the setting of parameters! Adding Buttons etc. to ngsgui is a great feature, but my application is too extensive to be embedded in the ngs window (it contains several scrollbars, sliders, progressbars and so on).
I might have some new info on the clipping error though:
When running the program from a terminal, the following message is shown:
b’active samplers with a different type refer to the same texture image unit’, which relates to an OpenGL problem i think…
Displaying the edge numbers also reveals, that they are in fact in the right place and it is only a display-error.
Creating a plugin allows you to completely change everything about the gui. So basically you get the gui object at initialization and you can do with it whatever you want. You can patch classes and functions and therefore create the interface that you like. It has the advantage, that the gui class itself still handles the interfacing to the concurrent python thread in which it is running the code and it also handles shared contextes between multiple rendering windows. But you can of course build your own application and take some guidance from the source code of the ngsgui
I was trying to launch ngsgui, but it requires PySide2. However, I’m working with Python 3.12, and PySide6 is available instead of PySide2. I cannot use a lower version than 3.12, Is there a solution to resolve this compatibility issue?
This project has been deprecated in favor of webgui which is where we put our focus on now. Feel free to pick up where it was though, if you are interested in a PyQt version.