bauiv1lib.benchmarks

UIs for debugging purposes.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""UIs for debugging purposes."""
  4
  5from __future__ import annotations
  6
  7import logging
  8from typing import cast, override
  9
 10import bauiv1 as bui
 11
 12
 13class BenchmarksAndStressTestsWindow(bui.MainWindow):
 14    """Window for launching benchmarks or stress tests."""
 15
 16    def __init__(
 17        self,
 18        transition: str | None = 'in_right',
 19        origin_widget: bui.Widget | None = None,
 20    ):
 21        # pylint: disable=too-many-statements
 22        # pylint: disable=cyclic-import
 23        from bauiv1lib import popup
 24
 25        uiscale = bui.app.ui_v1.uiscale
 26        self._width = width = 650 if uiscale is bui.UIScale.SMALL else 580
 27        self._height = height = (
 28            330
 29            if uiscale is bui.UIScale.SMALL
 30            else 420 if uiscale is bui.UIScale.MEDIUM else 520
 31        )
 32
 33        self._scroll_width = self._width - 100
 34        self._scroll_height = self._height - 120
 35
 36        self._sub_width = self._scroll_width * 0.95
 37        self._sub_height = 520
 38
 39        self._stress_test_game_type = 'Random'
 40        self._stress_test_playlist = '__default__'
 41        self._stress_test_player_count = 8
 42        self._stress_test_round_duration = 30
 43
 44        self._r = 'debugWindow'
 45        uiscale = bui.app.ui_v1.uiscale
 46        super().__init__(
 47            root_widget=bui.containerwidget(
 48                size=(width, height),
 49                scale=(
 50                    2.32
 51                    if uiscale is bui.UIScale.SMALL
 52                    else 1.55 if uiscale is bui.UIScale.MEDIUM else 1.0
 53                ),
 54                stack_offset=(
 55                    (0, -30) if uiscale is bui.UIScale.SMALL else (0, 0)
 56                ),
 57                toolbar_visibility=(
 58                    'menu_minimal'
 59                    if uiscale is bui.UIScale.SMALL
 60                    else 'menu_full'
 61                ),
 62            ),
 63            transition=transition,
 64            origin_widget=origin_widget,
 65        )
 66
 67        if bui.app.ui_v1.uiscale is bui.UIScale.SMALL:
 68            bui.containerwidget(
 69                edit=self._root_widget, on_cancel_call=self.main_window_back
 70            )
 71            self._done_button = bui.get_special_widget('back_button')
 72        else:
 73            self._done_button = btn = bui.buttonwidget(
 74                parent=self._root_widget,
 75                position=(40, height - 67),
 76                size=(120, 60),
 77                scale=0.8,
 78                autoselect=True,
 79                label=bui.Lstr(resource='doneText'),
 80                on_activate_call=self.main_window_back,
 81            )
 82            bui.containerwidget(edit=self._root_widget, cancel_button=btn)
 83
 84        bui.textwidget(
 85            parent=self._root_widget,
 86            position=(0, height - 60),
 87            size=(width, 30),
 88            text=bui.Lstr(resource=f'{self._r}.titleText'),
 89            h_align='center',
 90            color=bui.app.ui_v1.title_color,
 91            v_align='center',
 92            maxwidth=260,
 93        )
 94
 95        self._scrollwidget = bui.scrollwidget(
 96            parent=self._root_widget,
 97            highlight=False,
 98            size=(self._scroll_width, self._scroll_height),
 99            position=((self._width - self._scroll_width) * 0.5, 50),
100        )
101        bui.containerwidget(edit=self._scrollwidget, claims_left_right=True)
102
103        self._subcontainer = bui.containerwidget(
104            parent=self._scrollwidget,
105            size=(self._sub_width, self._sub_height),
106            background=False,
107        )
108
109        v = self._sub_height - 70
110        button_width = 300
111        btn = bui.buttonwidget(
112            parent=self._subcontainer,
113            position=((self._sub_width - button_width) * 0.5, v),
114            size=(button_width, 60),
115            autoselect=True,
116            label=bui.Lstr(resource=f'{self._r}.runCPUBenchmarkText'),
117            on_activate_call=self._run_cpu_benchmark_pressed,
118        )
119        bui.widget(
120            edit=btn, up_widget=self._done_button, left_widget=self._done_button
121        )
122        v -= 60
123
124        bui.buttonwidget(
125            parent=self._subcontainer,
126            position=((self._sub_width - button_width) * 0.5, v),
127            size=(button_width, 60),
128            autoselect=True,
129            label=bui.Lstr(resource=f'{self._r}.runGPUBenchmarkText'),
130            on_activate_call=self._run_gpu_benchmark_pressed,
131        )
132        v -= 60
133
134        bui.buttonwidget(
135            parent=self._subcontainer,
136            position=((self._sub_width - button_width) * 0.5, v),
137            size=(button_width, 60),
138            autoselect=True,
139            label=bui.Lstr(resource=f'{self._r}.runMediaReloadBenchmarkText'),
140            on_activate_call=self._run_media_reload_benchmark_pressed,
141        )
142        v -= 60
143
144        bui.textwidget(
145            parent=self._subcontainer,
146            position=(self._sub_width * 0.5, v + 22),
147            size=(0, 0),
148            text=bui.Lstr(resource=f'{self._r}.stressTestTitleText'),
149            maxwidth=200,
150            color=bui.app.ui_v1.heading_color,
151            scale=0.85,
152            h_align='center',
153            v_align='center',
154        )
155        v -= 45
156
157        x_offs = 165
158        bui.textwidget(
159            parent=self._subcontainer,
160            position=(x_offs - 10, v + 22),
161            size=(0, 0),
162            text=bui.Lstr(resource=f'{self._r}.stressTestPlaylistTypeText'),
163            maxwidth=130,
164            color=bui.app.ui_v1.heading_color,
165            scale=0.65,
166            h_align='right',
167            v_align='center',
168        )
169
170        popup.PopupMenu(
171            parent=self._subcontainer,
172            position=(x_offs, v),
173            width=150,
174            choices=['Random', 'Teams', 'Free-For-All'],
175            choices_display=[
176                bui.Lstr(resource=a)
177                for a in [
178                    'randomText',
179                    'playModes.teamsText',
180                    'playModes.freeForAllText',
181                ]
182            ],
183            current_choice='Auto',
184            on_value_change_call=self._stress_test_game_type_selected,
185        )
186
187        v -= 46
188        bui.textwidget(
189            parent=self._subcontainer,
190            position=(x_offs - 10, v + 22),
191            size=(0, 0),
192            text=bui.Lstr(resource=f'{self._r}.stressTestPlaylistNameText'),
193            maxwidth=130,
194            color=bui.app.ui_v1.heading_color,
195            scale=0.65,
196            h_align='right',
197            v_align='center',
198        )
199
200        self._stress_test_playlist_name_field = bui.textwidget(
201            parent=self._subcontainer,
202            position=(x_offs + 5, v - 5),
203            size=(250, 46),
204            text=self._stress_test_playlist,
205            h_align='left',
206            v_align='center',
207            autoselect=True,
208            color=(0.9, 0.9, 0.9, 1.0),
209            description=bui.Lstr(
210                resource=f'{self._r}.stressTestPlaylistDescriptionText'
211            ),
212            editable=True,
213            padding=4,
214        )
215        v -= 29
216        x_sub = 60
217
218        # Player count.
219        bui.textwidget(
220            parent=self._subcontainer,
221            position=(x_offs - 10, v),
222            size=(0, 0),
223            text=bui.Lstr(resource=f'{self._r}.stressTestPlayerCountText'),
224            color=(0.8, 0.8, 0.8, 1.0),
225            h_align='right',
226            v_align='center',
227            scale=0.65,
228            maxwidth=130,
229        )
230        self._stress_test_player_count_text = bui.textwidget(
231            parent=self._subcontainer,
232            position=(246 - x_sub, v - 14),
233            size=(60, 28),
234            editable=False,
235            color=(0.3, 1.0, 0.3, 1.0),
236            h_align='right',
237            v_align='center',
238            text=str(self._stress_test_player_count),
239            padding=2,
240        )
241        bui.buttonwidget(
242            parent=self._subcontainer,
243            position=(330 - x_sub, v - 11),
244            size=(28, 28),
245            label='-',
246            autoselect=True,
247            on_activate_call=bui.Call(self._stress_test_player_count_decrement),
248            repeat=True,
249            enable_sound=True,
250        )
251        bui.buttonwidget(
252            parent=self._subcontainer,
253            position=(380 - x_sub, v - 11),
254            size=(28, 28),
255            label='+',
256            autoselect=True,
257            on_activate_call=bui.Call(self._stress_test_player_count_increment),
258            repeat=True,
259            enable_sound=True,
260        )
261        v -= 42
262
263        # Round duration.
264        bui.textwidget(
265            parent=self._subcontainer,
266            position=(x_offs - 10, v),
267            size=(0, 0),
268            text=bui.Lstr(resource=f'{self._r}.stressTestRoundDurationText'),
269            color=(0.8, 0.8, 0.8, 1.0),
270            h_align='right',
271            v_align='center',
272            scale=0.65,
273            maxwidth=130,
274        )
275        self._stress_test_round_duration_text = bui.textwidget(
276            parent=self._subcontainer,
277            position=(246 - x_sub, v - 14),
278            size=(60, 28),
279            editable=False,
280            color=(0.3, 1.0, 0.3, 1.0),
281            h_align='right',
282            v_align='center',
283            text=str(self._stress_test_round_duration),
284            padding=2,
285        )
286        bui.buttonwidget(
287            parent=self._subcontainer,
288            position=(330 - x_sub, v - 11),
289            size=(28, 28),
290            label='-',
291            autoselect=True,
292            on_activate_call=bui.Call(
293                self._stress_test_round_duration_decrement
294            ),
295            repeat=True,
296            enable_sound=True,
297        )
298        bui.buttonwidget(
299            parent=self._subcontainer,
300            position=(380 - x_sub, v - 11),
301            size=(28, 28),
302            label='+',
303            autoselect=True,
304            on_activate_call=bui.Call(
305                self._stress_test_round_duration_increment
306            ),
307            repeat=True,
308            enable_sound=True,
309        )
310        v -= 82
311        btn = bui.buttonwidget(
312            parent=self._subcontainer,
313            position=((self._sub_width - button_width) * 0.5, v),
314            size=(button_width, 60),
315            autoselect=True,
316            label=bui.Lstr(resource=f'{self._r}.runStressTestText'),
317            on_activate_call=self._stress_test_pressed,
318        )
319        bui.widget(btn, show_buffer_bottom=50)
320
321    @override
322    def get_main_window_state(self) -> bui.MainWindowState:
323        # Support recreating our window for back/refresh purposes.
324        cls = type(self)
325        return bui.BasicMainWindowState(
326            create_call=lambda transition, origin_widget: cls(
327                transition=transition, origin_widget=origin_widget
328            )
329        )
330
331    def _stress_test_player_count_decrement(self) -> None:
332        self._stress_test_player_count = max(
333            1, self._stress_test_player_count - 1
334        )
335        bui.textwidget(
336            edit=self._stress_test_player_count_text,
337            text=str(self._stress_test_player_count),
338        )
339
340    def _stress_test_player_count_increment(self) -> None:
341        self._stress_test_player_count = self._stress_test_player_count + 1
342        bui.textwidget(
343            edit=self._stress_test_player_count_text,
344            text=str(self._stress_test_player_count),
345        )
346
347    def _stress_test_round_duration_decrement(self) -> None:
348        self._stress_test_round_duration = max(
349            10, self._stress_test_round_duration - 10
350        )
351        bui.textwidget(
352            edit=self._stress_test_round_duration_text,
353            text=str(self._stress_test_round_duration),
354        )
355
356    def _stress_test_round_duration_increment(self) -> None:
357        self._stress_test_round_duration = self._stress_test_round_duration + 10
358        bui.textwidget(
359            edit=self._stress_test_round_duration_text,
360            text=str(self._stress_test_round_duration),
361        )
362
363    def _stress_test_game_type_selected(self, game_type: str) -> None:
364        self._stress_test_game_type = game_type
365
366    def _run_cpu_benchmark_pressed(self) -> None:
367        if bui.app.classic is None:
368            logging.warning('run-cpu-benchmark requires classic')
369            return
370        bui.app.classic.run_cpu_benchmark()
371
372    def _run_gpu_benchmark_pressed(self) -> None:
373        if bui.app.classic is None:
374            logging.warning('run-gpu-benchmark requires classic')
375            return
376        bui.app.classic.run_gpu_benchmark()
377
378    def _run_media_reload_benchmark_pressed(self) -> None:
379        if bui.app.classic is None:
380            logging.warning('run-media-reload-benchmark requires classic')
381            return
382        bui.app.classic.run_media_reload_benchmark()
383
384    def _stress_test_pressed(self) -> None:
385        if bui.app.classic is None:
386            logging.warning('stress-test requires classic')
387            return
388
389        bui.app.classic.run_stress_test(
390            playlist_type=self._stress_test_game_type,
391            playlist_name=cast(
392                str, bui.textwidget(query=self._stress_test_playlist_name_field)
393            ),
394            player_count=self._stress_test_player_count,
395            round_duration=self._stress_test_round_duration,
396        )
397        bui.containerwidget(edit=self._root_widget, transition='out_right')
class BenchmarksAndStressTestsWindow(bauiv1._uitypes.MainWindow):
 14class BenchmarksAndStressTestsWindow(bui.MainWindow):
 15    """Window for launching benchmarks or stress tests."""
 16
 17    def __init__(
 18        self,
 19        transition: str | None = 'in_right',
 20        origin_widget: bui.Widget | None = None,
 21    ):
 22        # pylint: disable=too-many-statements
 23        # pylint: disable=cyclic-import
 24        from bauiv1lib import popup
 25
 26        uiscale = bui.app.ui_v1.uiscale
 27        self._width = width = 650 if uiscale is bui.UIScale.SMALL else 580
 28        self._height = height = (
 29            330
 30            if uiscale is bui.UIScale.SMALL
 31            else 420 if uiscale is bui.UIScale.MEDIUM else 520
 32        )
 33
 34        self._scroll_width = self._width - 100
 35        self._scroll_height = self._height - 120
 36
 37        self._sub_width = self._scroll_width * 0.95
 38        self._sub_height = 520
 39
 40        self._stress_test_game_type = 'Random'
 41        self._stress_test_playlist = '__default__'
 42        self._stress_test_player_count = 8
 43        self._stress_test_round_duration = 30
 44
 45        self._r = 'debugWindow'
 46        uiscale = bui.app.ui_v1.uiscale
 47        super().__init__(
 48            root_widget=bui.containerwidget(
 49                size=(width, height),
 50                scale=(
 51                    2.32
 52                    if uiscale is bui.UIScale.SMALL
 53                    else 1.55 if uiscale is bui.UIScale.MEDIUM else 1.0
 54                ),
 55                stack_offset=(
 56                    (0, -30) if uiscale is bui.UIScale.SMALL else (0, 0)
 57                ),
 58                toolbar_visibility=(
 59                    'menu_minimal'
 60                    if uiscale is bui.UIScale.SMALL
 61                    else 'menu_full'
 62                ),
 63            ),
 64            transition=transition,
 65            origin_widget=origin_widget,
 66        )
 67
 68        if bui.app.ui_v1.uiscale is bui.UIScale.SMALL:
 69            bui.containerwidget(
 70                edit=self._root_widget, on_cancel_call=self.main_window_back
 71            )
 72            self._done_button = bui.get_special_widget('back_button')
 73        else:
 74            self._done_button = btn = bui.buttonwidget(
 75                parent=self._root_widget,
 76                position=(40, height - 67),
 77                size=(120, 60),
 78                scale=0.8,
 79                autoselect=True,
 80                label=bui.Lstr(resource='doneText'),
 81                on_activate_call=self.main_window_back,
 82            )
 83            bui.containerwidget(edit=self._root_widget, cancel_button=btn)
 84
 85        bui.textwidget(
 86            parent=self._root_widget,
 87            position=(0, height - 60),
 88            size=(width, 30),
 89            text=bui.Lstr(resource=f'{self._r}.titleText'),
 90            h_align='center',
 91            color=bui.app.ui_v1.title_color,
 92            v_align='center',
 93            maxwidth=260,
 94        )
 95
 96        self._scrollwidget = bui.scrollwidget(
 97            parent=self._root_widget,
 98            highlight=False,
 99            size=(self._scroll_width, self._scroll_height),
100            position=((self._width - self._scroll_width) * 0.5, 50),
101        )
102        bui.containerwidget(edit=self._scrollwidget, claims_left_right=True)
103
104        self._subcontainer = bui.containerwidget(
105            parent=self._scrollwidget,
106            size=(self._sub_width, self._sub_height),
107            background=False,
108        )
109
110        v = self._sub_height - 70
111        button_width = 300
112        btn = bui.buttonwidget(
113            parent=self._subcontainer,
114            position=((self._sub_width - button_width) * 0.5, v),
115            size=(button_width, 60),
116            autoselect=True,
117            label=bui.Lstr(resource=f'{self._r}.runCPUBenchmarkText'),
118            on_activate_call=self._run_cpu_benchmark_pressed,
119        )
120        bui.widget(
121            edit=btn, up_widget=self._done_button, left_widget=self._done_button
122        )
123        v -= 60
124
125        bui.buttonwidget(
126            parent=self._subcontainer,
127            position=((self._sub_width - button_width) * 0.5, v),
128            size=(button_width, 60),
129            autoselect=True,
130            label=bui.Lstr(resource=f'{self._r}.runGPUBenchmarkText'),
131            on_activate_call=self._run_gpu_benchmark_pressed,
132        )
133        v -= 60
134
135        bui.buttonwidget(
136            parent=self._subcontainer,
137            position=((self._sub_width - button_width) * 0.5, v),
138            size=(button_width, 60),
139            autoselect=True,
140            label=bui.Lstr(resource=f'{self._r}.runMediaReloadBenchmarkText'),
141            on_activate_call=self._run_media_reload_benchmark_pressed,
142        )
143        v -= 60
144
145        bui.textwidget(
146            parent=self._subcontainer,
147            position=(self._sub_width * 0.5, v + 22),
148            size=(0, 0),
149            text=bui.Lstr(resource=f'{self._r}.stressTestTitleText'),
150            maxwidth=200,
151            color=bui.app.ui_v1.heading_color,
152            scale=0.85,
153            h_align='center',
154            v_align='center',
155        )
156        v -= 45
157
158        x_offs = 165
159        bui.textwidget(
160            parent=self._subcontainer,
161            position=(x_offs - 10, v + 22),
162            size=(0, 0),
163            text=bui.Lstr(resource=f'{self._r}.stressTestPlaylistTypeText'),
164            maxwidth=130,
165            color=bui.app.ui_v1.heading_color,
166            scale=0.65,
167            h_align='right',
168            v_align='center',
169        )
170
171        popup.PopupMenu(
172            parent=self._subcontainer,
173            position=(x_offs, v),
174            width=150,
175            choices=['Random', 'Teams', 'Free-For-All'],
176            choices_display=[
177                bui.Lstr(resource=a)
178                for a in [
179                    'randomText',
180                    'playModes.teamsText',
181                    'playModes.freeForAllText',
182                ]
183            ],
184            current_choice='Auto',
185            on_value_change_call=self._stress_test_game_type_selected,
186        )
187
188        v -= 46
189        bui.textwidget(
190            parent=self._subcontainer,
191            position=(x_offs - 10, v + 22),
192            size=(0, 0),
193            text=bui.Lstr(resource=f'{self._r}.stressTestPlaylistNameText'),
194            maxwidth=130,
195            color=bui.app.ui_v1.heading_color,
196            scale=0.65,
197            h_align='right',
198            v_align='center',
199        )
200
201        self._stress_test_playlist_name_field = bui.textwidget(
202            parent=self._subcontainer,
203            position=(x_offs + 5, v - 5),
204            size=(250, 46),
205            text=self._stress_test_playlist,
206            h_align='left',
207            v_align='center',
208            autoselect=True,
209            color=(0.9, 0.9, 0.9, 1.0),
210            description=bui.Lstr(
211                resource=f'{self._r}.stressTestPlaylistDescriptionText'
212            ),
213            editable=True,
214            padding=4,
215        )
216        v -= 29
217        x_sub = 60
218
219        # Player count.
220        bui.textwidget(
221            parent=self._subcontainer,
222            position=(x_offs - 10, v),
223            size=(0, 0),
224            text=bui.Lstr(resource=f'{self._r}.stressTestPlayerCountText'),
225            color=(0.8, 0.8, 0.8, 1.0),
226            h_align='right',
227            v_align='center',
228            scale=0.65,
229            maxwidth=130,
230        )
231        self._stress_test_player_count_text = bui.textwidget(
232            parent=self._subcontainer,
233            position=(246 - x_sub, v - 14),
234            size=(60, 28),
235            editable=False,
236            color=(0.3, 1.0, 0.3, 1.0),
237            h_align='right',
238            v_align='center',
239            text=str(self._stress_test_player_count),
240            padding=2,
241        )
242        bui.buttonwidget(
243            parent=self._subcontainer,
244            position=(330 - x_sub, v - 11),
245            size=(28, 28),
246            label='-',
247            autoselect=True,
248            on_activate_call=bui.Call(self._stress_test_player_count_decrement),
249            repeat=True,
250            enable_sound=True,
251        )
252        bui.buttonwidget(
253            parent=self._subcontainer,
254            position=(380 - x_sub, v - 11),
255            size=(28, 28),
256            label='+',
257            autoselect=True,
258            on_activate_call=bui.Call(self._stress_test_player_count_increment),
259            repeat=True,
260            enable_sound=True,
261        )
262        v -= 42
263
264        # Round duration.
265        bui.textwidget(
266            parent=self._subcontainer,
267            position=(x_offs - 10, v),
268            size=(0, 0),
269            text=bui.Lstr(resource=f'{self._r}.stressTestRoundDurationText'),
270            color=(0.8, 0.8, 0.8, 1.0),
271            h_align='right',
272            v_align='center',
273            scale=0.65,
274            maxwidth=130,
275        )
276        self._stress_test_round_duration_text = bui.textwidget(
277            parent=self._subcontainer,
278            position=(246 - x_sub, v - 14),
279            size=(60, 28),
280            editable=False,
281            color=(0.3, 1.0, 0.3, 1.0),
282            h_align='right',
283            v_align='center',
284            text=str(self._stress_test_round_duration),
285            padding=2,
286        )
287        bui.buttonwidget(
288            parent=self._subcontainer,
289            position=(330 - x_sub, v - 11),
290            size=(28, 28),
291            label='-',
292            autoselect=True,
293            on_activate_call=bui.Call(
294                self._stress_test_round_duration_decrement
295            ),
296            repeat=True,
297            enable_sound=True,
298        )
299        bui.buttonwidget(
300            parent=self._subcontainer,
301            position=(380 - x_sub, v - 11),
302            size=(28, 28),
303            label='+',
304            autoselect=True,
305            on_activate_call=bui.Call(
306                self._stress_test_round_duration_increment
307            ),
308            repeat=True,
309            enable_sound=True,
310        )
311        v -= 82
312        btn = bui.buttonwidget(
313            parent=self._subcontainer,
314            position=((self._sub_width - button_width) * 0.5, v),
315            size=(button_width, 60),
316            autoselect=True,
317            label=bui.Lstr(resource=f'{self._r}.runStressTestText'),
318            on_activate_call=self._stress_test_pressed,
319        )
320        bui.widget(btn, show_buffer_bottom=50)
321
322    @override
323    def get_main_window_state(self) -> bui.MainWindowState:
324        # Support recreating our window for back/refresh purposes.
325        cls = type(self)
326        return bui.BasicMainWindowState(
327            create_call=lambda transition, origin_widget: cls(
328                transition=transition, origin_widget=origin_widget
329            )
330        )
331
332    def _stress_test_player_count_decrement(self) -> None:
333        self._stress_test_player_count = max(
334            1, self._stress_test_player_count - 1
335        )
336        bui.textwidget(
337            edit=self._stress_test_player_count_text,
338            text=str(self._stress_test_player_count),
339        )
340
341    def _stress_test_player_count_increment(self) -> None:
342        self._stress_test_player_count = self._stress_test_player_count + 1
343        bui.textwidget(
344            edit=self._stress_test_player_count_text,
345            text=str(self._stress_test_player_count),
346        )
347
348    def _stress_test_round_duration_decrement(self) -> None:
349        self._stress_test_round_duration = max(
350            10, self._stress_test_round_duration - 10
351        )
352        bui.textwidget(
353            edit=self._stress_test_round_duration_text,
354            text=str(self._stress_test_round_duration),
355        )
356
357    def _stress_test_round_duration_increment(self) -> None:
358        self._stress_test_round_duration = self._stress_test_round_duration + 10
359        bui.textwidget(
360            edit=self._stress_test_round_duration_text,
361            text=str(self._stress_test_round_duration),
362        )
363
364    def _stress_test_game_type_selected(self, game_type: str) -> None:
365        self._stress_test_game_type = game_type
366
367    def _run_cpu_benchmark_pressed(self) -> None:
368        if bui.app.classic is None:
369            logging.warning('run-cpu-benchmark requires classic')
370            return
371        bui.app.classic.run_cpu_benchmark()
372
373    def _run_gpu_benchmark_pressed(self) -> None:
374        if bui.app.classic is None:
375            logging.warning('run-gpu-benchmark requires classic')
376            return
377        bui.app.classic.run_gpu_benchmark()
378
379    def _run_media_reload_benchmark_pressed(self) -> None:
380        if bui.app.classic is None:
381            logging.warning('run-media-reload-benchmark requires classic')
382            return
383        bui.app.classic.run_media_reload_benchmark()
384
385    def _stress_test_pressed(self) -> None:
386        if bui.app.classic is None:
387            logging.warning('stress-test requires classic')
388            return
389
390        bui.app.classic.run_stress_test(
391            playlist_type=self._stress_test_game_type,
392            playlist_name=cast(
393                str, bui.textwidget(query=self._stress_test_playlist_name_field)
394            ),
395            player_count=self._stress_test_player_count,
396            round_duration=self._stress_test_round_duration,
397        )
398        bui.containerwidget(edit=self._root_widget, transition='out_right')

Window for launching benchmarks or stress tests.

BenchmarksAndStressTestsWindow( transition: str | None = 'in_right', origin_widget: _bauiv1.Widget | None = None)
 17    def __init__(
 18        self,
 19        transition: str | None = 'in_right',
 20        origin_widget: bui.Widget | None = None,
 21    ):
 22        # pylint: disable=too-many-statements
 23        # pylint: disable=cyclic-import
 24        from bauiv1lib import popup
 25
 26        uiscale = bui.app.ui_v1.uiscale
 27        self._width = width = 650 if uiscale is bui.UIScale.SMALL else 580
 28        self._height = height = (
 29            330
 30            if uiscale is bui.UIScale.SMALL
 31            else 420 if uiscale is bui.UIScale.MEDIUM else 520
 32        )
 33
 34        self._scroll_width = self._width - 100
 35        self._scroll_height = self._height - 120
 36
 37        self._sub_width = self._scroll_width * 0.95
 38        self._sub_height = 520
 39
 40        self._stress_test_game_type = 'Random'
 41        self._stress_test_playlist = '__default__'
 42        self._stress_test_player_count = 8
 43        self._stress_test_round_duration = 30
 44
 45        self._r = 'debugWindow'
 46        uiscale = bui.app.ui_v1.uiscale
 47        super().__init__(
 48            root_widget=bui.containerwidget(
 49                size=(width, height),
 50                scale=(
 51                    2.32
 52                    if uiscale is bui.UIScale.SMALL
 53                    else 1.55 if uiscale is bui.UIScale.MEDIUM else 1.0
 54                ),
 55                stack_offset=(
 56                    (0, -30) if uiscale is bui.UIScale.SMALL else (0, 0)
 57                ),
 58                toolbar_visibility=(
 59                    'menu_minimal'
 60                    if uiscale is bui.UIScale.SMALL
 61                    else 'menu_full'
 62                ),
 63            ),
 64            transition=transition,
 65            origin_widget=origin_widget,
 66        )
 67
 68        if bui.app.ui_v1.uiscale is bui.UIScale.SMALL:
 69            bui.containerwidget(
 70                edit=self._root_widget, on_cancel_call=self.main_window_back
 71            )
 72            self._done_button = bui.get_special_widget('back_button')
 73        else:
 74            self._done_button = btn = bui.buttonwidget(
 75                parent=self._root_widget,
 76                position=(40, height - 67),
 77                size=(120, 60),
 78                scale=0.8,
 79                autoselect=True,
 80                label=bui.Lstr(resource='doneText'),
 81                on_activate_call=self.main_window_back,
 82            )
 83            bui.containerwidget(edit=self._root_widget, cancel_button=btn)
 84
 85        bui.textwidget(
 86            parent=self._root_widget,
 87            position=(0, height - 60),
 88            size=(width, 30),
 89            text=bui.Lstr(resource=f'{self._r}.titleText'),
 90            h_align='center',
 91            color=bui.app.ui_v1.title_color,
 92            v_align='center',
 93            maxwidth=260,
 94        )
 95
 96        self._scrollwidget = bui.scrollwidget(
 97            parent=self._root_widget,
 98            highlight=False,
 99            size=(self._scroll_width, self._scroll_height),
100            position=((self._width - self._scroll_width) * 0.5, 50),
101        )
102        bui.containerwidget(edit=self._scrollwidget, claims_left_right=True)
103
104        self._subcontainer = bui.containerwidget(
105            parent=self._scrollwidget,
106            size=(self._sub_width, self._sub_height),
107            background=False,
108        )
109
110        v = self._sub_height - 70
111        button_width = 300
112        btn = bui.buttonwidget(
113            parent=self._subcontainer,
114            position=((self._sub_width - button_width) * 0.5, v),
115            size=(button_width, 60),
116            autoselect=True,
117            label=bui.Lstr(resource=f'{self._r}.runCPUBenchmarkText'),
118            on_activate_call=self._run_cpu_benchmark_pressed,
119        )
120        bui.widget(
121            edit=btn, up_widget=self._done_button, left_widget=self._done_button
122        )
123        v -= 60
124
125        bui.buttonwidget(
126            parent=self._subcontainer,
127            position=((self._sub_width - button_width) * 0.5, v),
128            size=(button_width, 60),
129            autoselect=True,
130            label=bui.Lstr(resource=f'{self._r}.runGPUBenchmarkText'),
131            on_activate_call=self._run_gpu_benchmark_pressed,
132        )
133        v -= 60
134
135        bui.buttonwidget(
136            parent=self._subcontainer,
137            position=((self._sub_width - button_width) * 0.5, v),
138            size=(button_width, 60),
139            autoselect=True,
140            label=bui.Lstr(resource=f'{self._r}.runMediaReloadBenchmarkText'),
141            on_activate_call=self._run_media_reload_benchmark_pressed,
142        )
143        v -= 60
144
145        bui.textwidget(
146            parent=self._subcontainer,
147            position=(self._sub_width * 0.5, v + 22),
148            size=(0, 0),
149            text=bui.Lstr(resource=f'{self._r}.stressTestTitleText'),
150            maxwidth=200,
151            color=bui.app.ui_v1.heading_color,
152            scale=0.85,
153            h_align='center',
154            v_align='center',
155        )
156        v -= 45
157
158        x_offs = 165
159        bui.textwidget(
160            parent=self._subcontainer,
161            position=(x_offs - 10, v + 22),
162            size=(0, 0),
163            text=bui.Lstr(resource=f'{self._r}.stressTestPlaylistTypeText'),
164            maxwidth=130,
165            color=bui.app.ui_v1.heading_color,
166            scale=0.65,
167            h_align='right',
168            v_align='center',
169        )
170
171        popup.PopupMenu(
172            parent=self._subcontainer,
173            position=(x_offs, v),
174            width=150,
175            choices=['Random', 'Teams', 'Free-For-All'],
176            choices_display=[
177                bui.Lstr(resource=a)
178                for a in [
179                    'randomText',
180                    'playModes.teamsText',
181                    'playModes.freeForAllText',
182                ]
183            ],
184            current_choice='Auto',
185            on_value_change_call=self._stress_test_game_type_selected,
186        )
187
188        v -= 46
189        bui.textwidget(
190            parent=self._subcontainer,
191            position=(x_offs - 10, v + 22),
192            size=(0, 0),
193            text=bui.Lstr(resource=f'{self._r}.stressTestPlaylistNameText'),
194            maxwidth=130,
195            color=bui.app.ui_v1.heading_color,
196            scale=0.65,
197            h_align='right',
198            v_align='center',
199        )
200
201        self._stress_test_playlist_name_field = bui.textwidget(
202            parent=self._subcontainer,
203            position=(x_offs + 5, v - 5),
204            size=(250, 46),
205            text=self._stress_test_playlist,
206            h_align='left',
207            v_align='center',
208            autoselect=True,
209            color=(0.9, 0.9, 0.9, 1.0),
210            description=bui.Lstr(
211                resource=f'{self._r}.stressTestPlaylistDescriptionText'
212            ),
213            editable=True,
214            padding=4,
215        )
216        v -= 29
217        x_sub = 60
218
219        # Player count.
220        bui.textwidget(
221            parent=self._subcontainer,
222            position=(x_offs - 10, v),
223            size=(0, 0),
224            text=bui.Lstr(resource=f'{self._r}.stressTestPlayerCountText'),
225            color=(0.8, 0.8, 0.8, 1.0),
226            h_align='right',
227            v_align='center',
228            scale=0.65,
229            maxwidth=130,
230        )
231        self._stress_test_player_count_text = bui.textwidget(
232            parent=self._subcontainer,
233            position=(246 - x_sub, v - 14),
234            size=(60, 28),
235            editable=False,
236            color=(0.3, 1.0, 0.3, 1.0),
237            h_align='right',
238            v_align='center',
239            text=str(self._stress_test_player_count),
240            padding=2,
241        )
242        bui.buttonwidget(
243            parent=self._subcontainer,
244            position=(330 - x_sub, v - 11),
245            size=(28, 28),
246            label='-',
247            autoselect=True,
248            on_activate_call=bui.Call(self._stress_test_player_count_decrement),
249            repeat=True,
250            enable_sound=True,
251        )
252        bui.buttonwidget(
253            parent=self._subcontainer,
254            position=(380 - x_sub, v - 11),
255            size=(28, 28),
256            label='+',
257            autoselect=True,
258            on_activate_call=bui.Call(self._stress_test_player_count_increment),
259            repeat=True,
260            enable_sound=True,
261        )
262        v -= 42
263
264        # Round duration.
265        bui.textwidget(
266            parent=self._subcontainer,
267            position=(x_offs - 10, v),
268            size=(0, 0),
269            text=bui.Lstr(resource=f'{self._r}.stressTestRoundDurationText'),
270            color=(0.8, 0.8, 0.8, 1.0),
271            h_align='right',
272            v_align='center',
273            scale=0.65,
274            maxwidth=130,
275        )
276        self._stress_test_round_duration_text = bui.textwidget(
277            parent=self._subcontainer,
278            position=(246 - x_sub, v - 14),
279            size=(60, 28),
280            editable=False,
281            color=(0.3, 1.0, 0.3, 1.0),
282            h_align='right',
283            v_align='center',
284            text=str(self._stress_test_round_duration),
285            padding=2,
286        )
287        bui.buttonwidget(
288            parent=self._subcontainer,
289            position=(330 - x_sub, v - 11),
290            size=(28, 28),
291            label='-',
292            autoselect=True,
293            on_activate_call=bui.Call(
294                self._stress_test_round_duration_decrement
295            ),
296            repeat=True,
297            enable_sound=True,
298        )
299        bui.buttonwidget(
300            parent=self._subcontainer,
301            position=(380 - x_sub, v - 11),
302            size=(28, 28),
303            label='+',
304            autoselect=True,
305            on_activate_call=bui.Call(
306                self._stress_test_round_duration_increment
307            ),
308            repeat=True,
309            enable_sound=True,
310        )
311        v -= 82
312        btn = bui.buttonwidget(
313            parent=self._subcontainer,
314            position=((self._sub_width - button_width) * 0.5, v),
315            size=(button_width, 60),
316            autoselect=True,
317            label=bui.Lstr(resource=f'{self._r}.runStressTestText'),
318            on_activate_call=self._stress_test_pressed,
319        )
320        bui.widget(btn, show_buffer_bottom=50)

Create a MainWindow given a root widget and transition info.

Automatically handles in and out transitions on the provided widget, so there is no need to set transitions when creating it.

@override
def get_main_window_state(self) -> bauiv1.MainWindowState:
322    @override
323    def get_main_window_state(self) -> bui.MainWindowState:
324        # Support recreating our window for back/refresh purposes.
325        cls = type(self)
326        return bui.BasicMainWindowState(
327            create_call=lambda transition, origin_widget: cls(
328                transition=transition, origin_widget=origin_widget
329            )
330        )

Return a WindowState to recreate this window, if supported.

Inherited Members
bauiv1._uitypes.MainWindow
main_window_back_state
main_window_close
can_change_main_window
main_window_back
main_window_replace
on_main_window_close
bauiv1._uitypes.Window
get_root_widget