def __init__(self, hostname, port=9998, interval=.1, alarm=None): # run the base class constructor super().__init__() # initialize the connection self.hostname = hostname self.port = port self.initialize() # set some properties self.setWindowTitle(hostname) self.setKeepDataAspectRatio(True) self.setColormap(normalization='log') self.setYAxisInverted(True) self.hasImage = False self.alarm = alarm self.waiting_for_frame = False self.latest_request = time.time() # a periodic timer triggers the update self.timer = qt.QTimer(self) self.timer.setInterval(interval * 1000.0) self.timer.timeout.connect(self._update) self.timer.start() # Display mouseover position info posInfo = [ ('X', lambda x, y: int(x)), ('Y', lambda x, y: int(y)), ('Data', self._getActiveImageValue)] self._positionWidget = tools.PositionInfo(plot=self, converters=posInfo) self.statusBar().addWidget(self._positionWidget)
def testCustomConverters(self): """Test PositionInfo with custom converters""" converters = [('Coords', lambda x, y: (int(x), int(y))), ('Radius', lambda x, y: numpy.sqrt(x * x + y * y)), ('Angle', lambda x, y: numpy.degrees(numpy.arctan2(y, x)))] positionWidget = tools.PositionInfo(plot=self.plot, converters=converters) self._test(positionWidget, ('Coords', 'Radius', 'Angle'))
def testFailingConverters(self): """Test PositionInfo with failing custom converters""" def raiseException(x, y): raise RuntimeError() positionWidget = tools.PositionInfo(plot=self.plot, converters=[('Exception', raiseException)]) self._test(positionWidget, ['Exception'], error=2)
def testUpdate(self): """Test :meth:`PositionInfo.updateInfo`""" calls = [] def update(calls, x, y): # Get number of calls calls.append((x, y)) return len(calls) positionWidget = tools.PositionInfo( plot=self.plot, converters=[('Call count', functools.partial(update, calls))]) positionWidget.updateInfo() self.assertEqual(len(calls), 1)
def testDefaultConverters(self): """Test PositionInfo with default converters""" positionWidget = tools.PositionInfo(plot=self.plot) self._test(positionWidget, ('X', 'Y'))