def test_encoding(self, qtbot): csvwidget = CSVExportDialog() qtbot.addWidget(csvwidget) csvwidget.show() comboboxes = csvwidget.findChildren(QtGui.QComboBox) comboboxes[0] assert comboboxes[0].itemText(comboboxes[0].currentIndex()) == 'UTF_8'
def test_header(self, qtbot): csvwidget = CSVExportDialog() qtbot.addWidget(csvwidget) csvwidget.show() checkboxes = csvwidget.findChildren(QtGui.QCheckBox) checkboxes[0].toggle() assert csvwidget._headerCheckBox.isChecked()
def test_delimiter(self, qtbot): csvwidget = CSVExportDialog() qtbot.addWidget(csvwidget) csvwidget.show() groupboxes = csvwidget.findChildren(QtGui.QGroupBox) radiobuttons = groupboxes[0].findChildren(QtGui.QRadioButton) lineedits = groupboxes[0].findChildren(QtGui.QLineEdit) delimiter = None for button in radiobuttons: qtbot.mouseClick(button, QtCore.Qt.LeftButton) if lineedits[0].isEnabled(): qtbot.keyPress(lineedits[0], ' ') assert lineedits[0].text() == '' qtbot.keyPress(lineedits[0], 'a') assert lineedits[0].text() == 'a' assert delimiter != groupboxes[0].currentSelected() delimiter = groupboxes[0].currentSelected()
def test_accept_reject(self, qtbot): csvwidget = CSVExportDialog() qtbot.addWidget(csvwidget) csvwidget.show() buttons = csvwidget.findChildren(QtGui.QPushButton) for button in buttons: qtbot.mouseClick(button, QtCore.Qt.LeftButton) if button.text() == 'Export Data': assert csvwidget.isVisible() == True else: assert csvwidget.isVisible() == False
def test_fileoutput(self, qtbot, csv_file): csvwidget = CSVExportDialog() qtbot.addWidget(csvwidget) csvwidget.show() labels = csvwidget.findChildren(QtGui.QLabel) assert labels[0].text() == u'Output File' lineedits = csvwidget.findChildren(QtGui.QLineEdit) qtbot.keyClicks(lineedits[0], csv_file) assert csvwidget._filenameLineEdit.text() == csv_file
def test_read_write(self, qtbot, csv_file, tmp): importWidget = CSVImportDialog() qtbot.addWidget(importWidget) importWidget.show() import_lineedits = importWidget.findChildren(QtGui.QLineEdit) qtbot.keyClicks(import_lineedits[0], csv_file) groupboxes = importWidget.findChildren(QtGui.QGroupBox) radiobuttons = groupboxes[0].findChildren(QtGui.QRadioButton) for button in radiobuttons: if str(button.text()) == 'Semicolon': qtbot.mouseClick(button, QtCore.Qt.LeftButton) break checkboxes = importWidget.findChildren(QtGui.QCheckBox) checkboxes[0].toggle() model_in = importWidget._previewTableView.model() # convert critical datetime column: column_model = model_in.columnDtypeModel() index = column_model.index(4, 1) column_model.setData(index, 'date and time') ## # now we export the data and load it again ## exportWidget = CSVExportDialog(model_in) qtbot.addWidget(exportWidget) exportWidget.show() lineedits = exportWidget.findChildren(QtGui.QLineEdit) qtbot.keyClicks(lineedits[0], tmp) groupboxes = exportWidget.findChildren(QtGui.QGroupBox) radiobuttons = groupboxes[0].findChildren(QtGui.QRadioButton) for button in radiobuttons: if str(button.text()) == 'Semicolon': qtbot.mouseClick(button, QtCore.Qt.LeftButton) break checkboxes = exportWidget.findChildren(QtGui.QCheckBox) checkboxes[0].toggle() buttons = exportWidget.findChildren(QtGui.QPushButton) with qtbot.waitSignal(exportWidget.exported, timeout=3000): for button in buttons: if str(button.text()) == 'Export Data': qtbot.mouseClick(button, QtCore.Qt.LeftButton) break import_lineedits[0].clear() qtbot.keyClicks(import_lineedits[0], tmp) buttons = importWidget.findChildren(QtGui.QPushButton) with qtbot.waitSignal(importWidget.load, timeout=3000): for button in buttons: if str(button.text()) == 'Load Data': model_out_in = importWidget._previewTableView.model() qtbot.mouseClick(button, QtCore.Qt.LeftButton) break column_model = model_out_in.columnDtypeModel() index = column_model.index(4, 1) column_model.setData(index, 'date and time') comparator = model_in.dataFrame() == model_out_in.dataFrame() assert all(comparator) df = model_out_in.dataFrame() assert not df.empty
def test_init(self, qtbot): csvwidget = CSVExportDialog() qtbot.addWidget(csvwidget) csvwidget.show() assert csvwidget.isModal() assert csvwidget.windowTitle() == u'Export to CSV'
def __init__(self, parent=None): super(TestWidget, self).__init__(parent) self.resize(1680, 756) self.move(0, 0) self.df = pandas.DataFrame() self.dataModel = None # init the data view's self.dataTableView = DataTableWidget(self) # self.dataTableView.setSortingEnabled(True) # self.dataTableView.setAlternatingRowColors(True) self.dataListView = QtGui.QListView(self) self.dataListView.setAlternatingRowColors(True) self.dataComboBox = QtGui.QComboBox(self) # make combobox to choose the model column for dataComboBox and dataListView self.chooseColumnComboBox = QtGui.QComboBox(self) self.buttonCsvData = QtGui.QPushButton("load csv data") self.buttonRandomData = QtGui.QPushButton("load random data") importDialog = CSVImportDialog(self) importDialog.load.connect(self.updateModel) self.buttonCsvData.clicked.connect(lambda: importDialog.show()) self.buttonRandomData.clicked.connect( lambda: self.setDataFrame(getRandomData(rows=100, columns=100))) self.exportDialog = CSVExportDialog(self) self.buttonCSVExport = QtGui.QPushButton("export to csv") self.buttonCSVExport.clicked.connect(self._exportModel) self.buttonLayout = QtGui.QHBoxLayout() self.buttonLayout.addWidget(self.buttonCsvData) self.buttonLayout.addWidget(self.buttonCSVExport) self.buttonLayout.addWidget(self.buttonRandomData) self.mainLayout = QtGui.QVBoxLayout() self.setLayout(self.mainLayout) self.mainLayout.addLayout(self.buttonLayout) self.mainLayout.addWidget(self.dataTableView) self.spinbox = QtGui.QSpinBox() self.mainLayout.addWidget(self.spinbox) self.spinbox.setMaximum(99999999999) self.spinbox.setValue(99999999999) self.rightLayout = QtGui.QVBoxLayout() self.chooseColumLayout = QtGui.QHBoxLayout() self.mainLayout.addLayout(self.rightLayout) self.rightLayout.addLayout(self.chooseColumLayout) self.chooseColumLayout.addWidget(QtGui.QLabel("Choose column:")) self.chooseColumLayout.addWidget(self.chooseColumnComboBox) self.rightLayout.addWidget(self.dataListView) self.rightLayout.addWidget(self.dataComboBox) self.tableViewColumnDtypes = QtGui.QTableView(self) self.rightLayout.addWidget(QtGui.QLabel('dtypes')) self.rightLayout.addWidget(self.tableViewColumnDtypes) self.buttonGoToColumn = QtGui.QPushButton("go to column") self.rightLayout.addWidget(self.buttonGoToColumn) self.buttonGoToColumn.clicked.connect(self.goToColumn) self.buttonSetFilter = QtGui.QPushButton("set filter") self.rightLayout.addWidget(self.buttonSetFilter) self.buttonSetFilter.clicked.connect(self.setFilter) self.buttonClearFilter = QtGui.QPushButton("clear filter") self.rightLayout.addWidget(self.buttonClearFilter) self.buttonClearFilter.clicked.connect(self.clearFilter) self.lineEditFilterCondition = QtGui.QLineEdit("freeSearch('am')") self.rightLayout.addWidget(self.lineEditFilterCondition) self.chooseColumnComboBox.currentIndexChanged.connect( self.setModelColumn) self.dataListView.mouseReleaseEvent = self.mouseReleaseEvent self.dropLineEdit = DropLineEdit("drop data from table here", self) self.rightLayout.addWidget(self.dropLineEdit) self.dropWidget = ComplexDropWidget(self) self.dropWidget.dropRecieved.connect(self.processDataDrops) self.rightLayout.addWidget(self.dropWidget)
class TestWidget(QtGui.QWidget): def __init__(self, parent=None): super(TestWidget, self).__init__(parent) self.resize(1680, 756) self.move(0, 0) self.df = pandas.DataFrame() self.dataModel = None # init the data view's self.dataTableView = DataTableWidget(self) # self.dataTableView.setSortingEnabled(True) # self.dataTableView.setAlternatingRowColors(True) self.dataListView = QtGui.QListView(self) self.dataListView.setAlternatingRowColors(True) self.dataComboBox = QtGui.QComboBox(self) # make combobox to choose the model column for dataComboBox and dataListView self.chooseColumnComboBox = QtGui.QComboBox(self) self.buttonCsvData = QtGui.QPushButton("load csv data") self.buttonRandomData = QtGui.QPushButton("load random data") importDialog = CSVImportDialog(self) importDialog.load.connect(self.updateModel) self.buttonCsvData.clicked.connect(lambda: importDialog.show()) self.buttonRandomData.clicked.connect( lambda: self.setDataFrame(getRandomData(rows=100, columns=100))) self.exportDialog = CSVExportDialog(self) self.buttonCSVExport = QtGui.QPushButton("export to csv") self.buttonCSVExport.clicked.connect(self._exportModel) self.buttonLayout = QtGui.QHBoxLayout() self.buttonLayout.addWidget(self.buttonCsvData) self.buttonLayout.addWidget(self.buttonCSVExport) self.buttonLayout.addWidget(self.buttonRandomData) self.mainLayout = QtGui.QVBoxLayout() self.setLayout(self.mainLayout) self.mainLayout.addLayout(self.buttonLayout) self.mainLayout.addWidget(self.dataTableView) self.spinbox = QtGui.QSpinBox() self.mainLayout.addWidget(self.spinbox) self.spinbox.setMaximum(99999999999) self.spinbox.setValue(99999999999) self.rightLayout = QtGui.QVBoxLayout() self.chooseColumLayout = QtGui.QHBoxLayout() self.mainLayout.addLayout(self.rightLayout) self.rightLayout.addLayout(self.chooseColumLayout) self.chooseColumLayout.addWidget(QtGui.QLabel("Choose column:")) self.chooseColumLayout.addWidget(self.chooseColumnComboBox) self.rightLayout.addWidget(self.dataListView) self.rightLayout.addWidget(self.dataComboBox) self.tableViewColumnDtypes = QtGui.QTableView(self) self.rightLayout.addWidget(QtGui.QLabel('dtypes')) self.rightLayout.addWidget(self.tableViewColumnDtypes) self.buttonGoToColumn = QtGui.QPushButton("go to column") self.rightLayout.addWidget(self.buttonGoToColumn) self.buttonGoToColumn.clicked.connect(self.goToColumn) self.buttonSetFilter = QtGui.QPushButton("set filter") self.rightLayout.addWidget(self.buttonSetFilter) self.buttonSetFilter.clicked.connect(self.setFilter) self.buttonClearFilter = QtGui.QPushButton("clear filter") self.rightLayout.addWidget(self.buttonClearFilter) self.buttonClearFilter.clicked.connect(self.clearFilter) self.lineEditFilterCondition = QtGui.QLineEdit("freeSearch('am')") self.rightLayout.addWidget(self.lineEditFilterCondition) self.chooseColumnComboBox.currentIndexChanged.connect( self.setModelColumn) self.dataListView.mouseReleaseEvent = self.mouseReleaseEvent self.dropLineEdit = DropLineEdit("drop data from table here", self) self.rightLayout.addWidget(self.dropLineEdit) self.dropWidget = ComplexDropWidget(self) self.dropWidget.dropRecieved.connect(self.processDataDrops) self.rightLayout.addWidget(self.dropWidget) @Slot('QMimeData') def processDataDrops(self, mimeData): """if you have more complicated stuff to do and you want to match some models, might be possible like that""" mimeDataPayload = mimeData.data() if isinstance(mimeDataPayload, PandasCellPayload): if self.dataModel is not None: if hex(id(self.dataModel)) == mimeDataPayload.parentId: self.dropWidget.setText( "complex stuff done after drop event. {0}".format( mimeDataPayload.column)) def setDataFrame(self, dataFrame): self.df = dataFrame dataModel = DataFrameModel() dataModel.setDataFrame(self.df) self.dataModel = dataModel self.dataListView.setModel(dataModel) self.dataTableView.setViewModel(dataModel) self.dataComboBox.setModel(dataModel) # self.dataTableView.resizeColumnsToContents() # create a simple item model for our choosing combobox columnModel = QtGui.QStandardItemModel() for column in self.df.columns: columnModel.appendRow(QtGui.QStandardItem(column)) self.chooseColumnComboBox.setModel(columnModel) self.tableViewColumnDtypes.setModel(dataModel.columnDtypeModel()) self.tableViewColumnDtypes.horizontalHeader().setDefaultSectionSize( 200) self.tableViewColumnDtypes.setItemDelegateForColumn( 1, DtypeComboDelegate(self.tableViewColumnDtypes)) dataModel.changingDtypeFailed.connect(self.changeColumnValue) @Slot() def _exportModel(self): model = self.dataTableView.view().model() self.exportDialog.setExportModel(model) self.exportDialog.show() @Slot('QAbstractItemModel') def updateModel(self, model): self.dataModel = model self.dataListView.setModel(model) self.dataTableView.setViewModel(model) self.dataComboBox.setModel(model) self.tableViewColumnDtypes.setModel(model.columnDtypeModel()) def setModelColumn(self, index): self.dataListView.setModelColumn(index) self.dataComboBox.setModelColumn(index) def goToColumn(self): print "go to column 7" index = self.dataTableView.view().model().index(7, 0) self.dataTableView.view().setCurrentIndex(index) def changeColumnValue(self, columnName, index, dtype): print "failed to change", columnName, "to", dtype print index.data(), index.isValid() self.dataTableView.view().setCurrentIndex(index) def setFilter(self): #filterIndex = eval(self.lineEditFilterCondition.text()) search = DataSearch("Test", self.lineEditFilterCondition.text()) self.dataTableView.view().model().setFilter(search) #raise NotImplementedError def clearFilter(self): self.dataTableView.view().model().clearFilter()