我制作了一个单独的模块来处理我在普通 Linux、Maemo 4.1 和 Maemo 5 之间的所有专长。它检测可用的功能并允许程序优雅地降级。
例如
def _fremantle_hildonize_window(app, window):
oldWindow = window
newWindow = hildon.StackableWindow()
oldWindow.get_child().reparent(newWindow)
app.add_window(newWindow)
return newWindow
def _hildon_hildonize_window(app, window):
oldWindow = window
newWindow = hildon.Window()
oldWindow.get_child().reparent(newWindow)
app.add_window(newWindow)
return newWindow
def _null_hildonize_window(app, window):
return window
try:
hildon.StackableWindow
hildonize_window = _fremantle_hildonize_window
except AttributeError:
try:
hildon.Window
hildonize_window = _hildon_hildonize_window
except AttributeError:
hildonize_window = _null_hildonize_window
有关更多信息,请参阅 Dialcentral、Gonert、ejpi 或 Quicknote 的源代码,以获取名为 hildonize.py 的文件
https://garage.maemo.org/plugins/ggit/browse.php/?p=gc-dialer;a=blob; f=src/hildonize.py;
The One Ring 的 GObject Utils (go_utils.py) 的另一个示例
def _old_timeout_add_seconds(timeout, callback):
return gobject.timeout_add(timeout * 1000, callback)
def _timeout_add_seconds(timeout, callback):
return gobject.timeout_add_seconds(timeout, callback)
try:
gobject.timeout_add_seconds
timeout_add_seconds = _timeout_add_seconds
except AttributeError:
timeout_add_seconds = _old_timeout_add_seconds