[Bf-python] Slider Button API

Thomas Bleicher tbleicher at arcor.de
Thu Apr 12 21:44:16 CEST 2007


On 11 Apr 2007, at 21:48, Dave Jarvis wrote:

> Hi,
>
> After I have created a Slider Button using:
>
>    slider = Draw.Slider( ... )
>
> How do I then change the minimum and maximum values for the slider?

As Joe already wrote, the buttons are re-created each time the
interface is redrawn. Changing the values of a button instance
after it has been drawn to the screen has no visible effect.

The only way to do what you want is to keep track of the button
value across redraw loops and to adjust your limits before the
Draw.Slider() call. I use classes for this problem, others may
advocate global variables.

This code below should give you an idea. Your _checkLimits() call
would go in a method that checks the contents of the wav file.

Regards,
Thomas


from Blender import Draw

class DynamicSliderGUI(object):

   def __init__(self):
     self.eventID = 101
     self.slider = Draw.Create(1.0)  # gives us an object with val  
attribute
     self.limit_min = 0.1
     self.limit_max = 10

   def _checkLimits(self):
     '''adjust limits of slider - a bit jumpy'''
     if self.slider.val > 0.8*self.limit_max:
       self.limit_max *= 2
       print "limit_max now", self.limit_max
     elif self.slider.val < 0.2*self.limit_max:
       self.limit_max *= 0.5
       print "limit_max now", self.limit_max
     self.limit_min = 0.1 * self.limit_max

   def draw(self):
     ## draw GUI elements
     lable = "max: %.1f" % self.limit_max
     self.slider = Draw.Slider(lable, self.eventID, 10, 10, 200, 20,  
self.slider.val, self.limit_min, self.limit_max, 0)

   def event(self, event, value):
     '''catch ESC key to exit loop'''
     if event == Draw.ESCKEY:
       Draw.Exit()
     else:
       Draw.Redraw()

   def button_event(self, event):
     '''do something useful after the slider has changed and  
calculate new limits'''
     if event == self.eventID:
       print "Slider value now %.1f" % self.slider.val
       ## now check limits
       self._checkLimits()
     Draw.Redraw()


## create a gui instance and start everything with Draw.Register()
gui = DynamicSliderGUI()
Draw.Register(gui.draw, gui.event, gui.button_event)










More information about the Bf-python mailing list