2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-04-25
|
2010-01-01 20:11:34 +00:00
|
|
|
# Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
#
|
|
|
|
# This software is licensed under the "HS" 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/hs_license
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
import os.path as op
|
2009-12-15 16:54:47 +00:00
|
|
|
import logging
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
from PyQt4.QtGui import QImage
|
|
|
|
import PIL.Image
|
|
|
|
|
2009-06-07 08:18:42 +00:00
|
|
|
from hsutil.str import get_file_ext
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2009-12-30 10:37:57 +00:00
|
|
|
from core import fs
|
|
|
|
from core_pe import data as data_pe
|
|
|
|
from core_pe.cache import Cache
|
|
|
|
from core_pe.scanner import ScannerPE
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
from block import getblocks
|
|
|
|
from base.app import DupeGuru as DupeGuruBase
|
|
|
|
from details_dialog import DetailsDialog
|
|
|
|
from main_window import MainWindow
|
|
|
|
from preferences import Preferences
|
|
|
|
from preferences_dialog import PreferencesDialog
|
|
|
|
|
2009-10-23 15:04:37 +00:00
|
|
|
class File(fs.File):
|
|
|
|
INITIAL_INFO = fs.File.INITIAL_INFO.copy()
|
2009-09-27 17:16:52 +00:00
|
|
|
INITIAL_INFO.update({
|
|
|
|
'dimensions': (0,0),
|
|
|
|
})
|
2009-10-24 16:30:37 +00:00
|
|
|
HANDLED_EXTS = set(['png', 'jpg', 'jpeg', 'gif', 'bmp', 'tiff', 'tif'])
|
2009-10-23 15:04:37 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def can_handle(cls, path):
|
|
|
|
return fs.File.can_handle(path) and get_file_ext(path[-1]) in cls.HANDLED_EXTS
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2009-09-27 17:16:52 +00:00
|
|
|
def _read_info(self, field):
|
2009-10-23 15:04:37 +00:00
|
|
|
fs.File._read_info(self, field)
|
2009-09-27 17:16:52 +00:00
|
|
|
if field == 'dimensions':
|
2009-12-15 16:54:47 +00:00
|
|
|
try:
|
|
|
|
im = PIL.Image.open(unicode(self.path))
|
|
|
|
self.dimensions = im.size
|
|
|
|
except IOError:
|
|
|
|
self.dimensions = (0, 0)
|
|
|
|
logging.warning(u"Could not read image '%s'", unicode(self.path))
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
def get_blocks(self, block_count_per_side):
|
|
|
|
image = QImage(unicode(self.path))
|
|
|
|
image = image.convertToFormat(QImage.Format_RGB888)
|
|
|
|
return getblocks(image, block_count_per_side)
|
|
|
|
|
|
|
|
|
|
|
|
class DupeGuru(DupeGuruBase):
|
|
|
|
LOGO_NAME = 'logo_pe'
|
|
|
|
NAME = 'dupeGuru Picture Edition'
|
2010-01-15 06:24:40 +00:00
|
|
|
VERSION = '1.8.1'
|
2009-06-01 09:55:11 +00:00
|
|
|
DELTA_COLUMNS = frozenset([2, 5, 6])
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
DupeGuruBase.__init__(self, data_pe, appid=5)
|
|
|
|
|
|
|
|
def _setup(self):
|
2009-10-18 09:26:04 +00:00
|
|
|
self.scanner = ScannerPE()
|
2009-10-23 15:04:37 +00:00
|
|
|
self.directories.fileclasses = [File]
|
2010-01-14 15:14:26 +00:00
|
|
|
self.scanner.cache_path = op.join(self.appdata, 'cached_pictures.db')
|
2009-06-01 09:55:11 +00:00
|
|
|
DupeGuruBase._setup(self)
|
|
|
|
|
|
|
|
def _update_options(self):
|
|
|
|
DupeGuruBase._update_options(self)
|
2009-10-18 09:26:04 +00:00
|
|
|
self.scanner.match_scaled = self.prefs.match_scaled
|
|
|
|
self.scanner.threshold = self.prefs.filter_hardness
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
def _create_details_dialog(self, parent):
|
|
|
|
return DetailsDialog(parent, self)
|
|
|
|
|
|
|
|
def _create_main_window(self):
|
|
|
|
return MainWindow(app=self)
|
|
|
|
|
|
|
|
def _create_preferences(self):
|
|
|
|
return Preferences()
|
|
|
|
|
|
|
|
def _create_preferences_dialog(self, parent):
|
|
|
|
return PreferencesDialog(parent, self)
|
|
|
|
|