2011-09-07 19:46:41 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2011-09-06
|
|
|
|
# Copyright 2011 Hardcoded Software (http://www.hardcoded.net)
|
|
|
|
#
|
|
|
|
# This software is licensed under the "BSD" 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/bsd_license
|
|
|
|
|
2012-03-13 18:27:08 +00:00
|
|
|
from hscommon.gui.base import GUIObject
|
2011-09-09 16:01:15 +00:00
|
|
|
from hscommon.gui.selectable_list import GUISelectableList
|
2011-09-07 19:46:41 +00:00
|
|
|
|
2011-09-09 16:01:15 +00:00
|
|
|
class CriterionCategoryList(GUISelectableList):
|
2011-09-07 19:46:41 +00:00
|
|
|
def __init__(self, dialog):
|
|
|
|
self.dialog = dialog
|
2011-09-09 16:01:15 +00:00
|
|
|
GUISelectableList.__init__(self, [c.NAME for c in dialog.categories])
|
2011-09-07 19:46:41 +00:00
|
|
|
|
|
|
|
def _update_selection(self):
|
|
|
|
self.dialog.select_category(self.dialog.categories[self.selected_index])
|
|
|
|
|
2011-09-09 22:24:17 +00:00
|
|
|
class PrioritizationList(GUISelectableList):
|
|
|
|
def __init__(self, dialog):
|
|
|
|
self.dialog = dialog
|
|
|
|
GUISelectableList.__init__(self)
|
|
|
|
|
2011-09-12 15:05:53 +00:00
|
|
|
def _refresh_contents(self):
|
|
|
|
self[:] = [crit.display for crit in self.dialog.prioritizations]
|
|
|
|
|
2011-09-09 22:24:17 +00:00
|
|
|
def move_indexes(self, indexes, dest_index):
|
|
|
|
indexes.sort()
|
|
|
|
prilist = self.dialog.prioritizations
|
|
|
|
selected = [prilist[i] for i in indexes]
|
|
|
|
for i in reversed(indexes):
|
|
|
|
del prilist[i]
|
|
|
|
prilist[dest_index:dest_index] = selected
|
2011-09-12 15:05:53 +00:00
|
|
|
self._refresh_contents()
|
|
|
|
|
|
|
|
def remove_selected(self):
|
|
|
|
prilist = self.dialog.prioritizations
|
|
|
|
for i in sorted(self.selected_indexes, reverse=True):
|
|
|
|
del prilist[i]
|
|
|
|
self._refresh_contents()
|
2011-09-07 19:46:41 +00:00
|
|
|
|
2012-03-13 18:27:08 +00:00
|
|
|
class PrioritizeDialog(GUIObject):
|
2012-01-13 21:14:06 +00:00
|
|
|
def __init__(self, app):
|
2012-03-13 18:27:08 +00:00
|
|
|
GUIObject.__init__(self)
|
2011-09-08 16:36:57 +00:00
|
|
|
self.app = app
|
2011-09-21 14:26:58 +00:00
|
|
|
self.categories = [cat(app.results) for cat in app._prioritization_categories()]
|
2011-09-07 19:46:41 +00:00
|
|
|
self.category_list = CriterionCategoryList(self)
|
2011-09-08 16:36:57 +00:00
|
|
|
self.criteria = []
|
2011-09-09 16:01:15 +00:00
|
|
|
self.criteria_list = GUISelectableList()
|
2011-09-08 16:36:57 +00:00
|
|
|
self.prioritizations = []
|
2011-09-09 22:24:17 +00:00
|
|
|
self.prioritization_list = PrioritizationList(self)
|
2012-03-13 18:27:08 +00:00
|
|
|
|
|
|
|
#--- Override
|
|
|
|
def _view_updated(self):
|
2011-09-13 20:31:25 +00:00
|
|
|
self.category_list.select(0)
|
2011-09-07 19:46:41 +00:00
|
|
|
|
2011-09-08 16:36:57 +00:00
|
|
|
#--- Private
|
|
|
|
def _sort_key(self, dupe):
|
2011-09-08 17:28:19 +00:00
|
|
|
return tuple(crit.sort_key(dupe) for crit in self.prioritizations)
|
2011-09-08 16:36:57 +00:00
|
|
|
|
|
|
|
#--- Public
|
2011-09-07 19:46:41 +00:00
|
|
|
def select_category(self, category):
|
2011-09-08 16:36:57 +00:00
|
|
|
self.criteria = category.criteria_list()
|
2011-09-08 17:28:19 +00:00
|
|
|
self.criteria_list[:] = [c.display_value for c in self.criteria]
|
2011-09-08 16:36:57 +00:00
|
|
|
|
|
|
|
def add_selected(self):
|
|
|
|
# Add selected criteria in criteria_list to prioritization_list.
|
2011-11-28 18:14:36 +00:00
|
|
|
if self.criteria_list.selected_index is None:
|
|
|
|
return
|
2011-09-08 16:36:57 +00:00
|
|
|
crit = self.criteria[self.criteria_list.selected_index]
|
|
|
|
self.prioritizations.append(crit)
|
2011-09-08 17:28:19 +00:00
|
|
|
self.prioritization_list[:] = [crit.display for crit in self.prioritizations]
|
2011-09-08 16:36:57 +00:00
|
|
|
|
2011-09-12 15:05:53 +00:00
|
|
|
def remove_selected(self):
|
|
|
|
self.prioritization_list.remove_selected()
|
|
|
|
|
2011-09-08 16:36:57 +00:00
|
|
|
def perform_reprioritization(self):
|
|
|
|
self.app.reprioritize_groups(self._sort_key)
|