[pygtk] how to change value in slider

Sibtey Mehdi sibteym at chetu.com
Sat Apr 4 01:54:42 WST 2009


hi
      I am trying to change the value in the slider bar but it is allowing to change the value within the range given in the 
      adjustment. if the current values are 1,2,4,5,6,7 then i want slider should show 1,2,4,8,16,32,64.how can i do this any one can help me out this problem? even the set_value(newvalue) function changes values within the lower and upper values but that changes are also not displayed on the slider.
      


Thanks,
Sibtey

my code :

import pygtk
pygtk.require('2.0')
import gtk


class Scale(object):
    """A scale that adheres to increment steps"""
    def __init__(self,x):
        self.a =  x
        self.set_update_policy(gtk.UPDATE_CONTINUOUS)
        
        self.set_size_request(150,35)
        self.connect("change-value", self.adjust)

    def adjust(self, range, scroll, value):
        adj = self.get_adjustment()
        lower = adj.get_property('lower')       
        upper = adj.get_property('upper')
        incr = adj.get_property('step-increment')
        
        value -= (value % incr)
        xx =  min(max(lower, value), upper)
        
        if int(value) == 7:
            a = 64
        elif int(value) == 6:
            a = 32
        elif int(value) == 5:
            a = 16
        elif int(value) == 4:
            a = 8
        elif int(value) == 3:
            a = 4
        elif int(value) == 2:
            a = 2
        elif int(value) == 1:
            a = 1

        range.set_value(a)    
        print a,  self.get_value()


class HScale(gtk.HScale, Scale):
    def __init__(self, x, *args):
        gtk.HScale.__init__(self, *args)
        Scale.__init__(self,x)




class RangeWidgets:

    def __init__(self):
        # Standard window-creating stuff
        self.window = gtk.Window (gtk.WINDOW_TOPLEVEL)
        self.window.connect("destroy", lambda w: gtk.main_quit())
        self.window.set_title("range controls")

        box1 = gtk.VBox(False, 0)
 

       # adj2 = gtk.Adjustment.set_all(1.0,1.0,64.0,1.0,1.0,2.0)
        adj2 = gtk.Adjustment(1.0,1.0,7.0,1.0,1.0,0.0)



       # adj2.connect("value_changed", self.cb_digits_scale)
        scale = HScale('k', adj2)
        scale.set_digits(0)
        box1.pack_start(scale, True, True, 0)
        scale.show()

        box1.show()
        self.window.add(box1)
        self.window.show()

def main():
    gtk.main()
    return 0            

if __name__ == "__main__":
    RangeWidgets()
    main() 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20090403/b5ed36c4/attachment.htm 


More information about the pygtk mailing list