Moved into a sub-dir, so that a svn checkout has the same structure as
[rox-lib.git] / ROX-Lib2 / python / rox / InfoWin.py
blob95b8c2d09c49907eaed1b934cf1644899c562d78
1 """Provide a standard window for displaying application information."""
3 import os
5 import rox
6 from rox import g
7 import webbrowser
9 class InfoWin(g.Dialog):
10 """Window to show app info"""
11 def __init__(self, program, purpose, version, author, website):
12 g.Dialog.__init__(self)
13 self.website=website
15 def close(iw, event=None, data=None):
16 iw.hide()
18 self.connect("delete_event", close)
20 hbox=g.HBox()
21 self.vbox.pack_start(hbox)
22 hbox.show()
24 try:
25 path=os.path.join(rox.app_dir, '.DirIcon')
26 pixbuf=g.gdk.pixbuf_new_from_file(path)
27 icon=g.Image()
28 icon.set_from_pixbuf(pixbuf)
29 hbox.pack_start(icon)
30 icon.show()
31 except:
32 #rox.report_exception()
33 pass
35 table=g.Table(5, 2)
36 hbox.pack_start(table)
38 label=g.Label("Program")
39 table.attach(label, 0, 1, 0, 1)
41 frame=g.Frame()
42 frame.set_shadow_type(g.SHADOW_IN)
43 table.attach(frame, 1, 2, 0, 1)
45 label=g.Label(program or '')
46 frame.add(label)
48 label=g.Label("Purpose")
49 table.attach(label, 0, 1, 1, 2)
51 frame=g.Frame()
52 frame.set_shadow_type(g.SHADOW_IN)
53 table.attach(frame, 1, 2, 1, 2)
55 label=g.Label(purpose or '')
56 frame.add(label)
58 label=g.Label("Version")
59 table.attach(label, 0, 1, 2, 3)
61 frame=g.Frame()
62 frame.set_shadow_type(g.SHADOW_IN)
63 table.attach(frame, 1, 2, 2, 3)
65 label=g.Label(version or '')
66 frame.add(label)
68 label=g.Label("Authors")
69 table.attach(label, 0, 1, 3, 4)
71 frame=g.Frame()
72 frame.set_shadow_type(g.SHADOW_IN)
73 table.attach(frame, 1, 2, 3, 4)
75 label=g.Label(author or '')
76 frame.add(label)
78 label=g.Label("Web site")
79 table.attach(label, 0, 1, 5, 6)
81 if website:
82 button=g.Button(website)
83 table.attach(button, 1, 2, 5, 6)
85 def goto_website(widget, iw):
86 webbrowser.open(iw.website)
88 button.connect("clicked", goto_website, self)
90 else:
91 frame=g.Frame()
92 frame.set_shadow_type(g.SHADOW_IN)
93 table.attach(frame, 1, 2, 5, 6)
95 hbox=self.action_area
97 button=g.Button(stock=g.STOCK_CLOSE)
98 hbox.pack_start(button)
100 def dismiss(widget, iw):
101 iw.hide()
103 button.connect("clicked", dismiss, self)
104 button.show()
106 self.vbox.show_all()
108 from rox import AppInfo
110 def infowin(pname, info=None):
111 """Open info window for this program. info is a source of the
112 AppInfo.xml file, if None then $APP_DIR/AppInfo.xml is loaded instead"""
114 if info is None:
115 info=os.path.join(rox.app_dir, 'AppInfo.xml')
117 try:
118 app_info=AppInfo.AppInfo(info)
119 except:
120 rox.report_exception()
121 return
123 try:
124 iw=InfoWin(pname, app_info.getAbout('Purpose')[1],
125 app_info.getAbout('Version')[1],
126 app_info.getAuthors(),
127 app_info.getAbout('Homepage')[1])
128 iw.show()
129 return iw
130 except:
131 rox.report_exception()