#!/var/lib/install/usr/bin/python2.4 # Imports gtk and hildon libraries so we can create # the user interface using those. import gtk import hildon # Creates a class called UITest class UITest: # This is the constructor. It is run each time # the UITest object is created, ie. when this # application is started. def __init__(self): # This is the main window of the application. self.app = hildon.App() # This is a view in the main window. # There can be multiple of these. self.appview = hildon.AppView("View One") # Set the view and titles to the application self.app.set_title("UITest") self.app.set_two_part_title(True) self.app.set_appview(self.appview) # This connects the X-mark in the top right # corner to the function "self.destroy" # that closes the application. self.appview.connect("destroy", self.destroy) # You can only add one widget inside one view. # This one widget then can of course contain # multiple widgets. We use a pane that divides # the view into two parts. self.hpane = gtk.HPaned() # Sets the separator in the pane to 450 # pixels. self.hpane.set_position(450) # Now we add a TextView and a ButtonBox # to the pane. self.hpane.add1(self.create_textview()) self.hpane.add2(self.create_buttons()) # This adds the pane to the view. gtk.Container.add(self.appview, self.hpane) # Creates and shows the menu. self.create_menu(self.appview) # Shows the pane and the app itself. self.hpane.show() self.app.show() # This is our own fuction that we can use to create # a menu for our application. def create_menu(self, appview): # Gets this views menu so we can add stuff # to it. main_menu = hildon.AppView.get_menu(appview) # This menu will be used as a submenu. menu_help = gtk.Menu() # Creates items for the menu. item_help = gtk.MenuItem('Help') item_about = gtk.MenuItem('About') item_separator = gtk.SeparatorMenuItem() item_close = gtk.MenuItem('Close') # Connects signals "activate" to the menu items # so that something actually happens when they # are activated. item_about.connect("activate", self.about_callback) item_close.connect("activate", self.destroy) # Adds the items to the menus. gtk.Menu.append(main_menu, item_help) gtk.Menu.append(menu_help, item_about) gtk.Menu.append(main_menu, item_separator) gtk.Menu.append(main_menu, item_close) # Adds the submenu to the main_menu. gtk.MenuItem.set_submenu(item_help, menu_help) # Shows all menu widgets. gtk.Widget.show_all(main_menu) # Creates a TextView that can be used for typing # or editing text in it. def create_textview(self): # Create new TextView textview = gtk.TextView() # Set some properties for it. textview.set_editable(True) textview.set_cursor_visible(True) textview.set_wrap_mode(gtk.WRAP_WORD) textview.set_justification(gtk.JUSTIFY_CENTER) # Get the textbuffer that contains the text # in the textview. textbuffer = textview.get_buffer() # Set the text that shows inside the textview. textbuffer.set_text('You can write here someting...') # Show the textview. textview.show() # Return the created textview. return textview # Creates a ButtonBox widget that can be used to easily # lay out buttons. def create_buttons(self): # Creates a vertical ButtonBox where buttons are # laid on top of each other. button_box = gtk.VButtonBox() # Set some properties for the ButtonBox button_box.set_layout(gtk.BUTTONBOX_SPREAD) button_box.set_border_width(10) button_box.set_spacing(20) # Create two buttons that will be added to the # ButtonBox. about_button = gtk.Button('About') close_button = gtk.Button(None, gtk.STOCK_QUIT) # Connect signals to the buttons so that something # actually happens when they are pressed. about_button.connect("clicked", self.about_callback) close_button.connect("clicked", self.destroy) # Add both buttons to the ButtonBox. button_box.add(about_button) button_box.add(close_button) # Show buttons and the ButtonBox. gtk.Widget.show_all(button_box) # Return created ButtonBox. return button_box # This is a callback function that is called when about # menuitem or button are clicked. It shows information # about the application using AboutDialog. def about_callback(self, widget, data=None): # Create the about dialog. dialog = gtk.AboutDialog() # Set the properties for it. dialog.set_name('UITest') dialog.set_version('0.0.1') dialog.set_comments('Describe your app here...') dialog.set_website('http://www.teemuharju.net') # Show the dialog. dialog.show() # This is also a callback function. This is called # when you want to close the application. def destroy(self, widget, data=None): gtk.main_quit() # This is the main function that will start the # application. Note that the __init__ function # is always called before this one. def main(self): gtk.main() # This creates the UITest class, ie. runs the __init__ # function and then calls the main function to start # the application. if __name__ == "__main__": uitest = UITest() uitest.main()