MicroPythonWidget: made the cross compile actions enable only, if the mpy-cross utility is found or properly configured.

Thu, 22 Aug 2019 15:47:14 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 22 Aug 2019 15:47:14 +0200
changeset 7150
cfe71cde2eec
parent 7149
6a9d4a241962
child 7152
a99df2004bb7
child 7153
ca02892fde13

MicroPythonWidget: made the cross compile actions enable only, if the mpy-cross utility is found or properly configured.

eric6/Documentation/Help/source.qch file | annotate | diff | comparison | revisions
eric6/Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
eric6/Documentation/Source/eric6.MicroPython.MicroPythonWidget.html file | annotate | diff | comparison | revisions
eric6/MicroPython/MicroPythonWidget.py file | annotate | diff | comparison | revisions
Binary file eric6/Documentation/Help/source.qch has changed
--- a/eric6/Documentation/Help/source.qhp	Wed Aug 21 16:31:03 2019 +0200
+++ b/eric6/Documentation/Help/source.qhp	Thu Aug 22 15:47:14 2019 +0200
@@ -11551,6 +11551,7 @@
       <keyword name="MicroPythonWidget.__doZoom" id="MicroPythonWidget.__doZoom" ref="eric6.MicroPython.MicroPythonWidget.html#MicroPythonWidget.__doZoom" />
       <keyword name="MicroPythonWidget.__getDeviceTime" id="MicroPythonWidget.__getDeviceTime" ref="eric6.MicroPython.MicroPythonWidget.html#MicroPythonWidget.__getDeviceTime" />
       <keyword name="MicroPythonWidget.__handlePreferencesChanged" id="MicroPythonWidget.__handlePreferencesChanged" ref="eric6.MicroPython.MicroPythonWidget.html#MicroPythonWidget.__handlePreferencesChanged" />
+      <keyword name="MicroPythonWidget.__mpyCrossAvailable" id="MicroPythonWidget.__mpyCrossAvailable" ref="eric6.MicroPython.MicroPythonWidget.html#MicroPythonWidget.__mpyCrossAvailable" />
       <keyword name="MicroPythonWidget.__paste" id="MicroPythonWidget.__paste" ref="eric6.MicroPython.MicroPythonWidget.html#MicroPythonWidget.__paste" />
       <keyword name="MicroPythonWidget.__populateDeviceTypeComboBox" id="MicroPythonWidget.__populateDeviceTypeComboBox" ref="eric6.MicroPython.MicroPythonWidget.html#MicroPythonWidget.__populateDeviceTypeComboBox" />
       <keyword name="MicroPythonWidget.__processData" id="MicroPythonWidget.__processData" ref="eric6.MicroPython.MicroPythonWidget.html#MicroPythonWidget.__processData" />
--- a/eric6/Documentation/Source/eric6.MicroPython.MicroPythonWidget.html	Wed Aug 21 16:31:03 2019 +0200
+++ b/eric6/Documentation/Source/eric6.MicroPython.MicroPythonWidget.html	Thu Aug 22 15:47:14 2019 +0200
@@ -97,6 +97,9 @@
 <td><a href="#MicroPythonWidget.__handlePreferencesChanged">__handlePreferencesChanged</a></td>
 <td>Private slot to handle a change in preferences.</td>
 </tr><tr>
+<td><a href="#MicroPythonWidget.__mpyCrossAvailable">__mpyCrossAvailable</a></td>
+<td>Private method to check the availability of mpy-cross.</td>
+</tr><tr>
 <td><a href="#MicroPythonWidget.__paste">__paste</a></td>
 <td>Private slot to perform a paste operation.</td>
 </tr><tr>
@@ -276,7 +279,22 @@
 <b>__handlePreferencesChanged</b>(<i></i>)
 <p>
         Private slot to handle a change in preferences.
-</p><a NAME="MicroPythonWidget.__paste" ID="MicroPythonWidget.__paste"></a>
+</p><a NAME="MicroPythonWidget.__mpyCrossAvailable" ID="MicroPythonWidget.__mpyCrossAvailable"></a>
+<h4>MicroPythonWidget.__mpyCrossAvailable</h4>
+<b>__mpyCrossAvailable</b>(<i></i>)
+<p>
+        Private method to check the availability of mpy-cross.
+</p><dl>
+<dt>Returns:</dt>
+<dd>
+flag indicating the availability of mpy-cross
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+bool
+</dd>
+</dl><a NAME="MicroPythonWidget.__paste" ID="MicroPythonWidget.__paste"></a>
 <h4>MicroPythonWidget.__paste</h4>
 <b>__paste</b>(<i></i>)
 <p>
--- a/eric6/MicroPython/MicroPythonWidget.py	Wed Aug 21 16:31:03 2019 +0200
+++ b/eric6/MicroPython/MicroPythonWidget.py	Thu Aug 22 15:47:14 2019 +0200
@@ -847,7 +847,8 @@
         if self.__interface.connectToDevice(port):
             self.__setConnected(True)
             
-            if Preferences.getMicroPython("SyncTimeAfterConnect"):
+            if (Preferences.getMicroPython("SyncTimeAfterConnect") and
+                    self.__device.hasTimeCommands()):
                 self.__synchronizeTime(quiet=True)
         else:
             E5MessageBox.warning(
@@ -1107,16 +1108,18 @@
             act = self.__superMenu.addAction(
                 self.tr("Show Device Time"), self.__showDeviceTime)
             act.setEnabled(self.__connected)
-            self.__superMenu.addAction(
-                self.tr("Show Local Time"), self.__showLocalTime)
-            self.__superMenu.addSeparator()
+        self.__superMenu.addAction(
+            self.tr("Show Local Time"), self.__showLocalTime)
+        self.__superMenu.addSeparator()
         if not Globals.isWindowsPlatform():
-            self.__superMenu.addAction(
+            available = self.__mpyCrossAvailable()
+            act = self.__superMenu.addAction(
                 self.tr("Compile Python File"), self.__compileFile2Mpy)
+            act.setEnabled(available)
             act = self.__superMenu.addAction(
                 self.tr("Compile Current Editor"), self.__compileEditor2Mpy)
             aw = e5App().getObject("ViewManager").activeWindow()
-            act.setEnabled(bool(aw))
+            act.setEnabled(available and bool(aw))
             self.__superMenu.addSeparator()
         if self.__device:
             self.__device.addDeviceMenuEntries(self.__superMenu)
@@ -1275,6 +1278,25 @@
                     " device.</p><p>Method: {0}</p><p>Message: {1}</p>")
             .format(method, error))
     
+    def __mpyCrossAvailable(self):
+        """
+        Private method to check the availability of mpy-cross.
+        
+        @return flag indicating the availability of mpy-cross
+        @rtype bool
+        """
+        available = False
+        program = Preferences.getMicroPython("MpyCrossCompiler")
+        if not program:
+            program = "mpy-cross"
+            if Utilities.isinpath(program):
+                available = True
+        else:
+            if Utilities.isExecutable(program):
+                available = True
+        
+        return available
+    
     def __crossCompile(self, pythonFile="", title=""):
         """
         Private method to cross compile a Python file to a .mpy file.

eric ide

mercurial