Ejemplo n.º 1
0
 def __init__(self, parent, client):
     uipath = findResource('nicos_ess/loki/gui/ui_files/table.ui')
     Cmdlet.__init__(self, parent, client, uipath)
     self.measdef = self.meas_def_class()
     self.updateTable()
     for loop in LOOPS:
         self.outerLoop.addItem(loop)
     self.outerLoop.setCurrentIndex(0)
     client.experiment.connect(self.on_client_experiment)
     self.expandBtn = QToolButton()
     self.expandBtn.setIcon(QIcon(':/down'))
     self.expandBtn.setAutoRaise(True)
     self.expandBtn.clicked.connect(self.on_expandBtn_clicked)
     self.table.setCornerWidget(self.expandBtn)
Ejemplo n.º 2
0
 def __init__(self, parent, client, uifile):
     QWidget.__init__(self, parent)
     new_layout = QHBoxLayout()
     self.subwidget = QWidget(self)
     if uifile:
         uic.loadUi(uifile, self.subwidget)
     self.button = QToolButton(self)
     self.setButton('+')
     self.button.clicked.connect(self.on_button_click)
     new_layout.addWidget(self.subwidget)
     new_layout.addSpacerItem(QSpacerItem(15, 1, QSizePolicy.Fixed))
     new_layout.addWidget(self.button)
     new_layout.setContentsMargins(0, 0, 0, 0)
     self.setLayout(new_layout)
     for ch in self.subwidget.findChildren(NicosWidget):
         ch.setClient(client)
Ejemplo n.º 3
0
 def __init__(self, parent, client):
     uipath = findResource('nicos_mlz/kws1/gui/table.ui')
     Cmdlet.__init__(self, parent, client, uipath)
     self.measdef = self.meas_def_class(rtmode=False)
     self.rt_settings = RtConfigDialog.DEFAULT_SETTINGS.copy()
     self.rtConfBtn.setEnabled(False)
     self.updateTable()
     for loop in LOOPS:
         self.outerLoop.addItem(loop)
     self.outerLoop.setCurrentIndex(0)
     client.experiment.connect(self.on_client_experiment)
     self.expandBtn = QToolButton()
     self.expandBtn.setIcon(QIcon(':/down'))
     self.expandBtn.setAutoRaise(True)
     self.expandBtn.clicked.connect(self.on_expandBtn_clicked)
     self.table.setCornerWidget(self.expandBtn)
Ejemplo n.º 4
0
class MultiEntry(QWidget):
    addOrRemove = pyqtSignal()

    def __init__(self, parent, client, uifile):
        QWidget.__init__(self, parent)
        new_layout = QHBoxLayout()
        self.subwidget = QWidget(self)
        if uifile:
            uic.loadUi(uifile, self.subwidget)
        self.button = QToolButton(self)
        self.setButton('+')
        self.button.clicked.connect(self.on_button_click)
        new_layout.addWidget(self.subwidget)
        new_layout.addSpacerItem(QSpacerItem(15, 1, QSizePolicy.Fixed))
        new_layout.addWidget(self.button)
        new_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(new_layout)
        for ch in self.subwidget.findChildren(NicosWidget):
            ch.setClient(client)

    def setButton(self, plusminus):
        self.button.setText(plusminus)
        if plusminus == '+':
            self.button.setToolTip('Add another')
        else:
            self.button.setToolTip('Remove this')

    def on_button_click(self):
        self.addOrRemove.emit()
Ejemplo n.º 5
0
    def __init__(self, parent, client, options):
        LokiPanelBase.__init__(self, parent, client, options)
        loadUi(self,
               findResource('nicos_ess/loki/gui/ui_files/scriptbuilder.ui'))

        self.window = parent
        self.runBtn.setVisible(False)
        self.mapping = {}
        self.expertmode = self.mainwindow.expertmode

        self._cmdlet = self.sender()
        self._layout = self.frame.layout()
        self.index = self._layout.indexOf(self._cmdlet)

        self.initialise_connection_status_listeners()

        modules = options.get('modules', [])
        for module in modules:
            importString(module)  # should register cmdlets

        for cmdlet in all_cmdlets:

            def callback(on, cmdlet=cmdlet):
                inst = cmdlet(self, self.client)
                inst.cmdletUp.connect(self.on_cmdletUp)
                inst.cmdletDown.connect(self.on_cmdletDown)
                inst.cmdletRemove.connect(self.on_cmdletRemove)
                self.runBtn.setVisible(True)
                self.frame.layout().insertWidget(
                    self.frame.layout().count() - 2, inst)

            action = QAction(cmdlet.name, self)
            action.triggered.connect(callback)
            self.mapping.setdefault(cmdlet.category, []).append(action)

        for category in all_categories[::-1]:
            if category not in self.mapping:
                return
            toolbtn = QToolButton(self)
            toolbtn.setText(category)
            toolbtn.setPopupMode(QToolButton.InstantPopup)
            menu = QMenu(self)
            menu.addActions(self.mapping[category])
            toolbtn.setMenu(menu)
            self.btnLayout.insertWidget(1, toolbtn)
