return '{:f}'.format(mag)
def getItem(self, device, channel):
- '''Returns the item for the device + channel combination from the model,
- or creates a new item if no existing one matches.'''
+ '''Return the item for the device + channel combination from the
+ model, or create a new item if no existing one matches.'''
- # unique identifier for the device + channel
- # TODO: isn't there something better?
+ # Unique identifier for the device + channel.
+ # TODO: Isn't there something better?
uid = (
device.vendor,
device.model,
channel.index
)
- # find the correct item in the model
+ # Find the correct item in the model.
for row in range(self.rowCount()):
item = self.item(row)
rid = item.data(MeasurementDataModel._idRole)
- rid = tuple(rid) # PySide returns a list
+ rid = tuple(rid) # PySide returns a list.
if uid == rid:
return item
- # nothing found, create a new item
+ # Nothing found, create a new item.
desc = '{} {}, channel "{}"'.format(
device.vendor, device.model, channel.name)
@QtCore.Slot(object, object, object)
def update(self, device, channel, data):
- '''Updates the data for the device (+channel) with the most recent
+ '''Update the data for the device (+channel) with the most recent
measurement from the given payload.'''
item = self.getItem(device, channel)
'''Delegate to show the data items from a MeasurementDataModel.'''
def __init__(self, parent, font):
- '''Initializes the delegate.
+ '''Initialize the delegate.
:param font: Font used for the description text, the value is drawn
with a slightly bigger and bold variant of the font.
value, unit = index.data(QtCore.Qt.DisplayRole)
desc = index.data(MeasurementDataModel.descRole)
- # description in the top left corner
+ # Description in the top left corner.
painter.setFont(self._nfont)
p = options.rect.topLeft()
p += QtCore.QPoint(self._nfontheight, 2 * self._nfontheight)
painter.setFont(self._bfont)
- # value about in the center
+ # Value about in the center.
p = options.rect.center()
p += QtCore.QPoint(-3 * self._space_width, self._nfontheight)
rect = QtCore.QRect(0, 0, self._value_width, 2 * self._nfontheight)
rect.moveCenter(p)
painter.drawText(rect, QtCore.Qt.AlignRight, value)
- # unit right of the value
+ # Unit right of the value.
rect.moveLeft(rect.right())
rect.adjust(self._space_width, 0, 0, 0)
painter.drawText(rect, QtCore.Qt.AlignLeft, unit)
def setup_ui(self):
self.setWindowTitle('sigrok-meter')
- # resizing the listView below will increase this again
+ # Resizing the listView below will increase this again.
self.resize(10, 10)
p = os.path.abspath(os.path.dirname(__file__))
def show_about(self):
text = textwrap.dedent('''\
<div align="center">
- <b>sigrok-meter</b><br/>
- 0.1.0<br/>
- Using libsigrok {} (lib version {}).<br/>
+ <b>sigrok-meter 0.1.0</b><br/><br/>
+ Using libsigrok {} (lib version {}).<br/><br/>
<a href='http://www.sigrok.org'>
http://www.sigrok.org</a><br/>
<br/>
+ License: GNU GPL, version 3 or later<br/>
+ <br/>
This program comes with ABSOLUTELY NO WARRANTY;<br/>
for details visit
<a href='http://www.gnu.org/licenses/gpl.html'>
@QtCore.Slot(object, int, int)
def modelRowsInserted(self, parent, start, end):
- '''Resizes the list view to the size of the content.'''
-
+ '''Resize the list view to the size of the content.'''
rows = self.model.rowCount()
dh = self.delegate.sizeHint().height()
self.listView.setMinimumHeight(dh * rows)
_QtCore.Signal = _QtCore.pyqtSignal
_QtCore.Slot = _QtCore.pyqtSlot
except:
- sys.stderr.write('import of PyQt4 failed, using PySide\n')
+ sys.stderr.write('Import of PyQt4 failed, using PySide,\n')
import PySide.QtCore as _QtCore
import PySide.QtGui as _QtGui
QtGui = qtcompat.QtGui
class SamplingThread(QtCore.QObject):
- '''A class that handles the reception of sigrok packets in the background.'''
+ '''Class that handles the reception of sigrok packets in the background.'''
class Worker(QtCore.QObject):
'''Helper class that does the actual work in another thread.'''
self.sampling = False
def parse_configstring(self, cs):
- '''Dissects a config string and returns the options as a
+ '''Dissect a config string and return the options as a
dictionary.'''
def parse_option(k, v):
return dict(opts)
def parse_driverstring(self, ds):
- '''Dissects the driver string and returns a tuple consiting of
+ '''Dissect the driver string and return a tuple consisting of
the driver name and the options (as a dictionary).'''
m = re.match('(?P<name>[^:]+)(?P<opts>(:[^:=]+=[^:=]+)*)$', ds)
def start_sampling(self):
devices = []
for (ds, cs) in self.drivers:
- # process driver string
+ # Process driver string.
try:
(name, opts) = self.parse_driverstring(ds)
if not name in self.context.drivers:
- raise RuntimeError('No driver called "{}".'.format(name))
+ raise RuntimeError('No driver named "{}".'.format(name))
driver = self.context.drivers[name]
devs = driver.scan(**opts)
'Error processing driver string:\n{}'.format(e))
return
- # process configuration string
+ # Process configuration string.
try:
cfgs = self.parse_configstring(cs)
for k, v in cfgs.items():
# TODO: find a device with multiple channels in one packet
channel = packet.payload.channels[0]
- # the most recent value
+ # The most recent value.
value = packet.payload.data[0][-1]
self.measured.emit(device, channel,
(value, packet.payload.unit, packet.payload.mq_flags))
- # signal used to start the worker across threads
+ # Signal used to start the worker across threads.
_start_signal = QtCore.Signal()
def __init__(self, context, drivers):
self._start_signal.connect(self.worker.start_sampling)
- # expose the signals of the worker
+ # Expose the signals of the worker.
self.measured = self.worker.measured
self.error = self.worker.error
self.thread.start()
def start(self):
- '''Starts sampling'''
+ '''Start sampling.'''
self._start_signal.emit()
def stop(self):
- '''Stops sampling and the background thread.'''
+ '''Stop sampling and stop the background thread.'''
self.worker.stop_sampling()
self.thread.quit()
self.thread.wait()
#!/usr/bin/env python
-
##
## This file is part of the sigrok-meter project.
##
CONFIG is applied to the nth DRIVER. If there are more drivers
than configs, the remaining drivers use the default configuration.
- examples:
+ Examples:
%(prog)s --driver tecpel-dmm-8061-ser:conn=/dev/ttyUSB0
args = parser.parse_args()
if len(args.config) > len(args.driver):
- sys.exit('error: more configurations than drivers given')
+ sys.exit('Error: More configurations than drivers given.')
- # merge drivers and configurations into a list of tuples
+ # Merge drivers and configurations into a list of tuples.
setattr(args, 'drivers', [])
if not args.driver:
args.drivers = default_drivers
- sys.stderr.write('no driver given, using demo driver\n')
+ sys.stderr.write('No driver given, using demo driver.\n')
if args.driver:
args.config.extend([''] * (len(args.driver) - len(args.config)))
args.drivers = zip(args.driver, args.config)
loglevel = sr.LogLevel.get(args.loglevel)
context.log_level = loglevel
except:
- sys.exit('error: invalid log level')
+ sys.exit('Error: invalid log level.')
app = QtGui.QApplication([])
s = mainwindow.MainWindow(context, args.drivers)