-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha_test.py
333 lines (297 loc) · 9.82 KB
/
a_test.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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# a_test.py
# Copyrighted (C) 2009 by Conrad "Lynx" Wong
# Test dialog using the Kytten GUI
import os
import pyglet
# Disable error checking for increased performance
pyglet.options['debug_gl'] = False
from pyglet import gl
VERSION = '5.9'
import kytten
from background import Background
# Default theme, gold-colored
theme = kytten.Theme(os.path.join(os.getcwd(), 'theme'), override={
"gui_color": [64, 128, 255, 255],
"font_size": 14
})
# Default theme, blue-colored
theme2 = kytten.Theme(theme, override={
"gui_color": [255, 235, 128, 255],
"font_size": 12
})
# Callback functions for dialogs which may be of interest
def on_escape(dialog):
dialog.teardown()
def create_document_dialog():
document = pyglet.text.decode_attributed('''
With {bold True}kytten{bold False}, you can harness the power of
{underline (255, 255, 255, 255)}pyglet{underline None}'s documents in a
scrollable window!
{font_name "Courier New"}Change fonts{font_name Lucia Grande},
{italic True}italicize your text,{italic False} and more!
{align "center"}Center yourself!{align "left"}{}
{align "right"}Or go right.{align "left"}
{color (128, 255, 128, 255)}
Express
{color (255, 128, 128, 255)}
yourself
{color (128, 128, 255, 255)}
colorfully!
{color (255, 255, 255, 255}
''')
dialog = kytten.Dialog(
kytten.Frame(
kytten.Document(document, width=300, height=150)
),
window=window, batch=batch, group=fg_group,
anchor=kytten.ANCHOR_CENTER,
theme=theme2, on_escape=on_escape)
def create_form_dialog():
dialog = None
def on_enter(dialog):
print "Form submitted!"
for key, value in dialog.get_values().iteritems():
print " %s=%s" % (key, value)
on_escape(dialog)
def on_submit():
on_enter(dialog)
def on_cancel():
print "Form canceled."
on_escape(dialog)
dialog = kytten.Dialog(
kytten.Frame(
kytten.Scrollable(
kytten.VerticalLayout([
kytten.SectionHeader("Personnel Data",
align=kytten.HALIGN_LEFT),
kytten.Document("Try tabbing through fields, "
"if offscreen they'll be moved "
"automatically",
width=500),
kytten.GridLayout([
[kytten.Label("Name"), kytten.Input("name", "Lynx",
max_length=20)],
[kytten.Label("Job"), kytten.Input("job", "Cat",
max_length=80)],
[kytten.Label("Hobby"),
kytten.Input("hobby", "Programming")],
[kytten.Label("Class"),
kytten.Input("class", "Druid")],
[kytten.Label("Disabled"),
kytten.Input("disabled", "Disabled input",
disabled=True)],
[kytten.Label("Sign"),
kytten.Input("sign", "Free to good home")],
[kytten.Label("Blood Type"),
kytten.Input("bloodtype", "Red")],
[kytten.Label("Favored Weapon"),
kytten.Input("weapon", "Claws")],
]),
kytten.Checkbox("Full-Time", id="fulltime"),
kytten.Checkbox("Married", id="married", disabled=True),
kytten.SectionHeader("Actions",
align=kytten.HALIGN_LEFT),
kytten.HorizontalLayout([
kytten.Button("Submit", on_click=on_submit),
kytten.Button("Disabled", disabled=True),
None,
kytten.Button("Cancel", on_click=on_cancel),
]),
], align=kytten.HALIGN_LEFT),
height=200, width=360)
),
window=window, batch=batch, group=fg_group,
anchor=kytten.ANCHOR_CENTER,
theme=theme2, on_enter=on_enter, on_escape=on_escape)
def create_scrollable_dialog():
def on_select(choice):
print "Kytten is %s" % choice
def on_set(value):
print "Kytten rating is %0.0f" % value
dialog = kytten.Dialog(
kytten.Frame(
kytten.Scrollable(
kytten.VerticalLayout([
kytten.Label("Rate Kytten from 1 to 10:"),
kytten.Slider(7.0, 1.0, 10.0, steps=9, on_set=on_set),
kytten.Label("This slider is disabled:"),
kytten.Slider(1.0, 1.0, 10.0, steps=9, on_set=on_set,
disabled=True),
kytten.Label("Kytten is..."),
kytten.Menu(options=["Awesome",
"Cute",
"-Disabled Option",
"Excellent",
"Fantastic",
"Great",
"Supercalifragilistiexpialidocious",
"Terrific"],
align=kytten.HALIGN_LEFT, on_select=on_select),
], align=kytten.HALIGN_LEFT),
width=200, height=150)
),
window=window, batch=batch, group=fg_group,
anchor=kytten.ANCHOR_CENTER,
theme=theme2, on_escape=on_escape)
def create_folding_dialog():
document1 = pyglet.text.decode_attributed("""
Click on the section headers below to open them up.
Jellicle Cats is, of course, copyrighted by T. S. Eliot.
""")
document2 = pyglet.text.decode_attributed("""
Jellicle cats come out tonight{}
Jellicle cats come one, come all{}
The Jellicle moon is shining bright{}
Jellicles come to the Jellicle ball
""")
document3 = pyglet.text.decode_attributed("""
Jellicle cats are black and white{}
Jellicle cats are rather small{}
Jellicle cats are merry and bright{}
And pleasant to hear when we caterwaul
""")
document4 = pyglet.text.decode_attributed("""
Jellicle cats have cheerful faces{}
Jellicle cats have bright black eyes{}
We like to practice our airs and graces{}
And wait for the Jellicle moon to rise
""")
dialog = kytten.Dialog(
kytten.Frame(
kytten.Scrollable(
kytten.VerticalLayout([
kytten.SectionHeader("Jellicle Cats"),
kytten.Document(document1, width=300),
kytten.FoldingSection("Verse 1",
kytten.VerticalLayout([
kytten.Document(document2, width=300),
])),
kytten.FoldingSection("Verse 2",
kytten.VerticalLayout([
kytten.Document(document3, width=300),
]), is_open=False),
kytten.FoldingSection("Verse 3",
kytten.VerticalLayout([
kytten.Document(document4, width=300),
]), is_open=False),
], align=kytten.HALIGN_LEFT),
height=400)
),
window=window, batch=batch, group=fg_group,
anchor=kytten.ANCHOR_CENTER,
theme=theme2, on_escape=on_escape)
def create_dropdown_dialog():
def on_select(choice):
print "Selected: %s" % choice
dialog = kytten.Dialog(
kytten.Frame(
kytten.VerticalLayout([
kytten.Label("Select a letter:"),
kytten.Dropdown(['Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon',
'Zeta', 'Eta', 'Theta', 'Iota', 'Kappa',
'Lambda', 'Mu', 'Nu', 'Xi', 'Omicron',
'Pi', 'Rho', 'Sigma', 'Tau', 'Upsilon',
'Phi', 'Chi', 'Psi', 'Omega'],
on_select=on_select),
kytten.Label("This dropdown is disabled"),
kytten.Dropdown(['Disabled', 'Enabled'], disabled=True),
]),
),
window=window, batch=batch, group=fg_group,
anchor=kytten.ANCHOR_CENTER,
theme=theme2, on_escape=on_escape)
def create_file_load_dialog():
dialog = None
def on_select(filename):
print "File load: %s" % filename
on_escape(dialog)
dialog = kytten.FileLoadDialog( # by default, path is current working dir
extensions=['.png', '.jpg', '.bmp', '.gif'],
window=window, batch=batch, group=fg_group,
anchor=kytten.ANCHOR_CENTER,
theme=theme2, on_escape=on_escape, on_select=on_select)
def create_file_save_dialog():
dialog = None
def on_select(filename):
print "File save: %s" % filename
on_escape(dialog)
dialog = kytten.FileSaveDialog( # by default, path is current working dir
extensions=['.png', '.jpg', '.bmp', '.gif'],
window=window, batch=batch, group=fg_group,
anchor=kytten.ANCHOR_CENTER,
theme=theme2, on_escape=on_escape, on_select=on_select)
def create_directory_select_dialog():
dialog = None
def on_select(filename):
print "Directory: %s" % filename
on_escape(dialog)
dialog = kytten.DirectorySelectDialog(
window=window, batch=batch, group=fg_group,
anchor=kytten.ANCHOR_CENTER,
theme=theme2, on_escape=on_escape, on_select=on_select)
def on_select(choice):
if choice == 'Document':
create_document_dialog()
elif choice == 'Form':
create_form_dialog()
elif choice == 'Scrollable':
create_scrollable_dialog()
elif choice == 'Folding':
create_folding_dialog()
elif choice == 'Dropdown':
create_dropdown_dialog()
elif choice == 'File Load':
create_file_load_dialog()
elif choice == 'File Save':
create_file_save_dialog()
elif choice == 'Directory Select':
create_directory_select_dialog()
else:
print "Unexpected menu selection: %s" % choice
if __name__ == '__main__':
window = pyglet.window.Window(
640, 480, caption='Kytten Test %s' % VERSION,
resizable=True, vsync=False)
batch = pyglet.graphics.Batch()
bg_group = pyglet.graphics.OrderedGroup(0)
fg_group = pyglet.graphics.OrderedGroup(1)
fps = pyglet.clock.ClockDisplay()
@window.event
def on_draw():
window.clear()
batch.draw()
fps.draw()
# Update as often as possible (limited by vsync, if not disabled)
window.register_event_type('on_update')
def update(dt):
window.dispatch_event('on_update', dt)
pyglet.clock.schedule(update)
# Set up a background which changes when user hits left or right arrow
background = Background(batch=batch, group=bg_group)
window.push_handlers(background)
# Set up a Dialog to choose test dialogs to show
dialog = kytten.Dialog(
kytten.TitleFrame("Kytten Demo",
kytten.VerticalLayout([
kytten.Label("Select dialog to show"),
kytten.Menu(options=["Document", "Form", "Scrollable",
"Folding", "Dropdown",
"File Load", "File Save",
"Directory Select"],
on_select=on_select),
]),
),
window=window, batch=batch, group=fg_group,
anchor=kytten.ANCHOR_TOP_LEFT,
theme=theme)
# Change this flag to run with profiling and dump top 20 cumulative times
if True:
pyglet.app.run()
else:
import cProfile
cProfile.run('pyglet.app.run()', 'kytten.prof')
import pstats
p = pstats.Stats('kytten.prof')
p.strip_dirs()
p.sort_stats('cumulative')
p.print_stats(20)