8 class FakeHildonModule(object):
14 except (ImportError, OSError):
15 hildon = FakeHildonModule
18 IS_HILDON = hildon is not FakeHildonModule
21 class FakeHildonProgram(object):
30 return FakeHildonProgram
34 def set_application_title(window, title):
37 def set_application_title(window, title):
38 window.set_title(title)
42 def hildonize_window(app, window):
44 newWindow = hildon.Window()
45 oldWindow.get_child().reparent(newWindow)
46 app.add_window(newWindow)
49 def hildonize_window(app, window):
54 def hildonize_menu(window, gtkMenu):
55 hildonMenu = gtk.Menu()
56 for child in gtkMenu.get_children():
57 child.reparent(hildonMenu)
58 window.set_menu(hildonMenu)
62 def hildonize_menu(window, gtkMenu):
67 def set_cell_thumb_selectable(renderer):
68 renderer.set_property("scale", 1.5)
70 def set_cell_thumb_selectable(renderer):
75 def hildonize_text_entry(textEntry):
76 textEntry.set_property('hildon-input-mode', 7)
78 def hildonize_text_entry(textEntry):
83 hildon.HILDON_PORTRAIT_MODE_SUPPORT
85 def mark_window_rotatable(window):
86 # gtk documentation is unclear whether this does a "=" or a "|="
87 window.set_flags(hildon.HILDON_PORTRAIT_MODE_SUPPORT)
88 except AttributeError:
89 def mark_window_rotatable(window):
94 hildon.HILDON_PORTRAIT_MODE_SUPPORT
95 hildon.HILDON_PORTRAIT_MODE_REQUEST
97 def window_to_portrait(window):
98 # gtk documentation is unclear whether this does a "=" or a "|="
99 window.set_flags(hildon.HILDON_PORTRAIT_MODE_SUPPORT)
101 def window_to_landscape(window):
102 # gtk documentation is unclear whether this does a "=" or a "&= ~"
103 window.unset_flags(hildon.HILDON_PORTRAIT_MODE_REQUEST)
104 except AttributeError:
105 def window_to_portrait(window):
108 def window_to_landscape(window):
112 def get_device_orientation():
113 bus = dbus.SystemBus()
115 rawMceRequest = bus.get_object("com.nokia.mce", "/com/nokia/mce/request")
116 mceRequest = dbus.Interface(rawMceRequest, dbus_interface="com.nokia.mce.request")
117 orientation, standState, faceState, xAxis, yAxis, zAxis = mceRequest.get_device_orientation()
118 except dbus.exception.DBusException:
119 # catching for documentation purposes that when a system doesn't
120 # support this, this is what to expect
123 if orientation == "":
124 return gtk.ORIENTATION_HORIZONTAL
125 elif orientation == "":
126 return gtk.ORIENTATION_VERTICAL
128 raise RuntimeError("Unknown orientation: %s" % orientation)
132 def hildonize_password_entry(textEntry):
133 textEntry.set_property('hildon-input-mode', 7 | (1 << 29))
135 def hildonize_password_entry(textEntry):
140 def hildonize_combo_entry(comboEntry):
141 comboEntry.set_property('hildon-input-mode', 1 << 4)
143 def hildonize_combo_entry(textEntry):
150 def set_thumb_scrollbar(scrolledWindow):
151 pannableWindow = hildon.PannableArea()
153 child = scrolledWindow.get_child()
154 scrolledWindow.remove(child)
155 pannableWindow.add(child)
157 parent = scrolledWindow.get_parent()
158 parent.remove(scrolledWindow)
159 parent.add(pannableWindow)
161 return pannableWindow
162 except AttributeError:
164 hildon.hildon_helper_set_thumb_scrollbar
165 def set_thumb_scrollbar(scrolledWindow):
166 hildon.hildon_helper_set_thumb_scrollbar(scrolledWindow, True)
167 return scrolledWindow
168 except AttributeError:
169 def set_thumb_scrollbar(scrolledWindow):
170 return scrolledWindow
174 hildon.NumberEditor # TODO deprecated in fremantle
175 def request_number(parent, title, range, default):
176 spinner = hildon.NumberEditor(*range)
177 spinner.set_value(default)
182 gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT,
183 (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL),
185 dialog.set_default_response(gtk.RESPONSE_CANCEL)
186 dialog.get_child().add(spinner)
190 response = dialog.run()
194 if response == gtk.RESPONSE_OK:
195 return spinner.get_value()
196 elif response == gtk.RESPONSE_CANCEL or response == gtk.RESPONSE_DELETE_EVENT:
197 raise RuntimeError("User cancelled request")
199 raise RuntimeError("Unrecognized response %r", response)
200 except AttributeError:
201 def request_number(parent, title, range, default):
202 adjustment = gtk.Adjustment(default, range[0], range[1], 1, 5, 0)
203 spinner = gtk.SpinButton(adjustment, 0, 0)
204 spinner.set_wrap(False)
209 gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT,
210 (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL),
212 dialog.set_default_response(gtk.RESPONSE_CANCEL)
213 dialog.get_child().add(spinner)
217 response = dialog.run()
221 if response == gtk.RESPONSE_OK:
222 return spinner.get_value_as_int()
223 elif response == gtk.RESPONSE_CANCEL or response == gtk.RESPONSE_DELETE_EVENT:
224 raise RuntimeError("User cancelled request")
226 raise RuntimeError("Unrecognized response %r", response)