]>
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.
8 from typing
import Callable
11 gi
.require_version("Gtk", "4.0")
12 from gi
.repository
import Gtk
# nopep8 pylint: disable=wrong-import-position
18 def on_start_recording(_
: Gtk
.Button
, stack
: Gtk
.Stack
) -> None:
19 global recording
# pylint: disable=global-statement
20 assert recording
is None
21 screen_size
= '1366x768' # TODO
24 '-video_size', screen_size
,
26 '-f', 'x11grab', '-i', ':0.0+0,0',
27 '-f', 'pulse', '-ac', '2', '-i', 'default',
28 'screen-recording.mkv'] # nopep8
29 # pylint: disable=consider-using-with
30 recording
= subprocess
.Popen(command
, stdin
=subprocess
.PIPE
)
31 stack
.set_visible_child_name("recording")
34 def on_stop_recording(_
: Gtk
.Button
, stack
: Gtk
.Stack
) -> None:
35 global recording
# pylint: disable=global-statement
36 assert recording
is not None
37 stdin
= recording
.stdin
38 assert stdin
is not None
43 stack
.set_visible_child_name("not_recording")
46 def make_button(label
: str, action
: Callable
[[
47 Gtk
.Button
, Gtk
.Stack
], None], stack
: Gtk
.Stack
) -> Gtk
.Button
:
48 button
= Gtk
.Button(label
=label
)
49 button
.connect('clicked', action
, stack
)
50 button
.set_margin_top(10)
51 button
.set_margin_start(10)
52 button
.set_margin_end(10)
53 button
.set_margin_bottom(10)
57 def on_activate(app
: Gtk
.Application
) -> None:
58 win
= Gtk
.ApplicationWindow(application
=app
)
62 start_recording
= make_button("Start Recording", on_start_recording
, stack
)
63 stack
.add_named(start_recording
, "not_recording")
66 box
.set_orientation(Gtk
.Orientation
.VERTICAL
)
67 stop_recording
= make_button("Stop Recording", on_stop_recording
, stack
)
68 box
.append(stop_recording
)
69 stack
.add_named(box
, "recording")
76 app
= Gtk
.Application(application_id
='net.chkno.srec')
77 app
.connect('activate', on_activate
)
81 if __name__
== '__main__':