Method-chaining and Simple-types as objects

Daniel B. Faken faken at cascv.brown.edu
Thu May 19 13:07:44 PDT 2005


The code I attached may be too cryptic, so here is the complete python 
script.

The Squeak (smalltalk) service has address and interface 'org.squeak'.  
Its root object is at /Squeak, and /Squeak/XYZ refers to the class-object 
for class XYZ.

------------------------------
# tobj-service.py:
import dbus

def sqobj(path):
    # wrap an object up to make calling easy
    return dbus.Interface(bus.get_object("org.squeak", path), 
"org.squeak")

class TObject(dbus.Object):
    def __init__(self, service):
        dbus.Object.__init__(self, "/TObject", service)
        self.myobj = 'error'

    @dbus.method("org.squeak")
    def setTFrame(self, obj):
        self.myobj = obj
        print("HI! setTFrame:: myobj -> %s" % obj)

    @dbus.method("org.squeak")
    def render(self, ogl):
        #print("Python TObject: would render with ogl=%s!\n" % ogl)
        sqobj(ogl).glColor3f_with_with(0.5, 0.5, 0.5)
        sqobj(self.myobj).renderCube_scale(ogl, 1.0)

bus = dbus.SessionBus()
squeak = bus.get_object("org.squeak", "/Squeak")
cGlobals = sqobj("/Squeak/CroquetGlobals")

squeak = dbus.Interface(squeak, "org.squeak")

tpm = sqobj(cGlobals.theTeapotMorph())
cam = sqobj(tpm.activeCamera())
spacepath = cam.currentSpace()  # used as just path below
space = sqobj( spacepath )


tpclass = sqobj("/Squeak/TDBusProxy")



service = dbus.Service("org.python", bus=bus)
tobj = TObject(service)

def handle_reply(msg):
    tpc = msg

def handle_error(msg):
    print("ERROR HANDLER: %s" % msg)


# get reply async so we don't block
tpclass.newAsChildOf_withProxy(spacepath, dbus.ObjectPath("/TObject"),
            reply_handler=handle_reply, error_handler=handle_error)

n = 0
tpc = 0
while(True):
    # bus.domainloopstep() just does a single iteration of the GLIB 
mainloop
    # this allows us to not need PyGTK+ and friends
    bus.domainloopstep()
    if(tpc != 0):
        print("tpclass = %s " % (tpc))
        tpc = 0
    n = n + 1
    if(n - 200000*(n // 200000) == 0):
        print("n = %d" % n)




More information about the dbus mailing list