2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-12 21:26:37 +08:00

scanwidget: handle min, max, suffix (closes #352)

This commit is contained in:
Robert Jördens 2016-03-28 16:59:49 +02:00 committed by Sebastien Bourdeauducq
parent 9de11dd958
commit b04b5c8239
2 changed files with 54 additions and 14 deletions

View File

@ -139,20 +139,20 @@ class _RangeScan(LayoutWidget):
scale = procdesc["scale"] scale = procdesc["scale"]
def apply_properties(spinbox): def apply_properties(widget):
spinbox.setDecimals(procdesc["ndecimals"]) widget.setDecimals(procdesc["ndecimals"])
if procdesc["global_min"] is not None: if procdesc["global_min"] is not None:
spinbox.setMinimum(procdesc["global_min"]/scale) widget.setMinimum(procdesc["global_min"]/scale)
else: else:
spinbox.setMinimum(float("-inf")) widget.setMinimum(float("-inf"))
if procdesc["global_max"] is not None: if procdesc["global_max"] is not None:
spinbox.setMaximum(procdesc["global_max"]/scale) widget.setMaximum(procdesc["global_max"]/scale)
else: else:
spinbox.setMaximum(float("inf")) widget.setMaximum(float("inf"))
if procdesc["global_step"] is not None: if procdesc["global_step"] is not None:
spinbox.setSingleStep(procdesc["global_step"]/scale) widget.setSingleStep(procdesc["global_step"]/scale)
if procdesc["unit"]: if procdesc["unit"]:
spinbox.setSuffix(" " + procdesc["unit"]) widget.setSuffix(" " + procdesc["unit"])
scanner = ScanWidget() scanner = ScanWidget()
disable_scroll_wheel(scanner) disable_scroll_wheel(scanner)
@ -200,6 +200,7 @@ class _RangeScan(LayoutWidget):
scanner.setStop(state["stop"]/scale) scanner.setStop(state["stop"]/scale)
apply_properties(start) apply_properties(start)
apply_properties(stop) apply_properties(stop)
apply_properties(scanner)
class _ExplicitScan(LayoutWidget): class _ExplicitScan(LayoutWidget):

View File

@ -14,11 +14,12 @@ class ScanWidget(QtWidgets.QWidget):
stopChanged = QtCore.pyqtSignal(float) stopChanged = QtCore.pyqtSignal(float)
numChanged = QtCore.pyqtSignal(int) numChanged = QtCore.pyqtSignal(int)
def __init__(self, zoomFactor=1.05, zoomMargin=.1, dynamicRange=1e9): def __init__(self):
QtWidgets.QWidget.__init__(self) QtWidgets.QWidget.__init__(self)
self.zoomMargin = zoomMargin self.zoomMargin = .1
self.dynamicRange = dynamicRange self.zoomFactor = 1.05
self.zoomFactor = zoomFactor self.dynamicRange = 1e9
self.suffix = ""
self.ticker = Ticker() self.ticker = Ticker()
@ -40,6 +41,7 @@ class ScanWidget(QtWidgets.QWidget):
qfm.lineSpacing()) qfm.lineSpacing())
self._start, self._stop, self._num = None, None, None self._start, self._stop, self._num = None, None, None
self._min, self._max = None, None
self._axisView = None self._axisView = None
self._offset, self._drag, self._rubber = None, None, None self._offset, self._drag, self._rubber = None, None, None
@ -68,7 +70,15 @@ class ScanWidget(QtWidgets.QWidget):
left = self.width()/2 - center*scale left = self.width()/2 - center*scale
self._setView(left, scale) self._setView(left, scale)
def _clamp(self, v):
if self._min is not None:
v = max(self._min, v)
if self._max is not None:
v = min(self._max, v)
return v
def setStart(self, val): def setStart(self, val):
val = self._clamp(val)
if self._start == val: if self._start == val:
return return
self._start = val self._start = val
@ -76,6 +86,7 @@ class ScanWidget(QtWidgets.QWidget):
self.startChanged.emit(val) self.startChanged.emit(val)
def setStop(self, val): def setStop(self, val):
val = self._clamp(val)
if self._stop == val: if self._stop == val:
return return
self._stop = val self._stop = val
@ -89,6 +100,31 @@ class ScanWidget(QtWidgets.QWidget):
self.update() self.update()
self.numChanged.emit(val) self.numChanged.emit(val)
def setMinimum(self, v):
self._min = v
self.setStart(self._start)
self.setStop(self._stop)
def setMaximum(self, v):
self._max = v
self.setStart(self._start)
self.setStop(self._stop)
def setDecimals(self, n):
# TODO
# the axis should always use compressed notation is useful
# do not:
# self.ticker.precision = n
pass
def setSingleStep(self, v):
# TODO
# use this (and maybe decimals) to snap to "nice" values when dragging
pass
def setSuffix(self, v):
self.suffix = v
def viewRange(self): def viewRange(self):
center = (self._stop + self._start)/2 center = (self._stop + self._start)/2
scale = self.width()*(1 - 2*self.zoomMargin) scale = self.width()*(1 - 2*self.zoomMargin)
@ -207,8 +243,11 @@ class ScanWidget(QtWidgets.QWidget):
ticks, prefix, labels = self.ticker(self._pixelToAxis(0), ticks, prefix, labels = self.ticker(self._pixelToAxis(0),
self._pixelToAxis(self.width())) self._pixelToAxis(self.width()))
painter.drawText(0, 0, prefix) rect = QtCore.QRect(0, 0, self.width(), lineSpacing)
painter.translate(0, lineSpacing) painter.drawText(rect, QtCore.Qt.AlignLeft, prefix)
painter.drawText(rect, QtCore.Qt.AlignRight, self.suffix)
painter.translate(0, lineSpacing + ascent)
for t, l in zip(ticks, labels): for t, l in zip(ticks, labels):
t = self._axisToPixel(t) t = self._axisToPixel(t)