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.
 
 
 
 
 
 

148 lines
5.8 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 PyQt5.QtCore import Qt, QMimeData, QByteArray
  9. from PyQt5.QtWidgets import (
  10. QDialog,
  11. QVBoxLayout,
  12. QHBoxLayout,
  13. QPushButton,
  14. QComboBox,
  15. QListView,
  16. QDialogButtonBox,
  17. QAbstractItemView,
  18. QLabel,
  19. QStyle,
  20. QSplitter,
  21. QWidget,
  22. QSizePolicy,
  23. )
  24. from hscommon.trans import trget
  25. from qtlib.selectable_list import ComboboxModel, ListviewModel
  26. from qtlib.util import verticalSpacer
  27. from core.gui.prioritize_dialog import PrioritizeDialog as PrioritizeDialogModel
  28. tr = trget("ui")
  29. MIME_INDEXES = "application/dupeguru.rowindexes"
  30. class PrioritizationList(ListviewModel):
  31. def flags(self, index):
  32. if not index.isValid():
  33. return Qt.ItemIsEnabled | Qt.ItemIsDropEnabled
  34. return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled
  35. # --- Drag & Drop
  36. def dropMimeData(self, mimeData, action, row, column, parentIndex):
  37. if not mimeData.hasFormat(MIME_INDEXES):
  38. return False
  39. # Since we only drop in between items, parentIndex must be invalid, and we use the row arg
  40. # to know where the drop took place.
  41. if parentIndex.isValid():
  42. return False
  43. strMimeData = bytes(mimeData.data(MIME_INDEXES)).decode()
  44. indexes = list(map(int, strMimeData.split(",")))
  45. self.model.move_indexes(indexes, row)
  46. self.view.selectionModel().clearSelection()
  47. return True
  48. def mimeData(self, indexes):
  49. rows = {str(index.row()) for index in indexes}
  50. data = ",".join(rows)
  51. mimeData = QMimeData()
  52. mimeData.setData(MIME_INDEXES, QByteArray(data.encode()))
  53. return mimeData
  54. def mimeTypes(self):
  55. return [MIME_INDEXES]
  56. def supportedDropActions(self):
  57. return Qt.MoveAction
  58. class PrioritizeDialog(QDialog):
  59. def __init__(self, parent, app, **kwargs):
  60. flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
  61. super().__init__(parent, flags, **kwargs)
  62. self._setupUi()
  63. self.model = PrioritizeDialogModel(app=app.model)
  64. self.categoryList = ComboboxModel(
  65. model=self.model.category_list, view=self.categoryCombobox
  66. )
  67. self.criteriaList = ListviewModel(
  68. model=self.model.criteria_list, view=self.criteriaListView
  69. )
  70. self.prioritizationList = PrioritizationList(
  71. model=self.model.prioritization_list, view=self.prioritizationListView
  72. )
  73. self.model.view = self
  74. self.addCriteriaButton.clicked.connect(self.model.add_selected)
  75. self.removeCriteriaButton.clicked.connect(self.model.remove_selected)
  76. self.buttonBox.accepted.connect(self.accept)
  77. self.buttonBox.rejected.connect(self.reject)
  78. def _setupUi(self):
  79. self.setWindowTitle(tr("Re-Prioritize duplicates"))
  80. self.resize(700, 400)
  81. # widgets
  82. msg = tr(
  83. "Add criteria to the right box and click OK to send the dupes that correspond the "
  84. "best to these criteria to their respective group's "
  85. "reference position. Read the help file for more information."
  86. )
  87. self.promptLabel = QLabel(msg)
  88. self.promptLabel.setWordWrap(True)
  89. self.categoryCombobox = QComboBox()
  90. self.criteriaListView = QListView()
  91. self.criteriaListView.setSelectionMode(QAbstractItemView.ExtendedSelection)
  92. self.addCriteriaButton = QPushButton(
  93. self.style().standardIcon(QStyle.SP_ArrowRight), ""
  94. )
  95. self.removeCriteriaButton = QPushButton(
  96. self.style().standardIcon(QStyle.SP_ArrowLeft), ""
  97. )
  98. self.prioritizationListView = QListView()
  99. self.prioritizationListView.setAcceptDrops(True)
  100. self.prioritizationListView.setDragEnabled(True)
  101. self.prioritizationListView.setDragDropMode(QAbstractItemView.InternalMove)
  102. self.prioritizationListView.setSelectionBehavior(QAbstractItemView.SelectRows)
  103. self.prioritizationListView.setSelectionMode(QAbstractItemView.ExtendedSelection)
  104. self.buttonBox = QDialogButtonBox()
  105. self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok)
  106. # layout
  107. self.mainLayout = QVBoxLayout(self)
  108. self.mainLayout.addWidget(self.promptLabel)
  109. self.splitter = QSplitter()
  110. sp = self.splitter.sizePolicy()
  111. sp.setVerticalPolicy(QSizePolicy.Expanding)
  112. self.splitter.setSizePolicy(sp)
  113. self.leftSide = QWidget()
  114. self.leftWidgetsLayout = QVBoxLayout()
  115. self.leftWidgetsLayout.addWidget(self.categoryCombobox)
  116. self.leftWidgetsLayout.addWidget(self.criteriaListView)
  117. self.leftSide.setLayout(self.leftWidgetsLayout)
  118. self.splitter.addWidget(self.leftSide)
  119. self.rightSide = QWidget()
  120. self.rightWidgetsLayout = QHBoxLayout()
  121. self.addRemoveButtonsLayout = QVBoxLayout()
  122. self.addRemoveButtonsLayout.addItem(verticalSpacer())
  123. self.addRemoveButtonsLayout.addWidget(self.addCriteriaButton)
  124. self.addRemoveButtonsLayout.addWidget(self.removeCriteriaButton)
  125. self.addRemoveButtonsLayout.addItem(verticalSpacer())
  126. self.rightWidgetsLayout.addLayout(self.addRemoveButtonsLayout)
  127. self.rightWidgetsLayout.addWidget(self.prioritizationListView)
  128. self.rightSide.setLayout(self.rightWidgetsLayout)
  129. self.splitter.addWidget(self.rightSide)
  130. self.mainLayout.addWidget(self.splitter)
  131. self.mainLayout.addWidget(self.buttonBox)