]>
git.scottworley.com Git - srec/blob - srec.py
1 # srec: A simple GUI for screen recording
3 # This program is free software: you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License as published by the
5 # Free Software Foundation, version 3.
7 from dataclasses
import dataclass
9 from typing
import Callable
12 gi
.require_version("Gtk", "4.0")
13 from gi
.repository
import Gtk
# nopep8 pylint: disable=wrong-import-position
18 process
: subprocess
.Popen
[bytes]
21 recording
: Recording |
None = None
24 def on_start_recording(_
: Gtk
.Button
, stack
: Gtk
.Stack
) -> None:
25 global recording
# pylint: disable=global-statement
26 assert recording
is None
27 screen_size
= '1366x768' # TODO
30 '-video_size', screen_size
,
32 '-f', 'x11grab', '-i', ':0.0+0,0',
33 '-f', 'pulse', '-ac', '2', '-i', 'default',
34 'screen-recording.mkv'] # nopep8
35 # pylint: disable=consider-using-with
36 recording
= Recording(
37 process
=subprocess
.Popen(command
, stdin
=subprocess
.PIPE
))
38 stack
.set_visible_child_name("recording")
41 def on_stop_recording(_
: Gtk
.Button
, stack
: Gtk
.Stack
) -> None:
42 global recording
# pylint: disable=global-statement
43 assert recording
is not None
44 stdin
= recording
.process
.stdin
45 assert stdin
is not None
48 recording
.process
.wait()
50 stack
.set_visible_child_name("not_recording")
53 def make_button(label
: str, action
: Callable
[[
54 Gtk
.Button
, Gtk
.Stack
], None], stack
: Gtk
.Stack
) -> Gtk
.Button
:
55 button
= Gtk
.Button(label
=label
)
56 button
.connect('clicked', action
, stack
)
57 button
.set_margin_top(10)
58 button
.set_margin_start(10)
59 button
.set_margin_end(10)
60 button
.set_margin_bottom(10)
64 def on_activate(app
: Gtk
.Application
) -> None:
65 win
= Gtk
.ApplicationWindow(application
=app
)
69 start_recording
= make_button("Start Recording", on_start_recording
, stack
)
70 stack
.add_named(start_recording
, "not_recording")
73 box
.set_orientation(Gtk
.Orientation
.VERTICAL
)
74 stop_recording
= make_button("Stop Recording", on_stop_recording
, stack
)
75 box
.append(stop_recording
)
76 stack
.add_named(box
, "recording")
83 app
= Gtk
.Application(application_id
='net.chkno.srec')
84 app
.connect('activate', on_activate
)
88 if __name__
== '__main__':