def test_click_each_button(self, qtbot, dataModel): widget = DataTableWidget() qtbot.addWidget(widget) widget.show() widget.setViewModel(dataModel) buttons = widget.findChildren(QtGui.QToolButton) for btn in buttons: if btn.isEnabled: qtbot.mouseClick(btn, QtCore.Qt.LeftButton) break for btn in buttons: if btn.objectName() == 'editbutton': continue if btn.objectName() in ['addcolumnbutton', 'removecolumnbutton']: qtbot.mouseClick(btn, QtCore.Qt.LeftButton) dlg = widget.findChildren(QtGui.QDialog)[-1] dlg_buttons = dlg.findChildren(QtGui.QPushButton) for b in dlg_buttons: if b.text() == 'Cancel': qtbot.mouseClick(b, QtCore.Qt.LeftButton) break else: qtbot.mouseClick(btn, QtCore.Qt.LeftButton)
def test_enableToolBar(self, qtbot): widget = DataTableWidget() qtbot.addWidget(widget) widget.show() assert widget.view().model() is None buttons = widget.findChildren(QtGui.QToolButton) exclude_button = None for btn in buttons: if btn.isEnabled: qtbot.mouseClick(btn, QtCore.Qt.LeftButton) exclude_button = btn assert btn.isChecked() break for button in buttons: assert button.isEnabled() qtbot.mouseClick(btn, QtCore.Qt.LeftButton) for button in buttons: if button == exclude_button: continue assert not button.isEnabled() assert not button.isChecked()
def test_removeColumns(self, qtbot, dataModel2): widget = DataTableWidget() qtbot.addWidget(widget) widget.show() widget.setViewModel(dataModel2) df = dataModel2.dataFrame().copy() buttons = widget.findChildren(QtGui.QToolButton) for btn in buttons: if btn.isEnabled: qtbot.mouseClick(btn, QtCore.Qt.LeftButton) break for btn in buttons: if btn.objectName() == 'removecolumnbutton': qtbot.mouseClick(btn, QtCore.Qt.LeftButton) dlg = widget.findChildren(QtGui.QDialog)[-1] listview = dlg.findChildren(QtGui.QListView)[-1] listview.selectAll() dlg_buttons = dlg.findChildren(QtGui.QPushButton) for b in dlg_buttons: if b.text() == 'OK': qtbot.mouseClick(b, QtCore.Qt.LeftButton) break assert widget.view().model().columnCount() == 0
def test_addColumn(self, qtbot, dataModel): widget = DataTableWidget() qtbot.addWidget(widget) widget.show() widget.setViewModel(dataModel) buttons = widget.findChildren(QtGui.QToolButton) for btn in buttons: if btn.isEnabled: qtbot.mouseClick(btn, QtCore.Qt.LeftButton) break columns = [] addButton = None for btn in buttons: if btn.objectName == 'addcolumnbutton': addbutton = btn qtbot.mouseClick(btn, QtCore.Qt.LeftButton) dlg = widget.findChildren(QtGui.QDialog)[-1] dlg_buttons = dlg.findChildren(QtGui.QPushButton) comboBox = dlg.findChildren(QtGui.QComboBox)[-1] for i in xrange(comboBox.count()): columns.append(comboBox.itemText(i)) for b in dlg_buttons: if b.text() == 'Cancel': qtbot.mouseClick(b, QtCore.Qt.LeftButton) break break columnCountBeforeInsert = widget.view().model().columnCount() for index, column in enumerate(columns): qtbot.mouseClick(addbutton, QtCore.Qt.LeftButton) dlg = widget.findChildren(QtGui.QDialog)[-1] textedits = dlg.findChildren(QtGui.QLineEdit) qtbot.keyClicks(textedits[0], column) comboBox = dlg.findChildren(QtGui.QComboBox)[-1] comboBox.setCurrentIndex(index) dlg_buttons = dlg.findChildren(QtGui.QPushButton) for b in dlg_buttons: if b.text() == 'OK': qtbot.mouseClick(b, QtCore.Qt.LeftButton) break assert widget.view().model().columnCount() == columnCountBeforeInsert + 1 + index
def display_query(selcols): ## setup a new empty model model1 = DataFrameModel() ## setup an application and create a table view widget app = QtGui.QApplication([]) widget1 = DataTableWidget() widget1.resize(1600, 800) widget1.show() ## asign the created model widget1.setViewModel(model1) ## fill the model with data model1.setDataFrame(selcols) ## start the app""" app.exec_() return
def test_init(self, qtbot): widget = DataTableWidget() qtbot.addWidget(widget) widget.show() assert widget.view().model() is None buttons = widget.findChildren(QtGui.QToolButton) enabled_counter = 0 for btn in buttons: assert not btn.isChecked() if btn.isEnabled(): enabled_counter += 1 assert enabled_counter == 1
def test_setModel(self, qtbot, dataModel): widget = DataTableWidget() qtbot.addWidget(widget) widget.show() widget.setViewModel(dataModel) assert widget.view().model() is not None assert widget.view().model() == dataModel buttons = widget.findChildren(QtGui.QToolButton) for btn in buttons: if btn.isEnabled: qtbot.mouseClick(btn, QtCore.Qt.LeftButton) assert widget.view().model().editable qtbot.mouseClick(btn, QtCore.Qt.LeftButton) assert not widget.view().model().editable break
import sys from pandasqt.excepthook import excepthook sys.excepthook = excepthook # use QtGui from the compat module to take care if correct sip version, etc. from pandasqt.compat import QtGui from pandasqt.models.DataFrameModel import DataFrameModel from pandasqt.views.DataTableView import DataTableWidget from pandasqt.views._ui import icons_rc """setup a new empty model""" model = DataFrameModel() """setup an application and create a table view widget""" app = QtGui.QApplication([]) widget = DataTableWidget() widget.resize(800, 600) widget.show() """asign the created model""" widget.setViewModel(model) """create some test data""" data = { 'A': [10, 11, 12], 'B': [20, 21, 22], 'C': ['Peter Pan', 'Cpt. Hook', 'Tinkerbell'] } df = pandas.DataFrame(data) """convert the column to the numpy.int8 datatype to test the delegates in the table int8 is limited to -128-127 """ df['A'] = df['A'].astype(numpy.int8) df['B'] = df['B'].astype(numpy.float16) """fill the model with data"""
sys.excepthook = excepthook # use QtGui from the compat module to take care if correct sip version, etc. from pandasqt.compat import QtGui from pandasqt.models.DataFrameModel import DataFrameModel from pandasqt.views.DataTableView import DataTableWidget from pandasqt.views._ui import icons_rc """setup a new empty model""" model = DataFrameModel() """setup an application and create a table view widget""" app = QtGui.QApplication([]) widget = DataTableWidget() widget.resize(800, 600) widget.show() """asign the created model""" widget.setViewModel(model) """create some test data""" data = { 'A': [10, 11, 12], 'B': [20, 21, 22], 'C': ['Peter Pan', 'Cpt. Hook', 'Tinkerbell'] } df = pandas.DataFrame(data) """convert the column to the numpy.int8 datatype to test the delegates in the table int8 is limited to -128-127 """ df['A'] = df['A'].astype(numpy.int8) df['B'] = df['B'].astype(numpy.float16)