Esempio n. 1
0
class Detector(MeasElement):
    """Element for selecting detector distance, depending on selector."""

    CACHE_KEY = 'detector/presets'
    SORT_KEY = lambda self, x: num_sort(x)
    LABEL = 'Detector'

    _allvalues = None

    def clientUpdate(self, client):
        self._allvalues = client.getDeviceParam(*self.CACHE_KEY.split('/'))
        self._values = []

    def createWidget(self, parent, client):
        self.clientUpdate(client)
        self._widget = QComboBox(parent)
        self._updateWidget()
        self._widget.currentIndexChanged.connect(self._updateValue)
        return self._widget

    def _updateWidget(self):
        self._widget.clear()
        self._widget.addItems(self._values)
        if self.value in self._values:
            self._widget.setCurrentIndex(self._values.index(self.value))

    def otherChanged(self, eltype, value):
        if eltype == 'selector' and self._allvalues is not None:
            self._values = sorted(self._allvalues[value], key=self.SORT_KEY)
            if self.value not in self._values:
                if self._values:
                    self.value = self._values[0]
                else:
                    self.value = None
            if self._widget is not None:
                self._updateWidget()

    def _updateValue(self, index):
        self.value = self._values[index]
        self.changed.emit(self.value)
Esempio n. 2
0
class Chopper(MeasElement):
    """Element for selecting chopper TOF resolution."""

    CACHE_KEY = 'chopper/resolutions'
    SORT_KEY = lambda self, x: num_sort(x)
    LABEL = 'TOF dλ/λ'

    def createWidget(self, parent, client):
        resos = client.getDeviceParam(*self.CACHE_KEY.split('/'))
        self._values = ['off'] + ['%.1f%%' % v
                                  for v in (resos or [])] + ['manual']
        self._widget = QComboBox(parent)
        self._widget.addItems(self._values)
        if self.value is not None and self.value in self._values:
            self._widget.setCurrentIndex(self._values.index(self.value))
        elif self.value is None and self._values:
            self.value = self._values[0]
        self._widget.currentIndexChanged.connect(self._updateValue)
        return self._widget

    def _updateValue(self, index):
        self.value = self._values[index]
        self.changed.emit(self.value)
Esempio n. 3
0
class Collimation(ChoiceElement):
    CACHE_KEY = 'collimation/mapping'
    SORT_KEY = lambda self, x: num_sort(x)
    LABEL = 'Collimation'
Esempio n. 4
0
class Selector(ChoiceElement):
    CACHE_KEY = 'selector/mapping'
    SORT_KEY = lambda self, x: num_sort(x)
    LABEL = 'Selector'
Esempio n. 5
0
class SamplePos(ChoiceElement):
    CACHE_KEY = 'sample_pos/presets'
    SORT_KEY = lambda self, x: num_sort(x)
    LABEL = 'Sample position'
Esempio n. 6
0
class Resolution(ChoiceElement):
    CACHE_KEY = 'resolution/mapping'
    SORT_KEY = lambda self, x: num_sort(x)
    LABEL = 'Resolution'