+ self.delegate = MultimeterDelegate(self, self.font())
+ self.model = MeasurementDataModel(self)
+ self.model.rowsInserted.connect(self.modelRowsInserted)
+
+ self.setup_ui()
+
+ self.thread = thread
+ self.thread.measured.connect(self.model.update)
+ self.thread.error.connect(self.error)
+ self.thread.start()
+
+ def setup_ui(self):
+ self.setWindowTitle('sigrok-meter')
+ # resizing the listView below will increase this again
+ self.resize(10, 10)
+
+ p = os.path.abspath(os.path.dirname(__file__))
+ p = os.path.join(p, 'sigrok-logo-notext.png')
+ self.setWindowIcon(QtGui.QIcon(p))
+
+ actionQuit = QtGui.QAction(self)
+ actionQuit.setText('&Quit')
+ actionQuit.setIcon(QtGui.QIcon.fromTheme('application-exit'))
+ actionQuit.setShortcut('Ctrl+Q')
+ actionQuit.triggered.connect(self.close)
+
+ actionAbout = QtGui.QAction(self)
+ actionAbout.setText('&About')
+ actionAbout.setIcon(QtGui.QIcon.fromTheme('help-about'))
+ actionAbout.triggered.connect(self.show_about)
+
+ menubar = self.menuBar()
+ menuFile = menubar.addMenu('&File')
+ menuFile.addAction(actionQuit)
+ menuHelp = menubar.addMenu('&Help')
+ menuHelp.addAction(actionAbout)
+
+ self.listView = EmptyMessageListView('waiting for data...')
+ self.listView.setFrameShape(QtGui.QFrame.NoFrame)
+ self.listView.viewport().setBackgroundRole(QtGui.QPalette.Window)
+ self.listView.viewport().setAutoFillBackground(True)
+ self.listView.setMinimumWidth(260)
+ self.listView.setSelectionMode(QtGui.QAbstractItemView.NoSelection)
+ self.listView.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
+ self.listView.setVerticalScrollMode(QtGui.QAbstractItemView.ScrollPerPixel)
+ self.listView.setItemDelegate(self.delegate)
+ self.listView.setModel(self.model)
+ self.listView.setUniformItemSizes(True)
+ self.listView.setMinimumSize(self.delegate.sizeHint())
+
+ self.setCentralWidget(self.listView)
+ self.centralWidget().setContentsMargins(0, 0, 0, 0)
+
+ @QtCore.Slot()
+ def show_about(self):
+ text = textwrap.dedent('''\
+ <div align="center">
+ <b>sigrok-meter</b><br/>
+ 0.1.0<br/>
+ Using libsigrok {} (lib version {}).<br/>
+ <a href='http://www.sigrok.org'>
+ http://www.sigrok.org</a><br/>
+ <br/>
+ This program comes with ABSOLUTELY NO WARRANTY;<br/>
+ for details visit
+ <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()))
+
+ QtGui.QMessageBox.about(self, 'About sigrok-meter', text)
+
+ @QtCore.Slot(str)
+ def error(self, msg):
+ '''Error handler for the sampling thread.'''
+ QtGui.QMessageBox.critical(self, 'Error', msg)
+ self.close()
+
+ @QtCore.Slot(object, int, int)
+ def modelRowsInserted(self, parent, start, end):
+ '''Resizes the list view to the size of the content.'''
+
+ rows = self.model.rowCount()
+ dh = self.delegate.sizeHint().height()
+ self.listView.setMinimumHeight(dh * rows)
+
+if __name__ == '__main__':