src/eric7/MicroPython/MicroPythonWidget.py

branch
mpy_network
changeset 9787
163511257f24
parent 9776
210bf87ae5c7
child 9799
a79430a8811d
diff -r 5f84d5eeee9e -r 163511257f24 src/eric7/MicroPython/MicroPythonWidget.py
--- a/src/eric7/MicroPython/MicroPythonWidget.py	Tue Feb 21 10:53:46 2023 +0100
+++ b/src/eric7/MicroPython/MicroPythonWidget.py	Wed Feb 22 07:45:54 2023 +0100
@@ -223,7 +223,9 @@
         self.layout().setContentsMargins(0, 3, 0, 0)
 
         self.__ui = parent
+
         self.__wifiController = WifiController(self, self)
+        self.__wifiMenu = None
 
         self.__superMenu = QMenu(self)
         self.__superMenu.aboutToShow.connect(self.__aboutToShowSuperMenu)
@@ -619,6 +621,9 @@
                 self.tr("Press to connect the selected device")
             )
 
+        if not connected and self.__wifiMenu and self.__wifiMenu.isTearOffMenuVisible():
+            self.__wifiMenu.hideTearOffMenu()
+
     def isConnected(self):
         """
         Public method to get the MicroPython device connection state.
@@ -1449,9 +1454,11 @@
 
         # prepare the WiFi menu
         if self.__device and self.__connected and self.__device.getDeviceData("wifi"):
-            wifiMenu = self.__wifiController.createMenu(self.__superMenu)
+            if self.__wifiMenu is not None:
+                self.__wifiMenu.deleteLater()
+            self.__wifiMenu = self.__wifiController.createMenu(self.__superMenu)
         else:
-            wifiMenu = None
+            self.__wifiMenu = None
 
         # populate the super menu
         hasTime = self.__device.hasTimeCommands() if self.__device else False
@@ -1496,8 +1503,8 @@
         if self.__device:
             self.__device.addDeviceMenuEntries(self.__superMenu)
             self.__superMenu.addSeparator()
-            if wifiMenu is not None:
-                self.__superMenu.addMenu(wifiMenu)
+            if self.__wifiMenu is not None:
+                self.__superMenu.addMenu(self.__wifiMenu)
                 self.__superMenu.addSeparator()
             if downloadMenu is None:
                 # generic download action
@@ -1606,7 +1613,7 @@
             dlg = BoardDataDialog(boardInfo)
             dlg.exec()
         except Exception as exc:
-            self.__showError("getBoardInformation()", str(exc))
+            self.showError("getBoardInformation()", str(exc))
 
     @pyqtSlot()
     def __synchronizeTime(self, quiet=False):
@@ -1636,7 +1643,7 @@
                             + self.__getDeviceTime(),
                         )
             except Exception as exc:
-                self.__showError("syncTime()", str(exc))
+                self.showError("syncTime()", str(exc))
 
     def __getDeviceTime(self):
         """
@@ -1663,7 +1670,7 @@
                         dateTimeString.strip()
                     )
             except Exception as exc:
-                self.__showError("getTime()", str(exc))
+                self.showError("getTime()", str(exc))
                 return ""
         else:
             return ""
@@ -1740,11 +1747,11 @@
                     ).format(localdate, localtime, deviceDateTimeString.strip()),
                 )
         except Exception as exc:
-            self.__showError("getTime()", str(exc))
+            self.showError("getTime()", str(exc))
 
-    def __showError(self, method, error):
+    def showError(self, method, error):
         """
-        Private method to show some error message.
+        Public method to show some error message.
 
         @param method name of the method the error occured in
         @type str
@@ -2007,4 +2014,4 @@
                 )
                 dlg.show()
             except Exception as exc:
-                self.__showError("getModules()", str(exc))
+                self.showError("getModules()", str(exc))

eric ide

mercurial