[Sugar-devel] gtk.button initial state on?

Art Hunkins abhunkin at uncg.edu
Tue Aug 23 15:00:10 EDT 2011


In my latest activity (SamplePlay), I've several normal buttons for which 
I'd like the initial state to be *on*. Can someone show me how to modify the 
code below to achieve this? (The off state is gray; the on state, green.)

The code works fine except for the initial state (by default, off). (The 
code is from Victor Lazzarini's csndsugui.py, a gtk gui toolkit for 
Sugar/Csound.)

    def buttcallback(self, widget, data=None):
      for i in self.buttons:
         if i[0] == widget:
          if i[2]:
            i[2] = 0
            i[0].modify_bg(gtk.STATE_NORMAL, 
gtk.gdk.Color(0x8000,0x8000,0x8000, 2))
            i[0].modify_bg(gtk.STATE_PRELIGHT, 
gtk.gdk.Color(0x8000,0x8000,0x8000, 2))
          else:
            i[2] = 1
            i[0].modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0,0x7700,0, 1))
            i[0].modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0,0x7700,0, 2))
          self.set_channel(i[1], i[2])

    def button(self,box, title="",label=""):
       """Creates a button (on/off)
           box: parent box
           title: if given, the button name,
             which will also be the bus channel
             name. Otherwise a default name is
             given, BN, where N is button number
             in order of creation.
           label: if given, an alternative button name,
             which will be displayed instead of title
           returns the widget instance"""
       self.butts = self.butts + 1
       if title == "":
         title = "B%d" % self.butts
       if label == "": name = title
       else: name = label
       butt = gtk.Button(" %s " % name)
       self.scale_font(butt.child)
       butt.modify_bg(gtk.STATE_PRELIGHT, 
gtk.gdk.Color(0x8000,0x8000,0x8000, 2))
       box.pack_start(butt, False, False, 1)
       self.buttons.append([butt,title,0])
       butt.connect("clicked", self.buttcallback)
       butt.show()
       return butt

Art Hunkins



More information about the Sugar-devel mailing list