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 (
|
|
|
|
QDialog, QVBoxLayout, QHBoxLayout, QPushButton, QComboBox, QListView,
|
|
|
|
QDialogButtonBox, QAbstractItemView, QLabel, QStyle, QSplitter, QWidget, QSizePolicy
|
|
|
|
)
|
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
|
2011-09-12 15:05:53 +00:00
|
|
|
from qtlib.util import verticalSpacer
|
2011-09-09 16:01:15 +00:00
|
|
|
from core.gui.prioritize_dialog import PrioritizeDialog as PrioritizeDialogModel
|
|
|
|
|
2011-11-01 19:44:18 +00:00
|
|
|
tr = trget('ui')
|
|
|
|
|
2011-09-09 22:24:17 +00:00
|
|
|
MIME_INDEXES = 'application/dupeguru.rowindexes'
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-09-09 22:24:17 +00:00
|
|
|
#--- Drag & Drop
|
|
|
|
def dropMimeData(self, mimeData, action, row, column, parentIndex):
|
|
|
|
if not mimeData.hasFormat(MIME_INDEXES):
|
|
|
|
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.
|
|
|
|
if parentIndex.isValid():
|
|
|
|
return False
|
|
|
|
strMimeData = bytes(mimeData.data(MIME_INDEXES)).decode()
|
|
|
|
indexes = list(map(int, strMimeData.split(',')))
|
|
|
|
self.model.move_indexes(indexes, row)
|
|
|
|
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}
|
|
|
|
data = ','.join(rows)
|
|
|
|
mimeData = QMimeData()
|
|
|
|
mimeData.setData(MIME_INDEXES, QByteArray(data.encode()))
|
|
|
|
return mimeData
|
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
|
|
|
|
|
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)
|
2011-09-09 16:01:15 +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)
|
2011-09-12 15:05:53 +00:00
|
|
|
self.removeCriteriaButton.clicked.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
|
|
|
|
2011-09-09 16:01:15 +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()
|
2013-08-04 13:20:08 +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)
|
2011-09-09 16:01:15 +00:00
|
|
|
self.buttonBox = QDialogButtonBox()
|
|
|
|
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()
|
|
|
|
self.addRemoveButtonsLayout.addItem(verticalSpacer())
|
|
|
|
self.addRemoveButtonsLayout.addWidget(self.addCriteriaButton)
|
2011-09-16 22:01:56 +00:00
|
|
|
self.addRemoveButtonsLayout.addWidget(self.removeCriteriaButton)
|
2011-09-12 15:05:53 +00:00
|
|
|
self.addRemoveButtonsLayout.addItem(verticalSpacer())
|
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)
|