]>
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
8 from datetime
import datetime
11 from typing
import Callable
14 gi
.require_version("Gtk", "4.0")
15 from gi
.repository
import Gtk
# nopep8 pylint: disable=wrong-import-position
21 process
: subprocess
.Popen
[bytes]
24 recording
: Recording |
None = None
27 def make_filename() -> str:
28 directory
= os
.environ
.get(
30 os
.path
.expanduser('~/Videos'))
31 os
.makedirs(directory
, exist_ok
=True)
32 timestamp
= datetime
.now().strftime('%Y-%m-%d %H:%M:%S')
33 return os
.path
.join(directory
, f
'srec {timestamp}.mkv')
36 def on_start_recording(_
: Gtk
.Button
, stack
: Gtk
.Stack
) -> None:
37 global recording
# pylint: disable=global-statement
38 assert recording
is None
39 filename
= make_filename()
43 '-f', 'x11grab', '-i', ':0.0+0,0',
44 '-f', 'pulse', '-ac', '2', '-i', 'default',
46 # pylint: disable=consider-using-with
47 recording
= Recording(
49 process
=subprocess
.Popen(command
, stdin
=subprocess
.PIPE
))
50 stack
.set_visible_child_name("recording")
53 def on_stop_recording(_
: Gtk
.Button
, stack
: Gtk
.Stack
) -> None:
54 global recording
# pylint: disable=global-statement
55 assert recording
is not None
56 stdin
= recording
.process
.stdin
57 assert stdin
is not None
60 recording
.process
.wait()
62 stack
.set_visible_child_name("not_recording")
65 def make_button(label
: str, action
: Callable
[[
66 Gtk
.Button
, Gtk
.Stack
], None], stack
: Gtk
.Stack
) -> Gtk
.Button
:
67 button
= Gtk
.Button(label
=label
)
68 button
.connect('clicked', action
, stack
)
69 button
.set_margin_top(10)
70 button
.set_margin_start(10)
71 button
.set_margin_end(10)
72 button
.set_margin_bottom(10)
76 def on_activate(app
: Gtk
.Application
) -> None:
77 win
= Gtk
.ApplicationWindow(application
=app
)
82 nr_box
.set_orientation(Gtk
.Orientation
.VERTICAL
)
83 nr_box
.append(make_button("Start Recording", on_start_recording
, stack
))
84 stack
.add_named(nr_box
, "not_recording")
87 r_box
.set_orientation(Gtk
.Orientation
.VERTICAL
)
88 r_box
.append(make_button("Stop Recording", on_stop_recording
, stack
))
89 stack
.add_named(r_box
, "recording")
96 app
= Gtk
.Application(application_id
='net.chkno.srec')
97 app
.connect('activate', on_activate
)
101 if __name__
== '__main__':