Compare commits

..

6 Commits

Author SHA1 Message Date
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
Matthias@Dell
89f6eadc30 add gitignore 2023-10-21 13:30:50 +02:00
Matthias@Dell
4e324fb571 changed setup script 2023-10-21 13:29:39 +02:00
9 changed files with 102 additions and 58 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*__pycache__*

0
LICENSE Normal file → Executable file
View File

4
README.md Normal file → Executable file
View File

@ -30,6 +30,10 @@ python3 -m pip install .
You can also install it system-wide using `sudo python3 -m pip install.`
## Changelog
### 1.2
- Works with ueberzugpp
- Use pyproject.toml for installation
### 1.1
- Terminal does not break anymore when program exits
- Todo-Images are now sorted by filename

View File

@ -1,12 +1,11 @@
#!/bin/python3
import curses as c
import ueberzug.lib.v0 as uz
from imgsort.ueberzug import UeberzugLayer
from imgsort.configs import read_config, write_config, select_config, create_config
import curses as c
from os import path, getcwd, listdir, mkdir, makedirs, rename
from sys import argv
settings = {
@ -27,7 +26,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
@ -56,15 +55,13 @@ class Sorter:
c.echo()
# ueberzug
self.canvas = canvas
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
self._ueberzug = UeberzugLayer(pid_file="/tmp/ueberzu-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"
# version
self.version = "Image Sorter 1.1"
@ -101,9 +98,8 @@ 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):
"""
@ -231,7 +227,6 @@ class Sorter:
def main():
# set working directory
print("""
@ -256,10 +251,9 @@ Image Sorter
print(" Config:", config)
exit(1)
with uz.Canvas() as canvas:
sorter = Sorter(wd, canvas, config)
sorter.get_images()
sorter.sort()
sorter = Sorter(wd, config)
sorter.get_images()
sorter.sort()
if __name__ == "__main__":

45
imgsort/ueberzug.py Normal file
View File

@ -0,0 +1,45 @@
import subprocess
from os import path
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:
raise Exception(f"ueberzug layer exited with {ret.returncode}")
if not path.isfile(pid_file):
raise Exception(f"Ueberzug pid file not found: {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:
raise Exception(f"ueberzug cmd 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:
raise Exception(f"ueberzug cmd exited with {ret.returncode}")
def __del__(self):
from os import remove
try:
remove(self._pid_file)
except:
pass
import subprocess # might be unloaded
ret = subprocess.run(["ueberzug", "cmd", "-s", self._socket, "-a", "exit"])
if not ret.returncode == 0:
raise Exception(f"ueberzug cmd exited with {ret.returncode}")

33
pyproject.toml Normal file
View File

@ -0,0 +1,33 @@
[build-system]
requires = ["setuptools"]
[project]
name = "imgsort"
version = "1.2.0"
description = "A program that lets you easily sort images into different folders."
requires-python = ">=3.10"
readme = "README.md"
license = {file = "LICENSE"}
authors = [
{ name = "Matthias Quintern", email = "matthias.quintern@posteo.de" }
]
classifiers = [
"Operating System :: POSIX :: Linux",
"Environment :: Console :: Curses",
"Programming Language :: Python :: 3",
"Topic :: Multimedia :: Graphics",
"Topic :: Utilities",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
]
dependencies = [
]
[project.urls]
repository = "https://github.com/MatthiasQuintern/imgsort"
[project.scripts]
imgsort = "imgsort.sorter:main"
[tool.setuptools.packages.find]
where = ["."]

View File

@ -1,33 +0,0 @@
from setuptools import setup
setup(
name="imgsort",
version="1.1",
description="A program that lets you easily sort images into different folders.",
author="Matthias Quintern",
author_email="matthiasqui@protonmail.com",
url="https://github.com/MatthiasQuintern/imgsort.git",
license="GPLv3",
packages=["imgsort"], #, "imgsort.sorter", "imgsort.config"],
# packages=setuptools.find_packages(),
install_requires=["ueberzug"],
classifiers=[
"Operating System :: POSIX :: Linux",
"Environment :: Console :: Curses",
"Programming Language :: Python :: 3",
"Topic :: Multimedia :: Graphics",
"Topic :: Utilities",
],
# scripts=["bin/imgsort"],
entry_points={
"console_scripts": [ "imgsort=imgsort.sorter:main" ],
},
)