From cc7ccff48e0d4e6a8493241227427be4f71b8c93 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sun, 29 May 2011 10:18:03 -0400 Subject: [PATCH] [#154] Created the cross-platform unit core_pe.photo in prep for rotation support. --- core_pe/app_cocoa.py | 19 ++++++------------- core_pe/photo.py | 26 ++++++++++++++++++++++++++ qt/pe/app.py | 18 +++--------------- 3 files changed, 35 insertions(+), 28 deletions(-) create mode 100644 core_pe/photo.py diff --git a/core_pe/app_cocoa.py b/core_pe/app_cocoa.py index 75294782..b9b7d6c8 100644 --- a/core_pe/app_cocoa.py +++ b/core_pe/app_cocoa.py @@ -14,31 +14,24 @@ import re from appscript import app, its, CommandError, ApplicationNotFoundError from hscommon import io -from hscommon.util import get_file_ext, remove_invalid_xml +from hscommon.util import remove_invalid_xml from hscommon.path import Path from hscommon.cocoa.objcmin import NSUserDefaults, NSURL from hscommon.trans import tr -from core import fs from core import app_cocoa, directories from . import data, _block_osx +from .photo import Photo as PhotoBase from .scanner import ScannerPE IPHOTO_PATH = Path('iPhoto Library') -class Photo(fs.File): - INITIAL_INFO = fs.File.INITIAL_INFO.copy() - INITIAL_INFO.update({ - 'dimensions': (0,0), - }) - HANDLED_EXTS = {'png', 'jpg', 'jpeg', 'gif', 'psd', 'bmp', 'tiff', 'tif', 'nef', 'cr2'} - - @classmethod - def can_handle(cls, path): - return fs.File.can_handle(path) and get_file_ext(path[-1]) in cls.HANDLED_EXTS +class Photo(PhotoBase): + HANDLED_EXTS = PhotoBase.HANDLED_EXTS.copy() + HANDLED_EXTS.update({'psd', 'nef', 'cr2'}) def _read_info(self, field): - fs.File._read_info(self, field) + PhotoBase._read_info(self, field) if field == 'dimensions': self.dimensions = _block_osx.get_image_size(str(self.path)) diff --git a/core_pe/photo.py b/core_pe/photo.py new file mode 100644 index 00000000..3e47dac9 --- /dev/null +++ b/core_pe/photo.py @@ -0,0 +1,26 @@ +# Created By: Virgil Dupras +# Created On: 2011-05-29 +# 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 + +from hscommon.util import get_file_ext +from core import fs + +class Photo(fs.File): + INITIAL_INFO = fs.File.INITIAL_INFO.copy() + INITIAL_INFO.update({ + 'dimensions': (0,0), + }) + # These extensions are supported on all platforms + HANDLED_EXTS = {'png', 'jpg', 'jpeg', 'gif', 'bmp', 'tiff', 'tif'} + + @classmethod + def can_handle(cls, path): + return fs.File.can_handle(path) and get_file_ext(path[-1]) in cls.HANDLED_EXTS + + def get_blocks(self, block_count_per_side): + raise NotImplementedError() + diff --git a/qt/pe/app.py b/qt/pe/app.py index 699c9382..457915b3 100644 --- a/qt/pe/app.py +++ b/qt/pe/app.py @@ -11,10 +11,8 @@ import logging from PyQt4.QtGui import QImage, QImageReader -from hscommon.util import get_file_ext - -from core import fs 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 @@ -24,19 +22,9 @@ from .result_window import ResultWindow from .preferences import Preferences from .preferences_dialog import PreferencesDialog -class File(fs.File): - INITIAL_INFO = fs.File.INITIAL_INFO.copy() - INITIAL_INFO.update({ - 'dimensions': (0,0), - }) - HANDLED_EXTS = set(['png', 'jpg', 'jpeg', 'gif', 'bmp', 'tiff', 'tif']) - - @classmethod - def can_handle(cls, path): - return fs.File.can_handle(path) and get_file_ext(path[-1]) in cls.HANDLED_EXTS - +class File(PhotoBase): def _read_info(self, field): - fs.File._read_info(self, field) + PhotoBase._read_info(self, field) if field == 'dimensions': try: ir = QImageReader(str(self.path))