Thread updating GUI

Anand B Pillai abpillai at lycos.com
Wed Dec 18 04:04:24 EST 2002


This is a wxPython question. Anyway since I am using python threads I
shall rather post it here.

 I am trying to update a bitmap embedded in a wxPanel using a separate
thread
subclassed from Thread class in module threading. The basic idea is to
run the
thread and let it run a slideshow by changing images on the panel. 

The run method of the thread calls a function that shows the next
image in the
directory, then sleeps for some prescribed time.

 def  run(self):
          "Run the thread"
          
          stindex=self._func(self._args)
          time.sleep(self._gap)          
          index=0

          while self._flag == 0:
                #function that draws bitmap onto a panel
               index=self._func(self._args)
               if self._loop == false:
                    #loop till you come back to the first image
                    if index == stindex:
                         break
               #sleep for certain time
               time.sleep(self._gap)

 
 Now if in the drawing function, I try to reposition the bitmap(an
instance
of wxStaticBitmap class), then the thread fails sometimes, showing a
blank panel instead of the image bitmap. If I draw the bitmap as such
(at default position of (0,0)) no problem.

 I tried to fix  this by executing the bitmap repositioning code in
another thread and calling t.join() on it so that the running thread
waits for its completion.

  if IsSlideShowrunning():
     t=threadint.Thread(None, self._bitmap.CenterOnParent, ())
     t.start()
     t.join()
  else:
     # no need of a separate thread cuz no slideshow is running
     self._bitmap.CenterOnParent()

 It now works better but still swallows some of the images.
 
 I could post the full code instead of the psuedocode if it can help
 someone in figuring out the problem.

 Thanks folks!

Anand B Pillai



More information about the Python-list mailing list