From da41d07dae07a75a6b648252ec4843de730b218c Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 29 Jan 2011 11:07:33 +0100 Subject: [PATCH] [#115 state:fixed] Re-factored the data columns (and delta columns) and made the Dimensions column a delta one. --- cocoa/base/PyDupeGuru.h | 1 + cocoa/base/ResultWindow.m | 1 + cocoa/me/ResultWindow.m | 9 -------- cocoa/pe/ResultWindow.m | 9 -------- cocoa/se/ResultWindow.m | 9 -------- core/app.py | 2 +- core/app_cocoa_inter.py | 3 +++ core/data.py | 4 ++++ core/gui/details_panel.py | 2 +- core/tests/data.py | 20 ++++++++--------- core_me/data.py | 47 ++++++++++++++++++++------------------- core_pe/data.py | 38 +++++++++++++++++++------------ core_se/data.py | 25 +++++++++++---------- qt/base/app.py | 1 - qt/base/result_window.py | 2 +- qt/base/results_model.py | 4 ++-- qt/me/app.py | 1 - qt/pe/app.py | 1 - qt/se/app.py | 1 - 19 files changed, 85 insertions(+), 95 deletions(-) diff --git a/cocoa/base/PyDupeGuru.h b/cocoa/base/PyDupeGuru.h index d914a998..44f670cd 100644 --- a/cocoa/base/PyDupeGuru.h +++ b/cocoa/base/PyDupeGuru.h @@ -45,6 +45,7 @@ http://www.hardcoded.net/licenses/bsd_license - (NSNumber *)getMarkCount; - (BOOL)scanWasProblematic; - (BOOL)resultsAreModified; +- (NSArray *)deltaColumns; //Scanning options - (void)setMinMatchPercentage:(NSNumber *)percentage; diff --git a/cocoa/base/ResultWindow.m b/cocoa/base/ResultWindow.m index 22f49bc9..5bb54d5f 100644 --- a/cocoa/base/ResultWindow.m +++ b/cocoa/base/ResultWindow.m @@ -29,6 +29,7 @@ http://www.hardcoded.net/licenses/bsd_license [self fillColumnsMenu]; [matches setTarget:self]; [matches setDoubleAction:@selector(openClicked:)]; + [table setDeltaColumns:[Utils array2IndexSet:[py deltaColumns]]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jobCompleted:) name:JobCompletedNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jobStarted:) name:JobStarted object:nil]; diff --git a/cocoa/me/ResultWindow.m b/cocoa/me/ResultWindow.m index 3681e819..22663776 100644 --- a/cocoa/me/ResultWindow.m +++ b/cocoa/me/ResultWindow.m @@ -14,15 +14,6 @@ http://www.hardcoded.net/licenses/bsd_license @implementation ResultWindow /* Override */ -- (id)initWithParentApp:(AppDelegateBase *)aApp; -{ - self = [super initWithParentApp:aApp]; - NSMutableIndexSet *deltaColumns = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(2,6)]; - [deltaColumns removeIndex:6]; - [table setDeltaColumns:deltaColumns]; - return self; -} - - (void)setScanOptions { NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; diff --git a/cocoa/pe/ResultWindow.m b/cocoa/pe/ResultWindow.m index 6b4a5a5b..963e2e33 100644 --- a/cocoa/pe/ResultWindow.m +++ b/cocoa/pe/ResultWindow.m @@ -14,15 +14,6 @@ http://www.hardcoded.net/licenses/bsd_license @implementation ResultWindow /* Override */ -- (id)initWithParentApp:(AppDelegateBase *)aApp; -{ - self = [super initWithParentApp:aApp]; - NSMutableIndexSet *deltaColumns = [NSMutableIndexSet indexSetWithIndex:2]; - [deltaColumns addIndex:5]; - [table setDeltaColumns:deltaColumns]; - return self; -} - - (void)initResultColumns { NSTableColumn *refCol = [matches tableColumnWithIdentifier:@"0"]; diff --git a/cocoa/se/ResultWindow.m b/cocoa/se/ResultWindow.m index dd000ebe..b117134d 100644 --- a/cocoa/se/ResultWindow.m +++ b/cocoa/se/ResultWindow.m @@ -13,15 +13,6 @@ http://www.hardcoded.net/licenses/bsd_license @implementation ResultWindow /* Override */ -- (id)initWithParentApp:(AppDelegateBase *)aApp; -{ - self = [super initWithParentApp:aApp]; - NSMutableIndexSet *deltaColumns = [NSMutableIndexSet indexSetWithIndex:2]; - [deltaColumns addIndex:4]; - [table setDeltaColumns:deltaColumns]; - return self; -} - - (void)initResultColumns { NSTableColumn *refCol = [matches tableColumnWithIdentifier:@"0"]; diff --git a/core/app.py b/core/app.py index af88c9f7..b2a7ad51 100644 --- a/core/app.py +++ b/core/app.py @@ -221,7 +221,7 @@ class DupeGuru(RegistrableApplication, Broadcaster): column_ids = [colid for colid in column_ids if colid.isdigit()] column_ids = list(map(int, column_ids)) column_ids.sort() - colnames = [col['display'] for i, col in enumerate(self.data.COLUMNS) if i in column_ids] + colnames = [col.display for i, col in enumerate(self.data.COLUMNS) if i in column_ids] rows = [] for group in self.results.groups: for dupe in group: diff --git a/core/app_cocoa_inter.py b/core/app_cocoa_inter.py index dc3f1aef..490ab35c 100644 --- a/core/app_cocoa_inter.py +++ b/core/app_cocoa_inter.py @@ -112,6 +112,9 @@ class PyDupeGuruBase(PyFairware): def resultsAreModified(self): return self.py.results.is_modified + def deltaColumns(self): + return list(self.py.data.DELTA_COLUMNS) + #---Properties @signature('v@:c') def setMixFileKind_(self, mix_file_kind): diff --git a/core/data.py b/core/data.py index 1a447e7f..ff24ba6f 100644 --- a/core/data.py +++ b/core/data.py @@ -6,10 +6,14 @@ # which should be included with this package. The terms are also available at # http://www.hardcoded.net/licenses/bsd_license +from collections import namedtuple + from hscommon.util import format_time_decimal, format_size import time +Column = namedtuple('Column', 'attr display') + def format_path(p): return str(p[:-1]) diff --git a/core/gui/details_panel.py b/core/gui/details_panel.py index a8459663..249b2dff 100644 --- a/core/gui/details_panel.py +++ b/core/gui/details_panel.py @@ -31,7 +31,7 @@ class DetailsPanel(GUIObject): # we don't want the two sides of the table to display the stats for the same file ref = group.ref if group is not None and group.ref is not dupe else None l2 = self.app._get_display_info(ref, group, False) - names = [c['display'] for c in self.app.data.COLUMNS] + names = [c.display for c in self.app.data.COLUMNS] self._table = list(zip(names, l1, l2)) #--- Public diff --git a/core/tests/data.py b/core/tests/data.py index a3a69c54..6caa395e 100644 --- a/core/tests/data.py +++ b/core/tests/data.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Created By: Virgil Dupras # Created On: 2009-10-23 # Copyright 2010 Hardcoded Software (http://www.hardcoded.net) @@ -10,16 +9,17 @@ # data module for tests from hscommon.util import format_size -from ..data import format_path, cmp_value +from ..data import format_path, cmp_value, Column COLUMNS = [ - {'attr':'name','display':'Filename'}, - {'attr':'path','display':'Directory'}, - {'attr':'size','display':'Size (KB)'}, - {'attr':'extension','display':'Kind'}, + Column('name', 'Filename'), + Column('path', 'Directory'), + Column('size', 'Size (KB)'), + Column('extension', 'Kind'), ] METADATA_TO_READ = ['size'] +DELTA_COLUMNS = {2,} def GetDisplayInfo(dupe, group, delta): size = dupe.size @@ -35,10 +35,10 @@ def GetDisplayInfo(dupe, group, delta): ] def GetDupeSortKey(dupe, get_group, key, delta): - r = cmp_value(getattr(dupe, COLUMNS[key]['attr'])) - if delta and (key == 2): - r -= cmp_value(getattr(get_group().ref, COLUMNS[key]['attr'])) + r = cmp_value(getattr(dupe, COLUMNS[key].attr)) + if delta and (key in DELTA_COLUMNS): + r -= cmp_value(getattr(get_group().ref, COLUMNS[key].attr)) return r def GetGroupSortKey(group, key): - return cmp_value(getattr(group.ref, COLUMNS[key]['attr'])) \ No newline at end of file + return cmp_value(getattr(group.ref, COLUMNS[key].attr)) \ No newline at end of file diff --git a/core_me/data.py b/core_me/data.py index 129aa53e..5929c223 100644 --- a/core_me/data.py +++ b/core_me/data.py @@ -9,33 +9,34 @@ from hscommon.util import format_time, format_size from hscommon.trans import tr as trbase from core.data import (format_path, format_timestamp, format_words, format_perc, - format_dupe_count, cmp_value) + format_dupe_count, cmp_value, Column) tr = lambda s: trbase(s, 'columns') COLUMNS = [ - {'attr': 'name', 'display': tr("Filename")}, - {'attr': 'path', 'display': tr("Folder")}, - {'attr': 'size', 'display': tr("Size (MB)")}, - {'attr': 'duration', 'display': tr("Time")}, - {'attr': 'bitrate', 'display': tr("Bitrate")}, - {'attr': 'samplerate', 'display': tr("Sample Rate")}, - {'attr': 'extension', 'display': tr("Kind")}, - {'attr': 'mtime', 'display': tr("Modification")}, - {'attr': 'title', 'display': tr("Title")}, - {'attr': 'artist', 'display': tr("Artist")}, - {'attr': 'album', 'display': tr("Album")}, - {'attr': 'genre', 'display': tr("Genre")}, - {'attr': 'year', 'display': tr("Year")}, - {'attr': 'track', 'display': tr("Track Number")}, - {'attr': 'comment', 'display': tr("Comment")}, - {'attr': 'percentage', 'display': tr("Match %")}, - {'attr': 'words', 'display': tr("Words Used")}, - {'attr': 'dupe_count', 'display': tr("Dupe Count")}, + Column('name', tr("Filename")), + Column('path', tr("Folder")), + Column('size', tr("Size (MB)")), + Column('duration', tr("Time")), + Column('bitrate', tr("Bitrate")), + Column('samplerate', tr("Sample Rate")), + Column('extension', tr("Kind")), + Column('mtime', tr("Modification")), + Column('title', tr("Title")), + Column('artist', tr("Artist")), + Column('album', tr("Album")), + Column('genre', tr("Genre")), + Column('year', tr("Year")), + Column('track', tr("Track Number")), + Column('comment', tr("Comment")), + Column('percentage', tr("Match %")), + Column('words', tr("Words Used")), + Column('dupe_count', tr("Dupe Count")), ] MATCHPERC_COL = 15 DUPECOUNT_COL = 17 +DELTA_COLUMNS = {2, 3, 4, 5, 7} METADATA_TO_READ = ['size', 'mtime', 'duration', 'bitrate', 'samplerate', 'title', 'artist', 'album', 'genre', 'year', 'track', 'comment'] @@ -87,9 +88,9 @@ def GetDupeSortKey(dupe, get_group, key, delta): return m.percentage if key == DUPECOUNT_COL: return 0 - r = cmp_value(getattr(dupe, COLUMNS[key]['attr'], '')) - if delta and (key in {2, 3, 4, 7}): - r -= cmp_value(getattr(get_group().ref, COLUMNS[key]['attr'], '')) + r = cmp_value(getattr(dupe, COLUMNS[key].attr, '')) + if delta and (key in DELTA_COLUMNS): + r -= cmp_value(getattr(get_group().ref, COLUMNS[key].attr, '')) return r def GetGroupSortKey(group, key): @@ -97,4 +98,4 @@ def GetGroupSortKey(group, key): return group.percentage if key == DUPECOUNT_COL: return len(group) - return cmp_value(getattr(group.ref, COLUMNS[key]['attr'], '')) + return cmp_value(getattr(group.ref, COLUMNS[key].attr, '')) diff --git a/core_pe/data.py b/core_pe/data.py index c5f2c21d..f76aeed1 100644 --- a/core_pe/data.py +++ b/core_pe/data.py @@ -8,7 +8,7 @@ from hscommon.util import format_size from hscommon.trans import tr as trbase -from core.data import format_path, format_timestamp, format_perc, format_dupe_count, cmp_value +from core.data import format_path, format_timestamp, format_perc, format_dupe_count, cmp_value, Column tr = lambda s: trbase(s, 'columns') @@ -16,26 +16,31 @@ def format_dimensions(dimensions): return '%d x %d' % (dimensions[0], dimensions[1]) COLUMNS = [ - {'attr':'name', 'display': tr("Filename")}, - {'attr':'path', 'display': tr("Folder")}, - {'attr':'size', 'display': tr("Size (KB)")}, - {'attr':'extension', 'display': tr("Kind")}, - {'attr':'dimensions', 'display': tr("Dimensions")}, - {'attr':'mtime', 'display': tr("Modification")}, - {'attr':'percentage', 'display': tr("Match %")}, - {'attr':'dupe_count', 'display': tr("Dupe Count")}, + Column('name', tr("Filename")), + Column('path', tr("Folder")), + Column('size', tr("Size (KB)")), + Column('extension', tr("Kind")), + Column('dimensions', tr("Dimensions")), + Column('mtime', tr("Modification")), + Column('percentage', tr("Match %")), + Column('dupe_count', tr("Dupe Count")), ] MATCHPERC_COL = 6 DUPECOUNT_COL = 7 +DELTA_COLUMNS = {2, 4, 5} METADATA_TO_READ = ['size', 'mtime', 'dimensions'] +def get_delta_dimensions(value, ref_value): + return (value[0]-ref_value[0], value[1]-ref_value[1]) + def GetDisplayInfo(dupe,group,delta=False): if (dupe is None) or (group is None): return ['---'] * len(COLUMNS) size = dupe.size mtime = dupe.mtime + dimensions = dupe.dimensions m = group.get_match_of(dupe) if m: percentage = m.percentage @@ -44,6 +49,7 @@ def GetDisplayInfo(dupe,group,delta=False): r = group.ref size -= r.size mtime -= r.mtime + dimensions = get_delta_dimensions(dimensions, r.dimensions) else: percentage = group.percentage dupe_count = len(group.dupes) @@ -53,7 +59,7 @@ def GetDisplayInfo(dupe,group,delta=False): format_path(dupe_path), format_size(size, 0, 1, False), dupe.extension, - format_dimensions(dupe.dimensions), + format_dimensions(dimensions), format_timestamp(mtime, delta and m), format_perc(percentage), format_dupe_count(dupe_count) @@ -65,9 +71,13 @@ def GetDupeSortKey(dupe, get_group, key, delta): return m.percentage if key == DUPECOUNT_COL: return 0 - r = cmp_value(getattr(dupe, COLUMNS[key]['attr'], '')) - if delta and (key in {2, 5}): - r -= cmp_value(getattr(get_group().ref, COLUMNS[key]['attr'], '')) + r = cmp_value(getattr(dupe, COLUMNS[key].attr, '')) + if delta and (key in DELTA_COLUMNS): + ref_value = cmp_value(getattr(get_group().ref, COLUMNS[key].attr, '')) + if key == 4: # dimensions + r = get_delta_dimensions(r, ref_value) + else: + r -= ref_value return r def GetGroupSortKey(group, key): @@ -75,5 +85,5 @@ def GetGroupSortKey(group, key): return group.percentage if key == DUPECOUNT_COL: return len(group) - return cmp_value(getattr(group.ref, COLUMNS[key]['attr'], '')) + return cmp_value(getattr(group.ref, COLUMNS[key].attr, '')) diff --git a/core_se/data.py b/core_se/data.py index 9d166cd6..de8a42f7 100644 --- a/core_se/data.py +++ b/core_se/data.py @@ -9,23 +9,24 @@ from hscommon.util import format_size from hscommon.trans import tr as trbase from core.data import (format_path, format_timestamp, format_words, format_perc, - format_dupe_count, cmp_value) + format_dupe_count, cmp_value, Column) tr = lambda s: trbase(s, 'columns') COLUMNS = [ - {'attr':'name', 'display': tr("Filename")}, - {'attr':'path', 'display': tr("Folder")}, - {'attr':'size', 'display': tr("Size (KB)")}, - {'attr':'extension', 'display': tr("Kind")}, - {'attr':'mtime', 'display': tr("Modification")}, - {'attr':'percentage', 'display': tr("Match %")}, - {'attr':'words', 'display': tr("Words Used")}, - {'attr':'dupe_count', 'display': tr("Dupe Count")}, + Column('name', tr("Filename")), + Column('path', tr("Folder")), + Column('size', tr("Size (KB)")), + Column('extension', tr("Kind")), + Column('mtime', tr("Modification")), + Column('percentage', tr("Match %")), + Column('words', tr("Words Used")), + Column('dupe_count', tr("Dupe Count")), ] MATCHPERC_COL = 5 DUPECOUNT_COL = 7 +DELTA_COLUMNS = {2, 4} METADATA_TO_READ = ['size', 'mtime'] @@ -60,9 +61,9 @@ def GetDupeSortKey(dupe, get_group, key, delta): return m.percentage if key == DUPECOUNT_COL: return 0 - r = cmp_value(getattr(dupe, COLUMNS[key]['attr'], '')) + r = cmp_value(getattr(dupe, COLUMNS[key].attr, '')) if delta and (key in {2, 4}): - r -= cmp_value(getattr(get_group().ref, COLUMNS[key]['attr'], '')) + r -= cmp_value(getattr(get_group().ref, COLUMNS[key].attr, '')) return r def GetGroupSortKey(group, key): @@ -70,4 +71,4 @@ def GetGroupSortKey(group, key): return group.percentage if key == DUPECOUNT_COL: return len(group) - return cmp_value(getattr(group.ref, COLUMNS[key]['attr'], '')) + return cmp_value(getattr(group.ref, COLUMNS[key].attr, '')) diff --git a/qt/base/app.py b/qt/base/app.py index 851f42ea..d05d78cb 100644 --- a/qt/base/app.py +++ b/qt/base/app.py @@ -41,7 +41,6 @@ JOBID2TITLE = { class DupeGuru(DupeGuruBase, QObject): LOGO_NAME = '' NAME = '' - DELTA_COLUMNS = frozenset() def __init__(self, data_module): appdata = str(QDesktopServices.storageLocation(QDesktopServices.DataLocation)) diff --git a/qt/base/result_window.py b/qt/base/result_window.py index 631cd393..6488205b 100644 --- a/qt/base/result_window.py +++ b/qt/base/result_window.py @@ -137,7 +137,7 @@ class ResultWindow(QMainWindow): menu = self.menuColumns self._column_actions = [] for index, column in enumerate(self.app.data.COLUMNS): - action = menu.addAction(column['display']) + action = menu.addAction(column.display) action.setCheckable(True) action.column_index = index self._column_actions.append(action) diff --git a/qt/base/results_model.py b/qt/base/results_model.py index f378ceac..4638292a 100644 --- a/qt/base/results_model.py +++ b/qt/base/results_model.py @@ -18,7 +18,7 @@ class ResultsModel(Table): model = ResultTableModel(self, app) self._app = app self._data = app.data - self._delta_columns = app.DELTA_COLUMNS + self._delta_columns = app.data.DELTA_COLUMNS Table.__init__(self, model, view) self.model.connect() @@ -63,7 +63,7 @@ class ResultsModel(Table): def headerData(self, section, orientation, role): if orientation == Qt.Horizontal and role == Qt.DisplayRole and section < len(self._data.COLUMNS): - return self._data.COLUMNS[section]['display'] + return self._data.COLUMNS[section].display return None def setData(self, index, value, role): diff --git a/qt/me/app.py b/qt/me/app.py index 03e2c07b..e4410cde 100644 --- a/qt/me/app.py +++ b/qt/me/app.py @@ -17,7 +17,6 @@ class DupeGuru(DupeGuruBase): EDITION = 'me' LOGO_NAME = 'logo_me' NAME = __appname__ - DELTA_COLUMNS = frozenset([2, 3, 4, 5, 7]) def __init__(self): DupeGuruBase.__init__(self, data) diff --git a/qt/pe/app.py b/qt/pe/app.py index 24a8fd9e..031b50d7 100644 --- a/qt/pe/app.py +++ b/qt/pe/app.py @@ -59,7 +59,6 @@ class DupeGuru(DupeGuruBase): EDITION = 'pe' LOGO_NAME = 'logo_pe' NAME = __appname__ - DELTA_COLUMNS = frozenset([2, 5]) def __init__(self): DupeGuruBase.__init__(self, data_pe) diff --git a/qt/se/app.py b/qt/se/app.py index 6addd556..ea9c0fea 100644 --- a/qt/se/app.py +++ b/qt/se/app.py @@ -27,7 +27,6 @@ class DupeGuru(DupeGuruBase): EDITION = 'se' LOGO_NAME = 'logo_se' NAME = __appname__ - DELTA_COLUMNS = frozenset([2, 4]) def __init__(self): DupeGuruBase.__init__(self, data)