-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSidebarPage.py
More file actions
206 lines (173 loc) · 5.46 KB
/
Copy pathSidebarPage.py
File metadata and controls
206 lines (173 loc) · 5.46 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
"""WebKit page template class for pages with a sidebar."""
from Page import Page
class SidebarPage(Page):
"""WebKit page template class for pages with a sidebar.
SidebarPage is an abstract superclass for pages that have a sidebar
(as well as a header and "content well"). Sidebars are normally used
for navigation (e.g., a menu or list of links), showing small bits
of info and occasionally a simple form (such as login or search).
Subclasses should override cornerTitle(), writeSidebar() and
writeContent() (and title() if necessary; see Page).
The utility methods menuHeading() and menuItem() can be used by
subclasses, typically in their implementation of writeSidebar().
WebKit itself uses this class: Examples/ExamplePage and Admin/AdminPage
both inherit from it.
TO DO
* More consequent use style sheets; get rid of tables completely.
* The header, corner and colors are not easy to customize via subclasses.
"""
## StyleSheet ##
_styleSheet = '''
<!--
body {
background-color: white;
color: #080810;
font-size: 11pt;
font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif;
margin: 0pt;
padding: 0pt;
}
h1 { font-size: 18pt; }
h2 { font-size: 16pt; }
h3 { font-size: 14pt; }
h4 { font-size: 12pt; }
h5 { font-size: 11pt; }
table#PageTable {
border-collapse: collapse;
}
td#CornerTitle {
background-color: #101040;
color: white;
padding: 6pt 6pt;
font-size: 14pt;
text-align: center;
vertical-align: middle;
}
td#Banner {
background-color: #202080;
color: white;
padding: 8pt 6pt;
font-size: 16pt;
font-weight: bold;
text-align: center;
vertical-align: middle;
}
td#Sidebar {
background-color: #E8E8F0;
padding: 4pt;
font-size: 10pt;
line-height: 13pt;
vertical-align: top;
white-space: nowrap;
height: 100%;
}
td#Sidebar div {
margin-bottom: 1pt;
}
td#Sidebar div.MenuHeading {
font-weight: bold;
margin-top: 6pt;
margin-bottom: 3pt;
width: 12em;
}
td#Content {
padding: 8pt;
vertical-align: top;
width: 100%;
}
table.NiceTable {
margin-bottom: 4pt;
}
table.NiceTable td, .Data {
background-color: #EEE;
color: #111;
}
table tr th, .SubHeading {
background-color: #CCC;
color: black;
}
table tr.TopHeading th, .TopHeading {
background-color: #555;
color: white;
}
td#Content table tr.NoTable td {
background-color: white;
color: #080810;
}
table.NiceTable th a:link, table.NiceTable th a:visited {
color: #101040;
}
-->
'''
def writeStyleSheet(self):
"""We're using a simple internal style sheet.
This way we avoid having to care about where an external style
sheet should be located when this class is used in another context.
"""
self.writeln('<style type="text/css">%s</style>' % self._styleSheet)
## Content methods ##
def writeBodyParts(self):
wr = self.writeln
wr('<table id="PageTable">')
self.writeBanner()
wr('<tr><td id="Sidebar">')
self.writeSidebar()
wr('</td>')
wr('<td id="Content">')
self.writeContent()
wr('</td>')
wr('</tr></table>')
def writeBanner(self):
self.writeln('<tr><td id="CornerTitle">%s</td>' % self.cornerTitle(),
'<td id="Banner">%s</td></tr>' % self.title())
def writeSidebar(self):
self.writeWebKitSidebarSections()
@staticmethod
def cornerTitle():
return ''
## Menu ##
def menuHeading(self, title):
self.writeln('<div class="MenuHeading">%s</div>' % title)
def menuItem(self, title, url=None, suffix=None, indentLevel=1):
if suffix:
suffix = ' ' + suffix
else:
suffix = ''
if url is not None:
title = '<a href="%s">%s</a>' % (url, title)
self.writeln('<div style="margin-left:%dpt">%s%s</div>'
% (4*indentLevel, title, suffix))
## WebKit sidebar sections ##
def writeWebKitSidebarSections(self):
"""Write sidebar sections.
This method (and consequently the methods it invokes)
are provided for WebKit's example and admin pages.
It writes sections such as contexts, e-mails, exits and versions.
"""
self.writeContextsMenu()
self.writeWebwareEmailMenu()
self.writeWebwareExitsMenu()
self.writeVersions()
def writeContextsMenu(self):
self.menuHeading('Contexts')
servletPath = self.request().servletPath()
for ctx in sorted(ctx for ctx in self.application().contexts()
if ctx != 'default' and not '/' in ctx):
self.menuItem(ctx, '%s/%s/' % (servletPath, ctx))
def writeWebwareEmailMenu(self):
self.menuHeading('E-mail')
self.menuItem('webware-discuss',
'mailto:webware-discuss@lists.sourceforge.net')
def writeWebwareExitsMenu(self):
self.menuHeading('Exits')
self.menuItem('Webware', 'https://webwareforpython.github.io/w4py/')
self.menuItem('Python', 'http://www.python.org')
def writeVersions(self):
app = self.application()
self.menuHeading('Versions')
self.menuItem('WebKit ' + app.webKitVersionString())
self.menuItem('Webware ' + app.webwareVersionString())
from sys import version
self.menuItem('Python ' + version.split(None, 1)[0])
def writeContent(self):
self.writeln('Woops, someone forgot to override writeContent().')