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):
......@@ -21,9 +21,9 @@ class ZLevelSetter(QtWidgets.QLabel):
super(ZLevelSetter, self).__init__()
layout = QtWidgets.QVBoxLayout()
self.setLayout(layout)
self.radioGroup = QtWidgets.QButtonGroup()
layout.addWidget(self._createRangeGroupBox())
layout.addLayout(self._createLevelSelectionLayout())
......@@ -36,10 +36,10 @@ 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)
self.minLevelSpinbox.setMaximum(1000)
......@@ -48,23 +48,28 @@ class ZLevelSetter(QtWidgets.QLabel):
self.maxLevelSpinbox = QtWidgets.QSpinBox()
self.maxLevelSpinbox.setValue(50)
self._minLevelBoxChanged()
self.numLevelsSpinbox = QtWidgets.QSpinBox()
self.numLevelsSpinbox.setMinimum(1)
self.numLevelsSpinbox.setMaximum(100)
self.numLevelsSpinbox.setValue(5)
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):
"""
Creates the Parent Group for selecting mode of level distribution
......@@ -75,7 +80,7 @@ class ZLevelSetter(QtWidgets.QLabel):
modeLayout.addWidget(self._createLogGroup())
modeLayout.addWidget(self._createCustomGroup())
return modeLayout
def _createLinGroup(self):
"""
Creates Widget group for linear level distribution
......@@ -85,18 +90,18 @@ class ZLevelSetter(QtWidgets.QLabel):
linLayout = QtWidgets.QVBoxLayout()
linGroup.setLayout(linLayout)
linGroup.sizePolicy().setVerticalPolicy(QtWidgets.QSizePolicy.Expanding)
self.linChecker = QtWidgets.QRadioButton('Linear')
self.linChecker.setChecked(True)
self.linChecker.toggled.connect(self._updateLevels)
linLayout.addWidget(self.linChecker)
self.linPreviewLayout = QtWidgets.QVBoxLayout()
linLayout.addLayout(self.linPreviewLayout)
self.linPreviewSteps = []
self._updateLinPreview()
return linGroup
def _createLogGroup(self):
"""
Creates Widget group for logarithmic level distribution
......@@ -106,19 +111,19 @@ class ZLevelSetter(QtWidgets.QLabel):
logLayout = QtWidgets.QVBoxLayout()
logGroup.setLayout(logLayout)
logGroup.sizePolicy().setVerticalPolicy(QtWidgets.QSizePolicy.Expanding)
self.logChecker = QtWidgets.QRadioButton('Logarithmic')
self.logChecker.setChecked(False)
self.logChecker.toggled.connect(self._updateLevels)
logLayout.addWidget(self.logChecker)
self.logPreviewLayout = QtWidgets.QVBoxLayout()
logLayout.addLayout(self.logPreviewLayout)
self.logPreviewSteps = []
self._updateLogPreview()
return logGroup
def _createCustomGroup(self):
"""
Creates Widget group for custom level distribution
......@@ -128,18 +133,18 @@ class ZLevelSetter(QtWidgets.QLabel):
customLayout = QtWidgets.QVBoxLayout()
customGroup.setLayout(customLayout)
customGroup.sizePolicy().setVerticalPolicy(QtWidgets.QSizePolicy.Expanding)
self.customChecker = QtWidgets.QRadioButton('Custom')
self.customChecker.setChecked(False)
self.customChecker.toggled.connect(self._updateLevels)
customLayout.addWidget(self.customChecker)
self.customPreviewLayout = QtWidgets.QVBoxLayout()
customLayout.addLayout(self.customPreviewLayout)
self.customPreviewSteps = []
self._updateCustomPreview()
return customGroup
def _updateLevels(self):
"""
Updates the previewed levels for all modes
......@@ -149,7 +154,7 @@ class ZLevelSetter(QtWidgets.QLabel):
self._updateLogPreview()
self._updateCustomPreview()
self._updateSize()
def _updateLinPreview(self):
"""
Updates linear level preview
......@@ -158,32 +163,38 @@ class ZLevelSetter(QtWidgets.QLabel):
for entry in self.linPreviewSteps:
entry.setParent(None)
zRange = np.linspace(self.minLevelSpinbox.value(), self.maxLevelSpinbox.value(), self.numLevelsSpinbox.value())
self.linPreviewSteps = []
for val in zRange:
newLabel = QtWidgets.QLabel(str(round(val, 1)))
newLabel.setEnabled(self.linChecker.isChecked())
self.linPreviewSteps.append(newLabel)
self.linPreviewLayout.addWidget(newLabel)
def _updateLogPreview(self):
"""
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)
self.logPreviewLayout.addWidget(newLabel)
def _updateCustomPreview(self):
"""
Updates custom level preview
......@@ -191,24 +202,25 @@ 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)
self.customPreviewSteps[i].setEnabled(self.customChecker.isChecked())
elif i >= numCurrentEntries:
newEntry = QtWidgets.QLineEdit()
newEntry.setEnabled(self.customChecker.isChecked())
self.customPreviewSteps.append(newEntry)
self.customPreviewLayout.addWidget(newEntry)
if i >= numDesiredEntries:
entry = self.customPreviewSteps[i]
entry.setParent(None)
self.customPreviewSteps.remove(entry)
indicesToRemove.append(i)
for i in sorted(indicesToRemove, reverse=True):
entry = self.customPreviewSteps[i]
entry.setParent(None)
self.customPreviewSteps.remove(entry)
def _updateSize(self):
"""
......@@ -227,7 +239,7 @@ class ZLevelSetter(QtWidgets.QLabel):
"""
self.maxLevelSpinbox.setMinimum(self.minLevelSpinbox.value()+1)
self.maxLevelSpinbox.setMaximum(self.maxLevelSpinbox.value()+1000)
def _addRadioBtnsToGroup(self):
"""
Group Radio Buttons to have them in exclusive check mode
......@@ -236,7 +248,7 @@ class ZLevelSetter(QtWidgets.QLabel):
self.radioGroup.addButton(self.linChecker)
self.radioGroup.addButton(self.logChecker)
self.radioGroup.addButton(self.customChecker)
def getZLevels(self):
"""
retrieves the z-levels according to the chosen settings
......@@ -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