class MainWindow(QtGui.QMainWindow):
'''The main window of the application.'''
- # Number of seconds that the plots display.
- BACKLOG = 30
-
# Update interval of the plots in milliseconds.
UPDATEINTERVAL = 100
self._plot_update_timer.setInterval(MainWindow.UPDATEINTERVAL)
self._plot_update_timer.timeout.connect(self._updatePlots)
+ settings.graph.backlog.changed.connect(self.on_setting_graph_backlog_changed)
+
QtCore.QTimer.singleShot(0, self._start_acquisition)
def _start_acquisition(self):
#actionLog.setIcon(icons.log)
#actionLog.triggered.connect(self.showLogPage)
- #actionPreferences = self.sideBar.addAction('Preferences')
- #actionPreferences.setCheckable(True)
- #actionPreferences.setIcon(icons.preferences)
- #actionPreferences.triggered.connect(self.showPreferencesPage)
+ actionPreferences = self.sideBar.addAction('Preferences')
+ actionPreferences.setCheckable(True)
+ actionPreferences.setIcon(icons.preferences)
+ actionPreferences.triggered.connect(self.showPreferencesPage)
# make the buttons at the top exclusive
self.actionGroup = QtGui.QActionGroup(self)
self.actionGroup.addAction(actionGraph)
#self.actionGroup.addAction(actionAdd)
#self.actionGroup.addAction(actionLog)
- #self.actionGroup.addAction(actionPreferences)
+ self.actionGroup.addAction(actionPreferences)
# show graph at startup
actionGraph.setChecked(True)
def _setup_preferencesPage(self):
self.preferencesPage = QtGui.QWidget(self)
- layout = QtGui.QVBoxLayout(self.preferencesPage)
- label = QtGui.QLabel('preferences page')
- layout.addWidget(label)
+ layout = QtGui.QGridLayout(self.preferencesPage)
+
+ layout.addWidget(QtGui.QLabel('<b>Graph</b>'), 0, 0)
+ layout.addWidget(QtGui.QLabel('Recording time (seconds):'), 1, 0)
+
+ spin = QtGui.QSpinBox(self)
+ spin.setMinimum(10)
+ spin.setMaximum(3600)
+ spin.setSingleStep(10)
+ spin.setValue(settings.graph.backlog.value())
+ spin.valueChanged[int].connect(settings.graph.backlog.setValue)
+ layout.addWidget(spin, 1, 1)
+
+ layout.setRowStretch(layout.rowCount(), 100)
def showPage(self, page):
self.stackedWidget.setCurrentIndex(self._pages.index(page))
def showPreferencesPage(self):
self.showPage(self.preferencesPage)
+ @QtCore.Slot(int)
+ def on_setting_graph_backlog_changed(self, bl):
+ for unit in self._plots:
+ plot = self._plots[unit]
+
+ # Remove the limits first, otherwise the range update would
+ # be ignored.
+ plot.view.setLimits(xMin=None, xMax=None)
+
+ # Now change the range, and then use the calculated limits
+ # (also see the comment in '_getPlot()').
+ plot.view.setXRange(-bl, 0, update=True)
+ r = plot.view.viewRange()
+ plot.view.setLimits(xMin=r[0][0], xMax=r[0][1])
+
def _getPlot(self, unit):
'''Looks up or creates a new plot for 'unit'.'''
# create a new plot for the unit
plot = self.plotwidget.addPlot()
plot.yaxis.setLabel(util.quantity_from_unit(unit), units=util.format_unit(unit))
- plot.view.setXRange(-MainWindow.BACKLOG, 0, update=False)
+ plot.view.setXRange(-settings.graph.backlog.value(), 0, update=False)
plot.view.setYRange(-1, 1)
plot.view.enableAutoRange(axis=pyqtgraph.ViewBox.YAxis)
# lock to the range calculated by the view using additional padding,
now = time.time()
# remove old samples
- l = now - MainWindow.BACKLOG
+ l = now - settings.graph.backlog.value()
while trace.samples and trace.samples[0][0] < l:
trace.samples.pop(0)
'''Signal emitted when the setting has changed.'''
changed = QtCore.Signal(object)
- def __init__(self, key, default=None):
+ def __init__(self, key, default=None, conv=None):
+ '''Initializes the Settings object.
+
+ :param key: The key of the used 'QSettings' object.
+ :param default: Value returned if the setting doesn't already exist.
+ :param conv: Function used to convert the setting to the correct type.
+ '''
+
super(self.__class__, self).__init__()
self._key = key
self._default = default
+ self._conv = conv
self._value = None
def value(self):
s = QtCore.QSettings()
- self._value = s.value(self._key, self._default)
+ v = s.value(self._key, self._default)
+ self._value = self._conv(v) if self._conv else v
return self._value
@QtCore.Slot(object)
mainwindow.size = Setting('mainwindow/size', QtCore.QSize(900, 550))
mainwindow.pos = Setting('mainwindow/pos')
globals()['mainwindow'] = mainwindow
+
+ graph = _SettingsGroup()
+ graph.backlog = Setting('graph/backlog', 30, conv=int)
+ globals()['graph'] = graph