3535from PyQt5 .QtGui import *
3636
3737# App name
38- APP_NAME = 'SumoManager v0.5.1 '
38+ APP_NAME = 'SumoManager v0.5.2 '
3939
4040# Firmware URLs
4141MICROPYTHON_URL = 'http://micropython.org/download'
@@ -64,8 +64,6 @@ def __init__(self):
6464 super ().__init__ ()
6565 self .initUI ()
6666
67- self .dialog_title = None
68- self .dialog_message = None
6967 self .connected_port = None
7068 self .update_config = False
7169 self .update_firmware = False
@@ -92,12 +90,14 @@ def initUI(self):
9290 self .wifi_select .addItems (['Network name' ])
9391 self .wifi_select .setEnabled (False )
9492 self .wifi_pwd_edit = QLineEdit ()
93+ self .wifi_pwd_edit .setEchoMode (QLineEdit .Password );
9594 self .wifi_pwd_edit .setPlaceholderText ("Password" )
9695
9796 # WiFi add button
9897 self .add_wifi_btn = QPushButton ('Add WiFi network' , self )
9998 self .add_wifi_btn .setCursor (QCursor (Qt .PointingHandCursor ))
10099 self .add_wifi_btn .clicked .connect (self .button_clicked )
100+ self .wifi_pwd_edit .returnPressed .connect (self .button_clicked )
101101
102102 # Add the statusbar into a toolbar
103103 self .tool_bar = self .addToolBar ('Main' )
@@ -133,6 +133,8 @@ def initUI(self):
133133 self .setCentralWidget (main_widget )
134134 self .show ()
135135 self .center ()
136+ # To lose focus on the textedit field
137+ self .setFocus ()
136138
137139 # Function to center the mainwindow on the screen
138140 def center (self ):
@@ -146,12 +148,12 @@ def center(self):
146148 def show_message (self , type , message ):
147149 self .status_bar .setCursor (QCursor (Qt .ArrowCursor ))
148150 if type == 'error' :
149- style = 'color: #d9534f ;'
151+ style = 'color: #d63634 ;'
150152 self .status_bar .setCursor (QCursor (Qt .PointingHandCursor ))
151153 elif type == 'warning' :
152- style = 'color: #f0ad4e ;'
154+ style = 'color: #e77e34 ;'
153155 elif type == 'info' :
154- style = 'color: #5cb85c ;'
156+ style = 'color: #1cc761 ;'
155157 else : # Unrecognized message type
156158 return
157159
@@ -170,15 +172,14 @@ def button_clicked(self):
170172 self .wifi_select .setStyleSheet ('background-color: #d9534f;' )
171173 return
172174 else : # When the network name is valid, remove the error
173- self .wifi_select .setStyleSheet ('background: rgba(212,212,255,0.035) ;' )
175+ self .wifi_select .setStyleSheet ('background-color: #2d3252 ;' )
174176
175177 # Disable adding another network until the current one is added
176178 self .update_config = True
177179
178180 # When mouse clicked clear the focus on the input fields
179181 def mousePressEvent (self , event ):
180182 # When the status bar is pressed
181- self .wifi_select .clearFocus ()
182183 self .wifi_pwd_edit .clearFocus ()
183184
184185 @pyqtSlot ()
@@ -190,7 +191,7 @@ def usb_action(self, data = None):
190191 self .wifi_select .addItems (data )
191192 self .wifi_select .setEnabled (True )
192193 self .show_message ('info' , 'Successfuly loaded WiFi networks' )
193- self .wifi_select .setStyleSheet ('background: #2d3252;' )
194+ self .wifi_select .setStyleSheet ('background-color : #2d3252;' )
194195 elif isinstance (data , str ):
195196 self .serial_image .setPixmap (QPixmap (USB_CONNECTED_IMG ))
196197 self .show_message ('warning' , 'Loading Wifi netwroks...' )
@@ -294,16 +295,17 @@ def run(self):
294295 # Close serial port
295296 board .close ()
296297 window .message .emit ('info' , 'Successfully updated firmware' )
298+ # Try to laod WiFi networks again
299+ window .connected_port = None ;
297300 except :
298301 # Close the serial port
299302 esp ._port .close ()
300303 board .close ()
301- window .dialog .emit ('Error adding WiFi credentials' ,
302- '* Please turn the SumoRobot off\n ' +
304+ window .dialog .emit ('Error updating firmware' ,
303305 '* Try reconnecting the SumoRobot\n ' +
304- '* Check your Internet connection' ,
306+ '* Check your Internet connection\n ' , +
307+ '* Finally try updating firmware again' ,
305308 traceback .format_exc (), None )
306- window .dialog_title = 'Error updating firmware'
307309 window .message .emit ('error' , 'Error updating firmware' )
308310
309311 # Stop the update thread
@@ -349,9 +351,9 @@ def run(self):
349351 # Close the serial connection
350352 board .close ()
351353 window .dialog .emit ('Error adding WiFi credentials' ,
352- '* Please turn the SumoRobot off\n ' +
353354 '* Try reconnecting the SumoRobot\n ' +
354- '* Try updating firmware File > Update Firmware' ,
355+ '* Try adding WiFi credentials again\n ' , +
356+ '* When nothing helped, try File > Update Firmware' ,
355357 traceback .format_exc (), None )
356358 window .message .emit ('error' , 'Error adding WiFi credentials' )
357359
@@ -390,9 +392,8 @@ def run(self):
390392 # Close the serial connection
391393 board .close ()
392394 window .dialog .emit ('Error loading WiFi networks' ,
393- '* Please turn the SumoRobot off\n ' +
394395 '* Try reconnecting the SumoRobot\n ' +
395- '* Try updating firmware File > Update Firmware' ,
396+ '* Try updating firmware File > Update Firmware (close this dialog first) ' ,
396397 traceback .format_exc (), None )
397398 window .message .emit ('error' , 'Error loading WiFi networks' )
398399
0 commit comments