Pygame event problem

Anand anandpillai6 at
Wed Sep 25 11:02:49 EDT 2002

Hi !

  I wrote a simple image viewer in python using pygame image api. The
 is in wxPython. There are 2 classes, one for the window frame and one
 the pygame image processing.

   I added an effect in the pygame class which is called from a menu
in the
  wxPython GUI. Here is the code of the GUI class which makes the

  def OnLiquidEffect(self, event):
          #imgview is of type MyPyGameImgViewer which is the pygame
          #class used to load the images.


  Here is the method which it calls on the MyPyGameImgViewer class.

 class MyPyGameImgViewer:


           def LiquidEffect(self):
          anim = 0.0

          if self.imgfile is not None:
               self.flag = 0
               bitmap = pygame.Surface((self.h, self.w))
               bitmap.blit(self.screen, (0, 0))
               print self.h, self.w
               while 1:
                    anim = anim + 0.4
                    for x in range(0, self.h, 20):
                         for y in range(0, self.w, 20):
                              xpos = (x + (sin(anim + x * .01) * 15))
+ 20
                              ypos = (y + (sin(anim + y * .01) * 15))
+ 20
                              self.screen.blit(bitmap, (x, y), (xpos,
ypos, 20, 20))

                    #I think this code will remove all the
                    #events from the queue once it detects
                    #a mouse event.
                    if pygame.event.peek([MOUSEBUTTONDOWN]):
               print "No image loaded!"

   The effect is stopped by clicking with the mouse on the pygame
window. My problem is that if I try to invoke any other menu methods
in the
main GUI frame *without doing this*, the application ie both the
wxFrame and
the pygame display window, hangs.

  I have a gut-feeling that this is because I am calling a method on
the MyPyGameImgViewer class without exiting the while loop.

 Is there a way around this, ie to call any method in the
MyPyGameImgViewer class
from the GUI class, while one of its methods is executing a while loop


Anand Pillai

More information about the Python-list mailing list