]> sigrok.org Git - sigrok-meter.git/commitdiff
Allow saving the log messages to a file.
authorJens Steinhauser <redacted>
Fri, 16 Oct 2015 11:41:07 +0000 (13:41 +0200)
committerJens Steinhauser <redacted>
Sun, 18 Oct 2015 15:32:36 +0000 (17:32 +0200)
mainwindow.py
settings.py

index a28e15c5990e53e1893d7f7a25ae37db5250c03f..be39a4ec59f31a5ffb23efb51412d07682a1493b 100644 (file)
@@ -273,15 +273,19 @@ class MainWindow(QtGui.QMainWindow):
         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)
@@ -498,6 +502,26 @@ class MainWindow(QtGui.QMainWindow):
             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('''\
index c779ce460e5035a3dba743165274df6d86bb8c14..a04b0eba84fce6fecbf7e4612209db9073d6858f 100644 (file)
@@ -114,4 +114,5 @@ def init():
     logging.level = Setting('logging/level', _default_loglevel,
         s=_s_loglevel, d=_d_loglevel)
     logging.lines = Setting('logging/lines', 1000, d=int)
+    logging.filename = Setting('logging/filename', '')
     globals()['logging'] = logging