Skip to content

Commit

Permalink
scanwidget: handle min, max, suffix (closes #352)
Browse files Browse the repository at this point in the history
jordens authored and sbourdeauducq committed Mar 28, 2016
1 parent 9de11dd commit b04b5c8
Showing 2 changed files with 54 additions and 14 deletions.
17 changes: 9 additions & 8 deletions artiq/gui/entries.py
Original file line number Diff line number Diff line change
@@ -139,20 +139,20 @@ def __init__(self, procdesc, state):

scale = procdesc["scale"]

def apply_properties(spinbox):
spinbox.setDecimals(procdesc["ndecimals"])
def apply_properties(widget):
widget.setDecimals(procdesc["ndecimals"])
if procdesc["global_min"] is not None:
spinbox.setMinimum(procdesc["global_min"]/scale)
widget.setMinimum(procdesc["global_min"]/scale)
else:
spinbox.setMinimum(float("-inf"))
widget.setMinimum(float("-inf"))
if procdesc["global_max"] is not None:
spinbox.setMaximum(procdesc["global_max"]/scale)
widget.setMaximum(procdesc["global_max"]/scale)
else:
spinbox.setMaximum(float("inf"))
widget.setMaximum(float("inf"))
if procdesc["global_step"] is not None:
spinbox.setSingleStep(procdesc["global_step"]/scale)
widget.setSingleStep(procdesc["global_step"]/scale)
if procdesc["unit"]:
spinbox.setSuffix(" " + procdesc["unit"])
widget.setSuffix(" " + procdesc["unit"])

scanner = ScanWidget()
disable_scroll_wheel(scanner)
@@ -200,6 +200,7 @@ def update_npoints(value):
scanner.setStop(state["stop"]/scale)
apply_properties(start)
apply_properties(stop)
apply_properties(scanner)


class _ExplicitScan(LayoutWidget):
51 changes: 45 additions & 6 deletions artiq/gui/scanwidget.py
Original file line number Diff line number Diff line change
@@ -14,11 +14,12 @@ class ScanWidget(QtWidgets.QWidget):
stopChanged = QtCore.pyqtSignal(float)
numChanged = QtCore.pyqtSignal(int)

def __init__(self, zoomFactor=1.05, zoomMargin=.1, dynamicRange=1e9):
def __init__(self):
QtWidgets.QWidget.__init__(self)
self.zoomMargin = zoomMargin
self.dynamicRange = dynamicRange
self.zoomFactor = zoomFactor
self.zoomMargin = .1
self.zoomFactor = 1.05
self.dynamicRange = 1e9
self.suffix = ""

self.ticker = Ticker()

@@ -40,6 +41,7 @@ def __init__(self, zoomFactor=1.05, zoomMargin=.1, dynamicRange=1e9):
qfm.lineSpacing())

self._start, self._stop, self._num = None, None, None
self._min, self._max = None, None
self._axisView = None
self._offset, self._drag, self._rubber = None, None, None

@@ -68,14 +70,23 @@ def _setViewAxis(self, center, scale):
left = self.width()/2 - center*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):
val = self._clamp(val)
if self._start == val:
return
self._start = val
self.update()
self.startChanged.emit(val)

def setStop(self, val):
val = self._clamp(val)
if self._stop == val:
return
self._stop = val
@@ -89,6 +100,31 @@ def setNum(self, val):
self.update()
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):
center = (self._stop + self._start)/2
scale = self.width()*(1 - 2*self.zoomMargin)
@@ -207,8 +243,11 @@ def paintEvent(self, ev):

ticks, prefix, labels = self.ticker(self._pixelToAxis(0),
self._pixelToAxis(self.width()))
painter.drawText(0, 0, prefix)
painter.translate(0, lineSpacing)
rect = QtCore.QRect(0, 0, self.width(), 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):
t = self._axisToPixel(t)

0 comments on commit b04b5c8

Please sign in to comment.