Ejemplo n.º 6
0
    def __init__(self, parent, client, options):
        Panel.__init__(self, parent, client, options)
        loadUi(self, self.ui)

        self.window = parent
        self.mapping = {}
        self.current_cmdlet = None
        self.expertmode = self.mainwindow.expertmode

        # collect values of all cmdlets that have been added
        # so that the common fields carry over to the next cmdlet
        self.value_collection = {}

        self.commandInput.history = self.cmdhistory
        self.commandInput.completion_callback = self.completeInput
        self.console = None

        client.initstatus.connect(self.on_client_initstatus)
        client.mode.connect(self.on_client_mode)
        client.simresult.connect(self.on_client_simresult)

        modules = options.get('modules', [])
        for module in modules:
            importString(module)  # should register cmdlets

        for cmdlet in all_cmdlets:
            action = QAction(cmdlet.name, self)

            def callback(on, cmdlet=cmdlet):
                self.selectCmdlet(cmdlet)

            action.triggered.connect(callback)
            self.mapping.setdefault(cmdlet.category, []).append(action)

        for category in all_categories[::-1]:
            if category not in self.mapping:
                continue
            toolbtn = QToolButton(self)
            toolbtn.setText(category)
            toolbtn.setPopupMode(QToolButton.InstantPopup)
            menu = QMenu(self)
            menu.addActions(self.mapping[category])
            toolbtn.setMenu(menu)
            self.btnLayout.insertWidget(1, toolbtn)
