比这篇新的文章: Python Cookbook: 比系统自带的更加友好的makedir函数
比这篇旧的文章: 猜数字游戏8步以内的完全求解决策树生成程序

PolicyKit SetTimeZone Demo

语言: Python, 标签: python dbus 2008/06/24发布 1年前更新
作者: TualatriX, 点击802次, 评论(0), 收藏者(0), , 打分:

背景
主题: 字体:
01 #!/usr/bin/python
02
03 import os
04 import gtk
05 import dbus
06
07 class A:
08     def __init__(self):
09         self.w = gtk.Window()
10         b = gtk.Button('Hello')
11         b.connect("clicked", self.on_clicked)
12
13         self.w.add(b)
14         self.w.show_all()
15
16     def main(self):
17         gtk.main()
18
19     def on_clicked(self, widget):
20         session_bus =  dbus.SessionBus()
21         system_bus = dbus.SystemBus()
22
23         polkit_gnome_proxy = session_bus.get_object('org.freedesktop.PolicyKit.AuthenticationAgent', '/', "org.freedesktop.PolicyKit.AuthenticationAgent")
24
25         grant = polkit_gnome_proxy.ObtainAuthorization("org.gnome.clockapplet.mechanism.settimezone", self.w.window.xid, os.getpid(), dbus_interface='org.freedesktop.PolicyKit.AuthenticationAgent')
26
27         if grant == 1:
28             mechanism_proxy = system_bus.get_object('org.gnome.ClockApplet.Mechanism', '/', "org.gnome.ClockApplet.Mechanism")
29
30             dialog = gtk.FileChooserDialog("Select zonefile",
31                     None,
32                     gtk.FILE_CHOOSER_ACTION_OPEN,
33                     (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
34
35             dialog.set_current_folder('/usr/share/zoneinfo')
36             if dialog.run() == gtk.RESPONSE_ACCEPT:
37                 filename = dialog.get_filename()
38                 dialog.destroy()
39
40             mechanism_proxy.SetTimezone(filename, dbus_interface='org.gnome.ClockApplet.Mechanism')
41
42
43 if __name__ == "__main__":
44     base = A()
45     base.main()


所有评论,共0条:( 我也来说两句)


发表评论

注册登录后再发表评论