You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

87 lines
3.0 KiB

  1. # Created By: Virgil Dupras
  2. # Created On: 2011-09-06
  3. # Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
  4. #
  5. # This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
  6. # which should be included with this package. The terms are also available at
  7. # http://www.gnu.org/licenses/gpl-3.0.html
  8. from hscommon.gui.base import GUIObject
  9. from hscommon.gui.selectable_list import GUISelectableList
  10. class CriterionCategoryList(GUISelectableList):
  11. def __init__(self, dialog):
  12. self.dialog = dialog
  13. GUISelectableList.__init__(self, [c.NAME for c in dialog.categories])
  14. def _update_selection(self):
  15. self.dialog.select_category(self.dialog.categories[self.selected_index])
  16. GUISelectableList._update_selection(self)
  17. class PrioritizationList(GUISelectableList):
  18. def __init__(self, dialog):
  19. self.dialog = dialog
  20. GUISelectableList.__init__(self)
  21. def _refresh_contents(self):
  22. self[:] = [crit.display for crit in self.dialog.prioritizations]
  23. def move_indexes(self, indexes, dest_index):
  24. indexes.sort()
  25. prilist = self.dialog.prioritizations
  26. selected = [prilist[i] for i in indexes]
  27. for i in reversed(indexes):
  28. del prilist[i]
  29. prilist[dest_index:dest_index] = selected
  30. self._refresh_contents()
  31. def remove_selected(self):
  32. prilist = self.dialog.prioritizations
  33. for i in sorted(self.selected_indexes, reverse=True):
  34. del prilist[i]
  35. self._refresh_contents()
  36. class PrioritizeDialog(GUIObject):
  37. def __init__(self, app):
  38. GUIObject.__init__(self)
  39. self.app = app
  40. self.categories = [cat(app.results) for cat in app._prioritization_categories()]
  41. self.category_list = CriterionCategoryList(self)
  42. self.criteria = []
  43. self.criteria_list = GUISelectableList()
  44. self.prioritizations = []
  45. self.prioritization_list = PrioritizationList(self)
  46. # --- Override
  47. def _view_updated(self):
  48. self.category_list.select(0)
  49. # --- Private
  50. def _sort_key(self, dupe):
  51. return tuple(crit.sort_key(dupe) for crit in self.prioritizations)
  52. # --- Public
  53. def select_category(self, category):
  54. self.criteria = category.criteria_list()
  55. self.criteria_list[:] = [c.display_value for c in self.criteria]
  56. def add_selected(self):
  57. # Add selected criteria in criteria_list to prioritization_list.
  58. if self.criteria_list.selected_index is None:
  59. return
  60. for i in self.criteria_list.selected_indexes:
  61. crit = self.criteria[i]
  62. self.prioritizations.append(crit)
  63. del crit
  64. self.prioritization_list[:] = [crit.display for crit in self.prioritizations]
  65. def remove_selected(self):
  66. self.prioritization_list.remove_selected()
  67. self.prioritization_list.select([])
  68. def perform_reprioritization(self):
  69. self.app.reprioritize_groups(self._sort_key)