Skip to content

Commit

Permalink
Merge pull request lukas-blecher#366 from jason44/main
Browse files Browse the repository at this point in the history
Add support for screencapture on KDE Wayland
  • Loading branch information
lukas-blecher authored Dec 5, 2024
2 parents 4122c89 + 917c78a commit 799e3ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ There are three ways to get a prediction from an image.

2. Thanks to [@katie-lim](https://github.com/katie-lim), you can use a nice user interface as a quick way to get the model prediction. Just call the GUI with `latexocr`. From here you can take a screenshot and the predicted latex code is rendered using [MathJax](https://www.mathjax.org/) and copied to your clipboard.

Under linux, it is possible to use the GUI with `gnome-screenshot` (which comes with multiple monitor support) if `gnome-screenshot` was installed beforehand. For Wayland, `grim` and `slurp` will be used when they are both available. Note that `gnome-screenshot` is not compatible with wlroots-based Wayland compositors. Since `gnome-screenshot` will be preferred when available, you may have to set the environment variable `SCREENSHOT_TOOL` to `grim` in this case (other available values are `gnome-screenshot` and `pil`).
Under linux, it is possible to use the GUI with `gnome-screenshot` (which comes with multiple monitor support). For other Wayland compositers, `grim` and `slurp` will be used for wlroots-based Wayland compositers and `spectacle` for KDE Plasma. Note that `gnome-screenshot` is not compatible with wlroots or Qt based compositers. Since `gnome-screenshot` will be preferred when available, you may have to set the environment variable `SCREENSHOT_TOOL` to `grim` or `spectacle` in these cases (other available values are `gnome-screenshot` and `pil`).

![demo](https://user-images.githubusercontent.com/55287601/117812740-77b7b780-b262-11eb-81f6-fc19766ae2ae.gif)

Expand Down
14 changes: 13 additions & 1 deletion pix2tex/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def onClick(self):
self.close()
if os.environ.get('SCREENSHOT_TOOL') == "gnome-screenshot":
self.snip_using_gnome_screenshot()
elif os.environ.get('SCREENSHOT_TOOL') == "spectacle":
self.snip_using_spectacle()
elif os.environ.get('SCREENSHOT_TOOL') == "grim":
self.snip_using_grim()
elif os.environ.get('SCREENSHOT_TOOL') == "pil":
Expand Down Expand Up @@ -142,6 +144,16 @@ 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", "-r", "-b", "-n", "-o", f"{tmp.name}"])
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 Expand Up @@ -351,4 +363,4 @@ def main(arguments):
os.environ['QTWEBENGINE_DISABLE_SANDBOX'] = '1'
app = QApplication(sys.argv)
ex = App(arguments)
sys.exit(app.exec())
sys.exit(app.exec())

0 comments on commit 799e3ed

Please sign in to comment.