-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreenshotters.py
41 lines (31 loc) · 1.36 KB
/
screenshotters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import subprocess
from SystemInfo import SystemInfo
sysInfo: SystemInfo = SystemInfo()
def runCmd(cmd: list[str]) -> subprocess.CompletedProcess:
if sysInfo.usedOS == "windows":
return subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags=subprocess.CREATE_NO_WINDOW)
return subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def hasCmd(cmd: str) -> bool:
runcmd: list[str] = ["which", cmd]
if os.name.lower() == "nt":
runcmd = ["powershell", "-Command", f"(Get-Command {cmd}).Path"]
return len(runCmd(runcmd).stdout) > 0
def gnomeScreenshot():
filename = ".lc-gnome-sc.tmp.png"
runCmd(["gnome-screenshot", "-f", filename])
data = None
with open(filename, "rb") as f:
data = f.read()
os.remove(filename)
return data
tools: dict[str, callable] = {
"flameshot": lambda: runCmd(["flameshot", "full", "--raw"]).stdout,
"spectacle": lambda: runCmd(["spectacle", "-nbfo", "/dev/stdout"]).stdout,
"gnome": gnomeScreenshot,
"scrot": lambda: runCmd(["scrot", "-"]).stdout,
"grim": lambda: runCmd(["grim", "-"]).stdout,
"grimblast": lambda: runCmd(["grimblast", "save", "screen", "-"]).stdout
}
defaultTool = ["Default"] if not sysInfo.isWaylandSession() else []
availableTools: list[str] = defaultTool + [cmd for cmd in tools.keys() if hasCmd(cmd)]