In the movies, when it is time to detonate the explosives, the person setting off the KABOOM has a sweet remote control with either a two part switch or with two separate switches. Damn, I love a good movie explosion.
The two part switch allows the user to:
- activate the explosive
- blow shit up
Because the switch has two components, activate and detonate, it is uncommon for there to be accidental explosions. This is a damn fine safety measure and when adding the ability to block an identi.ca user with heybuddy, I wanted a similar safety precaution; blocking someone by accident should not be possible. So that is what I did.
To accomplish this, it was necessary to do the following
- create a disabled button that brings the hammer down!
- create a checkbox that will activate the button
In GTK parlance, to disable a button, one needs to set the button sensitivity to false. Since I am using Python, this is accomplished thusly
To show this idea as a small working bit of code, I wrote a quick Python-GTK app that almost does the bare minimum.
Enter the Python
#I want to keep track of click counts
'''build the UI'''
#make the window
winder = gtk.Window(gtk.WINDOW_TOPLEVEL)
#make some boxes
vbox = gtk.VBox()
hbox = gtk.HBox()
#make some buttons
self.button = gtk.Button("Click Me")
self.checkbutton = gtk.CheckButton(label="Enable Button")
#add the buttons to the hbox
#add the hbox to the vbox
#create a Label
self.label = gtk.Label()
#add the label to the vbox
#add the vbox to the window
#disable the button
#connect the buttons
self.checkbutton.connect('toggled', self.toggle_clicked )
#show it all!
def toggle_clicked(self, widget):
#is the checkbutton active?
active = widget.get_active()
#increment the click count
#make a string
string = "clicks: %d" %(self.click_count)
#set the label to the string
a = application()
It may not be the best solution, but it is a solution and it works.
Well that's it for now. Quit reading, and go write some code.