--- a/src/eric7/MicroPython/Devices/MicrobitDevices.py Thu Jan 18 13:17:38 2024 +0100 +++ b/src/eric7/MicroPython/Devices/MicrobitDevices.py Fri Jan 19 09:36:51 2024 +0100 @@ -492,34 +492,34 @@ connected device. """ aw = ericApp().getObject("ViewManager").activeWindow() - if not aw: - return - - title = self.tr("Save Script as 'main.py'") + if aw: + title = self.tr("Save Script as 'main.py'") - if not (aw.isPyFile() or aw.isMicroPythonFile()): - yes = EricMessageBox.yesNo( - self.microPython, - title, - self.tr( - """The current editor does not contain a Python""" - """ script. Write it anyway?""" - ), - ) - if not yes: + if not (aw.isPyFile() or aw.isMicroPythonFile()): + yes = EricMessageBox.yesNo( + self.microPython, + title, + self.tr( + """The current editor does not contain a Python""" + """ script. Write it anyway?""" + ), + ) + if not yes: + return + + script = aw.text().strip() + if not script: + EricMessageBox.warning( + self.microPython, + title, + self.tr("""The script is empty. Aborting."""), + ) return - script = aw.text().strip() - if not script: - EricMessageBox.warning( - self.microPython, title, self.tr("""The script is empty. Aborting.""") - ) - return + self.putData("main.py", script.encode("utf-8")) - self.putData("main.py", script.encode("utf-8")) - - # reset the device - self.__resetDevice() + # reset the device + self.__resetDevice() @pyqtSlot() def __resetDevice(self):