View page as slide show

Graphical User Interfaces (GUI)

Maemo environment

  • 2 Main toolkits GTK+ & Qt
  • GTK toolkits (pyGTK & Python Hildon)
    • OOD based on Glib Object system (GObject)
    • GTK is noteable used in the GNOME project
    • Hildon still depends on GTK
    • Hildon has a long history and probably most straight foward choice
  • Qt toolkits (PySide & PyQt )
    • This set have brighter future compared to previous
    • PySide python bind for Qt is from Nokia OpenBossa project
    • PyQt is developed by Riverbank computing - its probably the hotest in current market
      • Visual (widgets like buttons etc) & non-visual (timers, painter etc) object
      • Singals (events emitted when internal object property changes) & slots (if connected to object its auto-executed)

PyGTK sample

#!/usr/bin/env python2.5
import gtk
 
class FileChooserApp:
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)                   # create new gtk window
        menu_bar = self.create_menu()                                   # create a new menu bar
        vbox = gtk.VBox(False, 10)                                      # the vertical box
        vbox.pack_start(menu_bar, False, False, 0)                      # add the menu bar to top
        button = gtk.Button("Choose a file...")                         # new button   
        button.connect("clicked", self.button_fileChooser, self.window) #activate clicked signal & tie it button_fileChooser() inheriting from self.window
        vbox.pack_start(button)                                         # add second item to vertical box
        self.window.add(vbox)                                           # add the vbox to the window
 
    def create_menu(self):                                                 #create a simple menu - #self#   
        menu_bar = gtk.MenuBar()
        menu = gtk.Menu()
        menuItemOpen = gtk.MenuItem("Open")
        menu.append(menuItemOpen)
        menuItemFile = gtk.MenuItem("File")
        menuItemFile.set_submenu(menu)
        menu_bar.append(menuItemFile)
        menuItemOpen.connect("activate", self.button_fileChooser, self.window)
        return menu_bar

PyGTK sample ...

    def button_fileChooser(widget, button, window):
        #Calling gtk in-built file chooser 
        chooser = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))   
        response = chooser.run()   
        if response == gtk.RESPONSE_OK:
            print chooser.get_filename(), 'selected'
        elif response == gtk.RESPONSE_CANCEL:
            print 'Closed, no files selected'
        chooser.destroy()
    
    def run(self):
        self.window.connect("destroy", gtk.main_quit)
        self.window.show_all()
        gtk.main()

if __name__ == "__main__":
    app = FileChooserApp()
    app.run()

Hildon GTK sample

#!/usr/bin/env python2.5
import gtk
import hildon

class Widgets(hildon.Program):   
    def __init__(self):                                               # class constructor
       hildon.Program.__init__(self)
       self.window = hildon.Window()                                  # new hildon window
       self.window.connect("delete_event", self.quit)                 # enable associate window delete/close event with quit()
       self.window.set_title("HildonHelloGUI - few widgets")          # hildon hello GUI
       self.add_window(self.window)
       hbox = gtk.HBox(False, 10)                                     # layout details - homogenous, spacing 
       vbox1 = gtk.VBox(False, 10)
       vbox2 = gtk.VBox(False, 10)
       button = gtk.Button("Calendar Popup")                          #new gtk.buttons,actvate signals & tie their functionalites
       button.connect("clicked", self.button_callendar, self.window)  # activate clicked signal to button_callendar() & tie it to self.window
       vbox1.pack_start(button)                                       # place on appropiate vbox 
       button = gtk.Button("Font Dialog")                              #Font Selector
       button.connect("clicked", self.button_font_selector, self.window)
       vbox2.pack_start(button)
       
       button = gtk.Button("Login Prompt")                                #Password
       button.connect("clicked", self.button_login, self.window)
       vbox1.pack_start(button)
  
       button = gtk.Button("Confirmation Note")
       button.connect("clicked", self.button_note, self.window)
       vbox2.pack_start(button)

