1 """Provide a standard window for displaying application information."""
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
)
15 def close(iw
, event
=None, data
=None):
18 self
.connect("delete_event", close
)
21 self
.vbox
.pack_start(hbox
)
25 path
=os
.path
.join(rox
.app_dir
, '.DirIcon')
26 pixbuf
=g
.gdk
.pixbuf_new_from_file(path
)
28 icon
.set_from_pixbuf(pixbuf
)
32 #rox.report_exception()
36 hbox
.pack_start(table
)
38 label
=g
.Label("Program")
39 table
.attach(label
, 0, 1, 0, 1)
42 frame
.set_shadow_type(g
.SHADOW_IN
)
43 table
.attach(frame
, 1, 2, 0, 1)
45 label
=g
.Label(program
or '')
48 label
=g
.Label("Purpose")
49 table
.attach(label
, 0, 1, 1, 2)
52 frame
.set_shadow_type(g
.SHADOW_IN
)
53 table
.attach(frame
, 1, 2, 1, 2)
55 label
=g
.Label(purpose
or '')
58 label
=g
.Label("Version")
59 table
.attach(label
, 0, 1, 2, 3)
62 frame
.set_shadow_type(g
.SHADOW_IN
)
63 table
.attach(frame
, 1, 2, 2, 3)
65 label
=g
.Label(version
or '')
68 label
=g
.Label("Authors")
69 table
.attach(label
, 0, 1, 3, 4)
72 frame
.set_shadow_type(g
.SHADOW_IN
)
73 table
.attach(frame
, 1, 2, 3, 4)
75 label
=g
.Label(author
or '')
78 label
=g
.Label("Web site")
79 table
.attach(label
, 0, 1, 5, 6)
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
)
92 frame
.set_shadow_type(g
.SHADOW_IN
)
93 table
.attach(frame
, 1, 2, 5, 6)
97 button
= g
.Button(stock
= g
.STOCK_CLOSE
)
98 hbox
.pack_start(button
)
100 def dismiss(widget
, iw
):
103 button
.connect("clicked", dismiss
, self
)
108 from xml
.dom
import Node
, minidom
, XML_NAMESPACE
112 """Return all the text directly inside this DOM Node."""
113 return ''.join([text
.nodeValue
for text
in node
.childNodes
114 if text
.nodeType
== Node
.TEXT_NODE
])
117 """Parsed AppInfo.xml file. Current only deals with the <About>
120 def __init__(self
, source
):
121 """Read the file and parse the <About> element."""
122 self
.doc
=minidom
.parse(source
)
125 for ab
in self
.doc
.documentElement
.getElementsByTagName('About'):
126 lang
=ab
.getAttributeNS(XML_NAMESPACE
, 'lang')
129 for node
in ab
.childNodes
:
130 if node
.nodeType
!= Node
.ELEMENT_NODE
:
133 self
.about
[lang
][name
]=data(node
)
135 def getAbout(self
, elname
, langs
=None):
136 """Return an entry from the <About> section.
137 elname is the name of the element to return text from
138 langs is a list of acceptable languages, or None to use rox.i18n.langs
144 if self
.about
.has_key(lang
):
145 if self
.about
[lang
].has_key(elname
):
146 return self
.about
[lang
][elname
]
148 if self
.about
[''].has_key(elname
):
149 return self
.about
[''][elname
]
153 def infowin(pname
, info
=None):
154 """Open info window for this program. info is a source of the
155 AppInfo.xml file, if None then $APP_DIR/AppInfo.xml is loaded instead"""
158 info
=os
.path
.join(rox
.app_dir
, 'AppInfo.xml')
161 app_info
=AppInfo(info
)
163 rox
.report_exception()
167 iw
=InfoWin(pname
, app_info
.getAbout('Purpose'),
168 app_info
.getAbout('Version'), app_info
.getAbout('Authors'),
169 app_info
.getAbout('Homepage'))
173 rox
.report_exception()