|
From: Jon S. <js...@so...> - 2004-11-13 21:31:42
|
Greetings I'm playing with visual.controls and want to mention 3 issues. ####### Issue1: I can't position the controls window. Help? ###### Issue2: it is apparently impossible to subclass vpython objects. ###### http://mail.python.org/pipermail/tutor/2002-November/018952.html ###### Issue3: ###### But I can simulate the effect I want by adding attributes (including methods) to an object. FYI. ###### (This should be documented shouldn't it?) Comment? These Issues are illustrated in the snippet below, which creates a variant slider that displays an ID and its current value. Visual 3.0 -2003-10-05, Mac OSX 10.3 Comments welcome. from visual.controls import * ####### Issue1: I can't position the controls window. c=controls(x=800) # Issue 1: print c.display.x ####### this confirms that the value of 800 'took', but it has no consequence. Help? ###### Issue2: it is apparently impossible to subclass vpython objects. ###### http://mail.python.org/pipermail/tutor/2002-November/018952.html ###### (This should be documented shouldn't it?) Comment? ###### Issue3: ###### But I can simulate the effect by adding attributes (including methods) to an object. FYI. def jslider2(**args): self=slider(**args) ######### create the object, passing all arguments up to the "parent" self.label=label(display=c.display, pos=(self.pos[0] , self.pos[1]+self.length), text=str(self.value), box=0 ) ######### turn the optional attribute ID into the text of a label if 'ID' in args: self.ID=label(display=c.display, pos=self.pos, text=args['ID'], box=0 ) ######### Create an internal function to def showVal(obj, intify=0): if intify: obj.value=int(round(obj.value)) obj.label.text=str(obj.value) ######### make showVal the "action" attribute self.action=lambda:showVal(self, intify=0) return self if __name__=='__main__': scene.autoscale=0 sph=sphere() b2=box(pos=(2,2)) s22 = jslider2(ID='s2', pos=(-30,-50), width=7, length=50, axis=(0,1,0) ) while 1: c.interact() sph.radius=1+s22.value |