Commit 90287adf authored by JosefBrandt's avatar JosefBrandt

Excel and SQL Export working (hotfix)

parent 8e7707c0
...@@ -160,11 +160,13 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -160,11 +160,13 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
optionsLayout = QtWidgets.QFormLayout() optionsLayout = QtWidgets.QFormLayout()
self.hqiSpinBox = QtWidgets.QDoubleSpinBox() self.hqiSpinBox = QtWidgets.QDoubleSpinBox()
self.hqiSpinBox.setValue(self.dataset.resultParams['minHQI'])
self.hqiSpinBox.setDecimals(1) self.hqiSpinBox.setDecimals(1)
self.hqiSpinBox.setMinimum(0) self.hqiSpinBox.setMinimum(0)
self.hqiSpinBox.setMaximum(100) self.hqiSpinBox.setMaximum(100)
self.hqiSpinBox.setMaximumWidth(100) self.hqiSpinBox.setMaximumWidth(100)
minHQI = self.dataset.resultParams['minHQI']
if minHQI is not None:
self.hqiSpinBox.setValue(minHQI)
self.hqiSpinBox.valueChanged.connect(self.applyHQIThresholdToResults) self.hqiSpinBox.valueChanged.connect(self.applyHQIThresholdToResults)
optionsLayout.addRow(QtWidgets.QLabel('minimum HQI:'), self.hqiSpinBox) optionsLayout.addRow(QtWidgets.QLabel('minimum HQI:'), self.hqiSpinBox)
...@@ -198,9 +200,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -198,9 +200,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.layout.addLayout(self.menuLayout) self.layout.addLayout(self.menuLayout)
self.layout.addLayout(viewLayout) self.layout.addLayout(viewLayout)
minHQI = self.dataset.resultParams['minHQI']
if minHQI is not None:
self.hqiSpinBox.setValue(minHQI)
self.createActions() self.createActions()
self.createMenus() self.createMenus()
...@@ -611,8 +611,14 @@ class ParticleAnalysis(QtWidgets.QMainWindow): ...@@ -611,8 +611,14 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
expWin.exec() expWin.exec()
def exportToSQL(self): def exportToSQL(self):
sqlexp = SQLExport(self.particleContainer, self) if len(self.dataset.resultsUploadedToSQL) > 0:
sqlexp.exec() reply = QtWidgets.QMessageBox.question(self, 'Warning!',
"The following results were already uploaded:\n\n{}\n\nContinue?".format('\n'.join(self.dataset.resultsUploadedToSQL)),
QtWidgets.QMessageBox.Yes |
QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
sqlexp = SQLExport(self.dataset)
sqlexp.exec()
def closeEvent(self, event): def closeEvent(self, event):
for window in [self.importWindow, self.dbWin]: for window in [self.importWindow, self.dbWin]:
......
...@@ -45,7 +45,6 @@ class ExpExcelDialog(QtWidgets.QDialog): ...@@ -45,7 +45,6 @@ class ExpExcelDialog(QtWidgets.QDialog):
self.exportOptions = ['Polymer Type (mandatory)', 'Long Size (µm)', 'Short Size (µm)', 'Area (µm²)', 'HQI', 'Size Classes'] self.exportOptions = ['Polymer Type (mandatory)', 'Long Size (µm)', 'Short Size (µm)', 'Area (µm²)', 'HQI', 'Size Classes']
self.checkBoxes = [] self.checkBoxes = []
self.sizeClasses = [5, 10, 20, 50, 100, 1e6] self.sizeClasses = [5, 10, 20, 50, 100, 1e6]
self.directory = self.dataset.path
for index, option in enumerate(self.exportOptions): for index, option in enumerate(self.exportOptions):
self.checkBoxes.append(QtWidgets.QCheckBox(self)) self.checkBoxes.append(QtWidgets.QCheckBox(self))
...@@ -76,8 +75,8 @@ class ExpExcelDialog(QtWidgets.QDialog): ...@@ -76,8 +75,8 @@ class ExpExcelDialog(QtWidgets.QDialog):
def toExcel(self): def toExcel(self):
requiredcolumns = [] requiredcolumns = []
uniquePolymers = self.particleContainer.getUniquePolymers() uniquePolymers = self.particleContainer.getUniquePolymers()
polymers = self.particleContainer.getListOfParticleAssignments() polymers = np.array(self.particleContainer.getListOfParticleAssignments())
sizes = self.particleContainer.getSizesOfAllParticles() sizes = np.array(self.particleContainer.getSizesOfAllParticles())
for box in self.checkBoxes: for box in self.checkBoxes:
...@@ -85,13 +84,13 @@ class ExpExcelDialog(QtWidgets.QDialog): ...@@ -85,13 +84,13 @@ class ExpExcelDialog(QtWidgets.QDialog):
if box.text() != 'Size Classes': if box.text() != 'Size Classes':
requiredcolumns.append(box.text()) requiredcolumns.append(box.text())
if box.text() == 'Long Size (µm)': if box.text() == 'Long Size (µm)':
longSizes = sizes longSizes = np.round(sizes)
elif box.text() == 'Short Size (µm)': elif box.text() == 'Short Size (µm)':
shortSizes = self.particleContainer.getShortSizesOfAllParticles() shortSizes = np.round(np.array(self.particleContainer.getShortSizesOfAllParticles()))
elif box.text() == 'HQI': elif box.text() == 'HQI':
hqis = self.particleContainer.getListOfHighestHQIs() hqis = np.array(self.particleContainer.getListOfHighestHQIs())
elif box.text() == 'Area (µm²)': elif box.text() == 'Area (µm²)':
areas = self.particleContainer.getAreasOfAllParticles() areas = np.array(self.particleContainer.getAreasOfAllParticles())
else: else:
requiredcolumns.append('0 - 5 µm') requiredcolumns.append('0 - 5 µm')
...@@ -101,13 +100,12 @@ class ExpExcelDialog(QtWidgets.QDialog): ...@@ -101,13 +100,12 @@ class ExpExcelDialog(QtWidgets.QDialog):
requiredcolumns.append('50 - 100 µm') requiredcolumns.append('50 - 100 µm')
requiredcolumns.append('> 100 µm') requiredcolumns.append('> 100 µm')
finalData = np.zeros((polymers.shape[0],len(requiredcolumns)-1)) finalData = np.zeros((len(polymers),len(requiredcolumns)-1))
polymertypes = [""]*polymers.shape[0] polymertypes = [""]*len(polymers)
rowindex = 0 rowindex = 0
for polymer in uniquePolymers: for polymer in uniquePolymers:
indices = self.particleContainer.getgetIndicesOfParticleType(polymer) indices = polymers == polymer
numentries = int(np.sum(indices)) numentries = int(np.sum(indices))
print("Num:", numentries)
sys.stdout.flush() sys.stdout.flush()
for colindex, column in enumerate(requiredcolumns): for colindex, column in enumerate(requiredcolumns):
...@@ -130,7 +128,7 @@ class ExpExcelDialog(QtWidgets.QDialog): ...@@ -130,7 +128,7 @@ class ExpExcelDialog(QtWidgets.QDialog):
upLimit = self.sizeClasses[classindex] upLimit = self.sizeClasses[classindex]
if classindex == 0: lowLimit = 0 if classindex == 0: lowLimit = 0
else: lowLimit = self.sizeClasses[classindex-1] else: lowLimit = self.sizeClasses[classindex-1]
curSize = self.sizes[dataindex] curSize = sizes[dataindex]
if curSize > lowLimit and curSize <= upLimit: if curSize > lowLimit and curSize <= upLimit:
finalData[rowindex+tableindex, numPrevCols + classindex] = np.int(1) finalData[rowindex+tableindex, numPrevCols + classindex] = np.int(1)
...@@ -140,17 +138,13 @@ class ExpExcelDialog(QtWidgets.QDialog): ...@@ -140,17 +138,13 @@ class ExpExcelDialog(QtWidgets.QDialog):
rowindex = rowindex + numentries rowindex = rowindex + numentries
#dump into excel file #dump into excel file
xlsname = self.directory + '//' + self.xlsFileName.text() + '.xlsx' xlsname = os.path.join(self.dataset.path, f'{self.xlsFileName.text()}.xlsx')
print('exporting excel to:\n file name: {} in directory: {}'.format(self.xlsFileName.text(), self.directory)) print('exporting excel to:\n file name: {} in directory: {}'.format(self.xlsFileName.text(), self.dataset.path))
validFileName = False
incr = 1 incr = 1
while not validFileName: while os.path.exists(xlsname):
if not os.path.exists(xlsname): xlsname = os.path.join(self.dataset.path, f'{self.xlsFileName.text()} {incr}.xlsx')
validFileName = True incr += 1
else:
xlsname = self.directory + '//' + self.xlsFileName.text() + ' {}.xlsx'.format(incr)
incr += 1
writer = pd.ExcelWriter(xlsname, engine = 'xlsxwriter') writer = pd.ExcelWriter(xlsname, engine = 'xlsxwriter')
df = pd.DataFrame(finalData, columns=requiredcolumns[1:]) df = pd.DataFrame(finalData, columns=requiredcolumns[1:])
...@@ -159,20 +153,20 @@ class ExpExcelDialog(QtWidgets.QDialog): ...@@ -159,20 +153,20 @@ class ExpExcelDialog(QtWidgets.QDialog):
if '> 100 µm' in requiredcolumns: if '> 100 µm' in requiredcolumns:
#generate particle statistics report #generate particle statistics report
header = ['0 - 5 µm', '5 - 10 µm', '10 - 20 µm', '20 - 50 µm', '50 - 100 µm', '> 100 µm'] header = ['0 - 5 µm', '5 - 10 µm', '10 - 20 µm', '20 - 50 µm', '50 - 100 µm', '> 100 µm']
index = np.unique(self.polymers)
particleclasses = [] particleclasses = []
for polymer in index: for polymer in uniquePolymers:
indices = np.where(self.polymers == polymer)[0] indices = self.particleContainer.getIndicesOfParticleType(polymer)
sortind = np.searchsorted([5,10,20,50,100], self.sizes[indices], 'right') sortind = np.searchsorted([5,10,20,50,100], sizes[indices], 'right')
classes = np.bincount(sortind, minlength=6) classes = np.bincount(sortind, minlength=6)
particleclasses.append(classes) particleclasses.append(classes)
particleclasses = np.array(particleclasses) particleclasses = np.array(particleclasses)
report = pd.DataFrame(np.array(particleclasses), columns=header, report = pd.DataFrame(np.array(particleclasses), columns=header,
dtype=int) dtype=int)
report.insert(0, 'Polymer Type', index) report.insert(0, 'Polymer Type', uniquePolymers)
report.insert(len(report.columns), 'Sum total', particleclasses.sum(axis=1)) report.insert(len(report.columns), 'Sum total', particleclasses.sum(axis=1))
report.to_excel(writer, sheet_name = 'Particle Statistics', index=False) report.to_excel(writer, sheet_name = 'Particle Statistics', index=False)
writer.save() writer.save()
self.accept() self.accept()
\ No newline at end of file QtWidgets.QMessageBox.about(self, 'Particles succesfully exported', 'List saved to\n' + str(xlsname))
\ No newline at end of file
...@@ -43,31 +43,6 @@ class LoadTrueMatchResults(QtWidgets.QDialog): ...@@ -43,31 +43,6 @@ class LoadTrueMatchResults(QtWidgets.QDialog):
self.loadBtn = QtWidgets.QPushButton('LoadTrueMatchResults') self.loadBtn = QtWidgets.QPushButton('LoadTrueMatchResults')
self.loadBtn.resize(self.loadBtn.sizeHint()) self.loadBtn.resize(self.loadBtn.sizeHint())
self.loadBtn.clicked.connect(self.loadFileManually) self.loadBtn.clicked.connect(self.loadFileManually)
# optionsLayout = QtWidgets.QFormLayout()
# self.optionsGroup = QtWidgets.QGroupBox('Compute Options')
# self.optionsGroup.setDisabled(True)
#
# self.label1 = QtWidgets.QLabel('HQI-Threshold:')
# self.spinbox1 = QtWidgets.QDoubleSpinBox(self)
# self.spinbox1.valueChanged.connect(self.runCalculations)
# optionsLayout.addRow(self.label1, self.spinbox1)
# self.label2 = QtWidgets.QLabel('ComponentThreshold:')
# self.spinbox2 = QtWidgets.QDoubleSpinBox(self)
# self.spinbox2.valueChanged.connect(self.updateParentSpinboxes)
# optionsLayout.addRow(self.label2, self.spinbox2)
# for box in [self.spinbox1, self.spinbox2]:
# for box in [self.spinbox1]:
# box.setValue(50)
# box.setDecimals(1)
# box.setSingleStep(5)
# box.setMinimum(0)
# box.setMaximum(100)
## self.spinbox2.setValue(30) #more reasonable...
#
# self.optionsGroup.setLayout(optionsLayout)
self.reviewGroup = QtWidgets.QGroupBox('Review Changes') self.reviewGroup = QtWidgets.QGroupBox('Review Changes')
self.reviewGroup.setDisabled(True) self.reviewGroup.setDisabled(True)
...@@ -80,7 +55,6 @@ class LoadTrueMatchResults(QtWidgets.QDialog): ...@@ -80,7 +55,6 @@ class LoadTrueMatchResults(QtWidgets.QDialog):
self.reviewGroup.setLayout(reviewLayout) self.reviewGroup.setLayout(reviewLayout)
self.layout.addWidget(self.loadBtn, 0, 0) self.layout.addWidget(self.loadBtn, 0, 0)
# self.layout.addWidget(self.optionsGroup, 1, 0)
self.layout.addWidget(self.reviewGroup, 2, 0) self.layout.addWidget(self.reviewGroup, 2, 0)
self.manualPolymers = {} self.manualPolymers = {}
...@@ -144,7 +118,12 @@ class LoadTrueMatchResults(QtWidgets.QDialog): ...@@ -144,7 +118,12 @@ class LoadTrueMatchResults(QtWidgets.QDialog):
specName = entry[0] specName = entry[0]
indexOpenBracket = specName.find('(') indexOpenBracket = specName.find('(')
indexCloseBracket = specName.find(')') indexCloseBracket = specName.find(')')
specIndex = int(specName[indexOpenBracket+1:indexCloseBracket]) inbrackets = specName[indexOpenBracket+1:indexCloseBracket]
try:
specIndex = int(inbrackets)
except:
print(inbrackets)
raise
#find yes-flags #find yes-flags
flags = np.where(np.array(entry) == 'yes')[0] flags = np.where(np.array(entry) == 'yes')[0]
...@@ -204,7 +183,6 @@ class LoadTrueMatchResults(QtWidgets.QDialog): ...@@ -204,7 +183,6 @@ class LoadTrueMatchResults(QtWidgets.QDialog):
if numcomps == 1: #####SINGLE COMPONENT SEARCH if numcomps == 1: #####SINGLE COMPONENT SEARCH
self.additives = None self.additives = None
self.addhqis = None self.addhqis = None
# self.spinbox2.setEnabled(False)
for index, entry in enumerate(self.resultList): for index, entry in enumerate(self.resultList):
if len(entry) == 0: if len(entry) == 0:
del self.resultList[index] del self.resultList[index]
...@@ -241,11 +219,6 @@ class LoadTrueMatchResults(QtWidgets.QDialog): ...@@ -241,11 +219,6 @@ class LoadTrueMatchResults(QtWidgets.QDialog):
def closeEvent(self, event): def closeEvent(self, event):
#TODO: SANITY CHECK FOR DATA CONSISTENCY!! #TODO: SANITY CHECK FOR DATA CONSISTENCY!!
# if not self.parent.datastats.saveAnalysisResults(minHQI, compHQI):
# QtWidgets.QMessageBox.warning(self.parent, 'Error!',
# 'Data inconsistency after saving!',
# QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok)
self.parent.setEnabled(True) self.parent.setEnabled(True)
event.accept() event.accept()
......
...@@ -83,17 +83,19 @@ class Particle(object): ...@@ -83,17 +83,19 @@ class Particle(object):
else: else:
print(f'Error, particle size requested, but not yet set.\nParticle Index is {self.index}') print(f'Error, particle size requested, but not yet set.\nParticle Index is {self.index}')
raise ValueError raise ValueError
assert size is not None, f'Error, size or particle {self.index} is None' assert size is not None, f'Error, size of particle {self.index} is None'
return round(size) return size
def getShortParticleSize(self): def getShortParticleSize(self):
if not np.isnan(self.shortSize_ellipse): if not np.isnan(self.shortSize_ellipse):
return self.shortSize_ellipse size = self.shortSize_ellipse
elif not np.isnan(self.shortSize_box): elif not np.isnan(self.shortSize_box):
return self.shortSize_box size = self.shortSize_box
else: else:
print(f'Error, particle size requested, but not yet set.\nParticle Index is {self.index}') print(f'Error, particle size requested, but not yet set.\nParticle Index is {self.index}')
raise ValueError raise ValueError
assert size is not None, f'Error, short size of particle {self.index} is None'
return size
def getNumberOfMeasurements(self): def getNumberOfMeasurements(self):
return len(self.measurements) return len(self.measurements)
......
...@@ -33,7 +33,6 @@ class ParticleContainer(object): ...@@ -33,7 +33,6 @@ class ParticleContainer(object):
self.datasetParent = datasetParent self.datasetParent = datasetParent
self.particles = [] self.particles = []
self.measurements = [] self.measurements = []
self.spectra = None
self.inconsistentParticles = [] self.inconsistentParticles = []
self.typeHistogram = None self.typeHistogram = None
...@@ -83,7 +82,6 @@ class ParticleContainer(object): ...@@ -83,7 +82,6 @@ class ParticleContainer(object):
if spectra is not None: if spectra is not None:
np.save(self.datasetParent.getSpectraFileName(), spectra) np.save(self.datasetParent.getSpectraFileName(), spectra)
return spectra return spectra
def initializeParticles(self, numParticles): def initializeParticles(self, numParticles):
......
...@@ -142,7 +142,7 @@ class ParticlePainter(QtWidgets.QGraphicsItem): ...@@ -142,7 +142,7 @@ class ParticlePainter(QtWidgets.QGraphicsItem):
elif y_shift == 0: elif y_shift == 0:
newImg[:, :self.img.shape[1]] = self.img newImg[:, :self.img.shape[1]] = self.img
elif y_shift > 0: elif y_shift > 0:
newImg[:y_shift, :self.img.shape[1]] = self.img newImg[:self.img.shape[0], :self.img.shape[1]] = self.img
self.img = np.uint8(newImg) self.img = np.uint8(newImg)
self.setBrect() self.setBrect()
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Created on Thu Nov 8 13:50:05 2018 GEPARD - Gepard-Enabled PARticle Detection
Copyright (C) 2018 Lars Bittrich and Josef Brandt, Leibniz-Institut für
Polymerforschung Dresden e. V. <bittrich-lars@ipfdd.de>
@author: brandt This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program, see COPYING.
If not, see <https://www.gnu.org/licenses/>.
""" """
from PyQt5 import QtWidgets from PyQt5 import QtWidgets, QtCore
import numpy as np import numpy as np
import mysql.connector import mysql.connector
import difflib import difflib
...@@ -14,18 +28,24 @@ import os ...@@ -14,18 +28,24 @@ import os
import datetime import datetime
import json import json
import analysis.DBAssignments as dbassignments
from analysis.DBAssignments import DBAssignment
class SQLExport(QtWidgets.QDialog): class SQLExport(QtWidgets.QDialog):
def __init__(self, particleContainer, parent): def __init__(self, dataset):
super(SQLExport, self).__init__(parent) super(SQLExport, self).__init__()
self.setWindowTitle('Export to SQL Database') self.setWindowTitle('Export to SQL Database')
self.particleContainer = particleContainer self.dataset = dataset
self.longSizes = self.particleContainer.getSizesOfAllParticles() self.particleContainer = dataset.particleContainer
self.shortSize = self.particleContainer.getShortSizesOfAllParticles()
self.spectra = self.particleContainer.spectra self.longSizes = np.round(self.particleContainer.getSizesOfAllParticles())
self.shortSize = np.round(self.particleContainer.getShortSizesOfAllParticles())
self.spectra = self.particleContainer.getSpectraFromDisk()
self.particleImages = None self.particleImages = None
self.log = [] self.log = []
self.dbAssignments = None
configfilename = os.path.join(os.path.split(__file__)[0], 'database_config.txt') configfilename = os.path.join(os.path.split(__file__)[0], 'database_config.txt')
...@@ -40,7 +60,7 @@ class SQLExport(QtWidgets.QDialog): ...@@ -40,7 +60,7 @@ class SQLExport(QtWidgets.QDialog):
for key in ['user', 'password', 'host', 'database', for key in ['user', 'password', 'host', 'database',
'raise_on_warnings', 'charset', 'use_unicode']: 'raise_on_warnings', 'charset', 'use_unicode']:
assert key in self.config, \ assert key in self.config, \
'all server config data must be defined in json file' f'server config key {key} is missing databae_config json file'
self.cnx = None self.cnx = None
self.createInterface() self.createInterface()
...@@ -49,6 +69,14 @@ class SQLExport(QtWidgets.QDialog): ...@@ -49,6 +69,14 @@ class SQLExport(QtWidgets.QDialog):
layout = QtWidgets.QVBoxLayout() layout = QtWidgets.QVBoxLayout()
self.setLayout(layout) self.setLayout(layout)
assignmentFolder = QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.AppLocalDataLocation)
assignmentPath = os.path.join(assignmentFolder, 'dbassignments.pkl')
if not os.path.exists(assignmentPath):
self.dbAssignments = DBAssignment()
self.dbAssignments.setFileName(assignmentPath)
else:
self.dbAssignments = dbassignments.loadAssigments(assignmentPath)
self.connect() self.connect()
promptGroup = QtWidgets.QGroupBox('General Properties') promptGroup = QtWidgets.QGroupBox('General Properties')
...@@ -64,10 +92,10 @@ class SQLExport(QtWidgets.QDialog): ...@@ -64,10 +92,10 @@ class SQLExport(QtWidgets.QDialog):
promptLayout.addWidget(self.sampleEdit, 0, 3) promptLayout.addWidget(self.sampleEdit, 0, 3)
promptLayout.addWidget(QtWidgets.QLabel(')'), 0, 4) promptLayout.addWidget(QtWidgets.QLabel(')'), 0, 4)
methodList = self.getEntireTable('methods')[1] self.methodIndices = self.getMethodIDs()
self.methodIndices = [i[0] for i in methodList]
self.methodSelector = QtWidgets.QComboBox() self.methodSelector = QtWidgets.QComboBox()
self.methodSelector.addItems([i[1] for i in methodList]) self.methodSelector.addItems(self.getMethodNames())
self.methodEdit = LinkedLineEdit(self.methodSelector) self.methodEdit = LinkedLineEdit(self.methodSelector)
self.methodEdit.setMaximumWidth(250) self.methodEdit.setMaximumWidth(250)
promptLayout.addWidget(QtWidgets.QLabel('Analysis Method*: '), 1, 0) promptLayout.addWidget(QtWidgets.QLabel('Analysis Method*: '), 1, 0)
...@@ -81,6 +109,7 @@ class SQLExport(QtWidgets.QDialog): ...@@ -81,6 +109,7 @@ class SQLExport(QtWidgets.QDialog):
self.analystSelector = QtWidgets.QComboBox() self.analystSelector = QtWidgets.QComboBox()
self.analystSelector.addItems([', '.join([i[2], i[1]]) for i in analystList]) self.analystSelector.addItems([', '.join([i[2], i[1]]) for i in analystList])
self.analysisDate = QtWidgets.QDateEdit() self.analysisDate = QtWidgets.QDateEdit()
self.analysisDate.setDate(QtCore.QDate().currentDate())
self.arrivalDate = QtWidgets.QDateEdit() self.arrivalDate = QtWidgets.QDateEdit()
furtherProperties = {QtWidgets.QLabel('ArrivalDate*: '): self.arrivalDate, furtherProperties = {QtWidgets.QLabel('ArrivalDate*: '): self.arrivalDate,
QtWidgets.QLabel('Analysis : '): self.analysisDate, QtWidgets.QLabel('Analysis : '): self.analysisDate,
...@@ -108,37 +137,43 @@ class SQLExport(QtWidgets.QDialog): ...@@ -108,37 +137,43 @@ class SQLExport(QtWidgets.QDialog):
self.polymerTypes = self.particleContainer.getUniquePolymers() self.polymerTypes = self.particleContainer.getUniquePolymers()
self.polymerCheckboxes = [] self.polymerCheckboxes = []
self.db_polyms = [] self.db_result_combos = []
self.db_categs = [] self.db_categs_combos = []
self.p_remarks = [] self.db_pRemark_combos = []
self.comments =[] self.comments =[]
for index, polymerType in enumerate(self.polymerTypes): for index, polymerType in enumerate(self.polymerTypes):
self.polymerCheckboxes.append(QtWidgets.QCheckBox()) self.polymerCheckboxes.append(QtWidgets.QCheckBox())
self.db_polyms.append(QtWidgets.QComboBox()) newPolymCombo = QtWidgets.QComboBox()
self.db_polyms[-1].addItems([i[1] for i in dbPolymResults]) newPolymCombo.addItems([i[1] for i in dbPolymResults])
self.setToClosestMatch(polymerType, self.db_polyms[-1]) self.db_result_combos.append(newPolymCombo)
self.db_categs.append(QtWidgets.QComboBox())
self.db_categs[-1].addItems([i[1] for i in dbCategResults]) newCategCombo = QtWidgets.QComboBox()
self.setToClosestMatch(polymerType, self.db_categs[-1]) newCategCombo.addItems([i[1] for i in dbCategResults])
self.p_remarks.append(QtWidgets.QComboBox()) self.db_categs_combos.append(newCategCombo)
self.p_remarks[-1].addItems([i[1] for i in dbPaintRemark])
self.p_remarks[-1].addItem('') newPaintRemarksCombo = QtWidgets.QComboBox()
self.p_remarks[-1].setCurrentIndex(self.p_remarks[-1].count()-1) newPaintRemarksCombo.addItems([i[1] for i in dbPaintRemark])
newPaintRemarksCombo.addItem('')
self.db_pRemark_combos.append(newPaintRemarksCombo)
self.setComboBoxesToAssignment(newPolymCombo, newCategCombo, newPaintRemarksCombo, polymerType)
self.comments.append(QtWidgets.QLineEdit()) self.comments.append(QtWidgets.QLineEdit())
self.polymerCheckboxes[-1].stateChanged.connect(self.makeStateChangedLambda(self.polymerCheckboxes[-1], self.polymerCheckboxes[-1].stateChanged.connect(self.makeStateChangedLambda(self.polymerCheckboxes[-1],
[self.db_polyms[-1], self.db_categs[-1], self.p_remarks[-1], self.comments[-1]])) [self.db_result_combos[-1], self.db_categs_combos[-1], self.db_pRemark_combos[-1], self.comments[-1]]))
self.polymerCheckboxes[-1].setChecked(True) self.polymerCheckboxes[-1].setChecked(True)
self.polymerCheckboxes[-1].setChecked(False) #switch twice, so that the stateChanged-function is called self.polymerCheckboxes[-1].setChecked(False) #switch twice, so that the stateChanged-function is called
typeLayout.addWidget(self.polymerCheckboxes[-1], index+1, 0) typeLayout.addWidget(self.polymerCheckboxes[-1], index+1, 0)
typeLayout.addWidget(QtWidgets.QLabel(polymerType), index+1, 1) typeLayout.addWidget(QtWidgets.QLabel(polymerType), index+1, 1)
typeLayout.addWidget(self.db_polyms[-1], index+1, 2) typeLayout.addWidget(self.db_result_combos[-1], index+1, 2)
typeLayout.addWidget(self.db_categs[-1], index+1, 3) typeLayout.addWidget(self.db_categs_combos[-1], index+1, 3)
typeLayout.addWidget(self.p_remarks[-1], index+1, 4) typeLayout.addWidget(self.db_pRemark_combos[-1], index+1, 4)
typeLayout.addWidget(self.comments[-1], index+1, 5) typeLayout.addWidget(self.comments[-1], index+1, 5)
for element in (self.db_polyms + self.db_categs + self.p_remarks + self.comments): for element in (self.db_result_combos + self.db_categs_combos + self.db_pRemark_combos + self.comments):