notebookvb

This commit is contained in:
Vladimir Buzalka
2026-05-04 21:26:44 +02:00
parent 417cf86b2d
commit ffb3db1e07
12 changed files with 1143 additions and 16 deletions
@@ -39,7 +39,21 @@ def _load_env():
_load_env()
POPPLER_PATH = r"C:/Poppler/Library/bin"
def _find_poppler() -> str | None:
candidates = [
r"C:/Poppler/Library/bin",
str(Path.home() / r"scoop\apps\poppler\current\Library\bin"),
str(Path.home() / r"scoop\apps\poppler\current\bin"),
]
for p in candidates:
if Path(p).exists():
return p
pdfinfo = shutil.which("pdfinfo")
if pdfinfo:
return str(Path(pdfinfo).parent)
return None
POPPLER_PATH = _find_poppler()
CORRECTIONS = True # True = corrections.json se načítá a ukládá; False = ignorovat
_DROPBOX = Path(get_dropbox_root())
@@ -292,7 +306,10 @@ def extract_info(pdf_path: Path) -> dict:
def open_preview(pdf_path: Path) -> tuple[subprocess.Popen, Path]:
geom_file = Path(tempfile.mktemp(suffix=".json"))
proc = subprocess.Popen([sys.executable, str(VIEWER), str(pdf_path), f"--write-geometry={geom_file}"])
proc = subprocess.Popen(
[sys.executable, str(VIEWER), str(pdf_path), f"--write-geometry={geom_file}"],
stderr=subprocess.PIPE,
)
return proc, geom_file
@@ -318,6 +335,8 @@ def run_rename_dialog(nazev: str, info_lines: list, below_y: int = None) -> str
env = {**os.environ, "PYTHONIOENCODING": "utf-8"}
proc = subprocess.run(args, capture_output=True, text=True, encoding="utf-8", env=env)
tmp.unlink(missing_ok=True)
if proc.stderr.strip():
print(f" [rename_dialog] CHYBA:\n{proc.stderr.strip()}")
out = proc.stdout.strip()
return json.loads(out).get("value") if out else None
@@ -390,6 +409,9 @@ def process_file(pdf_path: Path):
final_name = run_rename_dialog(nazev, info_lines, below_y=below_y)
preview.terminate()
stderr_out = preview.stderr.read().decode("utf-8", errors="replace").strip() if preview.stderr else ""
if stderr_out:
print(f" [preview] CHYBA: {stderr_out}")
if not final_name:
print(" Přeskočeno.")
+5 -1
View File
@@ -17,7 +17,8 @@ def main():
try:
from PIL import Image, ImageTk
import fitz
except ImportError:
except ImportError as e:
print(f"[preview_viewer] Chybí knihovna: {e}", file=sys.stderr)
sys.exit(2)
suffix = pdf_path.suffix.lower()
@@ -104,6 +105,9 @@ def main():
geom_path.write_text(_json.dumps({"x": x, "y": 0, "w": w, "h": h}), encoding="utf-8")
break
root.lift()
root.focus_force()
root.after(100, lambda: root.focus_force())
root.mainloop()
+14 -1
View File
@@ -81,19 +81,32 @@ def main():
root.update_idletasks()
sw = root.winfo_screenwidth()
w = root.winfo_width()
h = root.winfo_height()
x = (sw - w) // 2
# Skutečná použitelná výška (bez taskbaru)
import ctypes, ctypes.wintypes
rect = ctypes.wintypes.RECT()
ctypes.windll.user32.SystemParametersInfoW(48, 0, ctypes.byref(rect), 0)
work_bottom = rect.bottom # spodní hrana work area
# Pozice pod preview oknem pokud byl předán argument --below-y=N
below_y = None
for arg in sys.argv:
if arg.startswith("--below-y="):
below_y = int(arg.split("=", 1)[1])
break
y = below_y if below_y is not None else (root.winfo_screenheight() - root.winfo_height() - 60)
if below_y is not None and below_y + h + 10 <= work_bottom:
y = below_y # vejde se pod preview
else:
y = max(0, work_bottom - h - 10) # přilepit těsně nad taskbar
root.geometry(f"+{x}+{y}")
root.lift()
root.focus_force()
root.after(100, lambda: root.focus_force())
root.after(200, lambda: root.attributes("-topmost", True))
root.mainloop()
print(json.dumps({"value": result["value"]}, ensure_ascii=False))
@@ -133,6 +133,10 @@ def main():
root.bind("<Escape>", lambda e: preskocit())
show(0)
root.lift()
root.focus_force()
root.after(100, lambda: root.focus_force())
root.after(200, lambda: root.attributes("-topmost", True))
root.mainloop()
for d in docs: