Commit a2488054 authored by Martin Drechsler's avatar Martin Drechsler

added some files for starting to clean up the code and reformulate it as a...

added some files for starting to clean up the code and reformulate it as a backend-frontend scenario
parent 85dba8df
# -*- coding: utf-8 -*-
"""
This is a temporary script file.
"""
from ADoutputs import daq_AO, daq_DO
from PyQt5 import QtCore
AO_TYPES = ['cavity_piezo', 'electrode', 'laser_piezo']
class anal_control_signal(QtCore.QObject):
_registry = []
def __init__(self, name, channel, ao_type, out_minimum = -10, out_maximum = 10, out_step = 0.1, feedfoward = False):
super().__init__()
self._registry.append(self)
if ao_type not in AO_TYPES:
raise ValueError("Invalid ao type. Expected one of: %s" % AO_TYPES)
self.name = name
self.ch = channel
self.ao_type = ao_type
self.is_feedwoward_enabled = feedfoward
self.initial_value = 0
self.max = out_maximum
self.min = out_minimum
self.step = out_step
self.siPrefix = True
self.suffix = 'V'
\ No newline at end of file
...@@ -75,7 +75,7 @@ class GuiMainWindow(QMainWindow): ...@@ -75,7 +75,7 @@ class GuiMainWindow(QMainWindow):
self.dactivate.hideTitleBar() self.dactivate.hideTitleBar()
# Here I add the docks # Here I add the docks
self.area.addDock( self.dtrap_electrodes) self.area.addDock(self.dtrap_electrodes)
self.area.addDock(self.d397, 'bottom', self.dtrap_electrodes) self.area.addDock(self.d397, 'bottom', self.dtrap_electrodes)
self.area.addDock(self.d866, 'bottom', self.d397) self.area.addDock(self.d866, 'bottom', self.d397)
self.area.addDock(self.dWM) self.area.addDock(self.dWM)
......
from pyqtgraph import dockarea
from pyqtgraph.Qt import QtGui, QtCore
from PyQt5.QtWidgets import QPushButton, QProgressBar, QLabel
import pyqtgraph as pg
class CustomSpinBox(pg.SpinBox):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self._on_context_menu)
self.popMenu = QtGui.QMenu(self)
self.act_2_step = QtGui.QAction('2 mV step', self)
self.act_5_step = QtGui.QAction('5 mV step', self)
self.act_10_step = QtGui.QAction('10 mV step', self)
self.act_100_step = QtGui.QAction('100 mV step', self)
self.popMenu.addAction(self.act_2_step)
self.popMenu.addAction(self.act_5_step)
self.popMenu.addAction(self.act_10_step)
self.popMenu.addAction(self.act_100_step)
self.act_2_step.triggered.connect(lambda: self.setSingleStep(0.002))
self.act_5_step.triggered.connect(lambda: self.setSingleStep(0.005))
self.act_10_step.triggered.connect(lambda: self.setSingleStep(0.01))
self.act_100_step.triggered.connect(lambda: self.setSingleStep(0.1))
def _on_context_menu(self, point):
# show context menu
self.popMenu.exec_(self.mapToGlobal(point))
class LaserControlLayout(pg.LayoutWidget):
"""
A class for creating a layout with spinboxes and checkboxes to control a laser.
"""
def __init__(self, name, spinboxes = ['sbA', 'sbB'], checkboxes = ['cbA', 'cbB']):
super().__init__()
self.name = name
self.layout.addWidget(QtGui.QLabel(self.name), 0, 0)
self.spinboxes = {}
self.checkboxes = {}
for i, sb_name in enumerate(spinboxes, start = 1):
self.spinboxes[sb_name] = CustomSpinBox()
self.addWidget(QtGui.QLabel(sb_name), i, 0)
self.addWidget(self.spinboxes[sb_name], i, 1)
for i, cb_name in enumerate(checkboxes, start = 0):
self.checkboxes[cb_name] = QtGui.QCheckBox()
row = len(spinboxes) + 1
self.addWidget(QtGui.QLabel(cb_name), row, 2*i)
self.addWidget(self.checkboxes[cb_name], row, 2*i + 1)
class LaserScanLayout(pg.LayoutWidget):
"""
A class for creating a layout for scanning a laser piezo.
"""
def __init__(self, name, feedforward_enables = False):
super().__init__()
self.name = name
self.addWidget(QtGui.QLabel(self.name), 0, 0)
self.spinboxes = {}
self.spinboxes['start'] = CustomSpinBox()
self.spinboxes['stop'] = CustomSpinBox()
self.spinboxes['period'] = CustomSpinBox()
self.scan_button = QPushButton('Start scan')
self.scanpBar = QProgressBar(self)
self.scanLabelValue = QLabel(self)
self.addWidget(QtGui.QLabel('start'), 1, 0),
self.addWidget(self.spinboxes['start'], 1, 1)
self.addWidget(QtGui.QLabel('stop'), 2, 0)
self.addWidget(self.spinboxes['stop'], 2, 1)
self.addWidget(QtGui.QLabel('period'), 3, 0),
self.addWidget(self.spinboxes['period'], 3, 1)
self.addWidget(QtGui.QLabel('Scanning'), 4, 0)
self.addWidget(self.scan_button, 4, 1)
self.addWidget(self.scanLabelValue, 5, 0)
self.addWidget(self.scanpBar, 5, 1)
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QMainWindow
app = QtGui.QApplication([])
frame = QtGui.QFrame()
area = dockarea.DockArea()
grid = QtGui.QGridLayout()
frame.setLayout(grid)
myDock = dockarea.Dock('397', (100, 100))
area.addDock(myDock)
grid.addWidget(area, 0, 0)
l = LaserControlLayout('397', checkboxes = ['cb1', 'cb2', 'cb3'])
l_scan = LaserScanLayout('397 scan')
myDock.addWidget(l)
myDock.addWidget(l_scan)
frame.show()
sys.exit(app.exec_())
\ 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