## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
-## along with this program; if not, write to the Free Software
-## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+## along with this program; if not, see <http://www.gnu.org/licenses/>.
##
import acquisition
pyqtgraph = qtcompat.pyqtgraph
class EmptyMessageListView(QtGui.QListView):
- '''List view that shows a message if the model im empty.'''
+ '''List view that shows a message if the model is empty.'''
def __init__(self, message, parent=None):
super(self.__class__, self).__init__(parent)
actionPreferences.setIcon(icons.preferences)
actionPreferences.triggered.connect(self.showPreferencesPage)
- # make the buttons at the top exclusive
+ # 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)
- # show graph at startup
+ # Show graph at startup.
actionGraph.setChecked(True)
- # fill space between buttons on the top and on the bottom
+ # Fill space between buttons on the top and on the bottom.
fill = QtGui.QWidget(self)
fill.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding)
self.sideBar.addWidget(fill)
layout.addWidget(label)
def _setup_logPage(self):
+ self.logPage = QtGui.QWidget(self)
+ layout = QtGui.QVBoxLayout(self.logPage)
+
self.logView = QtGui.QListView(self)
self.logView.setModel(self.logModel)
self.logView.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.logView.setSelectionMode(QtGui.QAbstractItemView.NoSelection)
-
- self.logPage = QtGui.QWidget(self)
- layout = QtGui.QVBoxLayout(self.logPage)
layout.addWidget(self.logView)
+ btn = QtGui.QPushButton('Save to file...', self)
+ btn.clicked.connect(self.on_save_log_clicked)
+ layout.addWidget(btn)
+
def _setup_preferencesPage(self):
self.preferencesPage = QtGui.QWidget(self)
layout = QtGui.QGridLayout(self.preferencesPage)
if unit in self._plots:
return self._plots[unit]
- # create a new plot for the 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(-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,
- # looks nicer this way
+ # Lock to the range calculated by the view using additional padding,
+ # looks nicer this way.
r = plot.view.viewRange()
plot.view.setLimits(xMin=r[0][0], xMax=r[0][1])
if key in self._curves:
return self._curves[key]
- # create a new curve
+ # Create a new curve.
curve = pyqtgraph.PlotDataItem(
antialias=True,
symbolPen=pyqtgraph.mkPen(QtGui.QColor(QtCore.Qt.black)),
def _updatePlots(self):
'''Updates all plots.'''
- # loop over all devices and channels
+ # Loop over all devices and channels.
for row in range(self.model.rowCount()):
idx = self.model.index(row, 0)
deviceID = self.model.data(idx,
for unit, trace in traces.items():
now = time.time()
- # remove old samples
+ # Remove old samples.
l = now - settings.graph.backlog.value()
while trace.samples and trace.samples[0][0] < l:
trace.samples.pop(0)
# Mark all traces of all devices/channels with the same unit as the
# plot as "old" ('trace.new = False'). As soon as a new sample arrives
- # on one trace, the plot will be shown again
+ # on one trace, the plot will be shown again.
for row in range(self.model.rowCount()):
idx = self.model.index(row, 0)
traces = self.model.data(idx, datamodel.MeasurementDataModel.tracesRole)
self.actionStartStop.setText('Start Acquisition')
self.actionStartStop.setIcon(icons.start)
else:
- # before starting (again), remove all old samples and old curves
+ # Before starting (again), remove all old samples and old curves.
self.model.clear_samples()
for key in self._curves:
self.actionStartStop.setText('Stop Acquisition')
self.actionStartStop.setIcon(icons.stop)
+ @QtCore.Slot()
+ def on_save_log_clicked(self):
+ filename = QtGui.QFileDialog.getSaveFileName(self,
+ 'Save Log File', settings.logging.filename.value())
+
+ if not filename:
+ # User pressed 'cancel'.
+ return
+
+ try:
+ with open(filename, 'w') as f:
+ for line in self.logModel.stringList():
+ f.write(line)
+ f.write('\n')
+ except Exception as e:
+ QtGui.QMessageBox.critical(self, 'Error saving log file',
+ 'Unable to save the log messages:\n{}'.format(e))
+
+ settings.logging.filename.setValue(filename)
+
@QtCore.Slot()
def show_about(self):
text = textwrap.dedent('''\