mirror of
https://github.com/arsenetar/dupeguru.git
synced 2026-01-22 14:41:39 +00:00
Huge refactoring. I moved MGOutline from moneyGuru (as well as everything that comes with it) and used it to create DirectoryOutline for the directories panel.
This commit is contained in:
@@ -84,6 +84,7 @@ class DupeGuru(RegistrableApplication, Broadcaster):
|
||||
|
||||
def _do_load(self, j):
|
||||
self.directories.load_from_file(op.join(self.appdata, 'last_directories.xml'))
|
||||
self.notify('directories_changed')
|
||||
j = j.start_subjob([1, 9])
|
||||
self.results.load_from_xml(op.join(self.appdata, 'last_results.xml'), self._get_file, j)
|
||||
files = flatten(g[:] for g in self.results.groups)
|
||||
@@ -128,6 +129,7 @@ class DupeGuru(RegistrableApplication, Broadcaster):
|
||||
def add_directory(self, d):
|
||||
try:
|
||||
self.directories.add_path(Path(d))
|
||||
self.notify('directories_changed')
|
||||
return 0
|
||||
except directories.AlreadyThereError:
|
||||
return 1
|
||||
@@ -236,6 +238,13 @@ class DupeGuru(RegistrableApplication, Broadcaster):
|
||||
if self.selected_dupes:
|
||||
self._open_path(self.selected_dupes[0].path)
|
||||
|
||||
def remove_directory(self,index):
|
||||
try:
|
||||
del self.directories[index]
|
||||
self.notify('directories_changed')
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
def remove_duplicates(self, duplicates):
|
||||
self.results.remove_duplicates(duplicates)
|
||||
|
||||
|
||||
@@ -87,16 +87,6 @@ class DupeGuru(app.DupeGuru):
|
||||
except IndexError:
|
||||
return (None,None)
|
||||
|
||||
def get_folder_path(self, node_path, curr_path=None):
|
||||
if not node_path:
|
||||
return curr_path
|
||||
current_index = node_path[0]
|
||||
if curr_path is None:
|
||||
curr_path = self.directories[current_index]
|
||||
else:
|
||||
curr_path = self.directories.get_subfolders(curr_path)[current_index]
|
||||
return self.get_folder_path(node_path[1:], curr_path)
|
||||
|
||||
#---Public
|
||||
copy_or_move_marked = demo_method(app.DupeGuru.copy_or_move_marked)
|
||||
delete_marked = demo_method(app.DupeGuru.delete_marked)
|
||||
@@ -104,12 +94,6 @@ class DupeGuru(app.DupeGuru):
|
||||
def PurgeIgnoreList(self):
|
||||
self.scanner.ignore_list.Filter(lambda f,s:op.exists(f) and op.exists(s))
|
||||
|
||||
def RemoveDirectory(self,index):
|
||||
try:
|
||||
del self.directories[index]
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
def RenameSelected(self, newname):
|
||||
try:
|
||||
d = self.selected_dupes[0]
|
||||
@@ -172,10 +156,6 @@ class DupeGuru(app.DupeGuru):
|
||||
dupes = [self.results.dupes[row] for row in rows if row in xrange(len(self.results.dupes))]
|
||||
self._select_dupes(dupes)
|
||||
|
||||
def SetDirectoryState(self, node_path, state):
|
||||
p = self.get_folder_path(node_path)
|
||||
self.directories.set_state(p, state)
|
||||
|
||||
def sort_dupes(self,key,asc):
|
||||
self.results.sort_dupes(key,asc,self.display_delta_values)
|
||||
|
||||
@@ -190,8 +170,6 @@ class DupeGuru(app.DupeGuru):
|
||||
def GetOutlineViewMaxLevel(self, tag):
|
||||
if tag == 0:
|
||||
return 2
|
||||
elif tag == 1:
|
||||
return 0
|
||||
elif tag == 2:
|
||||
return 1
|
||||
|
||||
@@ -201,16 +179,6 @@ class DupeGuru(app.DupeGuru):
|
||||
if tag == 0: #Normal results
|
||||
assert not node_path # no other value is possible
|
||||
return [len(g.dupes) for g in self.results.groups]
|
||||
elif tag == 1: #Directories
|
||||
try:
|
||||
if node_path:
|
||||
path = self.get_folder_path(node_path)
|
||||
subfolders = self.directories.get_subfolders(path)
|
||||
else:
|
||||
subfolders = self.directories
|
||||
return [len(self.directories.get_subfolders(path)) for path in subfolders]
|
||||
except IndexError: # node_path out of range
|
||||
return []
|
||||
else: #Power Marker
|
||||
assert not node_path # no other value is possible
|
||||
return [0 for d in self.results.dupes]
|
||||
@@ -230,13 +198,6 @@ class DupeGuru(app.DupeGuru):
|
||||
g = self.results.get_group_of_duplicate(d)
|
||||
result = self._get_display_info(d, g, self.display_delta_values)
|
||||
return result
|
||||
elif tag == 1: #Directories
|
||||
try:
|
||||
path = self.get_folder_path(node_path)
|
||||
name = unicode(path) if len(node_path) == 1 else path[-1]
|
||||
return [name, self.directories.get_state(path)]
|
||||
except IndexError: # node_path out of range
|
||||
return []
|
||||
|
||||
def GetOutlineViewMarked(self, tag, node_path):
|
||||
# 0=unmarked 1=marked 2=unmarkable
|
||||
@@ -244,8 +205,6 @@ class DupeGuru(app.DupeGuru):
|
||||
return
|
||||
if not node_path:
|
||||
return 2
|
||||
if tag == 1: #Directories
|
||||
return 2
|
||||
if tag == 0: #Normal results
|
||||
g, d = self.GetObjects(node_path)
|
||||
else: #Power Marker
|
||||
|
||||
@@ -11,10 +11,11 @@
|
||||
|
||||
from hsutil.cocoa.objcmin import NSObject
|
||||
|
||||
from hsutil.cocoa import signature
|
||||
from hsutil.cocoa.inter import signature, PyOutline
|
||||
from hsutil.reg import InvalidCodeError
|
||||
|
||||
from .gui.details_panel import DetailsPanel
|
||||
from .gui.directory_tree import DirectoryTree
|
||||
|
||||
# Fix py2app's problems on relative imports
|
||||
from core import app, app_cocoa, data, directories, engine, export, ignore, results, fs, scanner
|
||||
@@ -26,185 +27,182 @@ class PyApp(NSObject):
|
||||
class PyDupeGuruBase(PyApp):
|
||||
#---Directories
|
||||
def addDirectory_(self, directory):
|
||||
return self.app.add_directory(directory)
|
||||
return self.py.add_directory(directory)
|
||||
|
||||
def removeDirectory_(self, index):
|
||||
self.app.RemoveDirectory(index)
|
||||
|
||||
def setDirectory_state_(self, node_path, state):
|
||||
self.app.SetDirectoryState(node_path, state)
|
||||
self.py.remove_directory(index)
|
||||
|
||||
#---Results
|
||||
def clearIgnoreList(self):
|
||||
self.app.scanner.ignore_list.Clear()
|
||||
self.py.scanner.ignore_list.Clear()
|
||||
|
||||
def doScan(self):
|
||||
return self.app.start_scanning()
|
||||
return self.py.start_scanning()
|
||||
|
||||
def exportToXHTMLwithColumns_(self, column_ids):
|
||||
return self.app.export_to_xhtml(column_ids)
|
||||
return self.py.export_to_xhtml(column_ids)
|
||||
|
||||
def loadIgnoreList(self):
|
||||
self.app.load_ignore_list()
|
||||
self.py.load_ignore_list()
|
||||
|
||||
def loadResults(self):
|
||||
self.app.load()
|
||||
self.py.load()
|
||||
|
||||
def markAll(self):
|
||||
self.app.results.mark_all()
|
||||
self.py.results.mark_all()
|
||||
|
||||
def markNone(self):
|
||||
self.app.results.mark_none()
|
||||
self.py.results.mark_none()
|
||||
|
||||
def markInvert(self):
|
||||
self.app.results.mark_invert()
|
||||
self.py.results.mark_invert()
|
||||
|
||||
def purgeIgnoreList(self):
|
||||
self.app.PurgeIgnoreList()
|
||||
self.py.PurgeIgnoreList()
|
||||
|
||||
def toggleSelectedMark(self):
|
||||
self.app.ToggleSelectedMarkState()
|
||||
self.py.ToggleSelectedMarkState()
|
||||
|
||||
def saveIgnoreList(self):
|
||||
self.app.save_ignore_list()
|
||||
self.py.save_ignore_list()
|
||||
|
||||
def saveResults(self):
|
||||
self.app.save()
|
||||
self.py.save()
|
||||
|
||||
def selectedResultNodePaths(self):
|
||||
return self.app.selected_result_node_paths()
|
||||
return self.py.selected_result_node_paths()
|
||||
|
||||
def selectResultNodePaths_(self,node_paths):
|
||||
self.app.SelectResultNodePaths(node_paths)
|
||||
self.py.SelectResultNodePaths(node_paths)
|
||||
|
||||
def selectedPowerMarkerNodePaths(self):
|
||||
return self.app.selected_powermarker_node_paths()
|
||||
return self.py.selected_powermarker_node_paths()
|
||||
|
||||
def selectPowerMarkerNodePaths_(self,node_paths):
|
||||
self.app.SelectPowerMarkerNodePaths(node_paths)
|
||||
self.py.SelectPowerMarkerNodePaths(node_paths)
|
||||
|
||||
#---Actions
|
||||
def addSelectedToIgnoreList(self):
|
||||
self.app.add_selected_to_ignore_list()
|
||||
self.py.add_selected_to_ignore_list()
|
||||
|
||||
def deleteMarked(self):
|
||||
self.app.delete_marked()
|
||||
self.py.delete_marked()
|
||||
|
||||
def applyFilter_(self, filter):
|
||||
self.app.apply_filter(filter)
|
||||
self.py.apply_filter(filter)
|
||||
|
||||
def makeSelectedReference(self):
|
||||
self.app.make_selected_reference()
|
||||
self.py.make_selected_reference()
|
||||
|
||||
def copyOrMove_markedTo_recreatePath_(self, copy, destination, recreate_path):
|
||||
self.app.copy_or_move_marked(copy, destination, recreate_path)
|
||||
self.py.copy_or_move_marked(copy, destination, recreate_path)
|
||||
|
||||
def openSelected(self):
|
||||
self.app.open_selected()
|
||||
self.py.open_selected()
|
||||
|
||||
def removeMarked(self):
|
||||
self.app.results.perform_on_marked(lambda x:True, True)
|
||||
self.py.results.perform_on_marked(lambda x:True, True)
|
||||
|
||||
def removeSelected(self):
|
||||
self.app.remove_selected()
|
||||
self.py.remove_selected()
|
||||
|
||||
def renameSelected_(self,newname):
|
||||
return self.app.RenameSelected(newname)
|
||||
return self.py.RenameSelected(newname)
|
||||
|
||||
def revealSelected(self):
|
||||
self.app.reveal_selected()
|
||||
self.py.reveal_selected()
|
||||
|
||||
#---Misc
|
||||
def sortDupesBy_ascending_(self, key, asc):
|
||||
self.app.sort_dupes(key, asc)
|
||||
self.py.sort_dupes(key, asc)
|
||||
|
||||
def sortGroupsBy_ascending_(self, key, asc):
|
||||
self.app.sort_groups(key, asc)
|
||||
self.py.sort_groups(key, asc)
|
||||
|
||||
#---Information
|
||||
def getIgnoreListCount(self):
|
||||
return len(self.app.scanner.ignore_list)
|
||||
return len(self.py.scanner.ignore_list)
|
||||
|
||||
def getMarkCount(self):
|
||||
return self.app.results.mark_count
|
||||
return self.py.results.mark_count
|
||||
|
||||
def getStatLine(self):
|
||||
return self.app.stat_line
|
||||
return self.py.stat_line
|
||||
|
||||
def getOperationalErrorCount(self):
|
||||
return self.app.last_op_error_count
|
||||
return self.py.last_op_error_count
|
||||
|
||||
#---Data
|
||||
@signature('i@:i')
|
||||
def getOutlineViewMaxLevel_(self, tag):
|
||||
return self.app.GetOutlineViewMaxLevel(tag)
|
||||
return self.py.GetOutlineViewMaxLevel(tag)
|
||||
|
||||
@signature('@@:i@')
|
||||
def getOutlineView_childCountsForPath_(self, tag, node_path):
|
||||
return self.app.GetOutlineViewChildCounts(tag, node_path)
|
||||
return self.py.GetOutlineViewChildCounts(tag, node_path)
|
||||
|
||||
def getOutlineView_valuesForIndexes_(self, tag, node_path):
|
||||
return self.app.GetOutlineViewValues(tag, node_path)
|
||||
return self.py.GetOutlineViewValues(tag, node_path)
|
||||
|
||||
def getOutlineView_markedAtIndexes_(self, tag, node_path):
|
||||
return self.app.GetOutlineViewMarked(tag, node_path)
|
||||
return self.py.GetOutlineViewMarked(tag, node_path)
|
||||
|
||||
def getTableViewCount_(self, tag):
|
||||
return self.app.GetTableViewCount(tag)
|
||||
return self.py.GetTableViewCount(tag)
|
||||
|
||||
def getTableViewMarkedIndexes_(self, tag):
|
||||
return self.app.GetTableViewMarkedIndexes(tag)
|
||||
return self.py.GetTableViewMarkedIndexes(tag)
|
||||
|
||||
def getTableView_valuesForRow_(self, tag, row):
|
||||
return self.app.GetTableViewValues(tag, row)
|
||||
return self.py.GetTableViewValues(tag, row)
|
||||
|
||||
#---Properties
|
||||
def setMixFileKind_(self, mix_file_kind):
|
||||
self.app.scanner.mix_file_kind = mix_file_kind
|
||||
self.py.scanner.mix_file_kind = mix_file_kind
|
||||
|
||||
def setDisplayDeltaValues_(self, display_delta_values):
|
||||
self.app.display_delta_values= display_delta_values
|
||||
self.py.display_delta_values= display_delta_values
|
||||
|
||||
def setEscapeFilterRegexp_(self, escape_filter_regexp):
|
||||
self.app.options['escape_filter_regexp'] = escape_filter_regexp
|
||||
self.py.options['escape_filter_regexp'] = escape_filter_regexp
|
||||
|
||||
def setRemoveEmptyFolders_(self, remove_empty_folders):
|
||||
self.app.options['clean_empty_dirs'] = remove_empty_folders
|
||||
self.py.options['clean_empty_dirs'] = remove_empty_folders
|
||||
|
||||
#---Worker
|
||||
def getJobProgress(self):
|
||||
return self.app.progress.last_progress
|
||||
return self.py.progress.last_progress
|
||||
|
||||
def getJobDesc(self):
|
||||
return self.app.progress.last_desc
|
||||
return self.py.progress.last_desc
|
||||
|
||||
def cancelJob(self):
|
||||
self.app.progress.job_cancelled = True
|
||||
self.py.progress.job_cancelled = True
|
||||
|
||||
#---Registration
|
||||
def demoLimitDescription(self):
|
||||
return self.app.DEMO_LIMIT_DESC
|
||||
return self.py.DEMO_LIMIT_DESC
|
||||
|
||||
@signature('i@:')
|
||||
def isRegistered(self):
|
||||
return self.app.registered
|
||||
return self.py.registered
|
||||
|
||||
def isCodeValid_withEmail_(self, code, email):
|
||||
try:
|
||||
self.app.validate_code(code, email)
|
||||
self.py.validate_code(code, email)
|
||||
return None
|
||||
except InvalidCodeError as e:
|
||||
return unicode(e)
|
||||
|
||||
def setRegisteredCode_andEmail_(self, code, email):
|
||||
self.app.set_registration(code, email)
|
||||
self.py.set_registration(code, email)
|
||||
|
||||
|
||||
class PyDetailsPanel(NSObject):
|
||||
def initWithCocoa_pyParent_(self, cocoa, pyparent):
|
||||
super(PyDetailsPanel, self).init()
|
||||
self.cocoa = cocoa
|
||||
self.py = DetailsPanel(self, pyparent.app)
|
||||
self.py = DetailsPanel(self, pyparent.py)
|
||||
return self
|
||||
|
||||
@signature('i@:')
|
||||
@@ -219,3 +217,10 @@ class PyDetailsPanel(NSObject):
|
||||
def refresh(self):
|
||||
self.cocoa.refresh()
|
||||
|
||||
|
||||
class PyDirectoryOutline(PyOutline):
|
||||
py_class = DirectoryTree
|
||||
|
||||
def addDirectory_(self, path):
|
||||
self.py.add_directory(path)
|
||||
|
||||
|
||||
23
core/gui/base.py
Normal file
23
core/gui/base.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Created By: Virgil Dupras
|
||||
# Created On: 2010-02-06
|
||||
# Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
||||
#
|
||||
# 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
|
||||
|
||||
from hsutil.notify import Listener
|
||||
|
||||
class GUIObject(Listener):
|
||||
def __init__(self, view, app):
|
||||
Listener.__init__(self, app)
|
||||
self.view = view
|
||||
self.app = app
|
||||
|
||||
def directories_changed(self):
|
||||
pass
|
||||
|
||||
def dupes_selected(self):
|
||||
pass
|
||||
|
||||
@@ -7,13 +7,11 @@
|
||||
# which should be included with this package. The terms are also available at
|
||||
# http://www.hardcoded.net/licenses/hs_license
|
||||
|
||||
from hsutil.notify import Listener
|
||||
from .base import GUIObject
|
||||
|
||||
class DetailsPanel(Listener):
|
||||
class DetailsPanel(GUIObject):
|
||||
def __init__(self, view, app):
|
||||
Listener.__init__(self, app)
|
||||
self.app = app
|
||||
self.view = view
|
||||
GUIObject.__init__(self, view, app)
|
||||
self._table = []
|
||||
self._refresh()
|
||||
self.connect()
|
||||
|
||||
73
core/gui/directory_tree.py
Normal file
73
core/gui/directory_tree.py
Normal file
@@ -0,0 +1,73 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Created By: Virgil Dupras
|
||||
# Created On: 2010-02-06
|
||||
# Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
||||
#
|
||||
# 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
|
||||
|
||||
from hsgui.tree import Tree, Node
|
||||
|
||||
from ..directories import STATE_NORMAL, STATE_REFERENCE, STATE_EXCLUDED
|
||||
from .base import GUIObject
|
||||
|
||||
STATE_ORDER = [STATE_NORMAL, STATE_REFERENCE, STATE_EXCLUDED]
|
||||
|
||||
# Lazily loads children
|
||||
class DirectoryNode(Node):
|
||||
def __init__(self, app, path, name):
|
||||
Node.__init__(self, name)
|
||||
self._app = app
|
||||
self._directory_path = path
|
||||
self._loaded = False
|
||||
self._state = STATE_ORDER.index(self._app.directories.get_state(path))
|
||||
|
||||
def _load(self):
|
||||
self.clear()
|
||||
subpaths = self._app.directories.get_subfolders(self._directory_path)
|
||||
for path in subpaths:
|
||||
self.append(DirectoryNode(self._app, path, path[-1]))
|
||||
self._loaded = True
|
||||
|
||||
@property
|
||||
def children_count(self):
|
||||
if not self._loaded:
|
||||
self._load()
|
||||
return len(self)
|
||||
|
||||
# The state propery is an index to the combobox
|
||||
@property
|
||||
def state(self):
|
||||
return self._state
|
||||
|
||||
@state.setter
|
||||
def state(self, value):
|
||||
if value == self._state:
|
||||
return
|
||||
self._state = value
|
||||
state = STATE_ORDER[value]
|
||||
self._app.directories.set_state(self._directory_path, state)
|
||||
|
||||
|
||||
class DirectoryTree(GUIObject, Tree):
|
||||
def __init__(self, view, app):
|
||||
GUIObject.__init__(self, view, app)
|
||||
Tree.__init__(self)
|
||||
self.connect()
|
||||
self._refresh()
|
||||
self.view.refresh()
|
||||
|
||||
def _refresh(self):
|
||||
self.clear()
|
||||
for path in self.app.directories:
|
||||
self.append(DirectoryNode(self.app, path, unicode(path)))
|
||||
|
||||
def add_directory(self, path):
|
||||
self.app.add_directory(path)
|
||||
|
||||
#--- Event Handlers
|
||||
def directories_changed(self):
|
||||
self._refresh()
|
||||
self.view.refresh()
|
||||
|
||||
@@ -27,6 +27,7 @@ except ImportError:
|
||||
from nose.plugins.skip import SkipTest
|
||||
raise SkipTest("These tests can only be run on OS X")
|
||||
from ..gui.details_panel import DetailsPanel
|
||||
from ..gui.directory_tree import DirectoryTree
|
||||
|
||||
class DupeGuru(DupeGuruBase):
|
||||
def __init__(self):
|
||||
@@ -61,6 +62,8 @@ class TCDupeGuru(TestCase):
|
||||
self.app = DupeGuru()
|
||||
self.dpanel_gui = CallLogger()
|
||||
self.dpanel = DetailsPanel(self.dpanel_gui, self.app)
|
||||
self.dtree_gui = CallLogger()
|
||||
self.dtree = DirectoryTree(self.dtree_gui, self.app)
|
||||
self.objects,self.matches,self.groups = GetTestGroups()
|
||||
self.app.results.groups = self.groups
|
||||
tmppath = self.tmppath()
|
||||
@@ -339,21 +342,6 @@ class TCDupeGuru(TestCase):
|
||||
app.SelectPowerMarkerNodePaths(r2np([2])) #The dupe of the second, 2 sized group
|
||||
app.add_selected_to_ignore_list()
|
||||
|
||||
def test_GetOutlineViewChildCounts_out_of_range(self):
|
||||
# Out of range requests don't crash and return an empty value
|
||||
app = self.app
|
||||
# [0, 2] is out of range
|
||||
eq_(app.GetOutlineViewChildCounts(1, [0, 2]), []) # no crash
|
||||
|
||||
def test_GetOutlineViewValues_out_of_range(self):
|
||||
# Out of range requests don't crash and return an empty value
|
||||
app = self.app
|
||||
# [0, 2] is out of range
|
||||
# Directories
|
||||
eq_(app.GetOutlineViewValues(1, [0, 2]), []) # no crash
|
||||
# Normal results
|
||||
app.GetOutlineViewValues(0, [42, 0]) # no crash
|
||||
|
||||
|
||||
class TCDupeGuru_renameSelected(TestCase):
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user