Problem with wxPython

A

Ali

Hi

I'm not sure if this is the right place to post, pardon me if it's not.
I'm having a problem with an application written with wxpython. The frame
seems only to refresh when moving my mouse of it, though i frequently call:
frame.Refresh(True). In fact, that line is called by another thread, right
after having modified some of the frames attributes.

here are some snippets of code :
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
self.queue=Queue.Queue(0)
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
iconFile = "gnobots2.xpm"
icon1 = wx.Icon(iconFile, wx.BITMAP_TYPE_XPM)
self.SetIcon(icon1)
self.panel_1 = wx.Panel(self, -1)
self.panel_1.Bind(wx.EVT_PAINT, self.on_paint)
self.static_line_1 = wx.StaticLine(self, -1)
self.text_ctrl_1 =
wx.TextCtrl(self, -1, "",style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_WORDWRAP)

self.__set_properties()
self.__do_layout()
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("Simulation")
self.SetSize((600, 400))
self.static_line_1.SetBackgroundColour(wx.Colour(0, 0, 0))
self.text_ctrl_1.SetMinSize((600, 100))
# end wxGlade

self.blues = []

def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
sizer_1.Add(self.static_line_1, 0, wx.EXPAND, 0)
sizer_1.Add(self.text_ctrl_1, 0, wx.ADJUST_MINSIZE, 0)
self.SetAutoLayout(True)
self.SetSizer(sizer_1)
self.Layout()
# end wxGlade

def on_paint(self, event):
dim = self.panel_1.GetSize()
dc = wx.PaintDC(self.panel_1)
total_types = len(Parameters.DEMANDERS_NUMBERS)
large = dim[1] / (total_types + 3)
long = dim[0] / Parameters.NUMBER_OF_BLUES - 1
for type in range(total_types):
counter = long
for blue in self.blues:
green = (int(blue.biais[type])) * 20
red = - green
if red<0:
red=0
if green<0:
green=0
color = wx.Colour(red, green, 75)
dc.SetPen(wx.Pen(color,long))
dc.DrawLine(counter,50 + (type * (20 +
large)),counter, 50 + large + (ty
pe * (20 + large)))
counter += long
while(not self.queue.empty()):
self.text_ctrl_1.AppendText(str(self.queue.get()) + "\n")


# end of class MyFrame

class MyApp( wx.App):
def OnInit(self):
self.text = ""
self.frame = MyFrame(None , -1, 'Frame Window Demo')
self.frame.Show(True)
self.SetTopWindow(self.frame)
return True
#this is called by an external thread
def paint(self, blues):
self.frame.blues = blues
self.frame.Refresh(True)



I don't know if that is enough information, feel free to ask for more.
 
C

Chris Mellon

Hi

I'm not sure if this is the right place to post, pardon me if it's not.
I'm having a problem with an application written with wxpython. The frame
seems only to refresh when moving my mouse of it, though i frequently call:
frame.Refresh(True). In fact, that line is called by another thread, right
after having modified some of the frames attributes.

In general, the wxpython-users list is a better source of wxPython
answers than c.l.p.

wxPython gui elements are not threadsafe unless otherwise indicated.
Don't make calls against gui objects from other threads. This includes
Refresh().

You can make this call in a threadsafe manner using wx.CallAfter like so:
wx.CallAfter(frame.Refresh, True)

<code snipped>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,920
Messages
2,570,038
Members
46,449
Latest member
onedumbsquirrel

Latest Threads

Top