Compare commits

..

26 Commits

Author SHA1 Message Date
d0ac564cee fix --sort-dir not respected 2024-02-07 11:22:59 +01:00
53c3a55e07 change exit code 2024-02-07 11:16:53 +01:00
1ae88d2182 fix typo 2023-12-16 01:16:37 +01:00
e0ce0d1b1d improve error handling 2023-12-16 00:54:49 +01:00
e88cf6b98d fix version 2023-12-16 00:34:24 +01:00
5775502dc1 improve dependecy info 2023-12-16 00:33:41 +01:00
c91b3a3f93 configman always return keys 2023-12-16 00:25:21 +01:00
ea80175dc7 bumb version 2023-12-16 00:25:17 +01:00
5f9d528f3e dont exit on user error 2023-12-16 00:25:10 +01:00
39d7471dc8 move line to avoid merge conflicts 2023-12-15 23:59:43 +01:00
f5344f606e refactor with configmanager 2023-12-15 23:50:34 +01:00
da43eae362 move shared variables 2023-12-15 23:50:24 +01:00
fdf3e0fb50 dont use o in example 2023-12-01 21:34:12 +01:00
5f200626b8 merge xdg-open functionality 2023-12-01 21:30:23 +01:00
1fd5e820f4 use argparse and allow sort into other dir 2023-12-01 20:55:57 +01:00
matthias@arch
429a7be16a fix changelog 1.2 2023-11-01 01:27:38 +01:00
matthias@arch
75bc8efbb8 bump version 2023-11-01 01:26:13 +01:00
Matthias Quintern
6be0e503fb
Center image 2023-11-01 01:21:21 +01:00
matthias@arch
6b48fbdec1 add example image 2023-11-01 01:17:09 +01:00
matthias@arch
6795766160 fix typo 2023-11-01 01:06:24 +01:00
matthias@arch
bb049d5e92 fix head 2023-10-23 00:47:18 +02:00
Matthias@Dell
86ab3a0596 add xdg-open 2023-10-23 00:37:53 +02:00
Matthias@Dell
59159e4ad2 rm cache 2023-10-21 13:33:08 +02:00
Matthias@Dell
8f9603976e ueberzug++ support 2023-10-21 13:32:55 +02:00
Matthias@Dell
4d86c53fe4 add ueberzugpp support 2023-10-21 13:32:29 +02:00
Matthias@Dell
5ee8743ed2 add 2023-10-21 13:32:11 +02:00
5 changed files with 66 additions and 18 deletions

0
LICENSE Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

View File

@ -1,5 +1,5 @@
version = "1.2.1"
fullversion = f"{version}-legacy"
fullversion = f"{version}"
settings_map = {
"q": "quit",

View File

@ -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
View 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}")