2011-09-09 16:01:15 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2011-09-06
|
2015-01-03 21:30:57 +00:00
|
|
|
# Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
|
2014-10-13 19:08:59 +00:00
|
|
|
#
|
2015-01-03 21:33:16 +00:00
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
2014-10-13 19:08:59 +00:00
|
|
|
# which should be included with this package. The terms are also available at
|
2015-01-03 21:33:16 +00:00
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
2011-09-09 16:01:15 +00:00
|
|
|
|
2013-10-20 19:15:09 +00:00
|
|
|
from PyQt5.QtCore import Qt, QMimeData, QByteArray
|
2014-10-13 19:08:59 +00:00
|
|
|
from PyQt5.QtWidgets import (
|
2020-01-01 02:16:27 +00:00
|
|
|
QDialog,
|
|
|
|
QVBoxLayout,
|
|
|
|
QHBoxLayout,
|
|
|
|
QPushButton,
|
|
|
|
QComboBox,
|
|
|
|
QListView,
|
|
|
|
QDialogButtonBox,
|
|
|
|
QAbstractItemView,
|
|
|
|
QLabel,
|
|
|
|
QStyle,
|
|
|
|
QSplitter,
|
|
|
|
QWidget,
|
|
|
|
QSizePolicy,
|
2014-10-13 19:08:59 +00:00
|
|
|
)
|
2011-09-09 16:01:15 +00:00
|
|
|
|
2011-11-01 19:44:18 +00:00
|
|
|
from hscommon.trans import trget
|
2011-09-09 16:01:15 +00:00
|
|
|
from qtlib.selectable_list import ComboboxModel, ListviewModel
|
2021-08-24 05:12:23 +00:00
|
|
|
from qtlib.util import vertical_spacer
|
2011-09-09 16:01:15 +00:00
|
|
|
from core.gui.prioritize_dialog import PrioritizeDialog as PrioritizeDialogModel
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
tr = trget("ui")
|
|
|
|
|
|
|
|
MIME_INDEXES = "application/dupeguru.rowindexes"
|
2011-11-01 19:44:18 +00:00
|
|
|
|
2011-09-09 22:24:17 +00:00
|
|
|
|
|
|
|
class PrioritizationList(ListviewModel):
|
|
|
|
def flags(self, index):
|
|
|
|
if not index.isValid():
|
|
|
|
return Qt.ItemIsEnabled | Qt.ItemIsDropEnabled
|
|
|
|
return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
# --- Drag & Drop
|
2021-08-24 05:12:23 +00:00
|
|
|
def dropMimeData(self, mime_data, action, row, column, parent_index):
|
|
|
|
if not mime_data.hasFormat(MIME_INDEXES):
|
2011-09-09 22:24:17 +00:00
|
|
|
return False
|
|
|
|
# Since we only drop in between items, parentIndex must be invalid, and we use the row arg
|
|
|
|
# to know where the drop took place.
|
2021-08-24 05:12:23 +00:00
|
|
|
if parent_index.isValid():
|
2011-09-09 22:24:17 +00:00
|
|
|
return False
|
2021-01-07 16:31:51 +00:00
|
|
|
# "When row and column are -1 it means that the dropped data should be considered as
|
|
|
|
# dropped directly on parent."
|
|
|
|
# Moving items to row -1 would put them before the last item. Fix the row to drop the
|
|
|
|
# dragged items after the last item.
|
|
|
|
if row < 0:
|
|
|
|
row = len(self.model) - 1
|
2021-08-24 05:12:23 +00:00
|
|
|
str_mime_data = bytes(mime_data.data(MIME_INDEXES)).decode()
|
|
|
|
indexes = list(map(int, str_mime_data.split(",")))
|
2011-09-09 22:24:17 +00:00
|
|
|
self.model.move_indexes(indexes, row)
|
2021-01-07 09:02:49 +00:00
|
|
|
self.view.selectionModel().clearSelection()
|
2011-09-09 22:24:17 +00:00
|
|
|
return True
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-09-09 22:24:17 +00:00
|
|
|
def mimeData(self, indexes):
|
|
|
|
rows = {str(index.row()) for index in indexes}
|
2020-01-01 02:16:27 +00:00
|
|
|
data = ",".join(rows)
|
2021-08-24 05:12:23 +00:00
|
|
|
mime_data = QMimeData()
|
|
|
|
mime_data.setData(MIME_INDEXES, QByteArray(data.encode()))
|
|
|
|
return mime_data
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-09-09 22:24:17 +00:00
|
|
|
def mimeTypes(self):
|
|
|
|
return [MIME_INDEXES]
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-09-09 22:24:17 +00:00
|
|
|
def supportedDropActions(self):
|
|
|
|
return Qt.MoveAction
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2011-09-09 16:01:15 +00:00
|
|
|
class PrioritizeDialog(QDialog):
|
2013-10-20 19:53:59 +00:00
|
|
|
def __init__(self, parent, app, **kwargs):
|
2011-09-09 16:01:15 +00:00
|
|
|
flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
|
2013-10-20 19:53:59 +00:00
|
|
|
super().__init__(parent, flags, **kwargs)
|
2011-09-09 16:01:15 +00:00
|
|
|
self._setupUi()
|
2012-01-16 14:29:57 +00:00
|
|
|
self.model = PrioritizeDialogModel(app=app.model)
|
2021-08-15 09:10:18 +00:00
|
|
|
self.categoryList = ComboboxModel(model=self.model.category_list, view=self.categoryCombobox)
|
|
|
|
self.criteriaList = ListviewModel(model=self.model.criteria_list, view=self.criteriaListView)
|
2014-10-13 19:08:59 +00:00
|
|
|
self.prioritizationList = PrioritizationList(
|
|
|
|
model=self.model.prioritization_list, view=self.prioritizationListView
|
|
|
|
)
|
2012-03-19 20:52:08 +00:00
|
|
|
self.model.view = self
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-09-09 16:01:15 +00:00
|
|
|
self.addCriteriaButton.clicked.connect(self.model.add_selected)
|
2021-01-07 16:13:17 +00:00
|
|
|
self.criteriaListView.doubleClicked.connect(self.model.add_selected)
|
2011-09-12 15:05:53 +00:00
|
|
|
self.removeCriteriaButton.clicked.connect(self.model.remove_selected)
|
2021-01-07 16:13:17 +00:00
|
|
|
self.prioritizationListView.doubleClicked.connect(self.model.remove_selected)
|
2011-09-09 16:01:15 +00:00
|
|
|
self.buttonBox.accepted.connect(self.accept)
|
|
|
|
self.buttonBox.rejected.connect(self.reject)
|
|
|
|
|
|
|
|
def _setupUi(self):
|
2011-09-16 22:01:56 +00:00
|
|
|
self.setWindowTitle(tr("Re-Prioritize duplicates"))
|
2011-09-12 15:05:53 +00:00
|
|
|
self.resize(700, 400)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
# widgets
|
2014-10-13 19:08:59 +00:00
|
|
|
msg = tr(
|
|
|
|
"Add criteria to the right box and click OK to send the dupes that correspond the "
|
2011-09-12 15:05:53 +00:00
|
|
|
"best to these criteria to their respective group's "
|
2014-10-13 19:08:59 +00:00
|
|
|
"reference position. Read the help file for more information."
|
|
|
|
)
|
2011-09-12 15:05:53 +00:00
|
|
|
self.promptLabel = QLabel(msg)
|
|
|
|
self.promptLabel.setWordWrap(True)
|
2011-09-09 16:01:15 +00:00
|
|
|
self.categoryCombobox = QComboBox()
|
|
|
|
self.criteriaListView = QListView()
|
2021-01-07 08:38:33 +00:00
|
|
|
self.criteriaListView.setSelectionMode(QAbstractItemView.ExtendedSelection)
|
2021-08-15 09:10:18 +00:00
|
|
|
self.addCriteriaButton = QPushButton(self.style().standardIcon(QStyle.SP_ArrowRight), "")
|
|
|
|
self.removeCriteriaButton = QPushButton(self.style().standardIcon(QStyle.SP_ArrowLeft), "")
|
2011-09-09 16:01:15 +00:00
|
|
|
self.prioritizationListView = QListView()
|
2011-09-09 22:24:17 +00:00
|
|
|
self.prioritizationListView.setAcceptDrops(True)
|
|
|
|
self.prioritizationListView.setDragEnabled(True)
|
|
|
|
self.prioritizationListView.setDragDropMode(QAbstractItemView.InternalMove)
|
|
|
|
self.prioritizationListView.setSelectionBehavior(QAbstractItemView.SelectRows)
|
2021-01-07 09:02:49 +00:00
|
|
|
self.prioritizationListView.setSelectionMode(QAbstractItemView.ExtendedSelection)
|
2011-09-09 16:01:15 +00:00
|
|
|
self.buttonBox = QDialogButtonBox()
|
2020-01-01 02:16:27 +00:00
|
|
|
self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok)
|
2014-10-13 19:08:59 +00:00
|
|
|
|
2011-09-09 16:01:15 +00:00
|
|
|
# layout
|
|
|
|
self.mainLayout = QVBoxLayout(self)
|
2011-09-12 15:05:53 +00:00
|
|
|
self.mainLayout.addWidget(self.promptLabel)
|
2013-08-04 13:20:08 +00:00
|
|
|
self.splitter = QSplitter()
|
|
|
|
sp = self.splitter.sizePolicy()
|
|
|
|
sp.setVerticalPolicy(QSizePolicy.Expanding)
|
|
|
|
self.splitter.setSizePolicy(sp)
|
|
|
|
self.leftSide = QWidget()
|
2011-09-09 16:01:15 +00:00
|
|
|
self.leftWidgetsLayout = QVBoxLayout()
|
|
|
|
self.leftWidgetsLayout.addWidget(self.categoryCombobox)
|
|
|
|
self.leftWidgetsLayout.addWidget(self.criteriaListView)
|
2013-08-04 13:20:08 +00:00
|
|
|
self.leftSide.setLayout(self.leftWidgetsLayout)
|
|
|
|
self.splitter.addWidget(self.leftSide)
|
|
|
|
self.rightSide = QWidget()
|
|
|
|
self.rightWidgetsLayout = QHBoxLayout()
|
2011-09-12 15:05:53 +00:00
|
|
|
self.addRemoveButtonsLayout = QVBoxLayout()
|
2021-08-24 05:12:23 +00:00
|
|
|
self.addRemoveButtonsLayout.addItem(vertical_spacer())
|
2011-09-12 15:05:53 +00:00
|
|
|
self.addRemoveButtonsLayout.addWidget(self.addCriteriaButton)
|
2011-09-16 22:01:56 +00:00
|
|
|
self.addRemoveButtonsLayout.addWidget(self.removeCriteriaButton)
|
2021-08-24 05:12:23 +00:00
|
|
|
self.addRemoveButtonsLayout.addItem(vertical_spacer())
|
2013-08-04 13:20:08 +00:00
|
|
|
self.rightWidgetsLayout.addLayout(self.addRemoveButtonsLayout)
|
|
|
|
self.rightWidgetsLayout.addWidget(self.prioritizationListView)
|
|
|
|
self.rightSide.setLayout(self.rightWidgetsLayout)
|
|
|
|
self.splitter.addWidget(self.rightSide)
|
|
|
|
self.mainLayout.addWidget(self.splitter)
|
2011-09-09 16:01:15 +00:00
|
|
|
self.mainLayout.addWidget(self.buttonBox)
|