Web page GUI update issue

I have a django site that will display various matplotlib plots. I can create a matplotlib plot, convert it to png and display it ... but only if all the logic is contained in the views.py file of the respective application.

It would be nice if I just wanted a simple page with a simple plot. However, the problem is that the site as a whole will need multiple plots, each including their own python files, logic, etc.

So what I have done is create a new folder in the application containing python files to compute various graphs. From within view.py, I was planning to just call the appropriate python file, which will return the plot. By doing this, I could maintain the logic around how the graphs are generated separately from the page display.

The problem I am facing is the following error

QPixmap: It is not safe to use pixmaps outside the GUI thread

      

After investigating this error, this is clearly and a problem when you are trying to update the GUI from another thread. However, this is not what I am trying to do. I am trying to create a plot outside the views.py file and then pass it and create a png to refresh the page. So the GUI update shouldn't happen on a different thread?

My code in views.py:

fig = plotLogic.getPlot() #this is a call to a separate file which returns the figure
canvas=FigureCanvas(fig)
response=django.http.HttpResponse(content_type='image/png')
canvas.print_png(response)
return response

      

Is there an alternative way to do what I am trying to do? Basically, just following the logic of how the plot is created separately and returns the plot so that it can be converted to png and displayed.

It seems to me that I am somehow making this more complicated than it should be. I'm not deliberately trying to do something interesting like updating the GUI in a separate thread. Many thanks.

+3


source to share





All Articles