Compare commits

...

2 Commits

Author SHA1 Message Date
Kameron Kenny 2a7262a273
cleanup 2024-09-17 17:15:24 -04:00
Kameron Kenny e1a7a5d88d
new class 2024-09-17 17:15:17 -04:00
3 changed files with 102 additions and 80 deletions

View File

@ -6,16 +6,14 @@ from PyQt6.QtCore import QThreadPool
from PyQt6.QtWidgets import QMainWindow, QApplication
from PyQt6.QtGui import QIcon,QPixmap
from PIL import Image
from configure import CONFIG_FILE, Configure
from file_stuff import is_file
from BitMover_MainWindow import Ui_MainWindow
from get_image_tag import get_exif_tag
from media import Media
from lumberjack import timber
from raw_photo import extract_jpg_thumb, get_raw_image_dimensions
from raw_photo import extract_jpg_thumb
from thread_my_stuff import Worker
from img_preview import ImgPreview
log = timber(__name__)
@ -23,107 +21,66 @@ log = timber(__name__)
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow,self).__init__(*args,**kwargs)
self.setupUi(self)
# uic.loadUi('BitMover.ui',self)
c = Configure(CONFIG_FILE)
self.config = c.load_config()
self.total_files = 0
self.file_total = 0
self.threads = {}
self.lcd_files_found.display(int(0))
self.set_progress(0, 0)
self.setupUi(self)
self.setWindowTitle("BitMover")
self.setWindowIcon(QIcon('assets/forklift.png'))
self.threadpool = QThreadPool()
print("Multithreading with maximum %d threads" % self.threadpool.maxThreadCount())
c = Configure(CONFIG_FILE)
self.config = c.load_config()
self.src_dir = self.config['folders']['source']['base']
self.dst_dir = self.config['folders']['destination']['base']
self.file_types = self.config['file_types']
self.lineEdit_src_dir.setText(self.src_dir)
self.lineEdit_dst_dir.setText(self.dst_dir)
# Button Setup
self.pushButton_src_browse.clicked.connect(self.select_src_directory)
self.pushButton_dst_browse.clicked.connect(self.select_dst_directory)
self.pushButton_3_scan_dir.clicked.connect(self.find_files)
self.toggle_scan_button(True)
# self.pushButton_3_scan_dir.clicked.connect(self.t_find_files.start)
# Initialize widgets
self.lcd_files_found.display(int(0))
self.set_progress(0, 0)
self.img_preview.setPixmap(QPixmap('assets/preview_placeholder.jpg'))
self.img_preview.setScaledContents(True)
self.file_list.currentItemChanged.connect(self.index_changed)
# File Stuff
self.total_files = 0
self.file_total = 0
self.files = {}
# Setup thread pool
self.threadpool = QThreadPool()
print("Multithreading with maximum %d threads" % self.threadpool.maxThreadCount())
def toggle_scan_button(self,enable=True):
if enable:
self.pushButton_3_scan_dir.setEnabled(True)
else:
self.pushButton_3_scan_dir.setDisabled(True)
self.pushButton_3_scan_dir.setEnabled(enable)
def index_changed(self,i):
f = i.text()
preview = ImgPreview(file=i.text(),event=self.get_event(),config=self.config)
event = self.get_event()
c = self.config
self.label_data_date_time_created.setText(preview.dtc)
m = Media(f,event,c)
if preview.file_type == 'image':
self.label_data_width_height.setText(str(preview.size))
self.label_data_dpi.setText(str(preview.dpi))
self.label_data_iso.setText(str(preview.iso))
self.label_data_lens.setText(str(preview.lens))
self.label_data_zoom.setText(str(preview.zoom))
self.label_data_camera.setText(str(preview.camera))
self.label_data_aperture.setText(str(preview.aperture))
self.label_data_megapixels.setText(str(preview.mpixels))
#
# h = self.img_preview.width * (preview.height / preview.width)
# self.img_preview.setFixedHeight(h)
dtc = f'{m.capture_date[0]}/{m.capture_date[1]}/{m.capture_date[2]}'
self.label_data_date_time_created.setText(dtc)
if m.file_type == 'image':
dpi = get_exif_tag(f,"xresolution")
if f.lower().endswith("jpg") or f.lower().endswith("jpeg"):
img = Image.open(f)
width = img.width
height = img.height
if preview.is_jpg:
self.img_preview.setPixmap(QPixmap(preview.file))
else:
width = get_raw_image_dimensions(f)[1]
height = get_raw_image_dimensions(f)[0]
size = f'{width}x{height}'
if width is not None and height is not None:
mpixels = round((width * height) / 1000000, 1)
else:
mpixels = ''
iso = get_exif_tag(f,"iso")
aperture = get_exif_tag(f,"fnumber")
camera = get_exif_tag(f,"cameramodelname")
if camera is None:
camera = get_exif_tag(f,"image model")
lens = get_exif_tag(f,"lensmodel")
zoom = get_exif_tag(f,"focallength")
print(f'size: {size}')
print(f'dpi: {dpi}')
print(f'iso: {iso}')
print(f'lens: {lens}')
print(f'zoom: {zoom}')
print(f'camera: {camera}')
print(f'aperture: {aperture}')
print(f'mpixels: {mpixels}')
self.label_data_width_height.setText(str(size))
self.label_data_dpi.setText(str(dpi))
self.label_data_iso.setText(str(iso))
self.label_data_lens.setText(str(lens))
self.label_data_zoom.setText(str(zoom))
self.label_data_camera.setText(str(camera))
self.label_data_aperture.setText(str(aperture))
self.label_data_megapixels.setText(str(mpixels))
if f.lower().endswith("jpg") or f.lower().endswith("jpeg"):
self.img_preview.setPixmap(QPixmap(f))
else:
# jpg = img.convert("RGB")
jpg = extract_jpg_thumb(f)
jpg = extract_jpg_thumb(preview.file)
self.img_preview.setPixmap(QPixmap(jpg))
def select_src_directory(self):
@ -262,7 +219,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.files[i]['folders']['destination_original'] = m.destination_originals_path
self.file_list.addItem(f"{self.files[i]['folders']['source_path']}/{self.files[i]['name']}")
app = QApplication(sys.argv)
window = MainWindow()

