Merge lp:~madmuffin/colourterm/autocomplete_ports into lp:colourterm

Proposed by Patrick Brueckner
Status: Merged
Merged at revision: 2
Proposed branch: lp:~madmuffin/colourterm/autocomplete_ports
Merge into: lp:colourterm
Diff against target: 125 lines (+45/-13)
2 files modified
colourterm/connectdialog.py (+37/-7)
colourterm/mainwindow.py (+8/-6)
To merge this branch: bzr merge lp:~madmuffin/colourterm/autocomplete_ports
Reviewer Review Type Date Requested Status
Raoul Snyman Approve
Patrick Brueckner (community) Approve
Review via email: mp+198046@code.launchpad.net

Description of the change

Autocomplete Ports using pyserials tools-method. Requires pyserial 2.6 or higher.

To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

The new functions should be in ConnectDialog, not in Ui_ConnectDialog. Additionally, the method names should match the naming conventions of the rest of the methods in the class.

review: Needs Fixing
Revision history for this message
Patrick Brueckner (madmuffin) wrote :

Please re-review.

review: Needs Resubmitting
Revision history for this message
Patrick Brueckner (madmuffin) :
review: Approve
Revision history for this message
Raoul Snyman (raoul-snyman) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'colourterm/connectdialog.py'
2--- colourterm/connectdialog.py 2013-12-05 14:16:09 +0000
3+++ colourterm/connectdialog.py 2013-12-10 06:29:57 +0000
4@@ -1,8 +1,9 @@
5 # -*- coding: utf-8 -*-
6-
7+import os
8 from PyQt4 import QtCore, QtGui
9-from serial import FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS, PARITY_NONE, PARITY_EVEN, PARITY_ODD, PARITY_MARK,\
10- PARITY_SPACE, STOPBITS_ONE, STOPBITS_ONE_POINT_FIVE, STOPBITS_TWO
11+from serial import Serial, FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS, PARITY_NONE, PARITY_EVEN, PARITY_ODD, PARITY_MARK,\
12+ PARITY_SPACE, STOPBITS_ONE, STOPBITS_ONE_POINT_FIVE, STOPBITS_TWO, SerialException
13+from serial.tools import list_ports
14
15 from colourterm import fromUtf8, translate
16
17@@ -36,9 +37,9 @@
18 self.portLabel = QtGui.QLabel(connectDialog)
19 self.portLabel.setObjectName(fromUtf8('portLabel'))
20 self.deviceLayout.addWidget(self.portLabel, 0, 0, 1, 1)
21- self.portEdit = QtGui.QLineEdit(connectDialog)
22- self.portEdit.setText(fromUtf8('/dev/ttyUSB0'))
23+ self.portEdit = QtGui.QComboBox(connectDialog)
24 self.portEdit.setObjectName(fromUtf8('portEdit'))
25+ self.portEdit.setEditable(True)
26 self.deviceLayout.addWidget(self.portEdit, 0, 1, 1, 1)
27 self.baudLabel = QtGui.QLabel(connectDialog)
28 self.baudLabel.setObjectName(fromUtf8('baudLabel'))
29@@ -151,7 +152,6 @@
30 self.readingCheckBox.setText(translate('ConnectDialog', 'Reading'))
31 self.writingCheckBox.setText(translate('ConnectDialog', 'Writing'))
32
33-
34 class ConnectDialog(QtGui.QDialog, Ui_ConnectDialog):
35
36 def __init__(self):
37@@ -159,7 +159,7 @@
38 self.setupUi(self)
39
40 def getPort(self):
41- return unicode(self.portEdit.text())
42+ return unicode(self.portEdit.currentText())
43
44 def getBaud(self):
45 return int(unicode(self.baudComboBox.currentText()))
46@@ -178,3 +178,33 @@
47
48 def getHardwareHandshake(self):
49 return self.hardwareCheckBox.isChecked()
50+
51+ def updatePortCombobox(self):
52+ self.portEdit.clear()
53+ ports = []
54+ for port in self._getSerialPorts():
55+ ports.append(port)
56+ ports.sort()
57+ self.portEdit.addItems(ports)
58+
59+ def _getSerialPorts(self):
60+ """
61+ Returns a generator for all available serial ports
62+ """
63+ if os.name == 'nt':
64+ # windows
65+ for i in range(256):
66+ try:
67+ s = Serial(i)
68+ s.close()
69+ yield 'COM' + str(i + 1)
70+ except SerialException:
71+ pass
72+ else:
73+ # unix
74+ try:
75+ for port in list_ports.comports():
76+ yield port[0]
77+ except NameError:
78+ # pyserial 2.6 cannot handle serial usb ports very well, in that case just do not provide a list
79+ pass
80
81=== modified file 'colourterm/mainwindow.py'
82--- colourterm/mainwindow.py 2013-12-05 14:16:09 +0000
83+++ colourterm/mainwindow.py 2013-12-10 06:29:57 +0000
84@@ -1,4 +1,5 @@
85 # -*- coding: utf-8 -*-
86+import os
87 import threading
88
89 from PyQt4 import QtCore, QtGui
90@@ -166,6 +167,7 @@
91 output = ''
92
93 def onOpenActionTriggered(self):
94+ self.connectDialog.updatePortCombobox()
95 if self.connectDialog.exec_() == QtGui.QDialog.Accepted:
96 if not self.deviceClosed:
97 self.deviceClosed = True
98@@ -239,7 +241,7 @@
99 self.sendComboBox.insertItem(0, output)
100 self.sendComboBox.setCurrentIndex(0)
101 self.sendComboBox.clearEditText()
102- self.device.write(output + u'\r\n')
103+ self.device.write(output + '\r\n')
104
105 def onContentsSizeChanged(self, size):
106 if self.followOutput:
107@@ -291,13 +293,13 @@
108 style = u'%sbackground-color: %s; ' % (style, highlight.background)
109 break
110 if style:
111- try:
112- output = u'<div style="%s">%s</div>' % (style, unicode(output, u'utf-8'))
113- except TypeError:
114- output = u'<div style="%s">%s</div>' % (style, output)
115+ try:
116+ output = u'<div style="%s">%s</div>' % (style, unicode(output, u'utf-8'))
117+ except TypeError:
118+ output = u'<div style="%s">%s</div>' % (style, output)
119 else:
120 output = u'<div>%s</div>' % output
121- return output
122+ return output
123
124 def saveHighlights(self, highlights):
125 settings = QtCore.QSettings()

Subscribers

People subscribed via source and target branches