Compare commits

..

22 Commits

Author SHA1 Message Date
cd541d23e4 fix --sort-dir not respected 2024-02-07 11:23:22 +01:00
2122627fdf change exit code 2024-02-07 11:23:15 +01:00
b83a400732 rm pycache 2023-12-16 00:48:35 +01:00
c305165edb improve dependecy info 2023-12-16 00:34:38 +01:00
ef48a089cf configman always return keys 2023-12-16 00:24:44 +01:00
d78f522743 bumb version 2023-12-16 00:24:27 +01:00
15578b4d3c dont exit on user error 2023-12-16 00:01:29 +01:00
8f8e6bdbc5 rm false import 2023-12-16 00:00:11 +01:00
217a034fbf refactor with configmanager 2023-12-15 23:56:45 +01:00
8eb54555f5 move shared variables 2023-12-15 23:50:54 +01:00
643673317b dont use o in example 2023-12-01 21:34:44 +01:00
4eba27bc89 unify style with ++ variant 2023-12-01 21:31:05 +01:00
07859d6682 merge fixes 2023-12-01 21:10:02 +01:00
56f5423766 use argparse and allow sort into other dir 2023-12-01 21:09:54 +01:00
Matthias Quintern
4dcda19614 Center image 2023-11-01 01:22:07 +01:00
matthias@arch
a1a0f52191 add example image 2023-11-01 01:22:07 +01:00
matthias@arch
195877b37a fix typo 2023-10-31 17:56:27 +01:00
matthias@arch
944d69505c fix head 2023-10-23 00:44:39 +02:00
Matthias@Dell
b1d3d76755 add xdg-open 2023-10-23 00:36:10 +02:00
Matthias@Dell
abdf937968 fix window resize issue 2023-10-23 00:18:04 +02:00
Matthias@Dell
17d9d1df43 use argparse, add xdg-open 2023-10-23 00:17:58 +02:00
Matthias@Dell
be6dc9f224 improve error handling 2023-10-23 00:06:56 +02:00
5 changed files with 18 additions and 66 deletions

0
LICENSE Executable file → Normal file
View File

0
README.md Executable file → Normal file
View File

View File

@ -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",

View File

@ -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()

View File

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