Ejemplo n.º 7
0
class MeasureTable(Cmdlet):
    name = 'Measurement'
    category = 'Measure'
    meas_def_class = MeasDef

    def __init__(self, parent, client):
        uipath = findResource('nicos_ess/loki/gui/ui_files/table.ui')
        Cmdlet.__init__(self, parent, client, uipath)
        self.measdef = self.meas_def_class()
        self.updateTable()
        for loop in LOOPS:
            self.outerLoop.addItem(loop)
        self.outerLoop.setCurrentIndex(0)
        client.experiment.connect(self.on_client_experiment)
        self.expandBtn = QToolButton()
        self.expandBtn.setIcon(QIcon(':/down'))
        self.expandBtn.setAutoRaise(True)
        self.expandBtn.clicked.connect(self.on_expandBtn_clicked)
        self.table.setCornerWidget(self.expandBtn)

    @pyqtSlot()
    def on_expandBtn_clicked(self):
        self.table.setMinimumSize(QSize(0, self.table.height() + 100))

    @pyqtSlot()
    def on_selSamples_clicked(self):
        if not self.client.isconnected:
            QMessageBox.warning(
                self, 'Error', 'You must be connected to '
                'a daemon to be able to select samples.')
            return
        dlg = SampleDialog(self, self.measdef, self.client)
        if dlg.exec_() != QDialog.Accepted:
            return
        self.measdef.samplefile = dlg.samplefile
        self.measdef.samples = dlg.toDefs()
        self.updateTable()

    @pyqtSlot()
    def on_selDetsets_clicked(self):
        if not self.client.isconnected:
            QMessageBox.warning(
                self, 'Error', 'You must be connected to '
                'a daemon to be able to select settings.')
            return
        dlg = DetsetDialog(self, self.measdef, self.client)
        if dlg.exec_() != QDialog.Accepted:
            return
        self.measdef.detsets = dlg.toDefs()
        self.updateTable()

    @pyqtSlot()
    def on_selDevices_clicked(self):
        if not self.client.isconnected:
            QMessageBox.warning(
                self, 'Error', 'You must be connected to '
                'a daemon to be able to select devices.')
            return
        dlg = DevicesDialog(self, self.measdef, self.client)
        if dlg.exec_() != QDialog.Accepted:
            return
        self.measdef.devices = dlg.toDefs()
        self.updateTable()

    @pyqtSlot(str)
    def on_outerLoop_currentIndexChanged(self, oloop):
        self.middleLoop.clear()
        for loop in LOOPS:
            if loop != oloop:
                self.middleLoop.addItem(loop)
        self.middleLoop.setCurrentIndex(0)

    @pyqtSlot(str)
    def on_middleLoop_currentIndexChanged(self, mloop):
        oloop = self.outerLoop.currentText()
        self.innerLoop.clear()
        for loop in LOOPS:
            if loop != mloop and loop != oloop:
                self.innerLoop.addItem(loop)
                self.measdef.loops = [oloop, mloop, loop]
                if mloop:
                    self.updateTable()
                break
        self.innerLoop.setCurrentIndex(0)

    def on_client_experiment(self, data):
        # reset everything
        self._clearTable()

    def _clearTable(self):
        self.measdef = self.meas_def_class(self.measdef.loops)
        self.updateTable()

    def setValues(self, values):
        pass

    def updateTable(self):
        self.table.setRowCount(0)
        table = self.measdef.getTable()
        if not table:
            return
        first = table[0]
        self.table.setRowCount(len(table))
        self.table.setColumnCount(len(first))
        self.table.setHorizontalHeaderLabels(first.keys())
        total_time = 0
        for i, entry in enumerate(table):
            for j, element in enumerate(entry.values()):
                item = QTableWidgetItem(element.getDispValue())
                self.table.setItem(i, j, item)
                if element.eltype == 'time':
                    total_time += element.getValue()
        self.table.resizeRowsToContents()
        self.totalTime.setText(formatDuration(total_time))
        self.changed()

    def generate(self, mode):
        out = []
        table = self.measdef.getTable()
        for entry in table:
            items = []
            sample = None
            count_time = 0
            devices_args = []
            is_trans = False
            for (k, v) in entry.items():
                if isinstance(v, Sample):
                    sample = v.getValue()
                    count_time = v.extra[1]
                elif isinstance(v, Device):
                    devices_args.append(k)
                    devices_args.append(repr(v.getValue()))
                elif isinstance(v, Mode):
                    is_trans = v.getValue() == Mode.VALUES[0]

            items.append(f"\n##### Measurement {len(out) + 1}")
            if sample:
                items.append(f'# SelectSample("{sample}")')
            if devices_args:
                args = ", ".join(devices_args)
                items.append(f"maw({args})")
            if is_trans:
                items.append("# enable_trans()")
            else:
                items.append("# enable_sans()")

            items.append(f"# loki_count(t={count_time})")
            out.append('\n'.join(items))
        return '\n'.join(out)
