Compare commits

..

No commits in common. "2a7262a273fa4e3e012223eac735fbef375fe380" and "e5487b0d29773e9f7954a25dda5dbf86bc1a4b93" have entirely different histories.

3 changed files with 94 additions and 116 deletions

View File

@ -6,14 +6,16 @@ from PyQt6.QtCore import QThreadPool
from PyQt6.QtWidgets import QMainWindow, QApplication from PyQt6.QtWidgets import QMainWindow, QApplication
from PyQt6.QtGui import QIcon,QPixmap from PyQt6.QtGui import QIcon,QPixmap
from PIL import Image
from configure import CONFIG_FILE, Configure from configure import CONFIG_FILE, Configure
from file_stuff import is_file from file_stuff import is_file
from BitMover_MainWindow import Ui_MainWindow from BitMover_MainWindow import Ui_MainWindow
from get_image_tag import get_exif_tag
from media import Media from media import Media
from lumberjack import timber from lumberjack import timber
from raw_photo import extract_jpg_thumb from raw_photo import extract_jpg_thumb, get_raw_image_dimensions
from thread_my_stuff import Worker from thread_my_stuff import Worker
from img_preview import ImgPreview
log = timber(__name__) log = timber(__name__)
@ -21,66 +23,107 @@ log = timber(__name__)
class MainWindow(QMainWindow, Ui_MainWindow): class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(MainWindow,self).__init__(*args,**kwargs) super(MainWindow,self).__init__(*args,**kwargs)
self.setupUi(self) 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.setWindowTitle("BitMover") self.setWindowTitle("BitMover")
self.setWindowIcon(QIcon('assets/forklift.png')) self.setWindowIcon(QIcon('assets/forklift.png'))
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)
# 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() self.threadpool = QThreadPool()
print("Multithreading with maximum %d threads" % self.threadpool.maxThreadCount()) print("Multithreading with maximum %d threads" % self.threadpool.maxThreadCount())
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)
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)
self.img_preview.setPixmap(QPixmap('assets/preview_placeholder.jpg'))
self.img_preview.setScaledContents(True)
self.file_list.currentItemChanged.connect(self.index_changed)
self.files = {}
def toggle_scan_button(self,enable=True): def toggle_scan_button(self,enable=True):
self.pushButton_3_scan_dir.setEnabled(enable) if enable:
self.pushButton_3_scan_dir.setEnabled(True)
else:
self.pushButton_3_scan_dir.setDisabled(True)
def index_changed(self,i): def index_changed(self,i):
preview = ImgPreview(file=i.text(),event=self.get_event(),config=self.config) f = i.text()
self.label_data_date_time_created.setText(preview.dtc) event = self.get_event()
c = self.config
if preview.file_type == 'image': m = Media(f,event,c)
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)
if preview.is_jpg: dtc = f'{m.capture_date[0]}/{m.capture_date[1]}/{m.capture_date[2]}'
self.img_preview.setPixmap(QPixmap(preview.file)) 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
else: else:
jpg = extract_jpg_thumb(preview.file) 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)
self.img_preview.setPixmap(QPixmap(jpg)) self.img_preview.setPixmap(QPixmap(jpg))
def select_src_directory(self): def select_src_directory(self):
@ -219,6 +262,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.files[i]['folders']['destination_original'] = m.destination_originals_path 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']}") self.file_list.addItem(f"{self.files[i]['folders']['source_path']}/{self.files[i]['name']}")
app = QApplication(sys.argv) app = QApplication(sys.argv)
window = MainWindow() window = MainWindow()

View File

@ -1,67 +0,0 @@
#!/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,6 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys, traceback
import traceback
from PyQt6.QtCore import pyqtSignal, pyqtSlot, QRunnable, QObject from PyQt6.QtCore import pyqtSignal, pyqtSlot, QRunnable, QObject