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