]> git.scottworley.com Git - srec/commitdiff
Recording object
authorScott Worley <scottworley@scottworley.com>
Sun, 21 Sep 2025 23:58:31 +0000 (16:58 -0700)
committerScott Worley <scottworley@scottworley.com>
Sun, 21 Sep 2025 23:58:31 +0000 (16:58 -0700)
srec.py

diff --git a/srec.py b/srec.py
index 36000c92019c20a196cd7853d412a12633c66876..0fc81a405c2bf92d0baf2599a7b8d61ed414143c 100644 (file)
--- a/srec.py
+++ b/srec.py
@@ -4,6 +4,7 @@
 # under the terms of the GNU General Public License as published by the
 # Free Software Foundation, version 3.
 
+from dataclasses import dataclass
 import subprocess
 from typing import Callable
 
@@ -12,7 +13,12 @@ gi.require_version("Gtk", "4.0")
 from gi.repository import Gtk  # nopep8 pylint: disable=wrong-import-position
 
 
-recording = None
+@dataclass
+class Recording:
+    process: subprocess.Popen[bytes]
+
+
+recording: Recording | None = None
 
 
 def on_start_recording(_: Gtk.Button, stack: Gtk.Stack) -> None:
@@ -27,18 +33,19 @@ def on_start_recording(_: Gtk.Button, stack: Gtk.Stack) -> None:
             '-f', 'pulse', '-ac', '2', '-i', 'default',
             'screen-recording.mkv']  # nopep8
     # pylint: disable=consider-using-with
-    recording = subprocess.Popen(command, stdin=subprocess.PIPE)
+    recording = Recording(
+        process=subprocess.Popen(command, stdin=subprocess.PIPE))
     stack.set_visible_child_name("recording")
 
 
 def on_stop_recording(_: Gtk.Button, stack: Gtk.Stack) -> None:
     global recording  # pylint: disable=global-statement
     assert recording is not None
-    stdin = recording.stdin
+    stdin = recording.process.stdin
     assert stdin is not None
     stdin.write(b'q')
     stdin.flush()
-    recording.wait()
+    recording.process.wait()
     recording = None
     stack.set_visible_child_name("not_recording")