123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742 |
- """
- This Module Is the Timingsettings subWindow.
- """
- import logging
- from PyQt4 import QtGui, QtCore
- import pyqtgraph as pg
- import numpy as np
- from ..base import kcgwidget as kcgw
- from ..base.backend import board
- from ..base.backend.board import available_boards
- from ..base import backendinterface as bif
- from ..base.groupedelements import Elements
- from ..base.globals import glob as global_objects
- from .. import config
- tr = kcgw.tr
- __widget_id__ = None
- __timing_plot_widget_id__ = {}
- __timing_plot_widget__ = None
- class timingPlotWidget(kcgw.KCGWidgets):
- """
- The Timescan result plot subwindow.
- """
- def __init__(self, unique_id, board_id, parent=None):
- """
- Initialises the timing plot window
- :param unique_id: the id for this window
- :param parent: parent object
- :return: -
- """
- super(timingPlotWidget, self).__init__()
- self.id = unique_id
- self.par = parent
- self.board_id = board_id
- # ------[ Variable declaration ]------------
- self.plot_type = "colour" # The Plot Type for this window (Changeable in this window)
- self.x = None # Number of Ticks in the x-direction This is set by the gui programmatically
- self.y = None # Number of Ticks in the y-direction This is set by the gui programmatically
- self.data = None # Data to plot
- self.levels = None # Levels for colors
- self.inputsSet = False # If Inputs (Timing) are set
- # -------[ Create Plot Elements ]-----------
- self.adc1_plot_widget = pg.PlotWidget(title="ADC 1")
- self.adc2_plot_widget = pg.PlotWidget(title="ADC 2")
- self.adc3_plot_widget = pg.PlotWidget(title="ADC 3")
- self.adc4_plot_widget = pg.PlotWidget(title="ADC 4")
- # -------[ Create structure ]----------
- self.outerLayout = QtGui.QVBoxLayout() # Outermost layout of this window
- self.setLayout(self.outerLayout)
- self.headerLayout = QtGui.QHBoxLayout() # Layout for the header (including the switch to change plots)
- self.outerLayout.addLayout(self.headerLayout)
- self.layout = QtGui.QGridLayout() # Main Layout to hold the most elements in this window
- # ------[ Create Some Elements ]-----------
- self.position_label = self.createLabel("")
- self.position_label.setAlignment(QtCore.Qt.AlignCenter)
- self.plot_type_switcher = self.createSwitch(connect=self.switch)
- # ------[ Add Elements to various layouts ]--------------
- self.headerLayout.addWidget(self.position_label)
- self.headerLayout.addWidget(self.createLabel("Colour Plot"))
- self.headerLayout.addWidget(self.plot_type_switcher)
- self.headerLayout.addWidget(self.createLabel("Line Plot"))
- self.headerLayout.setAlignment(QtCore.Qt.AlignRight)
- self.layout.addWidget(self.adc1_plot_widget, 0, 0)
- self.layout.addWidget(self.adc2_plot_widget, 0, 1)
- self.layout.addWidget(self.adc3_plot_widget, 1, 0)
- self.layout.addWidget(self.adc4_plot_widget, 1, 1)
- self.outerLayout.addLayout(self.layout)
- self.setWindowTitle(tr("Heading", "Timescan Results")+" "+available_boards.get_board_name_from_id(board_id))
- # Initially show the colour plot
- self.colour_plot()
- def switch(self):
- """
- Switch Plot types
- :return: -
- """
- if self.plot_type == 'colour':
- self.remove_colour_plot()
- self.line_plot()
- self.plot()
- else:
- self.adc1_plot_widget.plotItem.clearPlots()
- self.adc2_plot_widget.plotItem.clearPlots()
- self.adc3_plot_widget.plotItem.clearPlots()
- self.adc4_plot_widget.plotItem.clearPlots()
- self.colour_plot()
- self.plot()
- def colour_plot(self):
- """
- Initialize Color Plot
- :return: -
- """
- self.plot_type = "colour"
- self.adc1 = pg.ImageItem()
- self.adc2 = pg.ImageItem()
- self.adc3 = pg.ImageItem()
- self.adc4 = pg.ImageItem()
- self.adc1.mouseClickEvent = lambda x: self.click("ADC 1", x)
- self.adc2.mouseClickEvent = lambda x: self.click("ADC 2", x)
- self.adc3.mouseClickEvent = lambda x: self.click("ADC 3", x)
- self.adc4.mouseClickEvent = lambda x: self.click("ADC 4", x)
- def tickStrings(values, scale, spacing):
- """
- Generate the strings for ticks
- """
- if len(values) > 20:
- return [str(i) for i in range(int(values[0]), int(values[-1]), 2)]
- else:
- return [str(int(i)) for i in values]
- # ----------[ Configure and add color plots for ADC1 ]----------
- for i in range(1, 5):
- getattr(self, "adc{}_plot_widget".format(i)).getPlotItem().setLabel("left", tr("Heading", "Coarse delay"))
- getattr(self, "adc{}_plot_widget".format(i)).getPlotItem().setLabel("bottom", tr("Heading", "Fine delay"))
- getattr(self, "adc{}_plot_widget".format(i)).plotItem.addItem(getattr(self, "adc"+str(i)))
- bax = getattr(self, "adc{}_plot_widget".format(i)).plotItem.getAxis('bottom')
- lax = getattr(self, "adc{}_plot_widget".format(i)).plotItem.getAxis('left')
- bax.setTickSpacing(levels=[(1, 2.5),])
- bax.tickStrings = tickStrings
- lax.setTickSpacing(levels=[(1, 1.5),])
- lax.tickStrings = tickStrings
- pos = np.array([0, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 1])
- color = np.array([[0, 0, 255, 255], [0, 255, 255, 255], [0, 255, 0, 255], [130, 255, 0, 255], [255, 255, 0, 255], [255, 180, 0, 255], [255, 100, 0, 255], [255, 0, 0, 255]])
- cmap = pg.ColorMap(pos, color)
- lut = cmap.getLookupTable(0.0, 1.0, 256)
- self.adc1.setLookupTable(lut)
- self.adc2.setLookupTable(lut)
- self.adc3.setLookupTable(lut)
- self.adc4.setLookupTable(lut)
- def remove_colour_plot(self):
- """
- Remove the color plot elements
- :return: -
- """
- self.adc1_plot_widget.plotItem.removeItem(self.adc1)
- self.adc2_plot_widget.plotItem.removeItem(self.adc2)
- self.adc3_plot_widget.plotItem.removeItem(self.adc3)
- self.adc4_plot_widget.plotItem.removeItem(self.adc4)
- def line_plot_axis_strings(self, values, scale, spacing):
- """
- Plot to format the strings for the line plot
- This is used to override the default tickStrings method of pyqtgraph.AxisItem
- :param values: See pyqtgraph.AxisItem.tickStrings
- :param scale: See pyqtgraph.AxisItem.tickStrings
- :param spacing: See pyqtgraph.AxisItem.tickStrings
- :return: See pyqtgraph.AxisItem.tickStrings
- """
- coarses = [i//(self.x) for i in values]
- fines = [i%(self.x) for i in values]
- return [str(int(c))+"\n"+str(int(f)) for c, f in zip(coarses, fines)]
- def spacing(self, minVal, maxVal, size):
- """
- Calculate spacing between ticks
- This is used to override the default tickSpacing method of pyqtgraph.AxisItem
- :param minVal: See pyqtgraph.AxisItem.tickSpacing
- :param maxVal: See pyqtgraph.AxisItem.tickSpacing
- :param size: See pyqtgraph.AxisItem.tickSpacing
- :return: See pyqtgraph.AxisItem.tickSpacing
- """
- if maxVal - minVal < 20.:
- return [(1, 0),]
- else:
- return [(round((maxVal-minVal)/20.), 0),]
- def y_axis_strings(self, values, scale, spacing):
- """
- Sets the strings for the y axis
- :param values:
- :param scale:
- :param spacing:
- :return:
- """
- return [str(int(v)) for v in values]
- def line_plot(self):
- """
- Initialise the Line Plot
- :return: -
- """
- self.plot_type = "line"
- for i in range(1, 5):
- getattr(self, "adc{}_plot_widget".format(i)).getPlotItem().setLabel("left", tr("Heading", "Intensity"))
- getattr(self, "adc{}_plot_widget".format(i)).getPlotItem().setLabel("bottom", tr("Heading", "Coarse over Fine"))
- bax = getattr(self, "adc{}_plot_widget".format(i)).plotItem.getAxis('bottom')
- lax = getattr(self, "adc{}_plot_widget".format(i)).plotItem.getAxis('left')
- bax.tickSpacing = self.spacing
- bax.tickStrings = self.line_plot_axis_strings
- lax.setTickSpacing()
- lax.tickStrings = self.y_axis_strings
- def setInputs(self, coarse_input, fine_inputs):
- """
- Register the Inputfields for timing in the timingsettings window
- :param coarse_input: (QSpinBox) Spinbox for coarse timing settings
- :param fine_inputs: (list) List of (QSpinBox)es for fine timing settings
- :return: -
- """
- self.c_input = coarse_input
- self.adc1_f_input = fine_inputs[0]
- self.adc2_f_input = fine_inputs[1]
- self.adc3_f_input = fine_inputs[2]
- self.adc4_f_input = fine_inputs[3]
- self.inputsSet = True
- def click(self, adc, event):
- """
- Handler for the click event in color plots
- :param adc: (str) The ADC plot that was clicked on
- :param event: (QEvent) the event
- :return: -
- """
- event.accept()
- pos = event.pos()
- self.position_label.setText(adc + " - " + str(int(pos.x())) + ":"+str(int(pos.y())))
- if not self.inputsSet:
- return
- self.c_input.setValue(int(pos.y()))
- if adc == "ADC 1":
- self.adc1_f_input.setValue(int(pos.x()))
- elif adc == "ADC 2":
- self.adc2_f_input.setValue(int(pos.x()))
- elif adc == "ADC 3":
- self.adc3_f_input.setValue(int(pos.x()))
- elif adc == "ADC 4":
- self.adc4_f_input.setValue(int(pos.x()))
- def plot(self, data=None, levels=None, newTitle=None, maxima=None):
- """
- Plot Data
- :param data: (numpy 4d array) data to plot
- :param levels: (tuple) Min and Max Values for color plot
- :param newTitle: (str) The title for the window
- :param maxima: (list) Maximum for each adc
- :return: -
- """
- # if self.data is not None and data is not None: # keine ahnung
- # return
- if self.data is None and data is None:
- return
- if data is not None:
- self.data = data # if called with no data a replot is performed (if data is set previously)
- if levels is not None:
- self.levels = levels
- self.x = self.data.shape[1]
- self.y = self.data.shape[2]
- if self.plot_type == 'colour':
- # self.colour_plot()
- self.adc1.setImage(self.data[0])
- self.adc2.setImage(self.data[1])
- self.adc3.setImage(self.data[2])
- self.adc4.setImage(self.data[3])
- if self.levels:
- self.adc1.setLevels(self.levels)
- self.adc2.setLevels(self.levels)
- self.adc3.setLevels(self.levels)
- self.adc4.setLevels(self.levels)
- if newTitle:
- self.setWindowTitle(tr("Heading", "Timescan Result:") + " " + newTitle + " " +
- available_boards.get_board_name_from_id(self.board_id))
- if maxima is not None:
- self.adc1_plot_widget.getPlotItem().setTitle(str(tr("Heading", "ADC 1: Maximum C:{c} F:{f}")).format(
- c=int(maxima[0, 1]), f=int(maxima[0, 2])))
- self.adc2_plot_widget.getPlotItem().setTitle(str(tr("Heading", "ADC 2: Maximum C:{c} F:{f}")).format(
- c=int(maxima[1, 1]), f=int(maxima[1, 2])))
- self.adc3_plot_widget.getPlotItem().setTitle(str(tr("Heading", "ADC 3: Maximum C:{c} F:{f}")).format(
- c=int(maxima[2, 1]), f=int(maxima[2, 2])))
- self.adc4_plot_widget.getPlotItem().setTitle(str(tr("Heading", "ADC 4: Maximum C:{c} F:{f}")).format(
- c=int(maxima[3, 1]), f=int(maxima[3, 2])))
- if self.plot_type == 'line':
- # self.line_plot()
- def reshape(data):
- ''' simply reshape the data'''
- return np.reshape(data, data.shape[0]*data.shape[1], order='F')
- self.adc1_plot_widget.plotItem.clear()
- self.adc2_plot_widget.plotItem.clear()
- self.adc3_plot_widget.plotItem.clear()
- self.adc4_plot_widget.plotItem.clear()
- self.adc1_plot_widget.plotItem.plot(reshape(self.data[0]))
- self.adc2_plot_widget.plotItem.plot(reshape(self.data[1]))
- self.adc3_plot_widget.plotItem.plot(reshape(self.data[2]))
- self.adc4_plot_widget.plotItem.plot(reshape(self.data[3]))
- # ---[ Show this window and set focus to it ]------
- self.parent().show()
- self.show()
- self.setFocus()
- def closeEvent(self, event):
- """
- Event handler for closing this window
- """
- global __timing_plot_widget_id__
- __timing_plot_widget_id__ = {}
- del self.par.widgets[self.id]
- class timingPart(kcgw.KCGWidgets):
- """
- The actual timing settings window
- """
- def __init__(self, board_id, parent=None):
- """
- Initialise the timing settings window
- :param unique_id:
- :param parent:
- :return:
- """
- super(timingPart, self).__init__()
- if __timing_plot_widget__:
- self.plotWidget = __timing_plot_widget__
- self.parent = parent
- self.board_id = board_id
- self.layout = QtGui.QGridLayout()
- self.outerLayout = QtGui.QVBoxLayout()
- self.outerLayout.addLayout(self.layout)
- self.setLayout(self.outerLayout)
- self.time_scan_enabled = False
- # --------[ Create TimeScan part ]----------
- # --------[ Create Elements ]-------------
- self.coarse_scan_range_label = self.createLabel(tr("Label", "Coarse scan"))
- self.fine_scan_range_label = self.createLabel(tr("Label", "Fine scan"))
- self.from_label = self.createLabel(tr("Label", "From"))
- self.to_label = self.createLabel(tr("Label", "To"))
- self.coarse_scan_min_spinbox = self.createSpinbox(0, bif.bk_get_config(board_id, 'th_delay_max'), start_value=0)
- self.coarse_scan_max_spinbox = self.createSpinbox(0, bif.bk_get_config(board_id, 'th_delay_max'), start_value=bif.bk_get_config(board_id, 'th_delay_max'))
- self.fine_scan_min_spinbox = self.createSpinbox(0, bif.bk_get_config(board_id, 'chip_delay_max'), start_value=0)
- self.fine_scan_max_spinbox = self.createSpinbox(0, bif.bk_get_config(board_id, 'chip_delay_max'), start_value=bif.bk_get_config(board_id, 'chip_delay_max'))
- self.orbits_observe_spinbox = self.createSpinbox(1, 10000000, start_value=100)
- self.orbits_skip_spinbox = self.createSpinbox(0, 100, start_value=2)
- self.time_scan_progressbar = QtGui.QProgressBar()
- self.time_scan_button = self.createButton(tr("Button", "Start time scan"), connect=self.time_scan)
- Elements.addButton("start_time_scan_{}".format(board_id), self.time_scan_button)
- self.timeScan = QtGui.QWidget()
- # --------[ Create and Fill Timescan layouts ]----------------
- self.timeScanVLayout = QtGui.QVBoxLayout()
- self.timeScanLayout = QtGui.QGridLayout()
- self.timeScanVLayout.addWidget(self.time_scan_progressbar)
- self.timeScanVLayout.addLayout(self.timeScanLayout)
- self.timeScan.setLayout(self.timeScanVLayout)
- self.timeScanLayout.addWidget(self.from_label, 0, 1)
- self.timeScanLayout.addWidget(self.to_label, 0, 2)
- self.timeScanLayout.addWidget(self.coarse_scan_range_label, 1, 0)
- self.timeScanLayout.addWidget(self.coarse_scan_min_spinbox, 1, 1)
- self.timeScanLayout.addWidget(self.coarse_scan_max_spinbox, 1, 2)
- self.timeScanLayout.addWidget(self.fine_scan_range_label, 2, 0)
- self.timeScanLayout.addWidget(self.fine_scan_min_spinbox, 2, 1)
- self.timeScanLayout.addWidget(self.fine_scan_max_spinbox, 2, 2)
- self.timeScanLayout.addWidget(self.createLabel("Orbits to Observe"), 3, 1)
- self.timeScanLayout.addWidget(self.orbits_observe_spinbox, 3, 2)
- self.timeScanLayout.addWidget(self.createLabel("Orbits to Skip"), 4, 1)
- self.timeScanLayout.addWidget(self.orbits_skip_spinbox, 4, 2)
- self.timeScanLayout.addWidget(self.time_scan_button, 5, 2)
- self.setTabOrder(self.fine_scan_max_spinbox, self.time_scan_button)
- # --------[ End Time Scan Part ]-------------
- # --------[ Create Labels and corresponding Fields ]---------
- def update_delay(which, spinbox):
- '''update the delays on the board'''
- board.get_board_config(board_id).update(which, getattr(self, spinbox).value())
- board.get_board_config(board_id).set_delay(self.coarseInput.value())
- self.thdelayLabel = self.createLabel(tr("Label", "T/H Delay"))
- self.adc1thdelayLabel = self.createLabel(tr("Label", "2. ADC1 T/H Delay"))
- self.coarseLabel = self.createLabel(tr("Label", "Coarse Delay"))
- self.coarseInput = self.createSpinbox(0, 15, connect=lambda: update_delay("th_delay", "coarseInput"))
- self.adc1CoarseInput = self.createSpinbox(0, 15, connect=lambda: update_delay("adc_1_delay_individual", "adc1CoarseInput"))
- self.adc1CoarseInput.setEnabled(False)
- self.adc1CoarseInputSwitch = self.createCheckbox(tr("Label", "Enable second ADC1 T/H Delay"), connect=self.toggleAdc1IndividualDelay)
- self.fineLabel = self.createLabel(tr("Label", "Fine Delay"))
- self.fineAdc1Input = self.createSpinbox(0, 31, connect=self.on_adc_delay_changed)
- self.fineAdc2Input = self.createSpinbox(0, 31, connect=self.on_adc_delay_changed)
- self.fineAdc3Input = self.createSpinbox(0, 31, connect=self.on_adc_delay_changed)
- self.fineAdc4Input = self.createSpinbox(0, 31, connect=self.on_adc_delay_changed)
- self.toggleTimeScanCheckbox = self.createCheckbox(tr("Button", "Time Scan"), tr("Tooltip", "Show time scan part"),
- connect=self.showTimeScan)
- #---------[ End ]---------
- Elements.addItem(["timing_{}".format(self.board_id), "no_board_{}".format(self.board_id)], [
- self.coarseInput,
- self.fineAdc1Input,
- self.fineAdc2Input,
- self.fineAdc3Input,
- self.fineAdc4Input,
- self.time_scan_button,
- self.adc1CoarseInputSwitch
- ])
- Elements.addItem('acquire_{}'.format(self.board_id), self.time_scan_button)
- def setValueSilent(value, spinbox):
- '''set values silent to not trigger signals'''
- spinbox.blockSignals(True)
- spinbox.setValue(value)
- spinbox.blockSignals(False)
- # --------[ Set observers ]------------
- def obs(who, what):
- '''observe something'''
- board.get_board_config(board_id).observe(
- who,
- lambda value=None: setValueSilent(value=value, spinbox=who),
- what
- )
- obs(self.fineAdc1Input, 'chip_1_delay')
- obs(self.fineAdc2Input, 'chip_2_delay')
- obs(self.fineAdc3Input, 'chip_3_delay')
- obs(self.fineAdc4Input, 'chip_4_delay')
- obs(self.coarseInput, 'th_delay')
- obs(self.adc1CoarseInput, 'adc_1_delay_individual')
- # -------[ Create outputs ]---------------
- self.totalLabel = self.createLabel(tr("Label", "Total Delay"))
- self.totalAdc1Box = self.createInput("", read_only=True)
- self.totalAdc2Box = self.createInput("", read_only=True)
- self.totalAdc3Box = self.createInput("", read_only=True)
- self.totalAdc4Box = self.createInput("", read_only=True)
- def observe_function(x, box):
- '''method to pass as callable to to the configuration as observer'''
- box.setText('%i + %i' % (board.get_board_config(board_id).get('th_delay')*
- board.get_board_config(board_id).get('th_delay_factor'),
- x*board.get_board_config(board_id).get('chip_delay_factor')))
- def observe_function_total(x, box, adc):
- '''method to pass as callable to to the configuration as observer'''
- box.setText('%i + %i' % (x *
- board.get_board_config(board_id).get('th_delay_factor'),
- board.get_board_config(board_id).get('chip_'+adc+'_delay') *
- board.get_board_config(board_id).get('chip_delay_factor')))
- # def adc1_observe_function_total(x, box):
- # adc1_individual = board.get_board_config(board_id).get("adc_1_delay_individual")
- # if adc1_individual == -1:
- # adc1_individual = 0
- # box.setText('%i + %i' % ((x+adc1_individual)*
- # board.get_board_config(board_id).get('th_delay_factor'),
- # board.get_board_config(board_id).get('chip_1_delay') *
- # board.get_board_config(board_id).get('chip_delay_factor')))
- board.get_board_config(board_id).observe(self.totalAdc1Box,
- lambda x: observe_function(x, self.totalAdc1Box), 'chip_1_delay')
- board.get_board_config(board_id).observe(self.totalAdc1Box,
- lambda x: observe_function_total(x, self.totalAdc1Box, '1'), 'th_delay')
- # board.get_board_config(board_id).observe(self.totalAdc1Box, lambda x: adc1_observe_function_total(x, self.totalAdc1Box), 'th_delay')
- # board.get_board_config(board_id).observe(self.totalAdc1Box, lambda x: adc1_observe_function_total(x, self.totalAdc1Box), 'adc_1_delay_individual')
- board.get_board_config(board_id).observe(self.totalAdc2Box,
- lambda x: observe_function(x, self.totalAdc2Box), 'chip_2_delay')
- board.get_board_config(board_id).observe(self.totalAdc2Box,
- lambda x: observe_function_total(x, self.totalAdc2Box, '2'), 'th_delay')
- board.get_board_config(board_id).observe(self.totalAdc3Box,
- lambda x: observe_function(x, self.totalAdc3Box), 'chip_3_delay')
- board.get_board_config(board_id).observe(self.totalAdc3Box,
- lambda x: observe_function_total(x, self.totalAdc3Box, '3'), 'th_delay')
- board.get_board_config(board_id).observe(self.totalAdc4Box,
- lambda x: observe_function(x, self.totalAdc4Box), 'chip_4_delay')
- board.get_board_config(board_id).observe(self.totalAdc4Box,
- lambda x: observe_function_total(x, self.totalAdc4Box, '4'), 'th_delay')
- #--------[ Fill Grid ]----------------
- self.layout.addWidget(self.thdelayLabel, 0, 1)
- self.layout.addWidget(self.coarseLabel, 1, 0)
- self.layout.addWidget(self.coarseInput, 1, 1)
- self.layout.addWidget(self.adc1thdelayLabel, 0, 2)
- self.layout.addWidget(self.adc1CoarseInput, 1, 2)
- self.layout.addWidget(self.adc1CoarseInputSwitch, 1, 3, 1, 2)
- self.layout.addItem(QtGui.QSpacerItem(10, 15), 2, 1)
- # Leave some rows free for additional things (empty rows will not be shown)
- for i in range(4):
- self.layout.addWidget(self.createLabel("ADC "+str(i+1)), 5, i+1)
- self.layout.addWidget(self.fineLabel, 6, 0)
- self.layout.addWidget(self.fineAdc1Input, 6, 1)
- self.layout.addWidget(self.fineAdc2Input, 6, 2)
- self.layout.addWidget(self.fineAdc3Input, 6, 3)
- self.layout.addWidget(self.fineAdc4Input, 6, 4)
- self.layout.addItem(QtGui.QSpacerItem(10, 15), 7, 1)
- line = QtGui.QFrame()
- line.setFrameStyle(QtGui.QFrame.HLine)
- self.layout.addWidget(line, 8, 0, 1, 5)
- self.layout.addItem(QtGui.QSpacerItem(10, 15), 9, 1)
- self.layout.addWidget(self.totalLabel, 10, 0)
- self.layout.addWidget(self.totalAdc1Box, 10, 1)
- self.layout.addWidget(self.totalAdc2Box, 10, 2)
- self.layout.addWidget(self.totalAdc3Box, 10, 3)
- self.layout.addWidget(self.totalAdc4Box, 10, 4)
- self.layout.addItem(QtGui.QSpacerItem(10, 15), 11, 1)
- self.layout.addWidget(self.toggleTimeScanCheckbox, 12, 0)
- # -------[ Add TimeScan ]---------
- self.outerLayout.addWidget(self.timeScan)
- self.timeScan.hide()
- self.outerLayout.addStretch(1)
- # -------[ End ]-----------
- # ------[ Exclude Total Delay Boxes from Tab Order ]--------
- self.totalAdc1Box.setFocusPolicy(QtCore.Qt.ClickFocus)
- self.totalAdc2Box.setFocusPolicy(QtCore.Qt.ClickFocus)
- self.totalAdc3Box.setFocusPolicy(QtCore.Qt.ClickFocus)
- self.totalAdc4Box.setFocusPolicy(QtCore.Qt.ClickFocus)
- self.setTabOrder(self.fineAdc4Input, self.toggleTimeScanCheckbox)
- self.setValues()
- self.setWindowTitle(tr("Heading", "Timing"))
- def toggleAdc1IndividualDelay(self):
- """
- Toggle to use an individual delay for adc1 or not
- :return: -
- """
- self.adc1CoarseInput.setEnabled(self.adc1CoarseInputSwitch.checkState())
- if not self.adc1CoarseInput.isEnabled():
- board.get_board_config(self.board_id).update('adc_1_delay_individual', -1) # Be careful this does no silent update
- def showTimeScan(self):
- """
- Show the time scan part of this window
- :return: -
- """
- if self.timeScan.isHidden():
- # self.outerLayout.addWidget(self.timeScan)
- self.timeScan.show()
- else:
- self.timeScan.hide()
- # self.outerLayout.removeWidget(self.timeScan)
- self.parent.adjustSizeForTimeScan()
- def time_scan(self):
- """
- Toggle timescan and create timingPlotWidget if it doesn't exist
- :return: -
- """
- global __timing_plot_widget_id__
- global __timing_plot_widget__
- if not (self.board_id in __timing_plot_widget_id__):
- nid = kcgw.idg.genid()
- __timing_plot_widget_id__[self.board_id] = nid
- self.plotWidget = timingPlotWidget(nid, self.board_id, global_objects.get_global('area'))
- __timing_plot_widget__ = self.plotWidget
- global_objects.get_global('area').newWidget(self.plotWidget, tr("Heading", "Timing result"), nid, widget_type=5)
- self.plotWidget.parent().hide()
- self.plotWidget.setInputs(self.coarseInput, [
- self.fineAdc1Input,
- self.fineAdc2Input,
- self.fineAdc3Input,
- self.fineAdc4Input
- ])
- bif.bk_time_scan(
- self.board_id,
- self.coarse_scan_min_spinbox.value(),
- self.coarse_scan_max_spinbox.value(),
- self.fine_scan_min_spinbox.value(),
- self.fine_scan_max_spinbox.value(),
- self.time_scan_progressbar,
- self.plotWidget.plot,
- orbits_observe = self.orbits_observe_spinbox.value(),
- orbits_skip = self.orbits_skip_spinbox.value()
- )
- def setValueSilent(self, element, value):
- """
- Set Values to inputs without notifying observers
- :param element: the input
- :param value: the value
- :return: -
- """
- element.blockSignals(True)
- element.setValue(value)
- element.blockSignals(False)
- def setValues(self):
- """
- Set Values to inputs (initially)
- :return: -
- """
- self.setValueSilent(self.fineAdc1Input, board.get_board_config(self.board_id).get('chip_1_delay'))
- self.setValueSilent(self.fineAdc2Input, board.get_board_config(self.board_id).get('chip_2_delay'))
- self.setValueSilent(self.fineAdc3Input, board.get_board_config(self.board_id).get('chip_3_delay'))
- self.setValueSilent(self.fineAdc4Input, board.get_board_config(self.board_id).get('chip_4_delay'))
- self.setValueSilent(self.coarseInput, board.get_board_config(self.board_id).get('th_delay'))
- if board.get_board_config(self.board_id).get('adc_1_delay_individual') != -1: # This may be nonsense Also: it is only possible to set adc1 higher than th_delay
- self.totalAdc1Box.setText('%i + %i' % ((board.get_board_config(self.board_id).get('th_delay')+board.get_board_config(self.board_id).get('adc_1_delay_individual'))
- * board.get_board_config(self.board_id).get('th_delay_factor'),
- board.get_board_config(self.board_id).get('chip_1_delay')*board.get_board_config(self.board_id).get('chip_delay_factor')))
- else:
- self.totalAdc1Box.setText('%i + %i' % (board.get_board_config(self.board_id).get('th_delay')* board.get_board_config(self.board_id).get('th_delay_factor'),
- board.get_board_config(self.board_id).get('chip_1_delay')*board.get_board_config(self.board_id).get('chip_delay_factor')))
- self.totalAdc2Box.setText('%i + %i' % (board.get_board_config(self.board_id).get('th_delay')* board.get_board_config(self.board_id).get('th_delay_factor'),
- board.get_board_config(self.board_id).get('chip_2_delay')*board.get_board_config(self.board_id).get('chip_delay_factor')))
- self.totalAdc3Box.setText('%i + %i' % (board.get_board_config(self.board_id).get('th_delay')* board.get_board_config(self.board_id).get('th_delay_factor'),
- board.get_board_config(self.board_id).get('chip_3_delay')*board.get_board_config(self.board_id).get('chip_delay_factor')))
- self.totalAdc4Box.setText('%i + %i' % (board.get_board_config(self.board_id).get('th_delay')* board.get_board_config(self.board_id).get('th_delay_factor'),
- board.get_board_config(self.board_id).get('chip_4_delay')*board.get_board_config(self.board_id).get('chip_delay_factor')))
- def closeEvent(self, event):
- """
- Event handler when this window is closed
- """
- Elements.emptyGroup('timing_{}'.format(self.board_id))
- board.get_board_config(self.board_id).unobserve(self.fineAdc1Input, 'chip_1_delay')
- board.get_board_config(self.board_id).unobserve(self.fineAdc2Input, 'chip_2_delay')
- board.get_board_config(self.board_id).unobserve(self.fineAdc3Input, 'chip_3_delay')
- board.get_board_config(self.board_id).unobserve(self.fineAdc4Input, 'chip_4_delay')
- board.get_board_config(self.board_id).unobserve(self.coarseInput, 'th_delay')
- board.get_board_config(self.board_id).unobserve(self.totalAdc1Box, 'chip_1_delay')
- board.get_board_config(self.board_id).unobserve(self.totalAdc2Box, 'chip_2_delay')
- board.get_board_config(self.board_id).unobserve(self.totalAdc3Box, 'chip_3_delay')
- board.get_board_config(self.board_id).unobserve(self.totalAdc4Box, 'chip_4_delay')
- board.get_board_config(self.board_id).unobserve(self.totalAdc1Box, 'th_delay')
- board.get_board_config(self.board_id).unobserve(self.totalAdc2Box, 'th_delay')
- board.get_board_config(self.board_id).unobserve(self.totalAdc3Box, 'th_delay')
- board.get_board_config(self.board_id).unobserve(self.totalAdc4Box, 'th_delay')
- board.get_board_config(self.board_id).unobserve(self.adc1CoarseInput, 'adc_1_delay_individual')
- Elements.removeItem('no_board_{}'.format(self.board_id),
- [
- self.fineAdc1Input,
- self.fineAdc2Input,
- self.fineAdc3Input,
- self.fineAdc4Input,
- self.coarseInput,
- self.time_scan_button,
- self.adc1CoarseInputSwitch
- ])
- Elements.removeItem("start_time_scan_{}".format(self.board_id), self.time_scan_button)
- Elements.removeItem(['acquire_{}'.format(self.board_id), "start_time_scan_{}".format(self.board_id)], self.time_scan_button)
- super(timingPart, self).closeEvent(event)
- def on_adc_delay_changed(self):
- """
- Handler that gets called when an adc delay gets changed
- """
- try:
- board.get_board_config(self.board_id).set_delay(self.coarseInput.value())
- factors = [self.fineAdc1Input.value(), self.fineAdc2Input.value(),
- self.fineAdc3Input.value(), self.fineAdc4Input.value()]
- board.get_board_config(self.board_id).set_chip_delay([0, 1, 2, 3], factors)
- except board.BoardError as e:
- logging.error("ADC fine delay failed: {}".format(str(e)))
- bif.bk_status_readout(self.board_id)
- return
- class timingWidget(kcgw.KCGWidgets):
- """
- This is the container that holds the tab widget which contains the timing widgets for each board
- """
- def __init__(self, unique_id, parent=None):
- super(timingWidget, self).__init__()
- self.id = unique_id
- self.par = parent
- self.setWindowTitle("Timing")
- self.layout = QtGui.QHBoxLayout()
- self.setLayout(self.layout)
- self.widgets = {i: timingPart(i, self) for i in available_boards} # has to set parent with self because
- # otherwise the window does not get resized correctly upon enabling timescan
- if available_boards.multi_board:
- self.tabWidget = QtGui.QTabWidget()
- self.layout.addWidget(self.tabWidget)
- for id, widget in self.widgets.iteritems():
- self.tabWidget.addTab(widget, available_boards.get_board_name_from_id(id))
- else:
- self.single_board_widget = self.widgets.values()[0]
- self.layout.addWidget(self.single_board_widget)
- def adjustSizeForTimeScan(self):
- """
- Adjust the size of the widget to accomodate the time_scan part
- :return:
- """
- # self.parentWindow = self.parent().parent().parent().parent() # one up is stacked widget, second up is
- # tab widget, third up is timingWidget fourh up is KCGWSubWindow (the actual window)
- QtCore.QCoreApplication.processEvents()
- if self.parent().windowState() & QtCore.Qt.WindowMaximized:
- self.parent().setWindowState(QtCore.Qt.WindowMaximized)
- else:
- # self.parent().resize(self.minimumSizeHint().width() * 1.2, self.minimumSizeHint().height()*1.1)
- self.parent().adjustSize()
- def closeEvent(self, event):
- global __widget_id__
- __widget_id__ = None
- for widget in self.widgets.values():
- widget.closeEvent(event)
- del self.par.widgets[self.id]
- super(timingWidget, self).closeEvent(event)
- def addTimingWidget():
- """
- Add this widget to the gui.
- This function will actually open the subwindow.
- :return: -
- """
- global __widget_id__
- if __widget_id__:
- global_objects.get_global('area').widgets[__widget_id__].setFocus()
- else:
- nid = kcgw.idg.genid()
- __widget_id__ = nid
- w = timingWidget(nid, global_objects.get_global('area'))
- global_objects.get_global('area').newWidget(w, tr("Heading", "Timing"), nid, widget_type=4, minSize=True) #TODO: proper type
- kcgw.register_widget(QtGui.QIcon(config.install_path + config.timingIcon), tr("Heading", "Timing"), addTimingWidget, "Ctrl+T")
|