mirror of
https://github.com/HorlogeSkynet/archey4
synced 2025-06-23 16:00:12 +02:00
[SCREENSHOT] Add delay before screenshot is taken.
Rationale: Before, sometimes the screenshot would be taken before Archey's output was visible in the terminal. This delay ensures that the terminal has had the chance to display the output before we take any screenshot. Additionally, this commit adds a success message detailing the screenshot program used.
This commit is contained in:
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
from contextlib import ExitStack
|
from contextlib import ExitStack
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -49,6 +50,14 @@ def take_screenshot(output_file=None):
|
|||||||
screenshot_tools['KDE-Spectacle'] = ['spectacle', '-b', '-o', output_file]
|
screenshot_tools['KDE-Spectacle'] = ['spectacle', '-b', '-o', output_file]
|
||||||
screenshot_tools['Xfce4-Screenshooter'] = ['xfce4-screenshooter', '-f', '-s', output_dir]
|
screenshot_tools['Xfce4-Screenshooter'] = ['xfce4-screenshooter', '-f', '-s', output_dir]
|
||||||
|
|
||||||
|
# This part purposefully blocks so we wait a little bit before taking the screenshot.
|
||||||
|
# It prevents taking a screenshot before Archey's output has appeared.
|
||||||
|
for time_remaining in range(3, 0, -1):
|
||||||
|
print('\rTaking screenshot in {:1d}...'.format(time_remaining), end='', flush=True)
|
||||||
|
time.sleep(1)
|
||||||
|
print('\r' + ' ' * 26, end='\r', flush=True)
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
with ExitStack() as defer_stack:
|
with ExitStack() as defer_stack:
|
||||||
for screenshot_tool, screenshot_cmd in screenshot_tools.items():
|
for screenshot_tool, screenshot_cmd in screenshot_tools.items():
|
||||||
try:
|
try:
|
||||||
@ -64,6 +73,10 @@ def take_screenshot(output_file=None):
|
|||||||
file=sys.stderr
|
file=sys.stderr
|
||||||
))
|
))
|
||||||
continue
|
continue
|
||||||
|
defer_stack.callback(partial(
|
||||||
|
print,
|
||||||
|
'Took screenshot with {}'.format(screenshot_tool)
|
||||||
|
))
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
defer_stack.callback(partial(
|
defer_stack.callback(partial(
|
||||||
|
Reference in New Issue
Block a user