first commit
This commit is contained in:
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# Python-generated files
|
||||
__pycache__/
|
||||
*.py[oc]
|
||||
build/
|
||||
dist/
|
||||
wheels/
|
||||
*.egg-info
|
||||
|
||||
# Virtual environments
|
||||
.venv
|
||||
1
.python-version
Normal file
1
.python-version
Normal file
@@ -0,0 +1 @@
|
||||
3.12
|
||||
16
backends/spectacle.py
Normal file
16
backends/spectacle.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import os
|
||||
import subprocess
|
||||
from screenshot_backend import register_backend, ScreenshotBackend
|
||||
|
||||
|
||||
@register_backend
|
||||
class SpectacleBackend(ScreenshotBackend):
|
||||
def supports(self) -> bool:
|
||||
return "KDE" in os.environ.get("XDG_CURRENT_DESKTOP", "")
|
||||
|
||||
def active_window(self) -> str:
|
||||
path = "hgot.png"
|
||||
print("Running")
|
||||
subprocess.run(["spectacle", "-a", "-b", "-n", "-o", path])
|
||||
|
||||
return path
|
||||
15
main.py
Normal file
15
main.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import subprocess
|
||||
from screenshot_backend import get_backend
|
||||
from backends.spectacle import SpectacleBackend
|
||||
|
||||
|
||||
def main():
|
||||
print("Hello from wydt!")
|
||||
|
||||
backend = get_backend()
|
||||
path = backend.active_window()
|
||||
print(path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
7
pyproject.toml
Normal file
7
pyproject.toml
Normal file
@@ -0,0 +1,7 @@
|
||||
[project]
|
||||
name = "wydt"
|
||||
version = "0.1.0"
|
||||
description = "watcha doin' there? Your own digital invigilator making sure you're not distracted"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
dependencies = []
|
||||
26
screenshot_backend.py
Normal file
26
screenshot_backend.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class ScreenshotBackend(ABC):
|
||||
@abstractmethod
|
||||
def supports(self) -> bool:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def active_window(self) -> str:
|
||||
pass
|
||||
|
||||
|
||||
_backends = []
|
||||
|
||||
|
||||
def register_backend(cls):
|
||||
_backends.append(cls())
|
||||
return cls
|
||||
|
||||
|
||||
def get_backend() -> ScreenshotBackend:
|
||||
for backend in _backends:
|
||||
if backend.supports():
|
||||
return backend
|
||||
raise RuntimeError("No screenshot backend available")
|
||||
Reference in New Issue
Block a user