1
|
|
|
#!/usr/bin/python2 |
2
|
|
|
# |
3
|
|
|
# Copyright 2001 - 2016 Ludek Smid [http://www.ospace.net/] |
4
|
|
|
# |
5
|
|
|
# This file is part of Pygame.UI. |
6
|
|
|
# |
7
|
|
|
# Pygame.UI is free software; you can redistribute it and/or modify |
8
|
|
|
# it under the terms of the Lesser GNU General Public License as published by |
9
|
|
|
# the Free Software Foundation; either version 2.1 of the License, or |
10
|
|
|
# (at your option) any later version. |
11
|
|
|
# |
12
|
|
|
# Pygame.UI is distributed in the hope that it will be useful, |
13
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
# Lesser GNU General Public License for more details. |
16
|
|
|
# |
17
|
|
|
# You should have received a copy of the Lesser GNU General Public License |
18
|
|
|
# along with Pygame.UI; if not, write to the Free Software |
19
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
20
|
|
|
# |
21
|
|
|
|
22
|
|
|
import sys |
23
|
|
|
sys.path.append('../..') |
24
|
|
|
|
25
|
|
|
# pygame initialization |
26
|
|
|
import pygame |
27
|
|
|
|
28
|
|
|
#initialize SDL and prepare screen |
29
|
|
|
def update(): |
30
|
|
|
global screen |
31
|
|
|
|
32
|
|
|
rects = app.draw(screen) |
33
|
|
|
pygame.display.update(rects) |
34
|
|
|
|
35
|
|
|
pygame.init() |
36
|
|
|
|
37
|
|
|
screen = pygame.display.set_mode((800, 600), pygame.SWSURFACE, 32) |
38
|
|
|
pygame.mouse.set_visible(1) |
39
|
|
|
pygame.display.set_caption('PYGAME.UI 0.4 Test Client') |
40
|
|
|
colorBlack = screen.map_rgb((0x00, 0x00, 0x00)) |
41
|
|
|
pygame.display.flip() |
42
|
|
|
|
43
|
|
|
# create UI |
44
|
|
|
import pygameui as ui |
45
|
|
|
|
46
|
|
|
ui.SkinableTheme.setSkin("./OSSkin") |
47
|
|
|
app = ui.Application(update, theme = ui.SkinableTheme) |
48
|
|
|
app.background = pygame.Surface((800, 600)) |
49
|
|
|
app.background.fill(colorBlack) |
50
|
|
|
app.windowSurfaceFlags = pygame.SWSURFACE |
51
|
|
|
|
52
|
|
|
pygame.event.clear() |
53
|
|
|
|
54
|
|
|
def echoHandler(widget, action, data): |
55
|
|
|
print 'ACTION', widget, action, data |
56
|
|
|
|
57
|
|
|
popUpMenu = ui.Menu(app, title = "Test Menu", |
58
|
|
|
items = [ |
59
|
|
|
ui.Item("Test 1", action = "MENU TEST", data = 1), |
60
|
|
|
ui.Item("Test 2", action = "MENU TEST", data = 2), |
61
|
|
|
], |
62
|
|
|
) |
63
|
|
|
popUpMenu.subscribeAction("*", echoHandler) |
64
|
|
|
|
65
|
|
|
def menuHandler(widget, action, data): |
66
|
|
|
print "MENU" |
67
|
|
|
popUpMenu.show() |
68
|
|
|
|
69
|
|
|
# create status window |
70
|
|
|
progBars = [] |
71
|
|
|
|
72
|
|
|
for i in xrange(0, 2): |
|
|
|
|
73
|
|
|
win = ui.Window(app, font = 'large-bold') |
74
|
|
|
win.title = 'Test WINDOW {0}X'.format(i+1) |
75
|
|
|
#win.alwaysInBackground = 1 |
76
|
|
|
win.rect = pygame.Rect(100 + 10 * i, 100 + 10 * i, 600, 500) |
77
|
|
|
win.layoutManager = ui.SimpleGridLM() |
78
|
|
|
win.rightButtonClose = 0 |
79
|
|
|
w1 = ui.Button(win, |
80
|
|
|
text = '---', |
81
|
|
|
layout = (0, 0, 4, 1), |
82
|
|
|
tooltip = 'This is not real FPS counter.', |
83
|
|
|
) |
84
|
|
|
w1.subscribeAction('*', echoHandler) |
85
|
|
|
ui.Button(win, |
86
|
|
|
text = 'WEST (m)', |
87
|
|
|
statustip = 'This is super new button.', |
88
|
|
|
tooltip = 'Really?', |
89
|
|
|
align = ui.ALIGN_W, |
90
|
|
|
layout = (0, 1, 4, 1), |
91
|
|
|
rmbAction = "menu", |
92
|
|
|
action = "menu", |
93
|
|
|
).subscribeAction("menu", menuHandler) |
94
|
|
|
ui.Button(win, |
95
|
|
|
text = 'EAST', |
96
|
|
|
align = ui.ALIGN_E, |
97
|
|
|
layout = (0, 2, 4, 1) |
98
|
|
|
) |
99
|
|
|
ui.Button(win, |
100
|
|
|
text = 'NORTH', |
101
|
|
|
align = ui.ALIGN_N, |
102
|
|
|
layout = (0, 3, 4, 1) |
103
|
|
|
) |
104
|
|
|
ui.Button(win, |
105
|
|
|
text = 'SOUTH', |
106
|
|
|
align = ui.ALIGN_S, |
107
|
|
|
layout = (0, 4, 4, 1) |
108
|
|
|
) |
109
|
|
|
icon1 = pygame.image.load('img.png') |
110
|
|
|
icon2 = pygame.image.load('reddot.png') |
111
|
|
|
ui.Button(win, |
112
|
|
|
text = 'HELLO!', |
113
|
|
|
icons = ( |
114
|
|
|
(icon1, ui.ALIGN_NW), |
115
|
|
|
(icon2, ui.ALIGN_NW), |
116
|
|
|
(icon2, ui.ALIGN_NE), |
117
|
|
|
(icon2, ui.ALIGN_SW), |
118
|
|
|
(icon2, ui.ALIGN_SE), |
119
|
|
|
), |
120
|
|
|
layout = (0, 5, 5, 2) |
121
|
|
|
) |
122
|
|
|
statusBar = ui.Label(win, |
123
|
|
|
align = ui.ALIGN_W, |
124
|
|
|
tooltip = 'This is a status bar which contains reports about...', |
125
|
|
|
layout = (0, 7, 6, 1), |
126
|
|
|
) |
127
|
|
|
app.statusBar = statusBar |
128
|
|
|
ui.Entry(win, |
129
|
|
|
align = ui.ALIGN_W, |
130
|
|
|
tooltip = 'Enter anything you like.', |
131
|
|
|
layout = (0, 8, 4, 1), |
132
|
|
|
).subscribeAction('*', echoHandler) |
133
|
|
|
x = 0 |
134
|
|
|
for align in (ui.ALIGN_N, ui.ALIGN_S, ui.ALIGN_E, ui.ALIGN_W): |
135
|
|
|
ui.ArrowButton(win, |
136
|
|
|
direction = align, |
137
|
|
|
layout = (x, 9, 1, 1), |
138
|
|
|
) |
139
|
|
|
x += 1 |
140
|
|
|
slider = ui.ScrollSlider(win, |
141
|
|
|
shown = 50, |
142
|
|
|
layout = (0, 10, 8, 1) |
143
|
|
|
) |
144
|
|
|
ui.ScrollSlider(win, |
145
|
|
|
shown = 10, |
146
|
|
|
layout = (0, 11, 8, 1) |
147
|
|
|
) |
148
|
|
|
ui.ScrollSlider(win, |
149
|
|
|
shown = 10, |
150
|
|
|
layout = (7, 0, 1, 10) |
151
|
|
|
) |
152
|
|
|
ui.Scrollbar(win, |
153
|
|
|
layout = (0, 12, 8, 1) |
154
|
|
|
).subscribeAction('*', echoHandler) |
155
|
|
|
ui.Scrollbar(win, |
156
|
|
|
layout = (6, 0, 1, 10) |
157
|
|
|
).subscribeAction('*', echoHandler) |
158
|
|
|
|
159
|
|
|
for x in xrange(8, 20, 2): |
160
|
|
|
for y in xrange(0, 10): |
161
|
|
|
ui.Button(win, |
162
|
|
|
text = '%d,%d' % (x, y), |
163
|
|
|
layout = (x, y, 2, 1), |
164
|
|
|
font = 'small', |
165
|
|
|
statustip = '%d,%d' % (x, y), |
166
|
|
|
enabled = (x + y) % 2 |
167
|
|
|
) |
168
|
|
|
|
169
|
|
|
ui.Listbox(win, |
170
|
|
|
items = [ui.Item('One'), ui.Item('Two'), ui.Item('Three'), ui.Item('Four'), |
171
|
|
|
ui.Item('Five'), ui.Item('Six'), ui.Item('Seven'), ui.Item('Eight')], |
172
|
|
|
layout = (0, 13, 8, 7), |
173
|
|
|
multiselection = 1, |
174
|
|
|
).subscribeAction('*', echoHandler) |
175
|
|
|
|
176
|
|
|
ui.Listbox(win, |
177
|
|
|
items = [ui.Item('One', size = 1), ui.Item('Two', size = 2), ui.Item('Three', size = 3), |
178
|
|
|
ui.Item('Four', size = 4), ui.Item('Five', size = 5), ui.Item('Six', size = 6), |
179
|
|
|
ui.Item('Seven', size = 7), ui.Item('Eight', size = 8), ui.Item('Nine', size = 9)], |
180
|
|
|
columns = [('Name', 'text', 6, 0), ('Size', 'size', 6, ui.F_EDITABLE)], |
181
|
|
|
layout = (8, 13, 12, 7), |
182
|
|
|
columnLabels = 1, |
183
|
|
|
).subscribeAction('*', echoHandler) |
184
|
|
|
|
185
|
|
|
items = [] |
186
|
|
|
for i in xrange(0, 100): |
187
|
|
|
items.append(ui.Item(str(i), tooltip = 'This is a tooltip', statustip = 'This is a statustip')) |
188
|
|
|
ui.ButtonArray(win, |
189
|
|
|
items = items, |
190
|
|
|
layout = (20, 13, 9, 6), |
191
|
|
|
buttonSize = (2, 2), |
192
|
|
|
) |
193
|
|
|
ui.Title(win, |
194
|
|
|
text = 'This is a title', |
195
|
|
|
align = ui.ALIGN_W, |
196
|
|
|
layout = (8, 12, 12, 1) |
197
|
|
|
) |
198
|
|
|
pBar = ui.ProgressBar(win, layout = (0, 20, 10, 1)) |
199
|
|
|
progBars.append(pBar) |
200
|
|
|
scrlbar = ui.Scrollbar(win, layout = (28, 0, 1, 10)) |
201
|
|
|
text = ui.Text(win, layout = (20, 0, 8, 10), |
202
|
|
|
text = [ |
203
|
|
|
'This is a very looooong text which will be displayed in that text widget.', |
204
|
|
|
'And one more long line to show.', |
205
|
|
|
'And another one.', |
206
|
|
|
'And another one.', |
207
|
|
|
'And another one.', |
208
|
|
|
'And another one.', |
209
|
|
|
'And another one.', |
210
|
|
|
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' |
211
|
|
|
] |
212
|
|
|
) |
213
|
|
|
text.attachVScrollbar(scrlbar) |
214
|
|
|
app.setStatus('Ready.') |
215
|
|
|
|
216
|
|
|
win.show() |
217
|
|
|
|
218
|
|
|
# create top bar |
219
|
|
|
update() |
220
|
|
|
|
221
|
|
|
fps = 0 |
222
|
|
|
frame = 0 |
223
|
|
|
time = pygame.time.get_ticks() |
224
|
|
|
count = 0 |
225
|
|
|
|
226
|
|
|
# event loop |
227
|
|
|
running = 1 |
228
|
|
|
while running: |
229
|
|
|
evt = pygame.event.wait() |
230
|
|
|
evts = pygame.event.get() |
231
|
|
|
evts.insert(0, evt) |
232
|
|
|
|
233
|
|
|
for evt in evts: |
234
|
|
|
if evt.type == pygame.QUIT: |
235
|
|
|
running = 0 |
236
|
|
|
break |
237
|
|
|
if evt.type == pygame.KEYUP and evt.key == pygame.K_ESCAPE: |
238
|
|
|
running = 0 |
239
|
|
|
break |
240
|
|
|
evt = app.processEvent(evt) |
241
|
|
|
|
242
|
|
|
if app.needsUpdate(): |
243
|
|
|
update() |
244
|
|
|
frame += 1 |
245
|
|
|
|
246
|
|
|
now = pygame.time.get_ticks() |
247
|
|
|
if now - 1000 > time: |
248
|
|
|
time = now |
249
|
|
|
w1.text = u'FPS: %d' % frame |
|
|
|
|
250
|
|
|
frame = 0 |
251
|
|
|
count += 1 |
252
|
|
|
if count > 100: count = 0 |
253
|
|
|
|
254
|
|
|
for pBar in progBars: |
255
|
|
|
pBar.value += 1 |
256
|
|
|
if pBar.value > pBar.max: |
257
|
|
|
pBar.value = pBar.min |
258
|
|
|
|