[Stackless] Re: Stackless subscription notification

Christian Tismer tismer at tismer.com
Wed Aug 14 03:48:35 CEST 2002

mailman-owner at trixie.triqs.com wrote:
> aaron at reportlab.com has been successfully subscribed to Stackless.

Welcome! I'm in fact impressed of your interest!
On the other hand, I'm using Stackless myself, now.
And I find myself writing event handlers as simple,
endless lops, now. Look here, please:

     def OnMouseEvents(self, event):
         if not self.graph:
         # we must clone, since the C object dies
         # when we leave this stack.
         #dup = event.Clone()
         # oops, doesn't work either.
         # we need to unpack it all here :(
         class x: pass
         x.pos = event.GetPosition()
         x.enter = event.Entering()
         x.leave = event.Leaving()
         x.drag = event.Dragging()
         x.move = event.Moving()
         x.down1 = event.ButtonDown(1)
         if self.mouse:

     def mouseHandler(self):
         except SystemExit, msg:
             print msg
         except Exception, e:
             print "mist", e
             print "killing handler"
             self.mouse = None

     def shutdown(self):
         self.cache = None
         if self.mouse:
             mouse = self.mouse
             self.mouse = None
             mouse.send_exception(SystemExit, "thanks for all the fish :-)")

     def _mouseHandler(self):
         last = None

         def true_rec():
             i = 0
             while f:
                 i += 1
                 f = f.f_back
             return i

         while 1:
             g = self.graph
             event = self.mouse.receive()
             if not g: continue

             x, y = event.pos.x, event.pos.y
             what = g.test(x, y)
             if what < 0:
             elif what == 0:
             if event.down1:
                 g.setSpot(x, y)
             if event.drag:
                 if what < 0:
                     # shift
                     # stay in a loop or we might miss
                     while event.drag:
                         if g.allowedShift(x, y):
                             g.shiftTo(x, y)
                             if self.notify: self.notify()
                         event = self.mouse.receive()
                         x, y = event.pos.x, event.pos.y
                 elif what == 0:
                     # grow
                     while event.drag:
                         if g.allowedGrowth(x, y):
                             g.growTo(x, y)
                             if self.notify: self.notify()
                         event = self.mouse.receive()
                         x, y = event.pos.x, event.pos.y

This class implements a bitmap with some drawing upon it.
The drawing is not shown here, but it needs to complement
the existing bitmap. (circles/squares for selection)

Please, see this extremely simple event loop. This is a single
tasklet that stays waiting for mouse events, until it gets
blown by a SystemExit exception.
This is quite revealing. Now I can have program state in my
PC counter, as it was 20 years ago. The handler feels like
a main program.

As a side note, you can also see that I have to copy all relevant
mouse state into som etemp class. This is most probably
due to the fact (fault), that wxWindows keeps the mouse event
on its stack. When I use that in another tasklet, the result is bogus.
I will ask Robin to change that and do a proper copy.
Even event.Clone() doesn't help it.

But there is no free meal - ly y'rs - chris

Christian Tismer             :^)   <mailto:tismer at tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  pager +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/

Stackless mailing list
Stackless at www.tismer.com

More information about the Stackless mailing list