# First import all the neccesary libraries import gtk import hildon # This is an example callback function that can be put to a button and used to receive stuff # All buttons print hello world, but if it has data included, will print that aswell def hello(widget, data): print "Hello World!" if data != None: print "Data: ", data def main(): # Get an instance of HildonProgram. It is an object used to represent an # application running in the Hildon framework. program = hildon.Program.get_instance() # create a new hildon window window = hildon.Window() # Registers a window as belonging to the program program.add_window(window) # When the window is given the "delete_event" signal (this is given by the # window manager, usually by the "close" option, or on the titlebar), we # ask it to call the delete_event () function as defined above. The data # passed to the callback function is None and is ignored in the callback # function. window.connect("delete_event", gtk.main_quit, None) # Create three different buttons: 1st with no data, 2nd with data and 3rd as an Image button1 = hildon.Button(gtk.HILDON_SIZE_AUTO, hildon.BUTTON_ARRANGEMENT_VERTICAL, "First Button, no data") button2 = hildon.Button(gtk.HILDON_SIZE_AUTO, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Second Button, with data") button3 = hildon.Button(gtk.HILDON_SIZE_AUTO, hildon.BUTTON_ARRANGEMENT_VERTICAL, "") # When the button is given the "clicked" signal, we ask it to call the # hello () function as defined above. If the data passed to the callback # function is None and is ignored in the callback function. button1.connect("clicked", hello, None) button2.connect("clicked", hello, "a lot of numbers here") button3.connect("clicked", hello, None) # Set the button to have an image # First we need to load the image from file image = gtk.image_new_from_file("preview.jpg") # and then to set it to the button button3.set_image(image) # Now we create a button box, which is an container that can have multiple buttons in it # The one used here is Vertical box, that places the buttons on top of each other, but # you could create HButtonBox() that is a horizontal box, that puts buttons next to # each other buttonBox = gtk.VButtonBox() # Here the layour is defined to spread the buttons evenly, options to use here are # gtk.BUTTONBOX_SPREAD, gtk.BUTTONBOX_EDGE, gtk.BUTTONBOX_START and gtk.BUTTONBOX_END buttonBox.set_layout(gtk.BUTTONBOX_SPREAD) # And then finally add all the buttons to the buttonBox buttonBox.add(button1) buttonBox.add(button2) buttonBox.add(button3) # And then the buttonBox to the window window.add(buttonBox) # The final step is to display this newly created widget and all widgets it # contains. window.show_all() # All GTK+ applications must have a gtk_main(). Control ends here and waits # for an event to occur (like a key press or mouse event). gtk.main() if __name__ == "__main__": main()