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

James Cameron quozl at laptop.org
Fri Aug 26 20:11:34 EDT 2011


On Tue, Aug 23, 2011 at 03:00:10PM -0400, Art Hunkins wrote:
> In my latest activity (SamplePlay), I've several normal buttons for
> which I'd like the initial state to be *on*.

The code is creating a gtk.Button (which has no persistent state) and
then modifying the button background to indicate some sort of internal
persistent state.

(It should instead create a gtk.ToggleButton and use the set_active() and
get_active() methods; it would be much easier to comprehend and change.
But this code is written in a hurry using only the tools known to the
programmer.)

> Can someone show me how to modify the code below to achieve this? (The
> off state is gray; the on state, green.)

Sure.  It is the butt.modify_bg call when the button is created that is
responsible for showing the gray.  It is the 0 in self.buttons.append
that is responsible for setting the initial state off.

(The programmer has taken control of how to show the button state).

So you might change the butt.modify_bg call, and the self.buttons.append
call.  Change the butt.modify_bg call by adopting the colour green, in
the same way as you can see in buttcallback.  Change the
self.buttons.append call by switching from 0 to 1 in the last list
value.

-- 
James Cameron
http://quozl.linux.org.au/


More information about the Sugar-devel mailing list