Hildon GTK sample ...

       button = gtk.Button("Time Picker")                                #Time Picker
       button.connect("clicked", self.button_time_picker, self.window)
       vbox1.pack_start(button)

       button = gtk.Button("Code Dialog")                                #Code Dialog
       button.connect("clicked", self.button_code_dialog, self.window)
       vbox2.pack_start(button)

       button = gtk.Button("Sort Dialog")                               #Sort Dialog
       button.connect("clicked", self.button_sort_dialog, self.window)
       vbox1.pack_start(button)
      
       button = gtk.Button("Set Password Dialog")                        #Set Password Dialog
       button.connect("clicked", self.button_set_password, self.window)
       vbox2.pack_start(button)

       hbox.add(vbox1)
       hbox.add(vbox2)
      
       self.window.add(hbox)                                             #Adding Vbox
       self.window.show_all()
   
    def quit(self, *args):                                               # quit entire gtk toolkit
       gtk.main_quit()

Hildon GTK sample ...

    def button_callendar(widget, button, window):
       dialog = hildon.CalendarPopup(window, 2008, 04, 29)
       dialog.run()
       date_tuple = dialog.get_date()
       dialog.destroy()
     
    def button_font_selector(widget, button, window):
       fontDialog = hildon.FontSelectionDialog(window, "Choose a font...")
       fontDialog.set_preview_text ("Hildon Widgets")
       fontDialog.run()
       fontDialog.hide()

    def button_login(widget, button, window):
        dialog = hildon.LoginDialog(window)
        response = dialog.run()
        dialog.hide()
        dialog.destroy()

    def button_note(widget, button, window):
        dialog = hildon.Note ("confirmation", (window, "Do you confirm?", gtk.STOCK_DIALOG_WARNING) )
        dialog.set_button_texts ("Yes", "No")
        response = dialog.run()
        dialog.destroy()
   

Hildon GTK sample ...

 def button_time_picker(widget, button, window):
       time_picker = hildon.TimePicker(window)
       response = time_picker.run()
       time_picker.hide()
      
    def button_code_dialog(widget, button, window):
       dialog = hildon.CodeDialog()
       response = dialog.run()
       dialog.hide()

    def button_sort_dialog(widget, button, window):
        dialog = hildon.SortDialog(window)
        response = dialog.run()
        dialog.hide()

    def button_set_password(widget, button, window):
       dialog = hildon.SetPasswordDialog(window, False)
       response = dialog.run()
       dialog.hide()
  
    def run(self):
       self.window.show_all()
       gtk.main()

if __name__ == "__main__":
   app = Widgets()
   app.run()

PyQt4 sample

#!/usr/bin/env python2.5
import sys
from PyQt4 import QtCore, QtGui

class Application(QtGui.QApplication):
    def __init__(self):
        QtGui.QApplication.__init__(self, sys.argv)
        QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.BlankCursor));
        
        self.window = QtGui.QWidget()
        self.window.setWindowTitle(self.tr("Hello World"));
        self.button = QtGui.QPushButton(self.tr("Press Me"), self.window)
        
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.button, QtCore.Qt.AlignCenter)
        self.window.setLayout(layout)

        self.connect(self.button, QtCore.SIGNAL('clicked()'), self.handlePressed)
        self.window.show()

    def run(self):
        return self.exec_()

    def handlePressed(self):
        QtGui.QMessageBox.information(self.window, self.tr("Info"), self.tr("Hello World!!!"))
        
if __name__ == "__main__":
    app = Application()
    sys.exit(app.run())

Other GUI alternatives

  • Glade
  • RAD tool for quick & easy development
  • Based on GTK & Gnome desktop environment
  • Glade XML supported in C, C++, C#, Vala, Java, Perl, Python etc

Next HR

  • Libosso
  • Bluetooth part 1
Last modified: 2013/07/01 14:41