11
11
from Foundation import NSUserDefaults
12
12
13
13
14
- def dark_mode ():
14
+ def dark_mode () -> bool :
15
15
return NSUserDefaults .standardUserDefaults ().stringForKey_ ('AppleInterfaceStyle' ) == "Dark"
16
16
17
17
18
18
# Configuration
19
- start_recording = False # Start recording on launch
20
- encode = True # Create video after recording
21
- screenshot_interval = 1.5 # Number of seconds between screenshots
22
- dir_base = os .path .expanduser ("~" ) # Base directory
23
- dir_app = "timelapse" # Output directory
24
- dir_pictures = "Pictures" # Place for pictures in filesystem
25
- dir_movies = "Movies" # Place for movies in filesystem
26
- dir_resources = "./resources/"
19
+ start_recording : bool = False # Start recording on launch
20
+ encode : bool = True # Create video after recording
21
+ screenshot_interval : float = 1.5 # Number of seconds between screenshots
22
+ dir_base : str = os .path .expanduser ("~" ) # Base directory
23
+ dir_app : str = "timelapse" # Output directory
24
+ dir_pictures : str = "Pictures" # Place for pictures in filesystem
25
+ dir_movies : str = "Movies" # Place for movies in filesystem
26
+ dir_resources : str = "./resources/"
27
27
if dark_mode ():
28
28
dir_resources += "white"
29
29
else :
30
30
dir_resources += "black"
31
31
32
- subdir_suffix = "Session-" + time .strftime ("%Y%m%d" ) # Name of subdirectory
33
- image_recording = "record.gif" # App icon recording
34
- image_idle = "stop.gif" # App icon idle
35
- create_session_subdir = True # New screenshot directory for each session
36
- create_movies = True # Create movies from screenshots after recording
32
+ subdir_suffix : str = "Session-" + time .strftime ("%Y%m%d" ) # Name of subdirectory
33
+ image_recording : str = "record.gif" # App icon recording
34
+ image_idle : str = "stop.gif" # App icon idle
35
+ create_session_subdir : str = True # New screenshot directory for each session
36
+ create_movies : bool = True # Create movies from screenshots after recording
37
37
# Menu item text when recorder is running
38
- text_recorder_running = "Stop recording"
39
- text_recorder_idle = "Start recording" # Menu item text when recorder is idle
38
+ text_recorder_running : str = "Stop recording"
39
+ text_recorder_idle : str = "Start recording" # Menu item text when recorder is idle
40
40
# Tooltip of menu icon when not recording
41
- tooltip_idle = "Timelapse screen recorder"
42
- tooltip_running = "Recording | " + tooltip_idle # Tooltip when recording
41
+ tooltip_idle : str = "Timelapse screen recorder"
42
+ tooltip_running : str = "Recording | " + tooltip_idle # Tooltip when recording
43
43
44
44
45
45
###############
46
46
47
47
class Timelapse (NSObject ):
48
48
""" Creates a timelapse video """
49
49
50
- def applicationDidFinishLaunching_ (self , notification ):
50
+ def applicationDidFinishLaunching_ (self , notification ) -> None :
51
51
self .check_dependencies ()
52
52
53
53
# Initialize recording
54
- self .recording = start_recording
54
+ self .recording : bool = start_recording
55
55
self .recorder = None
56
56
57
57
# Set correct output paths
58
- self .recorder_output_basedir = os .path .join (
58
+ self .recorder_output_basedir : str = os .path .join (
59
59
dir_base , dir_pictures , dir_app )
60
- self .encoder_output_basedir = os .path .join (dir_base , dir_movies )
60
+ self .encoder_output_basedir : str = os .path .join (dir_base , dir_movies )
61
61
62
- self .image_dir = self .create_dir (self .recorder_output_basedir )
62
+ self .image_dir : str = self .create_dir (self .recorder_output_basedir )
63
63
64
64
# Create a reference to the statusbar (menubar)
65
65
self .statusbar = NSStatusBar .systemStatusBar ()
@@ -77,13 +77,13 @@ def applicationDidFinishLaunching_(self, notification):
77
77
self .loadIcons ()
78
78
self .setStatus ()
79
79
80
- def loadIcons (self ):
80
+ def loadIcons (self ) -> None :
81
81
self .icon_recording = NSImage .alloc ().initWithContentsOfFile_ (
82
82
os .path .join (dir_resources , image_recording ))
83
83
self .icon_idle = NSImage .alloc ().initWithContentsOfFile_ (
84
84
os .path .join (dir_resources , image_idle ))
85
85
86
- def setStatus (self ):
86
+ def setStatus (self ) -> None :
87
87
""" Sets the image and menu text according to recording status """
88
88
if self .recording :
89
89
self .statusitem .setImage_ (self .icon_recording )
@@ -94,7 +94,7 @@ def setStatus(self):
94
94
self .recordButton .setTitle_ (text_recorder_idle )
95
95
self .statusitem .setToolTip_ (tooltip_idle )
96
96
97
- def createMenu (self ):
97
+ def createMenu (self ) -> menu :
98
98
""" Status bar menu """
99
99
menu = NSMenu .alloc ().init ()
100
100
# Bind record event
@@ -107,7 +107,7 @@ def createMenu(self):
107
107
menu .addItem_ (menuitem )
108
108
return menu
109
109
110
- def startStopRecording_ (self , notification ):
110
+ def startStopRecording_ (self , notification ) -> None :
111
111
if self .recording :
112
112
self .recorder .join (timeout = screenshot_interval * 2 )
113
113
# Create timelapse after recording?
@@ -119,18 +119,18 @@ def startStopRecording_(self, notification):
119
119
notify ("Timelapse started" , "The recording has started" )
120
120
self .recorder = Recorder (self .image_dir , screenshot_interval )
121
121
self .recorder .start ()
122
- self .recording = not self .recording
122
+ self .recording : bool = not self .recording
123
123
self .setStatus ()
124
124
125
125
@objc .python_method
126
- def create_dir (self , base_dir ) :
126
+ def create_dir (self , base_dir : str ) -> str :
127
127
""" Creates a specified directory and the path to it if necessary """
128
128
if create_session_subdir :
129
129
# Create a new subdirectory
130
- output_dir = os .path .join (base_dir , self .get_sub_dir (base_dir ))
130
+ output_dir : str = os .path .join (base_dir , self .get_sub_dir (base_dir ))
131
131
else :
132
132
# Don't create a subdirectory. Use base directory for output
133
- output_dir = base_dir
133
+ output_dir : str = base_dir
134
134
# Create path if it doesn't exist
135
135
try :
136
136
print (f"Output directory: { output_dir } " )
@@ -144,20 +144,20 @@ def create_dir(self, base_dir):
144
144
return output_dir
145
145
146
146
@objc .python_method
147
- def get_sub_dir (self , base_dir ) :
147
+ def get_sub_dir (self , base_dir : str ) -> str :
148
148
""" Returns the next nonexistend subdirectory to base_dir """
149
- subdir_base = os .path .join (base_dir , subdir_suffix )
149
+ subdir_base : str = os .path .join (base_dir , subdir_suffix )
150
150
# Check if we can use subdir without any session id
151
- subdir = subdir_base
151
+ subdir : str = subdir_base
152
152
# Use a session id only if subdir already exists
153
- session_number = 0
153
+ session_number : int = 0
154
154
while os .path .exists (subdir ):
155
155
# We can't use subdir. Create directory with session id
156
156
session_number += 1
157
- subdir = subdir_base + "-" + str (session_number )
157
+ subdir : str = subdir_base + "-" + str (session_number )
158
158
return subdir
159
159
160
- def check_dependencies (self ):
160
+ def check_dependencies (self ) -> None :
161
161
try :
162
162
subprocess .run (['ffmpeg' ], check = True ,
163
163
capture_output = True , timeout = 10.0 )
0 commit comments