2011-09-09 16:01:15 +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
|
|
|
|
|
2011-09-09 22:24:17 +00:00
|
|
|
from PyQt4.QtCore import Qt, QMimeData, QByteArray
|
2011-09-09 16:01:15 +00:00
|
|
|
from PyQt4.QtGui import (QDialog, QVBoxLayout, QHBoxLayout, QPushButton, QComboBox, QListView,
|
2011-09-12 15:05:53 +00:00
|
|
|
QDialogButtonBox, QAbstractItemView, QLabel)
|
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
|
|
|
|
|
|
|
|
#--- 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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def mimeTypes(self):
|
|
|
|
return [MIME_INDEXES]
|
|
|
|
|
|
|
|
def supportedDropActions(self):
|
|
|
|
return Qt.MoveAction
|
|
|
|
|
2011-09-09 16:01:15 +00:00
|
|
|
class PrioritizeDialog(QDialog):
|
|
|
|
def __init__(self, parent, app):
|
|
|
|
flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
|
|
|
|
QDialog.__init__(self, parent, flags)
|
|
|
|
self.app = app
|
|
|
|
self._setupUi()
|
2011-09-20 19:06:29 +00:00
|
|
|
self.model = PrioritizeDialogModel(view=self, 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)
|
2011-09-09 22:24:17 +00:00
|
|
|
self.prioritizationList = PrioritizationList(model=self.model.prioritization_list, view=self.prioritizationListView)
|
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)
|
2011-09-09 16:01:15 +00:00
|
|
|
|
|
|
|
#widgets
|
2011-09-12 15:05:53 +00:00
|
|
|
msg = tr("Add criteria to the right box and click OK to send the dupes that correspond the "
|
|
|
|
"best to these criteria to their respective group's "
|
|
|
|
"reference position. Read the help file for more information.")
|
|
|
|
self.promptLabel = QLabel(msg)
|
|
|
|
self.promptLabel.setWordWrap(True)
|
2011-09-09 16:01:15 +00:00
|
|
|
self.categoryCombobox = QComboBox()
|
|
|
|
self.criteriaListView = QListView()
|
|
|
|
self.addCriteriaButton = QPushButton("-->")
|
2011-09-16 22:01:56 +00:00
|
|
|
self.removeCriteriaButton = QPushButton("<--")
|
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)
|
|
|
|
|
|
|
|
# layout
|
|
|
|
self.mainLayout = QVBoxLayout(self)
|
2011-09-12 15:05:53 +00:00
|
|
|
self.mainLayout.addWidget(self.promptLabel)
|
2011-09-09 16:01:15 +00:00
|
|
|
self.widgetsLayout = QHBoxLayout()
|
|
|
|
self.leftWidgetsLayout = QVBoxLayout()
|
|
|
|
self.leftWidgetsLayout.addWidget(self.categoryCombobox)
|
|
|
|
self.leftWidgetsLayout.addWidget(self.criteriaListView)
|
|
|
|
self.widgetsLayout.addLayout(self.leftWidgetsLayout)
|
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())
|
|
|
|
self.widgetsLayout.addLayout(self.addRemoveButtonsLayout)
|
2011-09-09 16:01:15 +00:00
|
|
|
self.widgetsLayout.addWidget(self.prioritizationListView)
|
|
|
|
self.mainLayout.addLayout(self.widgetsLayout)
|
|
|
|
self.mainLayout.addWidget(self.buttonBox)
|