67
img_preview.py Normal file
View File

@ -0,0 +1,67 @@
#!/usr/bin/env python
from media import Media
from get_image_tag import get_exif_tag
from PIL import Image
from raw_photo import get_raw_image_dimensions
class ImgPreview:
def __init__(self,*args,**kwargs):
super(ImgPreview,self).__init__()
self.args = args
self.kwargs = kwargs
self.file = kwargs['file']
self.event = kwargs['event']
self.config = kwargs['config']
self.m = Media(self.file,
self.event,
self.config)
self.file_type = self.m.file_type
self.is_jpg = False
self.is_raw = False
if self.file_type == 'image':
self._img_preview()
print(f'size: {self.size}')
print(f'dpi: {self.dpi}')
print(f'iso: {self.iso}')
print(f'lens: {self.lens}')
print(f'zoom: {self.zoom}')
print(f'camera: {self.camera}')
print(f'aperture: {self.aperture}')
print(f'mpixels: {self.mpixels}')
def _img_preview(self):
self.dtc = f'{self.m.capture_date[0]}/{self.m.capture_date[1]}/{self.m.capture_date[2]}'
self.dpi = get_exif_tag(self.file, "xresolution")
self.iso = get_exif_tag(self.file, 'iso')
self.aperture = get_exif_tag(self.file, 'fnumber')
self.camera = get_exif_tag(self.file,'cameramodelname')
if self.camera is None:
self.camera = get_exif_tag(self.file,'image model')
self.lens = get_exif_tag(self.file,'lensmodel')
self.zoom = get_exif_tag(self.file,'focallength')
if self.file.lower().endswith("jpg") \
or self.file.lower().endswith("jpeg"):
self._jpg_preview()
else:
self._raw_preview()
self.size = f'{self.width}x{self.height}'
if self.width is not None \
and self.height is not None:
self.mpixels = round((self.width * self.height) / 1000000, 1)
else:
self.mpixels = 'Unknown :('
def _jpg_preview(self):
self.is_jpg = True
img = Image.open(self.file)
self.width = img.width
self.height = img.height
def _raw_preview(self):
self.is_raw = True
self.width = get_raw_image_dimensions(self.file)[1]
self.height = get_raw_image_dimensions(self.file)[0]

View File

@ -1,7 +1,6 @@
#!/usr/bin/env python
import traceback
import sys, traceback
from PyQt6.QtCore import pyqtSignal, pyqtSlot, QRunnable, QObject