Commit edbb4267 authored by Martin Drechsler's avatar Martin Drechsler

Roi saveable

parent 63fbc7da
......@@ -59,9 +59,9 @@ class CameraGuiMainWindow(QMainWindow):
self.area.addDock(self.dCameraView)
self.area.addDock(self.dCameraScanAnal, "left", self.dCameraView)
self.area.addDock(self.dCameraTimeAnal, "above", self.dCameraScanAnal)
self.area.addDock(self.dCameraTimeAnal, "below", self.dCameraScanAnal)
self.area.addDock(self.dCameraControl, "right", self.dCameraView)
self.area.addDock(self.dConsole, "bottom", self.dCameraControl)
self.area.addDock(self.dConsole, "right", self.dCameraControl)
self.area.addDock(self.dMeasurement, "above", self.dConsole)
#measurement frame
......@@ -87,7 +87,6 @@ class CameraGuiMainWindow(QMainWindow):
self.timeAnalysisLayout = pg.GraphicsLayoutWidget()
self.scanAnalysisLayout = pg.GraphicsLayoutWidget()
# image layout
self.img = pg.ImageItem(border="w")
self.imv = pg.ImageView(imageItem=self.img, view=self.imageView)
......@@ -153,6 +152,15 @@ class CameraGuiMainWindow(QMainWindow):
)
self.measurementFrame.abortMeasureButton.clicked.connect(backend.abort_measurement)
for roi in self.rois:
self.cameraParamFrame.saveRoiButton.clicked.connect(lambda: roi.save(
current_binning=self.cameraParamFrame.paramTree.p.child('Basic acq parameters')
.child('Pixel Binning').value() ))
self.cameraParamFrame.loadRoiButton.clicked.connect(lambda: roi.load(
current_binning=self.cameraParamFrame.paramTree.p.child('Basic acq parameters')
.child('Pixel Binning').value() ))
def camera_button_pressed(self):
if self.isCameraAcquiring:
......@@ -160,9 +168,9 @@ class CameraGuiMainWindow(QMainWindow):
self.cameraButton.setText('Start Acquisition')
self.measurementFrame.startMeasureButton.setEnabled(True)
self.isCameraAcquiring = False
self.cameraParamFrame.paramTree.t.setEnabled(True)
else:
self.repositionRoi()
self.repositionRoi(self.current_image_size)
self.scanROIdataX = np.linspace(0, 1, 2000)
self.scanROIdataY = np.zeros(2000)
self.timeROIdataY = np.zeros(2000)
......@@ -173,6 +181,7 @@ class CameraGuiMainWindow(QMainWindow):
self.previous_frame_index = 0
self.frames_checker_timer.start(1000)
self.isCameraAcquiring = True
self.cameraParamFrame.paramTree.t.setEnabled(False)
def _initialize_image(self):
# lock the aspect ratio so pixels are always square
......@@ -197,9 +206,7 @@ class CameraGuiMainWindow(QMainWindow):
self.timeCurve.setData(self.timeROIdataY)
self.scanCurve.setData(self.scanROIdataX, self.scanROIdataY)
def repositionRoi(self):
old_size = self.current_image_size
def repositionRoi(self, old_size):
aux_dict = {'1x1': 2048, '2x2': 1024, '4x4': 512, '8x8': 256}
new_size = aux_dict[
self.cameraParamFrame.paramTree.p.child('Basic acq parameters')
......
......@@ -103,7 +103,7 @@ class ControlGui(QtGui.QFrame):
backend.scanEndSignal.connect(scan_layout.scan_end)
#%%
if __name__ == '__main__':
app = QtGui.QApplication([])
controlGui = ControlGui()
......
......@@ -34,28 +34,36 @@ class CameraParameterFrame(QtWidgets.QFrame):
self.grid.addWidget(self.saveToButton, 2, 0)
self.grid.addWidget(self.loadFromButton, 2, 1)
self.grid.addWidget(QtWidgets.QLabel(
' ROI Position and Size'), 3, 0, 1, 2)
self.grid.addWidget(QtWidgets.QLabel(
'Roi X Position'), 3, 0)
'Roi X Position'), 4, 0)
self.grid.addWidget(QtWidgets.QLabel(
'Roi Y Position'), 3, 1)
'Roi Y Position'), 4, 1)
self.RoiXPosSb = pg.SpinBox()
self.RoiYPosSb = pg.SpinBox()
self.grid.addWidget(self.RoiXPosSb, 4, 0)
self.grid.addWidget(self.RoiYPosSb, 4, 1)
self.grid.addWidget(self.RoiXPosSb, 5, 0)
self.grid.addWidget(self.RoiYPosSb, 5, 1)
self.grid.addWidget(QtWidgets.QLabel(
'Roi X Size'), 5, 0)
'Roi X Size'), 6, 0)
self.grid.addWidget(QtWidgets.QLabel(
'Roi Y Size'), 5, 1)
'Roi Y Size'), 6, 1)
self.RoiXPosSb = pg.SpinBox()
self.RoiYPosSb = pg.SpinBox()
self.grid.addWidget(self.RoiXPosSb, 6, 0)
self.grid.addWidget(self.RoiYPosSb, 6, 1)
self.grid.addWidget(self.RoiXPosSb, 7, 0)
self.grid.addWidget(self.RoiYPosSb, 7, 1)
self.roiLayout = QtWidgets.QHBoxLayout()
self.saveRoiButton = QtWidgets.QPushButton('Save Roi')
self.saveToRoiButton = QtWidgets.QPushButton('Save Roi As')
self.loadRoiButton = QtWidgets.QPushButton('Load Roi')
self.grid.addWidget(self.saveRoiButton, 8, 0)
self.grid.addWidget(self.loadRoiButton, 8, 1)
self.grid.addWidget(self.saveToRoiButton, 9, 1)
#self.grid.addWidget(self.roiLayout, 7, 0, 1, 2)
self.make_connections()
self.show()
......
......@@ -3,8 +3,6 @@
"""
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.parametertree.parameterTypes as pTypes
from pyqtgraph.parametertree import Parameter, ParameterTree
......@@ -90,13 +88,16 @@ class CameraParameterTree(ParameterTree):
for p in self.p.child('Basic acq parameters').children():
print(p.name(), p.value())
@QtCore.pyqtSlot()
def save(self, location = 'config.ini'):
settings = QSettings(str(location), QSettings.IniFormat)
settings.beginGroup('Camera')
for parameter in self.p.child('Basic acq parameters').children():
settings.setValue(parameter.name(), parameter.value())
settings.endGroup()
print('Tree saved')
@QtCore.pyqtSlot()
def load(self, location = 'config.ini'):
settings = QSettings(str(location), QSettings.IniFormat)
settings.beginGroup('Camera')
......
......@@ -4,7 +4,8 @@ Some sub-classes from pyqtgraph.
"""
from pyqtgraph import ROI
from PyQt5.QtCore import QSettings, pyqtSlot
from PyQt5.QtWidgets import QFileDialog
class CustomRectangularROI(ROI):
......@@ -40,8 +41,7 @@ class CustomRectangularROI(ROI):
self.addScaleHandle([1, 1], [0, 0])
self.addScaleHandle([0, 0], [1, 1])
#self.sigRegionChangeFinished.connect(self.correct_scaling)
self.current_binning = ''
def correct_scaling(self):
x, y = self.pos()[0], self.pos()[1]
......@@ -51,4 +51,44 @@ class CustomRectangularROI(ROI):
sx, sy = self.size()[0], self.size()[1]
if sx%8 != 0 or sy%8 != 0:
self.setSize((sx//8)*8, (sy//8)*8)
\ No newline at end of file
@pyqtSlot()
def save(self, current_binning='', location = 'config.ini'):
settings = QSettings(str(location), QSettings.IniFormat)
settings.beginGroup('Roi')
settings.setValue('Binning', current_binning)
settings.setValue('PositionX', self.pos()[0])
settings.setValue('PositionY', self.pos()[1])
settings.setValue('SizeX', self.size()[0])
settings.setValue('SizeY', self.size()[1])
settings.endGroup()
print('roi saved')
@pyqtSlot()
def load(self, current_binning='', location = 'config.ini'):
settings = QSettings(str(location), QSettings.IniFormat)
settings.beginGroup('Roi')
saved_binning = settings.value('Binning')
posX = settings.value('PositionX')
posY = settings.value('PositionY')
sizeX = settings.value('SizeX')
sizeY =settings.value('SizeY')
settings.endGroup()
self.setPos([posX, posY])
self.setSize([sizeX, sizeY])
self.repositionRoi(saved_binning, current_binning)
def repositionRoi(self, old_binning, new_binning):
aux_dict = {'1x1': 2048, '2x2': 1024, '4x4': 512, '8x8': 256}
old_size = aux_dict[old_binning]
new_size = aux_dict[new_binning]
x, y, sx, sy = self.pos()[0], self.pos()[1], self.size()[0], self.size()[1]
new_x, new_y = new_size/old_size * x, new_size/old_size * y
new_sx, new_sy = new_size/old_size * sx, new_size/old_size * sy
self.setPos([new_x, new_y])
self.setSize([new_sx, new_sy])
\ No newline at end of file
......@@ -38,7 +38,7 @@ class CameraWorker(QtCore.QObject):
def make_connections(self, frontend):
# frontend connections
live_acq_params = frontend.param_tree.p
live_acq_params = frontend.cameraParamFrame.paramTree.p
frontend.cameraButton.clicked.connect(lambda: self.run(live_acq_params))
frontend.signalWithMeasurementParameters.connect(self.simple_scan_measurement_start)
frontend.roiDataReadySignal.connect(self.save_data_from_scan_step)
......
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