Compare commits
No commits in common. "59159e4ad224024240f5dc68809714efc2a6f8d5" and "9563641e05ecce4588906aaa6b6e84e8158d68ea" have entirely different histories.
59159e4ad2
...
9563641e05
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
*__pycache__*
|
|
4
README.md
Executable file → Normal file
4
README.md
Executable file → Normal file
@ -30,10 +30,6 @@ 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
|
||||||
|
BIN
imgsort/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
imgsort/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
BIN
imgsort/__pycache__/configs.cpython-39.pyc
Normal file
BIN
imgsort/__pycache__/configs.cpython-39.pyc
Normal file
Binary file not shown.
@ -1,11 +1,12 @@
|
|||||||
#!/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 = {
|
||||||
@ -26,7 +27,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
|
||||||
@ -55,13 +56,15 @@ class Sorter:
|
|||||||
c.echo()
|
c.echo()
|
||||||
|
|
||||||
# ueberzug
|
# ueberzug
|
||||||
|
self.canvas = canvas
|
||||||
|
|
||||||
self._ueberzug = UeberzugLayer(pid_file="/tmp/ueberzu-imgsort.pid")
|
self.placement = self.canvas.create_placement("p1", x=0, y=0, path="")
|
||||||
self._img_x = SIDEBAR_WIDTH + 1
|
self.placement.visibility = uz.Visibility.VISIBLE
|
||||||
self._img_y = 2
|
self.placement.scaler = uz.ScalerOption.FIT_CONTAIN.value
|
||||||
self._img_width = self.win_x - SIDEBAR_WIDTH - 1
|
self.placement.x = SIDEBAR_WIDTH + 1
|
||||||
self._img_height = self.win_y - FOOTER_HEIGHT - 2
|
self.placement.y = 2
|
||||||
self._img_identifier = "imgsort_preview"
|
self.placement.width = self.win_x - SIDEBAR_WIDTH - 1
|
||||||
|
self.placement.height = self.win_y - FOOTER_HEIGHT - 2
|
||||||
|
|
||||||
# version
|
# version
|
||||||
self.version = "Image Sorter 1.1"
|
self.version = "Image Sorter 1.1"
|
||||||
@ -96,10 +99,11 @@ class Sorter:
|
|||||||
self.images.sort()
|
self.images.sort()
|
||||||
self.images_new = self.images.copy()
|
self.images_new = self.images.copy()
|
||||||
# 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):
|
||||||
"""
|
"""
|
||||||
@ -143,13 +147,13 @@ class Sorter:
|
|||||||
self.image_iter += 1
|
self.image_iter += 1
|
||||||
|
|
||||||
self.quit("All done!")
|
self.quit("All done!")
|
||||||
|
|
||||||
def print_window(self):
|
def print_window(self):
|
||||||
"""
|
"""
|
||||||
Draw lines and text
|
Draw lines and text
|
||||||
"""
|
"""
|
||||||
self.window.erase()
|
self.window.erase()
|
||||||
|
|
||||||
# lines
|
# lines
|
||||||
self.window.hline(self.win_y - FOOTER_HEIGHT, FOOTER_LEFT, '=', self.win_x)
|
self.window.hline(self.win_y - FOOTER_HEIGHT, FOOTER_LEFT, '=', self.win_x)
|
||||||
self.window.vline(0, SIDEBAR_WIDTH, '|', self.win_y - FOOTER_HEIGHT + 1)
|
self.window.vline(0, SIDEBAR_WIDTH, '|', self.win_y - FOOTER_HEIGHT + 1)
|
||||||
@ -205,13 +209,13 @@ class Sorter:
|
|||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
self.window.move(CURSOR_Y, CURSOR_X)
|
self.window.move(CURSOR_Y, CURSOR_X)
|
||||||
|
|
||||||
def move_file(self, file, dest):
|
def move_file(self, file, dest):
|
||||||
# if not path.isdir(dest):
|
# if not path.isdir(dest):
|
||||||
# makedirs(dest)
|
# makedirs(dest)
|
||||||
if not path.isfile(file): return False
|
if not path.isfile(file): return False
|
||||||
if not path.isdir(dest): return False
|
if not path.isdir(dest): return False
|
||||||
|
|
||||||
new_path = path.normpath(dest + '/' + path.split(file)[1])
|
new_path = path.normpath(dest + '/' + path.split(file)[1])
|
||||||
|
|
||||||
rename(file, new_path)
|
rename(file, new_path)
|
||||||
@ -224,6 +228,7 @@ class Sorter:
|
|||||||
print(message)
|
print(message)
|
||||||
print("Quitting " + self.version)
|
print("Quitting " + self.version)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -251,9 +256,10 @@ Image Sorter
|
|||||||
print(" Config:", config)
|
print(" Config:", config)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
sorter = Sorter(wd, config)
|
with uz.Canvas() as canvas:
|
||||||
sorter.get_images()
|
sorter = Sorter(wd, canvas, config)
|
||||||
sorter.sort()
|
sorter.get_images()
|
||||||
|
sorter.sort()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
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}")
|
|
@ -1,33 +0,0 @@
|
|||||||
[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
Executable file
33
setup.py
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
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