Ejemplo n.º 8
0
class MeasureTable(Cmdlet):

    name = 'Measurement'
    category = 'Measure'

    meas_def_class = MeasDef

    def __init__(self, parent, client):
        uipath = findResource('nicos_mlz/kws1/gui/table.ui')
        Cmdlet.__init__(self, parent, client, uipath)
        self.measdef = self.meas_def_class(rtmode=False)
        self.rt_settings = RtConfigDialog.DEFAULT_SETTINGS.copy()
        self.rtConfBtn.setEnabled(False)
        self.updateTable()
        for loop in LOOPS:
            self.outerLoop.addItem(loop)
        self.outerLoop.setCurrentIndex(0)
        client.experiment.connect(self.on_client_experiment)
        self.expandBtn = QToolButton()
        self.expandBtn.setIcon(QIcon(':/down'))
        self.expandBtn.setAutoRaise(True)
        self.expandBtn.clicked.connect(self.on_expandBtn_clicked)
        self.table.setCornerWidget(self.expandBtn)

    @pyqtSlot()
    def on_expandBtn_clicked(self):
        self.table.setMinimumSize(QSize(0, self.table.height() + 100))

    @pyqtSlot()
    def on_selSamples_clicked(self):
        if not self.client.isconnected:
            QMessageBox.warning(
                self, 'Error', 'You must be connected to '
                'a daemon to be able to select samples.')
            return
        dlg = SampleDialog(self, self.measdef, self.client)
        if dlg.exec_() != QDialog.Accepted:
            return
        self.measdef.samplefile = dlg.samplefile
        self.measdef.samples = dlg.toDefs()
        self.updateTable()

    @pyqtSlot()
    def on_selDetsets_clicked(self):
        if not self.client.isconnected:
            QMessageBox.warning(
                self, 'Error', 'You must be connected to '
                'a daemon to be able to select settings.')
            return
        dlg = DetsetDialog(self, self.measdef, self.client)
        if dlg.exec_() != QDialog.Accepted:
            return
        self.measdef.detsets = dlg.toDefs()
        self.updateTable()

    @pyqtSlot()
    def on_selDevices_clicked(self):
        if not self.client.isconnected:
            QMessageBox.warning(
                self, 'Error', 'You must be connected to '
                'a daemon to be able to select devices.')
            return
        dlg = DevicesDialog(self, self.measdef, self.client)
        if dlg.exec_() != QDialog.Accepted:
            return
        self.measdef.devices = dlg.toDefs()
        self.updateTable()

    @pyqtSlot(str)
    def on_outerLoop_currentIndexChanged(self, oloop):
        self.middleLoop.clear()
        for loop in LOOPS:
            if loop != oloop:
                self.middleLoop.addItem(loop)
        self.middleLoop.setCurrentIndex(0)

    @pyqtSlot(str)
    def on_middleLoop_currentIndexChanged(self, mloop):
        oloop = self.outerLoop.currentText()
        self.innerLoop.clear()
        for loop in LOOPS:
            if loop != mloop and loop != oloop:
                self.innerLoop.addItem(loop)
                self.measdef.loops = [oloop, mloop, loop]
                if mloop:
                    self.updateTable()
                break
        self.innerLoop.setCurrentIndex(0)

    def on_client_experiment(self, data):
        # reset everything
        self.rtBox.setChecked(False)
        self._clearTable()

    def on_rtBox_toggled(self, state):
        self.rtConfBtn.setEnabled(state)
        self._clearTable()

    def _clearTable(self):
        self.measdef = self.meas_def_class(self.rtBox.isChecked(),
                                           self.measdef.loops)
        self.updateTable()

    @pyqtSlot()
    def on_rtConfBtn_clicked(self):
        dlg = RtConfigDialog(self)
        dlg.setSettings(self.rt_settings)
        if not dlg.exec_():
            return
        self.rt_settings = dlg.getSettings()

    def getValues(self):
        return {}

    def setValues(self, values):
        pass

    def updateTable(self):
        self.table.setRowCount(0)
        table = self.measdef.getTable()
        if not table:
            return
        first = table[0]
        self.table.setRowCount(len(table))
        self.table.setColumnCount(len(first))
        self.table.setHorizontalHeaderLabels(first.keys())
        total_time = 0
        for i, entry in enumerate(table):
            for j, element in enumerate(entry.values()):
                item = QTableWidgetItem(element.getDispValue())
                self.table.setItem(i, j, item)
                if element.eltype == 'time':
                    total_time += element.getValue()
        self.table.resizeRowsToContents()
        if self.rtBox.isChecked():
            total_time = self.rt_settings['totaltime'] * len(table)
        self.totalTime.setText(formatDuration(total_time))
        self.changed()

    def generate(self, mode):
        out = []
        if self.measdef.samplefile is not None:
            out.append('run(%s)' % srepr(self.measdef.samplefile))
            out.append('')
        if self.rtBox.isChecked():
            out.append('SetupRealtime(%d, %d, %f, %s)' % (
                self.rt_settings['channels'],
                self.rt_settings['interval'] * (10**{
                    0: 0,
                    1: 3,
                    2: 6
                }[self.rt_settings['intervalunit']]),
                self.rt_settings['progq'],
                srepr(self.rt_settings['trigger']),
            ))
        else:
            out.append('SetupNormal()')
        table = self.measdef.getTable()
        # detect if we use a non-default value for these, and generate the
        # keywords only for these cases
        has_lenses = False
        has_chopper = False
        has_polarizer = False
        maxlen = {}
        for entry in table:
            for (k, v) in entry.items():
                vrepr = srepr(v.getValue())
                maxlen[k] = max(maxlen.get(k, 0), len(vrepr))
                if k == 'chopper' and v.getValue() != 'off':
                    has_chopper = True
                elif k == 'polarizer' and v.getValue() != 'out':
                    has_polarizer = True
                elif k == 'lenses' and v.getValue() != 'out-out-out':
                    has_lenses = True
        for entry in table:
            items = []
            for (k, v) in entry.items():
                if k == 'chopper' and not has_chopper:
                    continue
                if k == 'polarizer' and not has_polarizer:
                    continue
                if k == 'lenses' and not has_lenses:
                    continue
                items.append('%s=%-*s' % (k, maxlen[k], srepr(v.getValue())))
            out.append('kwscount(' + ', '.join(items) + ')')
        return '\n'.join(out)