2009-06-01 09:55:11 +00:00
|
|
|
import logging
|
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
from objp.util import pyref, dontwrap
|
2010-11-20 11:42:15 +00:00
|
|
|
from jobprogress import job
|
2012-01-05 21:57:31 +00:00
|
|
|
import cocoa
|
|
|
|
from cocoa import install_exception_hook, proxy
|
2012-01-13 20:25:34 +00:00
|
|
|
from cocoa.inter import PyFairware, FairwareView
|
2011-11-09 16:02:15 +00:00
|
|
|
from hscommon.trans import trget
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-09-21 20:02:13 +00:00
|
|
|
from core.app import JobType
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-11-09 16:02:15 +00:00
|
|
|
tr = trget('ui')
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
JOBID2TITLE = {
|
2011-09-21 17:55:26 +00:00
|
|
|
JobType.Scan: tr("Scanning for duplicates"),
|
|
|
|
JobType.Load: tr("Loading"),
|
|
|
|
JobType.Move: tr("Moving"),
|
|
|
|
JobType.Copy: tr("Copying"),
|
|
|
|
JobType.Delete: tr("Sending to Trash"),
|
2009-06-01 09:55:11 +00:00
|
|
|
}
|
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
class DupeGuruView(FairwareView):
|
2012-02-27 14:44:51 +00:00
|
|
|
pass
|
2012-01-13 19:43:43 +00:00
|
|
|
|
2011-09-20 22:40:27 +00:00
|
|
|
class PyDupeGuruBase(PyFairware):
|
2012-01-13 19:43:43 +00:00
|
|
|
FOLLOW_PROTOCOLS = ['Worker']
|
|
|
|
|
2012-01-15 16:00:34 +00:00
|
|
|
@dontwrap
|
2011-09-20 22:40:27 +00:00
|
|
|
def _init(self, modelclass):
|
|
|
|
logging.basicConfig(level=logging.WARNING, format='%(levelname)s %(message)s')
|
|
|
|
install_exception_hook()
|
2011-12-28 19:51:33 +00:00
|
|
|
appdata = proxy.getAppdataPath()
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model = modelclass(self, appdata)
|
2011-09-20 22:40:27 +00:00
|
|
|
self.progress = cocoa.ThreadedJobPerformer()
|
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
#---Sub-proxies
|
|
|
|
def detailsPanel(self) -> pyref:
|
|
|
|
return self.model.details_panel
|
|
|
|
|
|
|
|
def directoryTree(self) -> pyref:
|
|
|
|
return self.model.directory_tree
|
|
|
|
|
2012-01-13 20:25:34 +00:00
|
|
|
def problemDialog(self) -> pyref:
|
|
|
|
return self.model.problem_dialog
|
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
def statsLabel(self) -> pyref:
|
|
|
|
return self.model.stats_label
|
|
|
|
|
|
|
|
def resultTable(self) -> pyref:
|
|
|
|
return self.model.result_table
|
2011-11-27 17:47:00 +00:00
|
|
|
|
2011-09-20 22:40:27 +00:00
|
|
|
#---Directories
|
2012-01-13 19:43:43 +00:00
|
|
|
def addDirectory_(self, directory: str) -> int:
|
|
|
|
return self.model.add_directory(directory)
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
#---Results
|
|
|
|
def clearIgnoreList(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.scanner.ignore_list.Clear()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
def doScan(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.start_scanning()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
def exportToXHTML(self) -> str:
|
|
|
|
return self.model.export_to_xhtml()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
def loadSession(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.load()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
def loadResultsFrom_(self, filename: str):
|
|
|
|
self.model.load_from(filename)
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
def markAll(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.mark_all()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
def markNone(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.mark_none()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
def markInvert(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.mark_invert()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
def purgeIgnoreList(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.purge_ignore_list()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
def toggleSelectedMark(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.toggle_selected_mark_state()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
def saveSession(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.save()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
def saveResultsAs_(self, filename: str):
|
|
|
|
self.model.save_as(filename)
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
#---Actions
|
|
|
|
def addSelectedToIgnoreList(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.add_selected_to_ignore_list()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
def deleteMarked(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.delete_marked()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
def hardlinkMarked(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.delete_marked(replace_with_hardlinks=True)
|
2011-09-20 22:40:27 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
def applyFilter_(self, filter: str):
|
|
|
|
self.model.apply_filter(filter)
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
def makeSelectedReference(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.make_selected_reference()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
def copyOrMove_markedTo_recreatePath_(self, copy: bool, destination: str, recreate_path: bool):
|
|
|
|
self.model.copy_or_move_marked(copy, destination, recreate_path)
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
def openSelected(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.open_selected()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
def removeMarked(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.remove_marked()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
def revealSelected(self):
|
2012-01-13 19:43:43 +00:00
|
|
|
self.model.reveal_selected()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
def invokeCommand_(self, cmd: str):
|
|
|
|
self.model.invoke_command(cmd)
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
#---Information
|
2012-01-13 19:43:43 +00:00
|
|
|
def getIgnoreListCount(self) -> int:
|
|
|
|
return len(self.model.scanner.ignore_list)
|
2011-09-20 22:40:27 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
def getMarkCount(self) -> int:
|
|
|
|
return self.model.results.mark_count
|
2011-09-20 22:40:27 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
def scanWasProblematic(self) -> bool:
|
|
|
|
return bool(self.model.results.problems)
|
2011-09-20 22:40:27 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
def resultsAreModified(self) -> bool:
|
|
|
|
return self.model.results.is_modified
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
#---Properties
|
2012-01-13 19:43:43 +00:00
|
|
|
def setMixFileKind_(self, mix_file_kind: bool):
|
|
|
|
self.model.scanner.mix_file_kind = mix_file_kind
|
2011-09-20 22:40:27 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
def setEscapeFilterRegexp_(self, escape_filter_regexp: bool):
|
|
|
|
self.model.options['escape_filter_regexp'] = escape_filter_regexp
|
2011-09-20 22:40:27 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
def setRemoveEmptyFolders_(self, remove_empty_folders: bool):
|
|
|
|
self.model.options['clean_empty_dirs'] = remove_empty_folders
|
2011-09-20 22:40:27 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
def setIgnoreHardlinkMatches_(self, ignore_hardlink_matches: bool):
|
|
|
|
self.model.options['ignore_hardlink_matches'] = ignore_hardlink_matches
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
#---Worker
|
2012-01-13 19:43:43 +00:00
|
|
|
def getJobProgress(self) -> object: # NSNumber
|
2011-09-20 22:40:27 +00:00
|
|
|
try:
|
|
|
|
return self.progress.last_progress
|
|
|
|
except AttributeError:
|
|
|
|
# I have *no idea* why this can possible happen (last_progress is always set by
|
|
|
|
# create_job() *before* any threaded job notification, which shows the progress panel,
|
|
|
|
# is sent), but it happens anyway, so there we go. ref: #106
|
|
|
|
return -1
|
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
def getJobDesc(self) -> str:
|
2011-09-20 22:40:27 +00:00
|
|
|
try:
|
|
|
|
return self.progress.last_desc
|
|
|
|
except AttributeError:
|
|
|
|
# see getJobProgress
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def cancelJob(self):
|
|
|
|
self.progress.job_cancelled = True
|
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
def jobCompleted_(self, jobid: str):
|
|
|
|
self.model._job_completed(jobid)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-09-20 22:40:27 +00:00
|
|
|
#--- model --> view
|
2012-01-13 19:43:43 +00:00
|
|
|
@dontwrap
|
2011-09-20 22:40:27 +00:00
|
|
|
def open_path(self, path):
|
2011-12-28 19:51:33 +00:00
|
|
|
proxy.openPath_(str(path))
|
2010-02-06 11:36:43 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
@dontwrap
|
2011-09-20 22:40:27 +00:00
|
|
|
def reveal_path(self, path):
|
2011-12-28 19:51:33 +00:00
|
|
|
proxy.revealPath_(str(path))
|
2010-02-06 14:31:35 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
@dontwrap
|
2011-09-20 22:40:27 +00:00
|
|
|
def start_job(self, jobid, func, args=()):
|
2009-06-01 09:55:11 +00:00
|
|
|
try:
|
2011-09-20 22:40:27 +00:00
|
|
|
j = self.progress.create_job()
|
2010-09-25 13:37:18 +00:00
|
|
|
args = tuple([j] + list(args))
|
2011-09-20 22:40:27 +00:00
|
|
|
self.progress.run_threaded(func, args=args)
|
2009-06-01 09:55:11 +00:00
|
|
|
except job.JobInProgressError:
|
2011-12-28 19:51:33 +00:00
|
|
|
proxy.postNotification_userInfo_('JobInProgress', None)
|
2009-06-01 09:55:11 +00:00
|
|
|
else:
|
|
|
|
ud = {'desc': JOBID2TITLE[jobid], 'jobid':jobid}
|
2011-12-28 19:51:33 +00:00
|
|
|
proxy.postNotification_userInfo_('JobStarted', ud)
|
2009-06-01 09:55:11 +00:00
|
|
|
|