Compare commits
22 Commits
ueberzugpp
...
main
Author | SHA1 | Date | |
---|---|---|---|
cd541d23e4 | |||
2122627fdf | |||
b83a400732 | |||
c305165edb | |||
ef48a089cf | |||
d78f522743 | |||
15578b4d3c | |||
8f8e6bdbc5 | |||
217a034fbf | |||
8eb54555f5 | |||
643673317b | |||
4eba27bc89 | |||
07859d6682 | |||
56f5423766 | |||
|
4dcda19614 | ||
|
a1a0f52191 | ||
|
195877b37a | ||
|
944d69505c | ||
|
b1d3d76755 | ||
|
abdf937968 | ||
|
17d9d1df43 | ||
|
be6dc9f224 |
@ -1,5 +1,5 @@
|
|||||||
version = "1.2.1"
|
version = "1.2.1"
|
||||||
fullversion = f"{version}"
|
fullversion = f"{version}-legacy"
|
||||||
|
|
||||||
settings_map = {
|
settings_map = {
|
||||||
"q": "quit",
|
"q": "quit",
|
||||||
|
@ -13,7 +13,7 @@ if __name__ == "__main__": # make relative imports work as described here: http
|
|||||||
filepath = path.realpath(path.abspath(__file__))
|
filepath = path.realpath(path.abspath(__file__))
|
||||||
sys.path.insert(0, path.dirname(path.dirname(filepath)))
|
sys.path.insert(0, path.dirname(path.dirname(filepath)))
|
||||||
|
|
||||||
from .ueberzug import UeberzugLayer
|
import ueberzug.lib.v0 as uz
|
||||||
|
|
||||||
from .configs import ConfigManager
|
from .configs import ConfigManager
|
||||||
from .globals import version, fullversion, settings_map
|
from .globals import version, fullversion, settings_map
|
||||||
@ -31,7 +31,7 @@ CURSOR_Y = 2
|
|||||||
KEYS_BEGIN = 5
|
KEYS_BEGIN = 5
|
||||||
|
|
||||||
class Sorter:
|
class Sorter:
|
||||||
def __init__(self, wdir, config):
|
def __init__(self, wdir, canvas, config):
|
||||||
self.wd = wdir
|
self.wd = wdir
|
||||||
|
|
||||||
self.images = [] # old paths
|
self.images = [] # old paths
|
||||||
@ -58,15 +58,15 @@ class Sorter:
|
|||||||
c.echo()
|
c.echo()
|
||||||
|
|
||||||
# ueberzug
|
# ueberzug
|
||||||
self._ueberzug = UeberzugLayer(pid_file="/tmp/ueberzug-imgsort.pid")
|
self.canvas = canvas
|
||||||
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):
|
def get_images(self):
|
||||||
"""
|
"""
|
||||||
@ -85,9 +85,9 @@ class Sorter:
|
|||||||
# print(self.images)
|
# print(self.images)
|
||||||
|
|
||||||
def display_image(self):
|
def display_image(self):
|
||||||
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)
|
with self.canvas.lazy_drawing: # issue ueberzug command AFTER with-statement
|
||||||
self.window.addnstr(0, SIDEBAR_WIDTH + 1, self.image, self.win_x - SIDEBAR_WIDTH - 1)
|
self.placement.path = self.image
|
||||||
|
self.window.addnstr(0, SIDEBAR_WIDTH + 1, self.placement.path, self.win_x - SIDEBAR_WIDTH - 1)
|
||||||
|
|
||||||
def sort(self):
|
def sort(self):
|
||||||
"""
|
"""
|
||||||
@ -258,7 +258,8 @@ Image Sorter {fullversion}
|
|||||||
else:
|
else:
|
||||||
config = confman.present_config_selection(args.sort_dir)
|
config = confman.present_config_selection(args.sort_dir)
|
||||||
|
|
||||||
sorter = Sorter(wd, config)
|
with uz.Canvas() as canvas:
|
||||||
|
sorter = Sorter(wd, canvas, config)
|
||||||
sorter.get_images()
|
sorter.get_images()
|
||||||
sorter.sort()
|
sorter.sort()
|
||||||
|
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
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