Rename wxPython window strength, wxmpl graph

I am having problems updating my wxPython window. He is currently drawing a graph using wxmpl, which can be scaled, tinted, etc. Sometimes a user can draw a large amount of data and enlarge a small part, which can lead to freezing. By this I mean that the plot itself is not updated, and the axis labels are drawn one above the other. It changes the plot, just not displaying the updated information correctly. If you resize the window, the graph will be redrawn correctly.

I spent an excessive amount of time searching for source code and documentation for wx, wxmpl and matplotlib ... The best solution I came up with was resizing the window to make it redraw (thus displaying the updated plot correctly).

# All of these fail - displays the same, incorrect plot # (view is a wxmpl.PlotPanel object, which inherits from wx.Window among other things) view.Refresh() view.Update() view.draw() # This works, but is clearly less than ideal view.SetSize((view.GetSize().width, view.GetSize().height+1)) view.SetSize((view.GetSize().width, view.GetSize().height-1)) 

There should be a better way - I really want to know what wx.Window.SetSize does to redraw the window, and just name it instead. Or is there another method that I skipped somewhere?

+7
source share
4 answers

The panel.Layout () command is a great option because it is the same method that is called when the window is resized. I also had problems with update and update methods. The layout seems to work when these two are not working.

+3
source

If you cannot put it in another place, you can try

 wx.Yield() 

instead of Refresh or Update .

+1
source

I will also try Show (False) and then Show (True) on PlotPanel.

+1
source

In an expensive computing application, where you expect something to take more than 0.1 seconds and probably have user input, it is usually not recommended to do intensive drawing in the GUI stream.

It is not known about your specific situation, but the general approach is if you move all the time-consuming tasks (be it computing, adjusting the image (for example, scaling)) to a stream without a GUI. Just the normal Python thread is fine, and as soon as you have the long part, you will update your GUI. Of course, when calculating it would be convenient to display some kind of waiting sign. Also turn off other controls so that a bored user cannot change anything halfway to your calculations.

I got stuck in this issue from the first days of working with Java, and later with Python, mainly in connection with network operations (which should NEVER be in the GUI thread).

In case it is image processing (or graphics generation), which takes a lot of time, the background thread can prepare the image in wxMemoryDC, and then wxDC :: Blit it in the window of your choice. I don't know if this can be done with your wxmpl.PlotPanel component, so you will have to research this.

0
source

All Articles