From 719edb6b6ebe28644e3339096ba6135e17d443b3 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 4 Feb 2010 17:12:58 +0100 Subject: [PATCH] Use hsutil.cocoa.objcmin instead of Foundation and AppKit. --- core/app_cocoa.py | 17 +++++------------ core/app_cocoa_inter.py | 3 +-- core_pe/app_cocoa.py | 2 +- core_se/app_cocoa.py | 9 ++------- 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/core/app_cocoa.py b/core/app_cocoa.py index a5277116..97580c20 100644 --- a/core/app_cocoa.py +++ b/core/app_cocoa.py @@ -6,14 +6,14 @@ # which should be included with this package. The terms are also available at # http://www.hardcoded.net/licenses/hs_license -import objc -from Foundation import (NSNotificationCenter, NSUserDefaults, NSSearchPathForDirectoriesInDomains, - NSApplicationSupportDirectory, NSUserDomainMask) import logging import os.path as op from hsutil import cocoa, job from hsutil.cocoa import install_exception_hook +from hsutil.cocoa.objcmin import (NSNotificationCenter, NSUserDefaults, + NSSearchPathForDirectoriesInDomains, NSApplicationSupportDirectory, NSUserDomainMask, + NSWorkspace, NSWorkspaceRecycleOperation) from hsutil.misc import stripnone from hsutil.reg import RegistrationRequired @@ -54,15 +54,10 @@ class DupeGuru(app.DupeGuru): @staticmethod def _recycle_dupe(dupe): # local import because first appkit import takes a lot of memory. we want to avoid it. - from AppKit import NSWorkspace, NSWorkspaceRecycleOperation directory = unicode(dupe.path[:-1]) filename = dupe.name - if objc.__version__ == '1.4': # For a while, we have to support this. - result, tag = NSWorkspace.sharedWorkspace().performFileOperation_source_destination_files_tag_( - NSWorkspaceRecycleOperation, directory, '', [filename]) - else: - result, tag = NSWorkspace.sharedWorkspace().performFileOperation_source_destination_files_tag_( - NSWorkspaceRecycleOperation, directory, '', [filename], None) + result, tag = NSWorkspace.sharedWorkspace().performFileOperation_source_destination_files_tag_( + NSWorkspaceRecycleOperation, directory, '', [filename], None) def _start_job(self, jobid, func): try: @@ -117,7 +112,6 @@ class DupeGuru(app.DupeGuru): def OpenSelected(self): # local import because first appkit import takes a lot of memory. we want to avoid it. - from AppKit import NSWorkspace if self.selected_dupes: path = unicode(self.selected_dupes[0].path) NSWorkspace.sharedWorkspace().openFile_(path) @@ -154,7 +148,6 @@ class DupeGuru(app.DupeGuru): def RevealSelected(self): # local import because first appkit import takes a lot of memory. we want to avoid it. - from AppKit import NSWorkspace if self.selected_dupes: path = unicode(self.selected_dupes[0].path) NSWorkspace.sharedWorkspace().selectFile_inFileViewerRootedAtPath_(path,'') diff --git a/core/app_cocoa_inter.py b/core/app_cocoa_inter.py index 5e990da2..21bf04c9 100644 --- a/core/app_cocoa_inter.py +++ b/core/app_cocoa_inter.py @@ -9,8 +9,7 @@ # Common interface for all editions' dg_cocoa unit. -import objc -from Foundation import NSObject +from hsutil.cocoa.objcmin import NSObject from hsutil.cocoa import signature from hsutil.reg import InvalidCodeError diff --git a/core_pe/app_cocoa.py b/core_pe/app_cocoa.py index 8bf3f376..f30c2d4f 100644 --- a/core_pe/app_cocoa.py +++ b/core_pe/app_cocoa.py @@ -11,13 +11,13 @@ import logging import plistlib import re -from Foundation import NSUserDefaults, NSURL from appscript import app, k, CommandError from hsutil import io from hsutil.str import get_file_ext from hsutil.path import Path from hsutil.cocoa import as_fetch +from hsutil.cocoa.objcmin import NSUserDefaults, NSURL from core import fs from core import app_cocoa, directories diff --git a/core_se/app_cocoa.py b/core_se/app_cocoa.py index 689b230c..d7b474ff 100644 --- a/core_se/app_cocoa.py +++ b/core_se/app_cocoa.py @@ -10,11 +10,9 @@ from __future__ import unicode_literals import logging -import objc -from AppKit import NSWorkspace - from hsutil import io from hsutil.path import Path +from hsutil.cocoa.objcmin import NSWorkspace from core import fs from core.app_cocoa import DupeGuru as DupeGuruBase @@ -24,10 +22,7 @@ from .fs import Bundle as BundleBase def is_bundle(str_path): sw = NSWorkspace.sharedWorkspace() - if objc.__version__ == '1.4': # For a while, we have to support this. - uti, error = sw.typeOfFile_error_(str_path) - else: - uti, error = sw.typeOfFile_error_(str_path, None) + uti, error = sw.typeOfFile_error_(str_path, None) if error is not None: logging.warning(u'There was an error trying to detect the UTI of %s', str_path) return sw.type_conformsToType_(uti, 'com.apple.bundle') or sw.type_conformsToType_(uti, 'com.apple.package')