'''Signal emmited in case of an error.'''
error = QtCore.Signal(str)
- def __init__(self, drivers, loglevel):
+ def __init__(self, context, drivers):
super(self.__class__, self).__init__()
- self.sampling = False
+ self.context = context
self.drivers = drivers
- self.context = sr.Context_create()
- self.context.log_level = loglevel
-
- self.sr_pkg_version = self.context.package_version
- self.sr_lib_version = self.context.lib_version
+ self.sampling = False
@QtCore.Slot()
def start_sampling(self):
# signal used to start the worker across threads
_start_signal = QtCore.Signal()
- def __init__(self, drivers, loglevel):
+ def __init__(self, context, drivers):
super(self.__class__, self).__init__()
- self.worker = self.Worker(drivers, loglevel)
+ self.worker = self.Worker(context, drivers)
self.thread = QtCore.QThread()
self.worker.moveToThread(self.thread)
self.thread.quit()
self.thread.wait()
- def sr_pkg_version(self):
- '''Returns the version number of the libsigrok package.'''
- return self.worker.sr_pkg_version
-
- def sr_lib_version(self):
- '''Returns the version number fo the libsigrok library.'''
- return self.worker.sr_lib_version
-
class MeasurementDataModel(QtGui.QStandardItemModel):
'''Model to hold the measured values.'''
class SigrokMeter(QtGui.QMainWindow):
'''The main window of the application.'''
- def __init__(self, thread):
+ def __init__(self, context, drivers):
super(SigrokMeter, self).__init__()
+ self.context = context
+
self.delegate = MultimeterDelegate(self, self.font())
self.model = MeasurementDataModel(self)
self.model.rowsInserted.connect(self.modelRowsInserted)
self.setup_ui()
- self.thread = thread
+ self.thread = SamplingThread(self.context, drivers)
self.thread.measured.connect(self.model.update)
self.thread.error.connect(self.error)
self.thread.start()
self.setCentralWidget(self.listView)
self.centralWidget().setContentsMargins(0, 0, 0, 0)
+ def closeEvent(self, event):
+ self.thread.stop()
+ event.accept()
+
@QtCore.Slot()
def show_about(self):
text = textwrap.dedent('''\
<a href='http://www.gnu.org/licenses/gpl.html'>
http://www.gnu.org/licenses/gpl.html</a>
</div>
- '''.format(self.thread.sr_pkg_version(), self.thread.sr_lib_version()))
+ '''.format(self.context.package_version, self.context.lib_version))
QtGui.QMessageBox.about(self, 'About sigrok-meter', text)
self.listView.setMinimumHeight(dh * rows)
if __name__ == '__main__':
- thread = SamplingThread(args['drivers'], args['loglevel'])
+ context = sr.Context_create()
+ context.log_level = args['loglevel']
app = QtGui.QApplication([])
- s = SigrokMeter(thread)
+ s = SigrokMeter(context, args['drivers'])
s.show()
- r = app.exec_()
- thread.stop()
- sys.exit(r)
+ sys.exit(app.exec_())