allow users to choose between escrotum and i3-scrot for screen capture

This commit is contained in:
kageru 2017-11-22 09:49:00 +01:00
parent 92b255d612
commit caaba34666
2 changed files with 19 additions and 6 deletions

View File

@ -17,6 +17,12 @@ curl_command = None
# This is where the screenshots are saved locally
local_directory = '/home/kageru/pyshare/'
# Use i3scrot for screen capture. Otherwise, escrotum will be used.
# You might have to install the capture tool you want to use via your package manager.
# i3scrot was much faster for me when working with multiple high-res displays.
# If you do use it, you manually need to set its save directory to your local_directory (above) + 'tmp' in ~/.config/i3-scrot.conf
use_i3scrot = False
# Directory on the ftp server where you want the screenshots to be sent
remote_directory = '/usr/share/nginx/html/pyshare/'
# Template for the link that the script will generate. {} is the filename

View File

@ -46,12 +46,19 @@ def upload_local_file(path: str) -> str:
def take_screenshot() -> None:
tmppath = os.path.join(config.local_directory, 'tmp')
tmpdir = os.listdir(tmppath)
for f in tmpdir:
os.remove(os.path.join(tmppath, f))
# you can also use programs like escrotum here, but i3-scrot was much faster for me
call(['i3-scrot', '-s'])
file = os.path.join(config.local_directory, 'tmp', os.listdir(tmppath)[0])
if not os.path.isdir(tmppath):
os.mkdir(tmppath)
else:
tmpdir = os.listdir(tmppath)
for f in tmpdir:
os.remove(os.path.join(tmppath, f))
if config.use_i3scrot:
call(['i3-scrot', '-s'])
file = os.path.join(tmppath, os.listdir(tmppath)[0])
else:
tempname = generate_filename(3, 'png')
call(['escrotum', '-s', tempname])
file = os.path.join(tmppath, tempname)
ftp_upload(ext='png', sourcefile=file)
os.remove(file)