1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2024-11-18 04:59:03 +00:00
dupeguru/qt/pe/app.py
2011-05-31 10:05:12 -04:00

100 lines
3.5 KiB
Python

# Created By: Virgil Dupras
# Created On: 2009-04-25
# Copyright 2011 Hardcoded Software (http://www.hardcoded.net)
#
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
# which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/bsd_license
import os.path as op
import logging
from PyQt4.QtGui import QImage, QImageReader, QTransform
from core_pe import data as data_pe, __appname__
from core_pe.photo import Photo as PhotoBase
from core_pe.scanner import ScannerPE
from ..base.app import DupeGuru as DupeGuruBase
from .block import getblocks
from .details_dialog import DetailsDialog
from .result_window import ResultWindow
from .preferences import Preferences
from .preferences_dialog import PreferencesDialog
class File(PhotoBase):
def _plat_get_dimensions(self):
try:
ir = QImageReader(str(self.path))
size = ir.size()
if size.isValid():
return (size.width(), size.height())
else:
return (0, 0)
except EnvironmentError:
logging.warning("Could not read image '%s'", str(self.path))
return (0, 0)
def _plat_get_blocks(self, block_count_per_side, orientation):
image = QImage(str(self.path))
image = image.convertToFormat(QImage.Format_RGB888)
# MYSTERY TO SOLVE: For reasons I cannot explain, orientations 5 and 7 don't work for
# duplicate scanning. The transforms seems to work fine (if I try to save the image after
# the transform, we see that the image has been correctly flipped and rotated), but the
# analysis part yields wrong blocks. I spent enought time with this feature, so I'll leave
# like that for now. (by the way, orientations 5 and 7 work fine under Cocoa)
if 2 <= orientation <= 8:
t = QTransform()
if orientation == 2:
t.scale(-1, 1)
elif orientation == 3:
t.rotate(180)
elif orientation == 4:
t.scale(1, -1)
elif orientation == 5:
t.scale(-1, 1)
t.rotate(90)
elif orientation == 6:
t.rotate(90)
elif orientation == 7:
t.scale(-1, 1)
t.rotate(270)
elif orientation == 8:
t.rotate(270)
image = image.transformed(t)
return getblocks(image, block_count_per_side)
class DupeGuru(DupeGuruBase):
EDITION = 'pe'
LOGO_NAME = 'logo_pe'
NAME = __appname__
def __init__(self):
DupeGuruBase.__init__(self, data_pe)
def _setup(self):
self.scanner = ScannerPE()
self.directories.fileclasses = [File]
self.scanner.cache_path = op.join(self.appdata, 'cached_pictures.db')
DupeGuruBase._setup(self)
def _update_options(self):
DupeGuruBase._update_options(self)
self.scanner.scan_type = self.prefs.scan_type
self.scanner.match_scaled = self.prefs.match_scaled
self.scanner.threshold = self.prefs.filter_hardness
def _create_details_dialog(self, parent):
return DetailsDialog(parent, self)
def _create_result_window(self):
return ResultWindow(app=self)
def _create_preferences(self):
return Preferences()
def _create_preferences_dialog(self, parent):
return PreferencesDialog(parent, self)