X-Git-Url: http://git.scottworley.com/srec/blobdiff_plain/990069b559e1e3396745a09b2d2fe8612450a37e..6a0da393da2a364a1b77ac8e5ebfbfba4c2cd1a0:/srec.py diff --git a/srec.py b/srec.py index 36000c9..0fc81a4 100644 --- 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")