2017-11-06 22:46:35 +01:00
|
|
|
from PyQt4 import QtCore, QtGui
|
|
|
|
from . import ui_multiselectwidget
|
2012-01-24 01:18:32 +01:00
|
|
|
|
2017-11-06 23:18:18 +01:00
|
|
|
class MultiSelectWidget(
|
|
|
|
ui_multiselectwidget.Ui_MultiSelectWidget, QtGui.QWidget):
|
2012-01-24 01:18:32 +01:00
|
|
|
|
2012-02-20 07:56:38 +01:00
|
|
|
__pyqtSignals__ = ("selected_changed()",)
|
2013-02-28 02:15:06 +01:00
|
|
|
__pyqtSignals__ = ("items_added(PyQt_PyObject)",)
|
|
|
|
__pyqtSignals__ = ("items_removed(PyQt_PyObject)",)
|
2012-02-20 07:56:38 +01:00
|
|
|
|
2012-01-24 01:18:32 +01:00
|
|
|
def __init__(self, parent=None):
|
2017-11-09 16:08:16 +01:00
|
|
|
super(MultiSelectWidget, self).__init__(parent)
|
2014-02-23 00:44:08 +01:00
|
|
|
self.setupUi(self)
|
2012-01-24 01:18:32 +01:00
|
|
|
self.add_selected_button.clicked.connect(self.add_selected)
|
2012-02-05 18:41:41 +01:00
|
|
|
self.add_all_button.clicked.connect(self.add_all)
|
2012-01-24 01:18:32 +01:00
|
|
|
self.remove_selected_button.clicked.connect(self.remove_selected)
|
2012-02-05 18:41:41 +01:00
|
|
|
self.remove_all_button.clicked.connect(self.remove_all)
|
2017-11-06 23:18:18 +01:00
|
|
|
self.available_list.setSelectionMode(
|
|
|
|
QtGui.QAbstractItemView.ExtendedSelection)
|
|
|
|
self.selected_list.setSelectionMode(
|
|
|
|
QtGui.QAbstractItemView.ExtendedSelection)
|
2012-01-24 01:18:32 +01:00
|
|
|
|
|
|
|
def switch_selected(self, src, dst):
|
|
|
|
selected = src.selectedItems()
|
2012-04-04 01:40:13 +02:00
|
|
|
items = []
|
2012-01-24 01:18:32 +01:00
|
|
|
|
2017-11-08 16:53:49 +01:00
|
|
|
for selected_item in selected:
|
|
|
|
row = src.indexFromItem(selected_item).row()
|
2012-01-24 01:18:32 +01:00
|
|
|
item = src.takeItem(row)
|
|
|
|
dst.addItem(item)
|
2012-04-04 01:40:13 +02:00
|
|
|
items.append(item)
|
2012-02-05 18:41:41 +01:00
|
|
|
dst.sortItems()
|
2017-11-06 22:46:35 +01:00
|
|
|
self.emit(QtCore.SIGNAL("selected_changed()"))
|
2017-11-06 23:54:33 +01:00
|
|
|
if src is self.selected_list:
|
2017-11-06 22:46:35 +01:00
|
|
|
self.emit(QtCore.SIGNAL("items_removed(PyQt_PyObject)"), items)
|
2012-04-04 01:40:13 +02:00
|
|
|
else:
|
2017-11-06 22:46:35 +01:00
|
|
|
self.emit(QtCore.SIGNAL("items_added(PyQt_PyObject)"), items)
|
2012-01-24 01:18:32 +01:00
|
|
|
|
|
|
|
def add_selected(self):
|
2012-01-24 15:04:28 +01:00
|
|
|
self.switch_selected(self.available_list, self.selected_list)
|
2012-01-24 01:18:32 +01:00
|
|
|
|
|
|
|
def remove_selected(self):
|
2017-11-06 23:54:33 +01:00
|
|
|
self.switch_selected(self.selected_list, self.available_list)
|
|
|
|
|
2012-02-05 18:41:41 +01:00
|
|
|
def move_all(self, src, dst):
|
2012-04-04 01:40:13 +02:00
|
|
|
items = []
|
2012-02-05 18:41:41 +01:00
|
|
|
while src.count() > 0:
|
|
|
|
item = src.takeItem(0)
|
|
|
|
dst.addItem(item)
|
2012-04-04 01:40:13 +02:00
|
|
|
items.append(item)
|
2012-02-05 18:41:41 +01:00
|
|
|
dst.sortItems()
|
2017-11-06 22:46:35 +01:00
|
|
|
self.emit(QtCore.SIGNAL("selected_changed()"))
|
2017-11-06 23:54:33 +01:00
|
|
|
if src is self.selected_list:
|
2017-11-06 22:46:35 +01:00
|
|
|
self.emit(QtCore.SIGNAL("items_removed(PyQt_PyObject)"), items)
|
2012-04-04 01:40:13 +02:00
|
|
|
else:
|
2017-11-06 22:46:35 +01:00
|
|
|
self.emit(QtCore.SIGNAL("items_added(PyQt_PyObject)"), items)
|
2012-04-04 01:40:13 +02:00
|
|
|
|
2012-02-05 18:41:41 +01:00
|
|
|
|
|
|
|
def add_all(self):
|
|
|
|
self.move_all(self.available_list, self.selected_list)
|
|
|
|
|
|
|
|
def remove_all(self):
|
|
|
|
self.move_all(self.selected_list, self.available_list)
|
2012-01-24 15:04:28 +01:00
|
|
|
|
|
|
|
def clear(self):
|
|
|
|
self.available_list.clear()
|
|
|
|
self.selected_list.clear()
|
2012-01-24 01:18:32 +01:00
|
|
|
|