Commit 1fff5fef authored by Josef Brandt's avatar Josef Brandt

Merge branch 'CustomLevelsInOpticalScan' into Development

parents 0095fb1c e10a83d6
......@@ -5,8 +5,8 @@ Created on Fri Oct 25 09:39:14 2019
@author: brandt
"""
from PyQt5 import QtWidgets, QtCore
import sys
import numpy as np
import math
class ZLevelSetter(QtWidgets.QLabel):
......@@ -36,9 +36,9 @@ class ZLevelSetter(QtWidgets.QLabel):
:return:
"""
rangeGroupBox = QtWidgets.QGroupBox('Select Range of z-steps')
rangeGroupBox.setMinimumHeight(80)
rangesLayout = QtWidgets.QHBoxLayout()
rangeGroupBox.setLayout(rangesLayout)
rangeGroupBox.setFixedHeight(60)
self.minLevelSpinbox = QtWidgets.QSpinBox()
self.minLevelSpinbox.setMinimum(-1000)
......@@ -57,12 +57,17 @@ class ZLevelSetter(QtWidgets.QLabel):
for box in [self.minLevelSpinbox, self.maxLevelSpinbox, self.numLevelsSpinbox]:
box.valueChanged.connect(self._updateLevels)
rangesLayout.addWidget(QtWidgets.QLabel('z_min (µm): '))
minLabel = QtWidgets.QLabel('z_min\n(µm): ')
maxLabel = QtWidgets.QLabel(', z_max\n(µm): ')
numLabel = QtWidgets.QLabel(', Num.\nsteps: ')
rangesLayout.addWidget(minLabel)
rangesLayout.addWidget(self.minLevelSpinbox)
rangesLayout.addWidget(QtWidgets.QLabel(', z_max (µm): '))
rangesLayout.addWidget(maxLabel)
rangesLayout.addWidget(self.maxLevelSpinbox)
rangesLayout.addWidget(QtWidgets.QLabel(', Num. steps: '))
rangesLayout.addWidget(numLabel)
rangesLayout.addWidget(self.numLevelsSpinbox)
return rangeGroupBox
def _createLevelSelectionLayout(self):
......@@ -171,14 +176,20 @@ class ZLevelSetter(QtWidgets.QLabel):
Updates logarithmic level preview
:return:
"""
base = 2
for entry in self.logPreviewSteps:
entry.setParent(None)
zmin = self.minLevelSpinbox.value()
zmax = np.log2(self.maxLevelSpinbox.value())
zRange = np.logspace(zmin, zmax, self.numLevelsSpinbox.value(), base=2)
zmax = self.maxLevelSpinbox.value()
diff = -(zmin-1)
zmin = math.log((zmin+diff), base)
zmax = math.log((zmax+diff), base)
zRange = np.logspace(zmin, zmax, self.numLevelsSpinbox.value(), base=base)
self.logPreviewSteps = []
for val in zRange:
val -= diff
newLabel = QtWidgets.QLabel(str(round(val, 1)))
newLabel.setEnabled(self.logChecker.isChecked())
self.logPreviewSteps.append(newLabel)
......@@ -191,13 +202,11 @@ class ZLevelSetter(QtWidgets.QLabel):
"""
numCurrentEntries = len(self.customPreviewSteps)
numDesiredEntries = self.numLevelsSpinbox.value()
indicesToRemove = []
for i in range(max([numCurrentEntries, numDesiredEntries])):
if i < numCurrentEntries:
try:
self.customPreviewSteps[i].setEnabled(self.customChecker.isChecked())
except IndexError:
print(i, self.customPreviewSteps)
elif i >= numCurrentEntries:
newEntry = QtWidgets.QLineEdit()
......@@ -206,6 +215,9 @@ class ZLevelSetter(QtWidgets.QLabel):
self.customPreviewLayout.addWidget(newEntry)
if i >= numDesiredEntries:
indicesToRemove.append(i)
for i in sorted(indicesToRemove, reverse=True):
entry = self.customPreviewSteps[i]
entry.setParent(None)
self.customPreviewSteps.remove(entry)
......@@ -267,17 +279,3 @@ class ZLevelSetter(QtWidgets.QLabel):
except:
raise ValueError
return sorted(levels)
if __name__ == '__main__':
try:
del app
except:
pass
app = QtWidgets.QApplication(sys.argv)
zSetter = ZLevelSetter()
zSetter.show()
ret = app.exec_()
sys.exit(1)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment