Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for spectacle (KDE) #379

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
16 changes: 16 additions & 0 deletions pix2tex/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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',
Expand Down