2010-02-11 16:52:18 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2010-02-11
|
|
|
|
# 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
|
|
|
|
|
2010-02-12 10:07:33 +00:00
|
|
|
from operator import attrgetter
|
|
|
|
|
2010-02-11 16:52:18 +00:00
|
|
|
from hsgui.tree import Tree, Node
|
|
|
|
|
|
|
|
from .base import GUIObject
|
|
|
|
|
|
|
|
class DupeNode(Node):
|
|
|
|
def __init__(self, app, group, dupe):
|
|
|
|
Node.__init__(self, '')
|
|
|
|
self._app = app
|
|
|
|
self._group = group
|
|
|
|
self._dupe = dupe
|
|
|
|
self.data = app._get_display_info(dupe, group, False)
|
|
|
|
self.data_delta = app._get_display_info(dupe, group, True)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def markable(self):
|
|
|
|
return self._app.results.is_markable(self._dupe)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def marked(self):
|
|
|
|
return self._app.results.is_marked(self._dupe)
|
|
|
|
|
|
|
|
|
|
|
|
class ResultTree(GUIObject, Tree):
|
|
|
|
def __init__(self, view, app):
|
|
|
|
GUIObject.__init__(self, view, app)
|
|
|
|
Tree.__init__(self)
|
|
|
|
self._power_marker = False
|
2010-02-11 18:22:31 +00:00
|
|
|
self._delta_values = False
|
2010-02-11 20:03:22 +00:00
|
|
|
self._sort_descriptors = (0, True)
|
2010-02-11 16:52:18 +00:00
|
|
|
self.connect()
|
|
|
|
self._refresh()
|
|
|
|
self.view.refresh()
|
|
|
|
|
2010-02-12 10:07:33 +00:00
|
|
|
#--- Override
|
|
|
|
def _select_nodes(self, nodes):
|
|
|
|
Tree._select_nodes(self, nodes)
|
|
|
|
self.app._select_dupes(map(attrgetter('_dupe'), nodes))
|
|
|
|
|
|
|
|
#--- Private
|
2010-02-11 16:52:18 +00:00
|
|
|
def _refresh(self):
|
|
|
|
self.clear()
|
|
|
|
if not self.power_marker:
|
|
|
|
for group in self.app.results.groups:
|
|
|
|
group_node = DupeNode(self.app, group, group.ref)
|
|
|
|
self.append(group_node)
|
|
|
|
for dupe in group.dupes:
|
|
|
|
group_node.append(DupeNode(self.app, group, dupe))
|
|
|
|
else:
|
|
|
|
for dupe in self.app.results.dupes:
|
|
|
|
group = self.app.results.get_group_of_duplicate(dupe)
|
|
|
|
self.append(DupeNode(self.app, group, dupe))
|
|
|
|
if self.app.selected_dupes:
|
2010-02-12 10:07:33 +00:00
|
|
|
to_find = set(self.app.selected_dupes)
|
|
|
|
nodes = list(self.findall(lambda n: n is not self and n._dupe in to_find))
|
|
|
|
self.selected_nodes = nodes
|
2010-02-11 16:52:18 +00:00
|
|
|
|
2010-02-12 10:07:33 +00:00
|
|
|
#--- Public
|
2010-02-11 16:52:18 +00:00
|
|
|
def get_node_value(self, path, column):
|
|
|
|
try:
|
|
|
|
node = self.get_node(path)
|
|
|
|
except IndexError:
|
|
|
|
return '---'
|
2010-02-11 18:22:31 +00:00
|
|
|
if self.delta_values:
|
2010-02-11 16:52:18 +00:00
|
|
|
return node.data_delta[column]
|
|
|
|
else:
|
|
|
|
return node.data[column]
|
|
|
|
|
|
|
|
def sort(self, key, asc):
|
|
|
|
if self.power_marker:
|
2010-02-11 18:22:31 +00:00
|
|
|
self.app.results.sort_dupes(key, asc, self.delta_values)
|
2010-02-11 16:52:18 +00:00
|
|
|
else:
|
2010-02-11 18:22:31 +00:00
|
|
|
self.app.results.sort_groups(key, asc)
|
2010-02-11 20:03:22 +00:00
|
|
|
self._sort_descriptors = (key, asc)
|
|
|
|
self._refresh()
|
|
|
|
self.view.refresh()
|
2010-02-11 16:52:18 +00:00
|
|
|
|
2010-02-12 10:07:33 +00:00
|
|
|
#--- Properties
|
2010-02-11 16:52:18 +00:00
|
|
|
@property
|
|
|
|
def power_marker(self):
|
|
|
|
return self._power_marker
|
|
|
|
|
|
|
|
@power_marker.setter
|
|
|
|
def power_marker(self, value):
|
|
|
|
if value == self._power_marker:
|
|
|
|
return
|
|
|
|
self._power_marker = value
|
2010-02-11 20:03:22 +00:00
|
|
|
key, asc = self._sort_descriptors
|
|
|
|
self.sort(key, asc)
|
2010-02-11 16:52:18 +00:00
|
|
|
self._refresh()
|
|
|
|
self.view.refresh()
|
|
|
|
|
2010-02-11 18:22:31 +00:00
|
|
|
@property
|
|
|
|
def delta_values(self):
|
|
|
|
return self._delta_values
|
|
|
|
|
|
|
|
@delta_values.setter
|
|
|
|
def delta_values(self, value):
|
|
|
|
if value == self._delta_values:
|
|
|
|
return
|
|
|
|
self._delta_values = value
|
|
|
|
self._refresh()
|
|
|
|
self.view.refresh()
|
|
|
|
|
2010-02-11 16:52:18 +00:00
|
|
|
#--- Event Handlers
|
|
|
|
def results_changed(self):
|
|
|
|
self._refresh()
|
|
|
|
self.view.refresh()
|
|
|
|
|