]> git.scottworley.com Git - srec/blobdiff - srec.py
Factor out Recording.stop()
[srec] / srec.py
diff --git a/srec.py b/srec.py
index 01b5a8ca7ec1200aff08d41fe85e718f224f5341..50f311c14d1dd6d2ff4e4fac08a31fb9af03d645 100644 (file)
--- a/srec.py
+++ b/srec.py
@@ -20,9 +20,15 @@ from gi.repository import GLib  # nopep8 pylint: disable=wrong-import-position
 
 @dataclass
 class Recording:
-    filename: str
     process: subprocess.Popen[bytes]
 
+    def stop(self) -> None:
+        stdin = self.process.stdin
+        assert stdin is not None
+        stdin.write(b'q')
+        stdin.flush()
+        self.process.wait()
+
 
 recording: Recording | None = None
 
@@ -77,7 +83,6 @@ def on_start_recording(_: Gtk.Button, stack: Gtk.Stack) -> None:
                ['-f', 'pulse', '-ac', '2', '-i', 'default', filename])
     # pylint: disable=consider-using-with
     recording = Recording(
-        filename=filename,
         process=subprocess.Popen(command, stdin=subprocess.PIPE))
     stack.set_visible_child_name("recording")
 
@@ -85,11 +90,7 @@ def on_start_recording(_: Gtk.Button, stack: Gtk.Stack) -> None:
 def on_stop_recording(_: Gtk.Button, stack: Gtk.Stack) -> None:
     global recording  # pylint: disable=global-statement
     assert recording is not None
-    stdin = recording.process.stdin
-    assert stdin is not None
-    stdin.write(b'q')
-    stdin.flush()
-    recording.process.wait()
+    recording.stop()
     recording = None
     stack.set_visible_child_name("not_recording")