Question

I’m building an application using wxPython 3.0 on Windows, and I’m seeing an exception while trying to change the label of an existing wx.StaticText control. The exception is highly reproducible but unfortunately I haven’t been able to create a test case that displays the same behavior. The exception traceback looks like

Traceback (most recent call last):
  [...]
  File "...\application\views\markers_panel.py", line 137, in redraw
    self.grid_sizer.GetItem(num_cols*(index + 1) + 1).GetWindow().SetLabel(wavelength)
  File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_core.py", line 9210, in SetLabel
    return _core_.Window_SetLabel(*args, **kwargs)
PyAssertionError: C++ assertion "m_hdc" failed at ..\..\src\msw\textmeasure.cpp(64)
in wxTextMeasure::BeginMeasuring(): Must not be used with non-native wxDCs

I’m using a wx.FlexGridSizer as a data table by giving it a number of wx.StaticText children. Creating the StaticText objects goes fine, but when I try to change their labels (to update the data shown) I get this exception. The same code works fine under wxPython 2.9.5 in OS X.

I know it’s poor form to submit a crash report without any example code, but can anyone point me in the direction of what might be wrong here?

Was it helpful?

Solution

The problem turned out to be that I was trying to call SetLabel from one thread while another thread was also modifying the GUI. The solution was to schedule all GUI-updating tasks using wx.CallAfter() (as described in the accepted answer to this other question). Using this function forces the updating to take place on the main thread, which of course implies that only one updating task can be running at any given time.

OTHER TIPS

This is really weird, this assert shouldn't be triggered when using a control. Is it possible that you simply use too many controls and so run out of Windows resources? Have a look at the number of GDI objects (you may need to enable this column explicitly) used by your program in Process Explorer, does it look exceedingly high?

Otherwise I really have no idea about what could be causing this and if you can't reproduce this in a simple example the only way to debug it I see is to try debugging C++ code on your machine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top