/
about_dialog.py
142 lines (113 loc) · 4.06 KB
/
about_dialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#------------------------------------------------------------------------------
#
# Copyright (c) 2005, Enthought, Inc.
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in enthought/LICENSE.txt and may be redistributed only
# under the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
#
# Author: Enthought, Inc.
#
#------------------------------------------------------------------------------
""" Enthought pyface package component
"""
# Standard library imports.
import sys
# Major package imports.
import wx
import wx.html
import wx.lib.wxpTag
# Enthought library imports.
from enthought.traits.api import implements, Instance, List, Unicode
# Local imports.
from enthought.pyface.i_about_dialog import IAboutDialog, MAboutDialog
from enthought.pyface.image_resource import ImageResource
from dialog import Dialog
_DIALOG_TEXT = '''
<html>
<body>
<center>
<table width="100%%" cellspacing="4" cellpadding="0" border="0">
<tr>
<td align="center">
<p>
<img src="%s" alt="">
</td>
</tr>
</table>
<p>
%s<br>
<br>
Python %s<br>
wxPython %s<br>
</p>
<p>
Copyright © 2003-2010 Enthought, Inc.
</p>
<p>
<wxp module="wx" class="Button">
<param name="label" value="%s">
<param name="id" value="ID_OK">
</wxp>
</p>
</center>
</body>
</html>
'''
class AboutDialog(MAboutDialog, Dialog):
""" The toolkit specific implementation of an AboutDialog. See the
IAboutDialog interface for the API documentation.
"""
implements(IAboutDialog)
#### 'IAboutDialog' interface #############################################
additions = List(Unicode)
image = Instance(ImageResource, ImageResource('about'))
###########################################################################
# Protected 'IDialog' interface.
###########################################################################
def _create_contents(self, parent):
if parent.GetParent() is not None:
title = parent.GetParent().GetTitle()
else:
title = ""
# Set the title.
self.title = "About %s" % title
# Load the image to be displayed in the about box.
image = self.image.create_image()
path = self.image.absolute_path
# The additional strings.
additions = '<br />'.join(self.additions)
# The width of a wx HTML window is fixed (and is given in the
# constructor). We set it to the width of the image plus a fudge
# factor! The height of the window depends on the content.
width = image.GetWidth() + 80
html = wx.html.HtmlWindow(parent, -1, size=(width, -1))
# Get the version numbers.
py_version = sys.version[0:sys.version.find("(")]
wx_version = wx.VERSION_STRING
# Get the text of the OK button.
if self.ok_label is None:
ok = "OK"
else:
ok = self.ok_label
# Set the page contents.
html.SetPage(
_DIALOG_TEXT % (path, additions, py_version, wx_version, ok)
)
# Make the 'OK' button the default button.
ok_button = html.FindWindowById(wx.ID_OK)
ok_button.SetDefault()
# Set the height of the HTML window to match the height of the content.
internal = html.GetInternalRepresentation()
html.SetSize((-1, internal.GetHeight()))
# Make the dialog client area big enough to display the HTML window.
# We add a fudge factor to the height here, although I'm not sure why
# it should be necessary, the HTML window should report its required
# size!?!
width, height = html.GetSize()
parent.SetClientSize((width, height + 10))
### EOF #######################################################################