def updateDelegates(self, column, dtype): print "update delegate for column", column, dtype # as documented in the setDelegatesFromDtype function # we need to store all delegates, so going from # type A -> type B -> type A # would cause a segfault if not stored. view = self.dataTableView.tableView createDelegate(dtype, column, view)
def test_tableViewMissing(self, widgetClass, qtbot, model, exception, exceptionContains): widget = widgetClass() qtbot.addWidget(widget) with pytest.raises(exception) as excinfo: if model: widget.setModel(QtGui.QStandardItemModel()) createDelegate('foo', 'bar', widget) assert exceptionContains in str(excinfo.value)
def updateDelegate(self, column, dtype): """update the delegates for a specific column Args: column (int): column index. dtype (str): data type of column. """ # as documented in the setDelegatesFromDtype function # we need to store all delegates, so going from # type A -> type B -> type A # would cause a segfault if not stored. createDelegate(dtype, column, self.tableView)
def test_editing(self, dataFrame, qtbot): model = DataFrameModel(dataFrame) tableView = QtGui.QTableView() qtbot.addWidget(tableView) tableView.setModel(model) delegate = TextDelegate(tableView) createDelegate(numpy.dtype('O'), 0, tableView) tableView.show() index = model.index(0, 0) preedit_data = index.data() assert not model.editable model.enableEditing(True) tableView.edit(index) editor = tableView.findChildren(QtGui.QLineEdit)[0] qtbot.keyPress(editor, QtCore.Qt.Key_F) qtbot.keyPress(editor, QtCore.Qt.Key_Enter) QtGui.QApplication.processEvents() with qtbot.waitSignal(timeout=100): assert index.data(QtCore.Qt.DisplayRole) == 'f'
def test_setDelegates(self, qtbot, tableView, index, value, singleStep): dlg = createDelegate(numpy.dtype(value), 0, tableView) assert dlg is not None data = pandas.DataFrame([value], columns=['A']) data['A'] = data['A'].astype(value.dtype) model = tableView.model() model.setDataFrame(data) for i, delegate in enumerate([dlg]): assert tableView.itemDelegateForColumn(i) == delegate option = QtGui.QStyleOptionViewItem() option.rect = QtCore.QRect(0, 0, 100, 100) editor = delegate.createEditor(tableView, option, index) delegate.setEditorData(editor, index) assert editor.value() == index.data() delegate.setModelData(editor, model, index) delegate.updateEditorGeometry(editor, option, index) dtype = value.dtype if dtype in DataFrameModel._intDtypes: info = numpy.iinfo(dtype) assert isinstance(delegate, BigIntSpinboxDelegate) elif dtype in DataFrameModel._floatDtypes: info = numpy.finfo(dtype) assert isinstance(delegate, CustomDoubleSpinboxDelegate) assert delegate.decimals == DataFrameModel._float_precisions[ str(value.dtype)] assert delegate.maximum == info.max assert editor.maximum() == info.max assert delegate.minimum == info.min assert editor.minimum() == info.min assert delegate.singleStep == singleStep assert editor.singleStep() == singleStep def clickEvent(index): assert index.isValid() tableView.clicked.connect(clickEvent) with qtbot.waitSignal(tableView.clicked) as blocker: qtbot.mouseClick(tableView.viewport(), QtCore.Qt.LeftButton, pos=QtCore.QPoint(10, 10)) assert blocker.signal_triggered
def test_setDelegates(self, qtbot, tableView, index, value, singleStep): dlg = createDelegate(numpy.dtype(value), 0, tableView) assert dlg is not None data = pandas.DataFrame([value], columns=['A']) data['A'] = data['A'].astype(value.dtype) model = tableView.model() model.setDataFrame(data) for i, delegate in enumerate([dlg]): assert tableView.itemDelegateForColumn(i) == delegate option = QtGui.QStyleOptionViewItem() option.rect = QtCore.QRect(0, 0, 100, 100) editor = delegate.createEditor(tableView, option, index) delegate.setEditorData(editor, index) assert editor.value() == index.data() delegate.setModelData(editor, model, index) delegate.updateEditorGeometry(editor, option, index) dtype = value.dtype if dtype in DataFrameModel._intDtypes: info = numpy.iinfo(dtype) assert isinstance(delegate, BigIntSpinboxDelegate) elif dtype in DataFrameModel._floatDtypes: info = numpy.finfo(dtype) assert isinstance(delegate, CustomDoubleSpinboxDelegate) assert delegate.decimals == DataFrameModel._float_precisions[str(value.dtype)] assert delegate.maximum == info.max assert editor.maximum() == info.max assert delegate.minimum == info.min assert editor.minimum() == info.min assert delegate.singleStep == singleStep assert editor.singleStep() == singleStep def clickEvent(index): assert index.isValid() tableView.clicked.connect(clickEvent) with qtbot.waitSignal(tableView.clicked) as blocker: qtbot.mouseClick(tableView.viewport(), QtCore.Qt.LeftButton, pos=QtCore.QPoint(10, 10)) assert blocker.signal_triggered