-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcull_photos.py
More file actions
executable file
·86 lines (69 loc) · 2.28 KB
/
cull_photos.py
File metadata and controls
executable file
·86 lines (69 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
import argparse
import glob
import os
import pathlib
import shutil
import wx
def jpggen(basedir):
d = pathlib.Path(basedir)
for basedir, dirs, fnames in d.walk():
try:
dirs.remove("deleted")
except ValueError:
pass
for fname in fnames:
fpath = basedir / fname
if not fpath.is_file():
continue
if fpath.suffix in ('.jpg', '.JPG', '.jpeg', '.JPEG'):
yield fpath
def move_to_deleted(fpath):
deleted_dir = fpath.parent / "deleted"
deleted_dir.mkdir(exist_ok=True)
newpath = deleted_dir / fpath.name
fpath.rename(newpath)
def scale_image_to_fit_view(image, viewsize):
imgsize = image.GetSize()
# Calculate the aspect ratio of the image.
aspect_ratio = imgsize.width / imgsize.height
# Determine the maximum height and width the image can be while fitting in the view.
max_height = viewsize.height
max_width = int(max_height * aspect_ratio)
if max_width > viewsize.width:
max_width = viewsize.width
max_height = int(max_width / aspect_ratio)
image.Rescale(max_width, max_height)
class MainWindow(wx.Frame):
def __init__(self, path):
super().__init__(None)
self.current_jpg = None
self.jpggen = jpggen(path)
self.bmp = wx.StaticBitmap(self)
self.panel = wx.Panel(self)
self.panel.Bind(wx.EVT_KEY_DOWN, self.on_key_down)
self.panel.SetFocus()
def next_jpg(self):
self.current_jpg = next(self.jpggen)
image = wx.Image(str(self.current_jpg))
scale_image_to_fit_view(image, self.GetSize())
self.bmp.SetBitmap(image)
def on_key_down(self, event):
keycode = event.GetUnicodeKey()
if keycode != wx.WXK_NONE:
c = chr(keycode).lower()
match c:
case ' ':
self.next_jpg()
case 'x':
if self.current_jpg:
move_to_deleted(self.current_jpg)
self.next_jpg()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("path")
args = parser.parse_args()
app = wx.App()
gui = MainWindow(args.path)
gui.Show()
app.MainLoop()