Store the last used port and use it as default.

When opening a port for the first time the dropdown text will be blank (forcing you to use a port instead of accidentally selecting the first port in the list) but thereafter it will show the previously used port.
This commit is contained in:
Gerrit Vermeulen 2013-12-11 11:32:52 +02:00 committed by Raoul Snyman
commit 1db68ebd65
2 changed files with 6 additions and 0 deletions

View File

@ -209,6 +209,9 @@ class ConnectDialog(QtGui.QDialog, UiConnectDialog):
def get_hardware_handshake(self): def get_hardware_handshake(self):
return self.hardware_checkbox.isChecked() return self.hardware_checkbox.isChecked()
def set_port(self, port):
self.port_edit.setEditText(port)
def update_port_combobox(self): def update_port_combobox(self):
self.port_edit.clear() self.port_edit.clear()
ports = [] ports = []

View File

@ -201,11 +201,14 @@ class MainWindow(QtGui.QMainWindow, UiMainWindow):
def on_open_action_triggered(self): def on_open_action_triggered(self):
self.connect_dialog.update_port_combobox() self.connect_dialog.update_port_combobox()
settings = QtCore.QSettings()
self.connect_dialog.set_port(unicode(settings.value(u'previous-port', u'').toString()))
if self.connect_dialog.exec_() == QtGui.QDialog.Accepted: if self.connect_dialog.exec_() == QtGui.QDialog.Accepted:
if not self.device_closed: if not self.device_closed:
self.device_closed = True self.device_closed = True
self.device.close() self.device.close()
try: try:
settings.setValue(u'previous-port', self.connect_dialog.get_port())
self.device = Serial( self.device = Serial(
port=self.connect_dialog.get_port(), port=self.connect_dialog.get_port(),
baudrate=self.connect_dialog.get_baud(), baudrate=self.connect_dialog.get_baud(),