1212from pathlib import Path
1313from timeit import default_timer
1414
15- # pip install imagehash
15+ # pip install imagehash==4.3.2
1616import imagehash
1717
18+ # pip install pillow==12.1.1
1819from PIL import Image
1920
2021from PyQt5 .QtWidgets import (
4344)
4445from db import db_get_all , db_add_image , db_exists , db_create_backup
4546
46- sys .path .append (r"C:\Users\ipetrash\Projects\SimplePyScripts\qt__pyqt__pyside__pyqode" )
47- from layout_append_line__horizontal_vertical import VerticalLineWidget
48-
47+ from ui .layout_append_line__horizontal_vertical import VerticalLineWidget
4948from ui .FileListModel import FileListModel
5049from ui .ListImagesWidget import ListImagesWidget
5150from ui .FieldsProgressDialog import FieldsProgressDialog
@@ -72,6 +71,18 @@ def log_uncaught_exceptions(ex_cls, ex, tb) -> None:
7271IMAGE_CACHE = dict ()
7372
7473
74+ def parse_hash (algo_name , hex_value ):
75+ if not hex_value :
76+ return None
77+
78+ # colorhash требует особого метода восстановления
79+ if algo_name == "colorhash" :
80+ return imagehash .hex_to_flathash (hex_value , hashsize = 3 )
81+
82+ # Все остальные стандартные перцептивные хеши
83+ return imagehash .hex_to_hash (hex_value )
84+
85+
7586class MainWindow (QMainWindow ):
7687 def __init__ (self ) -> None :
7788 super ().__init__ ()
@@ -308,7 +319,7 @@ def _fill_ui(self) -> None:
308319 splitter = QSplitter (Qt .Vertical )
309320 splitter .addWidget (_top_widget )
310321 splitter .addWidget (_bottom_widget )
311- splitter .setSizes ([part_splitter_height * 2 , part_splitter_height / 2 ])
322+ splitter .setSizes ([part_splitter_height * 2 , part_splitter_height // 2 ])
312323
313324 self .setCentralWidget (splitter )
314325
@@ -375,7 +386,8 @@ def fill_images_db(self) -> None:
375386 for row in db_get_all ():
376387 file_name = row ["file_name" ]
377388 self .image_by_hashes [file_name ] = {
378- x : imagehash .hex_to_hash (row [x ]) for x in IMAGE_HASH_ALGO
389+ hash_name : parse_hash (hash_name , row [hash_name ])
390+ for hash_name in IMAGE_HASH_ALGO
379391 }
380392
381393 self .model_files .set_file_list (list (self .image_by_hashes .keys ()))
0 commit comments