diff --git a/README.md b/README.md index 9cf10af..59a9148 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +# Fork note +- It allows using spectacle. Since gnome protocol is not supported in KDE. +- I might work on the todos given the origin author seems no longer work on this project. + # pix2tex - LaTeX OCR [![GitHub](https://img.shields.io/github/license/lukas-blecher/LaTeX-OCR)](https://github.com/lukas-blecher/LaTeX-OCR) [![Documentation Status](https://readthedocs.org/projects/pix2tex/badge/?version=latest)](https://pix2tex.readthedocs.io/en/latest/?badge=latest) [![PyPI](https://img.shields.io/pypi/v/pix2tex?logo=pypi)](https://pypi.org/project/pix2tex) [![PyPI - Downloads](https://img.shields.io/pypi/dm/pix2tex?logo=pypi)](https://pypi.org/project/pix2tex) [![GitHub all releases](https://img.shields.io/github/downloads/lukas-blecher/LaTeX-OCR/total?color=blue&logo=github)](https://github.com/lukas-blecher/LaTeX-OCR/releases) [![Docker Pulls](https://img.shields.io/docker/pulls/lukasblecher/pix2tex?logo=docker)](https://hub.docker.com/r/lukasblecher/pix2tex) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/lukas-blecher/LaTeX-OCR/blob/main/notebooks/LaTeX_OCR_test.ipynb) [![Hugging Face Spaces](https://img.shields.io/badge/🤗%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/lukbl/LaTeX-OCR) diff --git a/pix2tex/gui.py b/pix2tex/gui.py index 1b0e93b..feef4e9 100644 --- a/pix2tex/gui.py +++ b/pix2tex/gui.py @@ -117,10 +117,14 @@ def onClick(self): self.snip_using_grim() elif os.environ.get('SCREENSHOT_TOOL') == "pil": self.snipWidget.snip() + elif os.environ.get('SCREENSHOT_TOOL') == "spectacle": + self.snip_using_spectacle() elif which('gnome-screenshot'): self.snip_using_gnome_screenshot() elif which('grim') and which('slurp'): self.snip_using_grim() + elif which('spectacle'): + self.snip_using_spectacle() else: self.snipWidget.snip() @@ -142,6 +146,18 @@ def snip_using_gnome_screenshot(self): print("If you don't have gnome-screenshot installed, please install it.") self.returnSnip() + def snip_using_spectacle(self): + try: + with tempfile.NamedTemporaryFile() as tmp: + subprocess.run(["spectacle", "-n", "-r", "-b", f"-o={tmp.name}"]) + # -n for no notification, -r for region screenshot, -b for no post-screenshot gui session + # Use `tmp.name` instead of `tmp.file` due to compatability issues between Pillow and tempfile + self.returnSnip(Image.open(tmp.name)) + except: + print(f"Failed to load saved screenshot! Did you cancel the screenshot?") + print("If you don't have spectacle installed, please install it.") + self.returnSnip() + def snip_using_grim(self): try: p = subprocess.run('slurp',