Favorites support
[gonvert] / src / hildonize.py
index 22ec02f..339eb2a 100755 (executable)
@@ -2,6 +2,7 @@
 
 """
 Open Issues
+       @bug not all of a message is shown
        @bug Buttons are too small
 """
 
@@ -46,24 +47,26 @@ except AttributeError:
        get_app_class = _null_get_app_class
 
 
-def _hildon_set_application_title(window, title):
-       pass
+def _hildon_set_application_name(name):
+       gtk.set_application_name(name)
 
 
-def _null_set_application_title(window, title):
-       window.set_title(title)
+def _null_set_application_name(name):
+       pass
 
 
-if IS_HILDON_SUPPORTED:
-       set_application_title = _hildon_set_application_title
-else:
-       set_application_title = _null_set_application_title
+try:
+       gtk.set_application_name
+       set_application_name = _hildon_set_application_name
+except AttributeError:
+       set_application_name = _null_set_application_name
 
 
 def _fremantle_hildonize_window(app, window):
        oldWindow = window
        newWindow = hildon.StackableWindow()
-       oldWindow.get_child().reparent(newWindow)
+       if oldWindow.get_child() is not None:
+               oldWindow.get_child().reparent(newWindow)
        app.add_window(newWindow)
        return newWindow
 
@@ -71,7 +74,8 @@ def _fremantle_hildonize_window(app, window):
 def _hildon_hildonize_window(app, window):
        oldWindow = window
        newWindow = hildon.Window()
-       oldWindow.get_child().reparent(newWindow)
+       if oldWindow.get_child() is not None:
+               oldWindow.get_child().reparent(newWindow)
        app.add_window(newWindow)
        return newWindow
 
@@ -91,16 +95,14 @@ except AttributeError:
                hildonize_window = _null_hildonize_window
 
 
-def _fremantle_hildonize_menu(window, gtkMenu, buttons):
+def _fremantle_hildonize_menu(window, gtkMenu):
        appMenu = hildon.AppMenu()
-       for button in buttons:
-               appMenu.append(button)
        window.set_app_menu(appMenu)
        gtkMenu.get_parent().remove(gtkMenu)
        return appMenu
 
 
-def _hildon_hildonize_menu(window, gtkMenu, ignoredButtons):
+def _hildon_hildonize_menu(window, gtkMenu):
        hildonMenu = gtk.Menu()
        for child in gtkMenu.get_children():
                child.reparent(hildonMenu)
@@ -109,7 +111,7 @@ def _hildon_hildonize_menu(window, gtkMenu, ignoredButtons):
        return hildonMenu
 
 
-def _null_hildonize_menu(window, gtkMenu, ignoredButtons):
+def _null_hildonize_menu(window, gtkMenu):
        return gtkMenu
 
 
@@ -189,6 +191,20 @@ else:
        set_cell_thumb_selectable = _null_set_cell_thumb_selectable
 
 
+def _hildon_set_pix_cell_thumb_selectable(renderer):
+       renderer.set_property("stock-size", 48)
+
+
+def _null_set_pix_cell_thumb_selectable(renderer):
+       pass
+
+
+if IS_HILDON_SUPPORTED:
+       set_pix_cell_thumb_selectable = _hildon_set_pix_cell_thumb_selectable
+else:
+       set_pix_cell_thumb_selectable = _null_set_pix_cell_thumb_selectable
+
+
 def _fremantle_show_information_banner(parent, message):
        hildon.hildon_banner_show_information(parent, "", message)
 
@@ -264,30 +280,16 @@ else:
        hildonize_text_entry = _null_hildonize_text_entry
 
 
-def _hildon_mark_window_rotatable(window):
-       # gtk documentation is unclear whether this does a "=" or a "|="
-       window.set_flags(hildon.HILDON_PORTRAIT_MODE_SUPPORT)
-
-
-def _null_mark_window_rotatable(window):
-       pass
-
-
-try:
-       hildon.HILDON_PORTRAIT_MODE_SUPPORT
-       mark_window_rotatable = _hildon_mark_window_rotatable
-except AttributeError:
-       mark_window_rotatable = _null_mark_window_rotatable
-
-
 def _hildon_window_to_portrait(window):
        # gtk documentation is unclear whether this does a "=" or a "|="
-       window.set_flags(hildon.HILDON_PORTRAIT_MODE_SUPPORT)
+       flags = hildon.PORTRAIT_MODE_SUPPORT | hildon.PORTRAIT_MODE_REQUEST
+       hildon.hildon_gtk_window_set_portrait_flags(window, flags)
 
 
 def _hildon_window_to_landscape(window):
        # gtk documentation is unclear whether this does a "=" or a "&= ~"
-       window.unset_flags(hildon.HILDON_PORTRAIT_MODE_REQUEST)
+       flags = hildon.PORTRAIT_MODE_SUPPORT
+       hildon.hildon_gtk_window_set_portrait_flags(window, flags)
 
 
 def _null_window_to_portrait(window):
@@ -299,8 +301,9 @@ def _null_window_to_landscape(window):
 
 
 try:
-       hildon.HILDON_PORTRAIT_MODE_SUPPORT
-       hildon.HILDON_PORTRAIT_MODE_REQUEST
+       hildon.PORTRAIT_MODE_SUPPORT
+       hildon.PORTRAIT_MODE_REQUEST
+       hildon.hildon_gtk_window_set_portrait_flags
 
        window_to_portrait = _hildon_window_to_portrait
        window_to_landscape = _hildon_window_to_landscape
@@ -356,6 +359,28 @@ else:
        hildonize_combo_entry = _null_hildonize_combo_entry
 
 
+def _null_create_seekbar():
+       adjustment = gtk.Adjustment(0, 0, 101, 1, 5, 1)
+       seek = gtk.HScale(adjustment)
+       seek.set_draw_value(False)
+       return seek
+
+
+def _fremantle_create_seekbar():
+       seek = hildon.Seekbar()
+       seek.set_range(0.0, 100)
+       seek.set_draw_value(False)
+       seek.set_update_policy(gtk.UPDATE_DISCONTINUOUS)
+       return seek
+
+
+try:
+       hildon.Seekbar
+       create_seekbar = _fremantle_create_seekbar
+except AttributeError:
+       create_seekbar = _null_create_seekbar
+
+
 def _fremantle_hildonize_scrollwindow(scrolledWindow):
        pannableWindow = hildon.PannableArea()
 
@@ -708,12 +733,21 @@ if __name__ == "__main__":
        win = gtk.Window()
        win.add(label)
        win = hildonize_window(app, win)
-       if False:
+       if False and IS_FREMANTLE_SUPPORTED:
+               appMenu = hildon.AppMenu()
+               for i in xrange(5):
+                       b = gtk.Button(str(i))
+                       appMenu.append(b)
+               win.set_app_menu(appMenu)
+               win.show_all()
+               appMenu.show_all()
+               gtk.main()
+       elif False:
                print touch_selector(win, "Test", ["A", "B", "C", "D"], 2)
-       if True:
+       elif False:
                print touch_selector_entry(win, "Test", ["A", "B", "C", "D"], "C")
                print touch_selector_entry(win, "Test", ["A", "B", "C", "D"], "Blah")
-       if False:
+       elif False:
                import pprint
                name, value = "", ""
                goodLocals = [
@@ -721,11 +755,11 @@ if __name__ == "__main__":
                        if not name.startswith("_")
                ]
                pprint.pprint(goodLocals)
-       if False:
+       elif False:
                import time
                show_information_banner(win, "Hello World")
                time.sleep(5)
-       if False:
+       elif False:
                import time
                banner = show_busy_banner_start(win, "Hello World")
                time.sleep(5)