class SelectActorsFormWrapper(): def __init__(self, parent, project, item, target, unselectable, single): self.parent = parent self.dialog = QtGui.QDialog() self.form = Ui_SelectForm() self.project = project self.item = None #item self.target = target self.unselectable = unselectable self.single = single def load(self): toSelect = [i.item for i in self.target] tmp = self.form.itemsView.selectionModel() for i, a in enumerate(self.project.actors): if a in toSelect: tmp.select( self.model.createIndex(i, 0, None), QtGui.QItemSelectionModel.Select | QtGui.QItemSelectionModel.Rows ) def show(self): self.form.setupUi(self.dialog) self.model = SelectActorsTableModel(self.form.itemsView, self.project, self.item, self.target, self.unselectable) self.form.itemsView.setModel(self.model) self.form.itemsView.horizontalHeader().setResizeMode(0, QtGui.QHeaderView.ResizeToContents) self.form.itemsView.horizontalHeader().setResizeMode(1, QtGui.QHeaderView.Stretch) self.form.itemsView.horizontalHeader().hide() self.form.itemsView.verticalHeader().hide() self.form.itemsView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) if self.single: self.form.itemsView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection) QtCore.QObject.connect(self.form.boxButton, QtCore.SIGNAL(_fromUtf8("accepted()")), self.clickedOKButton) QtCore.QObject.connect(self.form.boxButton, QtCore.SIGNAL(_fromUtf8("rejected()")), self.clickedCancelButton) self.load() self.dialog.exec_() def clickedCancelButton(self): self.dialog.close() def clickedOKButton(self): indexes = set([i.row() for i in self.form.itemsView.selectedIndexes()]) while len(self.target): del self.target[0] # ??? for i in indexes: self.target.append(self.project.actors[i].get_ref()) self.dialog.close()
def __init__(self, parent, project, item, target, unselectable, single): self.parent = parent self.dialog = QtGui.QDialog() self.form = Ui_SelectForm() self.project = project self.item = None #item self.target = target self.unselectable = unselectable self.single = single