Compare commits
6 Commits
9563641e05
...
59159e4ad2
Author | SHA1 | Date | |
---|---|---|---|
|
59159e4ad2 | ||
|
8f9603976e | ||
|
4d86c53fe4 | ||
|
5ee8743ed2 | ||
|
89f6eadc30 | ||
|
4e324fb571 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*__pycache__*
|
4
README.md
Normal file → Executable file
4
README.md
Normal file → Executable file
@ -30,6 +30,10 @@ python3 -m pip install .
|
|||||||
You can also install it system-wide using `sudo python3 -m pip install.`
|
You can also install it system-wide using `sudo python3 -m pip install.`
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
### 1.2
|
||||||
|
- Works with ueberzugpp
|
||||||
|
- Use pyproject.toml for installation
|
||||||
|
|
||||||
### 1.1
|
### 1.1
|
||||||
- Terminal does not break anymore when program exits
|
- Terminal does not break anymore when program exits
|
||||||
- Todo-Images are now sorted by filename
|
- Todo-Images are now sorted by filename
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -1,12 +1,11 @@
|
|||||||
#!/bin/python3
|
#!/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
|
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 os import path, getcwd, listdir, mkdir, makedirs, rename
|
||||||
|
|
||||||
from sys import argv
|
from sys import argv
|
||||||
|
|
||||||
settings = {
|
settings = {
|
||||||
@ -27,7 +26,7 @@ CURSOR_Y = 2
|
|||||||
KEYS_BEGIN = 5
|
KEYS_BEGIN = 5
|
||||||
|
|
||||||
class Sorter:
|
class Sorter:
|
||||||
def __init__(self, wdir, canvas, config):
|
def __init__(self, wdir, config):
|
||||||
self.wd = wdir
|
self.wd = wdir
|
||||||
|
|
||||||
self.images = [] # old paths
|
self.images = [] # old paths
|
||||||
@ -56,15 +55,13 @@ class Sorter:
|
|||||||
c.echo()
|
c.echo()
|
||||||
|
|
||||||
# ueberzug
|
# ueberzug
|
||||||
self.canvas = canvas
|
|
||||||
|
|
||||||
self.placement = self.canvas.create_placement("p1", x=0, y=0, path="")
|
self._ueberzug = UeberzugLayer(pid_file="/tmp/ueberzu-imgsort.pid")
|
||||||
self.placement.visibility = uz.Visibility.VISIBLE
|
self._img_x = SIDEBAR_WIDTH + 1
|
||||||
self.placement.scaler = uz.ScalerOption.FIT_CONTAIN.value
|
self._img_y = 2
|
||||||
self.placement.x = SIDEBAR_WIDTH + 1
|
self._img_width = self.win_x - SIDEBAR_WIDTH - 1
|
||||||
self.placement.y = 2
|
self._img_height = self.win_y - FOOTER_HEIGHT - 2
|
||||||
self.placement.width = self.win_x - SIDEBAR_WIDTH - 1
|
self._img_identifier = "imgsort_preview"
|
||||||
self.placement.height = self.win_y - FOOTER_HEIGHT - 2
|
|
||||||
|
|
||||||
# version
|
# version
|
||||||
self.version = "Image Sorter 1.1"
|
self.version = "Image Sorter 1.1"
|
||||||
@ -101,9 +98,8 @@ class Sorter:
|
|||||||
# print(self.images)
|
# print(self.images)
|
||||||
|
|
||||||
def display_image(self):
|
def display_image(self):
|
||||||
with self.canvas.lazy_drawing: # issue ueberzug command AFTER with-statement
|
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.placement.path = self.image
|
self.window.addnstr(0, SIDEBAR_WIDTH + 1, self.image, self.win_x - SIDEBAR_WIDTH - 1)
|
||||||
self.window.addnstr(0, SIDEBAR_WIDTH + 1, self.placement.path, self.win_x - SIDEBAR_WIDTH - 1)
|
|
||||||
|
|
||||||
def sort(self):
|
def sort(self):
|
||||||
"""
|
"""
|
||||||
@ -231,7 +227,6 @@ class Sorter:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# set working directory
|
# set working directory
|
||||||
print("""
|
print("""
|
||||||
@ -256,8 +251,7 @@ Image Sorter
|
|||||||
print(" Config:", config)
|
print(" Config:", config)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
with uz.Canvas() as canvas:
|
sorter = Sorter(wd, config)
|
||||||
sorter = Sorter(wd, canvas, config)
|
|
||||||
sorter.get_images()
|
sorter.get_images()
|
||||||
sorter.sort()
|
sorter.sort()
|
||||||
|
|
||||||
|
45
imgsort/ueberzug.py
Normal file
45
imgsort/ueberzug.py
Normal 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
33
pyproject.toml
Normal 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 = ["."]
|
33
setup.py
33
setup.py
@ -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" ],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user