Compare commits
26 Commits
main
...
ueberzugpp
Author | SHA1 | Date | |
---|---|---|---|
d0ac564cee | |||
53c3a55e07 | |||
1ae88d2182 | |||
e0ce0d1b1d | |||
e88cf6b98d | |||
5775502dc1 | |||
c91b3a3f93 | |||
ea80175dc7 | |||
5f9d528f3e | |||
39d7471dc8 | |||
f5344f606e | |||
da43eae362 | |||
fdf3e0fb50 | |||
5f200626b8 | |||
1fd5e820f4 | |||
|
429a7be16a | ||
|
75bc8efbb8 | ||
|
6be0e503fb | ||
|
6b48fbdec1 | ||
|
6795766160 | ||
|
bb049d5e92 | ||
|
86ab3a0596 | ||
|
59159e4ad2 | ||
|
8f9603976e | ||
|
4d86c53fe4 | ||
|
5ee8743ed2 |
@ -1,5 +1,5 @@
|
||||
version = "1.2.1"
|
||||
fullversion = f"{version}-legacy"
|
||||
fullversion = f"{version}"
|
||||
|
||||
settings_map = {
|
||||
"q": "quit",
|
||||
|
@ -13,7 +13,7 @@ if __name__ == "__main__": # make relative imports work as described here: http
|
||||
filepath = path.realpath(path.abspath(__file__))
|
||||
sys.path.insert(0, path.dirname(path.dirname(filepath)))
|
||||
|
||||
import ueberzug.lib.v0 as uz
|
||||
from .ueberzug import UeberzugLayer
|
||||
|
||||
from .configs import ConfigManager
|
||||
from .globals import version, fullversion, settings_map
|
||||
@ -31,7 +31,7 @@ CURSOR_Y = 2
|
||||
KEYS_BEGIN = 5
|
||||
|
||||
class Sorter:
|
||||
def __init__(self, wdir, canvas, config):
|
||||
def __init__(self, wdir, config):
|
||||
self.wd = wdir
|
||||
|
||||
self.images = [] # old paths
|
||||
@ -58,15 +58,15 @@ class Sorter:
|
||||
c.echo()
|
||||
|
||||
# ueberzug
|
||||
self.canvas = canvas
|
||||
self._ueberzug = UeberzugLayer(pid_file="/tmp/ueberzug-imgsort.pid")
|
||||
self._img_x = SIDEBAR_WIDTH + 1
|
||||
self._img_y = 2
|
||||
self._img_width = self.win_x - SIDEBAR_WIDTH - 1
|
||||
self._img_height = self.win_y - FOOTER_HEIGHT - 2
|
||||
self._img_identifier = "imgsort_preview"
|
||||
|
||||
|
||||
|
||||
self.placement = self.canvas.create_placement("p1", x=0, y=0, path="")
|
||||
self.placement.visibility = uz.Visibility.VISIBLE
|
||||
self.placement.scaler = uz.ScalerOption.FIT_CONTAIN.value
|
||||
self.placement.x = SIDEBAR_WIDTH + 1
|
||||
self.placement.y = 2
|
||||
self.placement.width = self.win_x - SIDEBAR_WIDTH - 1
|
||||
self.placement.height = self.win_y - FOOTER_HEIGHT - 2
|
||||
|
||||
def get_images(self):
|
||||
"""
|
||||
@ -85,9 +85,9 @@ class Sorter:
|
||||
# print(self.images)
|
||||
|
||||
def display_image(self):
|
||||
with self.canvas.lazy_drawing: # issue ueberzug command AFTER with-statement
|
||||
self.placement.path = self.image
|
||||
self.window.addnstr(0, SIDEBAR_WIDTH + 1, self.placement.path, self.win_x - SIDEBAR_WIDTH - 1)
|
||||
self._ueberzug.display_image(self.image, x=self._img_x, y=self._img_y, max_width=self._img_width, max_height=self._img_height, identifier=self._img_identifier)
|
||||
self.window.addnstr(0, SIDEBAR_WIDTH + 1, self.image, self.win_x - SIDEBAR_WIDTH - 1)
|
||||
|
||||
|
||||
def sort(self):
|
||||
"""
|
||||
@ -258,8 +258,7 @@ Image Sorter {fullversion}
|
||||
else:
|
||||
config = confman.present_config_selection(args.sort_dir)
|
||||
|
||||
with uz.Canvas() as canvas:
|
||||
sorter = Sorter(wd, canvas, config)
|
||||
sorter = Sorter(wd, config)
|
||||
sorter.get_images()
|
||||
sorter.sort()
|
||||
|
||||
|
49
imgsort/ueberzug.py
Normal file
49
imgsort/ueberzug.py
Normal file
@ -0,0 +1,49 @@
|
||||
import subprocess
|
||||
from os import path
|
||||
|
||||
from .globals import error
|
||||
|
||||
class UeberzugLayer():
|
||||
"""Wrapper for Ueberzug++"""
|
||||
|
||||
def __init__(self, pid_file = "/tmp/ueberzug-py.pid", socket="/tmp/ueberzugpp-%pid%.socket", no_opencv=True):
|
||||
self._socket = None
|
||||
self._pid_file = pid_file
|
||||
self._pid = None
|
||||
ret = subprocess.run(["ueberzug", "layer", "--pid-file", pid_file, "--no-stdin", "--no-opencv" if no_opencv else ""], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
if not ret.returncode == 0:
|
||||
error(f"UeberzugLayer.init: ueberzug layer exited with {ret.returncode}")
|
||||
if not path.isfile(pid_file):
|
||||
error(f"UeberzugLayer.init: can not find ueberzug pid file at '{pid_file}'")
|
||||
with open(pid_file, "r") as file:
|
||||
try:
|
||||
self._pid = int(file.read())
|
||||
except ValueError as e:
|
||||
raise Exception(f"Invalid content of pid file {pid_file}: {e}")
|
||||
self._socket = socket.replace("%pid%", str(self._pid))
|
||||
# if not path.exists(self._socket):
|
||||
# raise Exception(f"Ueberzug socket not found: {self._socket}")
|
||||
|
||||
def display_image(self, image, x=0, y=0, max_width=0, max_height=0, identifier="Image"):
|
||||
ret = subprocess.run(["ueberzug", "cmd", "-s", self._socket, "-a", "add", "-i", identifier, "-f", image, "-x", str(x), "-y", str(y), "--max-width", str(max_width), "--max-height", str(max_height)])
|
||||
if not ret.returncode == 0:
|
||||
self._socket = None
|
||||
error(f"UeberzugLayer.display_image: ueberzug layer exited with {ret.returncode}")
|
||||
|
||||
def remove_image(self, identifier="Image"):
|
||||
ret = subprocess.run(["ueberzug", "cmd", "-s", self._socket, "-a", "remove", "-i", identifier])
|
||||
if not ret.returncode == 0:
|
||||
self._socket = None
|
||||
error(f"UeberzugLayer.remove_image: ueberzug layer exited with {ret.returncode}")
|
||||
|
||||
def __del__(self):
|
||||
from os import remove
|
||||
try:
|
||||
remove(self._pid_file)
|
||||
except:
|
||||
pass
|
||||
if self._socket is not None:
|
||||
import subprocess # might be unloaded
|
||||
ret = subprocess.run(["ueberzug", "cmd", "-s", self._socket, "-a", "exit"])
|
||||
if not ret.returncode == 0:
|
||||
error(f"UeberzugLayer.__del__: ueberzug layer exited with {ret.returncode}")
|
Loading…
Reference in New Issue
Block a user