X-Git-Url: http://git.scottworley.com/srec/blobdiff_plain/e5b09945620ccdc8759cf6fe8f885854b6837596..dc3d1416ae804a5353f25a1eedcafdce762a29f7:/srec.py diff --git a/srec.py b/srec.py index 944cc5c..0828310 100644 --- a/srec.py +++ b/srec.py @@ -74,21 +74,27 @@ def summarize_size(n: int) -> str: return str(n) +def begin_monitoring_file_size(size_display: Gtk.Label, filename: str) -> None: + def update_size_display() -> Any: + done = recording is None + if done: + size_display.set_label('') + else: + try: + size = summarize_size(os.stat(filename).st_size) + except FileNotFoundError: + size = '--' + size_display.set_label(f'{size}') + return GLib.SOURCE_REMOVE if done else GLib.SOURCE_CONTINUE + GLib.timeout_add_seconds(1, update_size_display) + + def on_start_recording(_: Gtk.Button, stack: Gtk.Stack) -> None: global recording # pylint: disable=global-statement assert recording is None filename = make_filename() - size_display = find_size_display(stack) - - def update_size_display() -> Any: - try: - size = summarize_size(os.stat(filename).st_size) - except FileNotFoundError: - size = '--' - size_display.set_label(f'{size}') - return GLib.SOURCE_REMOVE if recording is None else GLib.SOURCE_CONTINUE - GLib.timeout_add_seconds(1, update_size_display) + begin_monitoring_file_size(find_size_display(stack), filename) recording = Stream.start( ['ffmpeg', '-framerate', '25'] + video_source(stack) +