[Bf-python] SpaceHandlers

Ed Blake kitsune_e at yahoo.com
Mon Jun 27 22:27:56 CEST 2005


I've started playing around with the new spacehandlers and I've had a few
thoughts about how they could be improved.

When I tried using the event handler it would have been helpful if I had been
given more direct access to the event queue.  Instead I had to use the Window
module to get the ID for the area I'm attached to (silly) and then use Qadd
to send events to my window.  This shows that currently the Window module not
only breaks Blenders independant spaces rule, it also is home to
functionality that belongs in the spacehandlers.

I know I'm not going to get any respect here since I'm not going to code
this, but this is my idea of a solution:

A Spacehandler is a class derived from a window super class from which it
inheirits methods for area specific functions.  The script would then have
overidable methods for event handling or drawing.  When the user enables the
script an instance of the class is created and stored in the global namespace
(where the registry dict is stored).  When a event is generated the object's
event method is called.  I don't understand the rational behind separating
drawing from events so I don't know how those methods would be called.

Psudocode:
# SPACEHANDLER.VIEW3D.EVENT

import Blender
#from Blender import Draw #Event types should end up some
                          #where more generic (e.g. Blender.Events)

class my_handler(Blender.Space): # Maybe names per type e.g. 3dView, oops,
etc.
    def event(self, evt):
        """Note: I used the python queue module as a model for
        the queue interface."""
        if evt == FKEY:
            self.queue.empty()
            self.queue.put(AKEY)
            self.queue.put(REDRAW)
            self.queue.put(BKEY)
        elif evt == ESCKEY:
            self.Disable()

Again as I commented on the wiki it might be easier to expose the c level
stuff very simply (no objects) and then wrap that with a higher level Python
interface (the Space object).  I think this would make less work on the c
side as you wouldn't need to emulate python objects.  Also it would make it
easier for Python coders to contribute if some of the bpy api was actually
writen in Python.

I hope someone actually reads this.  I think the spacehandlers are a great
step toward Blender automation with Python.  Also I really think coding the
api half in c and half in Python is the way to go.  Unfortunatly for me I
don't think anybody is going to care what I think unless I build an example
to demonstrait why it's better.



More information about the Bf-python mailing list