Write ASCII to serial, indentation fixes

This commit is contained in:
Patrick Brückner 2013-12-10 08:29:31 +02:00
parent 5ed2c2e86b
commit f52b1b2bfe
2 changed files with 39 additions and 39 deletions

View File

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
import os
from PyQt4 import QtCore, QtGui
from serial import Serial, FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS, PARITY_NONE, PARITY_EVEN, PARITY_ODD, PARITY_MARK,\
PARITY_SPACE, STOPBITS_ONE, STOPBITS_ONE_POINT_FIVE, STOPBITS_TWO, SerialException
from serial.tools import list_ports
@ -117,14 +116,6 @@ class Ui_ConnectDialog(object):
self.buttonBox.accepted.connect(connectDialog.accept)
self.buttonBox.rejected.connect(connectDialog.reject)
def update_port_list(self):
self.portEdit.clear()
ports = []
for port in self.serial_ports():
ports.append(port)
ports.sort()
self.portEdit.addItems(ports)
def retranslateUi(self, connectDialog):
connectDialog.setWindowTitle(translate('ConnectDialog', 'Open Port'))
self.portLabel.setText(translate('ConnectDialog', 'Port:'))
@ -161,28 +152,6 @@ class Ui_ConnectDialog(object):
self.readingCheckBox.setText(translate('ConnectDialog', 'Reading'))
self.writingCheckBox.setText(translate('ConnectDialog', 'Writing'))
def serial_ports(self):
"""
Returns a generator for all available serial ports
"""
if os.name == 'nt':
# windows
for i in range(256):
try:
s = Serial(i)
s.close()
yield 'COM' + str(i + 1)
except SerialException:
pass
else:
# unix
try:
for port in list_ports.comports():
yield port[0]
except NameError:
# pyserial 2.6 cannot handle serial usb ports very well, in that case just do not provide a list
pass
class ConnectDialog(QtGui.QDialog, Ui_ConnectDialog):
def __init__(self):
@ -209,3 +178,33 @@ class ConnectDialog(QtGui.QDialog, Ui_ConnectDialog):
def getHardwareHandshake(self):
return self.hardwareCheckBox.isChecked()
def updatePortCombobox(self):
self.portEdit.clear()
ports = []
for port in self._getSerialPorts():
ports.append(port)
ports.sort()
self.portEdit.addItems(ports)
def _getSerialPorts(self):
"""
Returns a generator for all available serial ports
"""
if os.name == 'nt':
# windows
for i in range(256):
try:
s = Serial(i)
s.close()
yield 'COM' + str(i + 1)
except SerialException:
pass
else:
# unix
try:
for port in list_ports.comports():
yield port[0]
except NameError:
# pyserial 2.6 cannot handle serial usb ports very well, in that case just do not provide a list
pass

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import os
import threading
from PyQt4 import QtCore, QtGui
@ -166,7 +167,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
output = ''
def onOpenActionTriggered(self):
self.connectDialog.update_port_list()
self.connectDialog.updatePortCombobox()
if self.connectDialog.exec_() == QtGui.QDialog.Accepted:
if not self.deviceClosed:
self.deviceClosed = True
@ -240,7 +241,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.sendComboBox.insertItem(0, output)
self.sendComboBox.setCurrentIndex(0)
self.sendComboBox.clearEditText()
self.device.write(output + u'\r\n')
self.device.write(output + '\r\n')
def onContentsSizeChanged(self, size):
if self.followOutput:
@ -292,13 +293,13 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
style = u'%sbackground-color: %s; ' % (style, highlight.background)
break
if style:
try:
output = u'<div style="%s">%s</div>' % (style, unicode(output, u'utf-8'))
except TypeError:
output = u'<div style="%s">%s</div>' % (style, output)
try:
output = u'<div style="%s">%s</div>' % (style, unicode(output, u'utf-8'))
except TypeError:
output = u'<div style="%s">%s</div>' % (style, output)
else:
output = u'<div>%s</div>' % output
return output
return output
def saveHighlights(self, highlights):
settings = QtCore.QSettings()