Skip to content

Commit 0e93b95

Browse files
committed
Add --title-status flag and default to "PyBoy" in window title
1 parent 4cf8acd commit 0e93b95

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

pyboy/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def valid_sample_rate(freq):
153153
help="Set sound sample rate. Has to be divisible in 60.",
154154
)
155155

156+
parser.add_argument("--title-status", action="store_true", help="Enable performance status in window title")
157+
156158
for arguments in parser_arguments():
157159
for a in arguments:
158160
*args, kwargs = a

pyboy/plugins/window_sdl2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ def init_audio(self, mb):
224224
self.sound_support = False
225225

226226
def set_title(self, title):
227-
# if self.sound_support:
228-
# queued_bytes = sdl2.SDL_GetQueuedAudioSize(self.sound_device)
229-
# title += f" {queued_bytes}"
227+
if self.sound_support and self.pyboy.title_status:
228+
queued_bytes = sdl2.SDL_GetQueuedAudioSize(self.sound_device)
229+
title += f" Sound: {queued_bytes}B"
230230
sdl2.SDL_SetWindowTitle(self._window, title.encode())
231231

232232
def handle_events(self, events):

pyboy/pyboy.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ cdef class PyBoy:
5454
cdef bint initialized
5555
cdef bint no_input
5656
cdef readonly str window_title
57+
cdef readonly bint title_status
5758
cdef readonly PyBoyMemoryView memory
5859
cdef readonly PyBoyRegisterFile register_file
5960
cdef readonly Screen screen

pyboy/pyboy.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def __init__(
8989
log_level=defaults["log_level"],
9090
color_palette=defaults["color_palette"],
9191
cgb_color_palette=defaults["cgb_color_palette"],
92+
title_status=False,
9293
**kwargs,
9394
):
9495
"""
@@ -129,6 +130,7 @@ def __init__(
129130
* log_level (str): "CRITICAL", "ERROR", "WARNING", "INFO" or "DEBUG"
130131
* color_palette (tuple): Specify the color palette to use for rendering.
131132
* cgb_color_palette (list of tuple): Specify the color palette to use for rendering in CGB-mode for non-color games.
133+
* title_status (bool): Enable performance status in window title
132134
133135
## Plugin kwargs:
134136
* autopause (bool): Enable auto-pausing when window looses focus [plugin: AutoPause]
@@ -232,7 +234,8 @@ def __init__(
232234
self.queued_input = []
233235
self.quitting = False
234236
self.stopped = False
235-
self.window_title = "PyBoy"
237+
self.window_title = ""
238+
self.title_status = title_status
236239

237240
###################
238241
# API attributes
@@ -637,10 +640,13 @@ def _post_handle_events(self):
637640
self.events.append(WindowEvent(_event))
638641

639642
def _update_window_title(self):
640-
self.window_title = f"CPU/frame: {(self.avg_tick) / SPF * 100:0.2f}%"
641-
self.window_title += f' Emulation: x{(round(SPF / self.avg_emu) if self.avg_emu > 0 else "INF")}'
643+
if self.title_status:
644+
self.window_title = f"CPU/frame: {(self.avg_tick) / SPF * 100:0.2f}%"
645+
self.window_title += f' Emulation: x{(round(SPF / self.avg_emu) if self.avg_emu > 0 else "INF")}'
646+
else:
647+
self.window_title = "PyBoy"
642648
if self.paused:
643-
self.window_title += "[PAUSED]"
649+
self.window_title += " [PAUSED]"
644650
self.window_title += self._plugin_manager.window_title()
645651
self._plugin_manager._set_title()
646652

0 commit comments

Comments
 (0)