42 def setButtons(self): |
42 def setButtons(self): |
43 """ |
43 """ |
44 Public method to enable the supported action buttons. |
44 Public method to enable the supported action buttons. |
45 """ |
45 """ |
46 super(CircuitPythonDevice, self).setButtons() |
46 super(CircuitPythonDevice, self).setButtons() |
47 self.microPython.setActionButtons(repl=True, chart=HAS_QTCHART) |
47 self.microPython.setActionButtons(run=True, repl=True, chart=HAS_QTCHART) |
|
48 |
|
49 workspace = self.getWorkspace() |
|
50 if workspace.endswith("CIRCUITPY"): |
|
51 self.microPython.setActionButtons(open=True, save=True) |
48 |
52 |
49 def forceInterrupt(self): |
53 def forceInterrupt(self): |
50 """ |
54 """ |
51 Public method to determine the need for an interrupt when opening the |
55 Public method to determine the need for an interrupt when opening the |
52 serial connection. |
56 serial connection. |
92 @param on flag indicating the active status |
96 @param on flag indicating the active status |
93 @type bool |
97 @type bool |
94 """ |
98 """ |
95 self.__plotterActive = on |
99 self.__plotterActive = on |
96 |
100 |
|
101 def canRunScript(self): |
|
102 """ |
|
103 Public method to determine, if a script can be executed. |
|
104 |
|
105 @return tuple containing a flag indicating it is safe to start a |
|
106 Plotter and a reason why it cannot. |
|
107 @rtype tuple of (bool, str) |
|
108 """ |
|
109 return True, "" |
|
110 |
|
111 def runScript(self, script): |
|
112 """ |
|
113 Public method to run the given Python script. |
|
114 |
|
115 @param script script to be executed |
|
116 @type str |
|
117 """ |
|
118 pythonScript = script.split("\n") |
|
119 self.sendCommands(pythonScript) |
|
120 |
97 def getWorkspace(self): |
121 def getWorkspace(self): |
98 """ |
122 """ |
99 Public method to get the workspace directory. |
123 Public method to get the workspace directory. |
100 |
124 |
101 @return workspace directory used for saving files |
125 @return workspace directory used for saving files |
129 # volume contains no media. Wrapping the check in SetErrorMode |
153 # volume contains no media. Wrapping the check in SetErrorMode |
130 # with SEM_FAILCRITICALERRORS (1) prevents this popup. |
154 # with SEM_FAILCRITICALERRORS (1) prevents this popup. |
131 # |
155 # |
132 oldMode = ctypes.windll.kernel32.SetErrorMode(1) |
156 oldMode = ctypes.windll.kernel32.SetErrorMode(1) |
133 try: |
157 try: |
134 for disk in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ': |
158 for disk in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": |
135 path = '{0}:\\'.format(disk) |
159 path = "{0}:\\".format(disk) |
136 if (os.path.exists(path) and |
160 if (os.path.exists(path) and |
137 getVolumeName(path) == 'CIRCUITPY'): |
161 getVolumeName(path) == "CIRCUITPY"): |
138 deviceDirectory = path |
162 deviceDirectory = path |
139 break |
163 break |
140 finally: |
164 finally: |
141 ctypes.windll.kernel32.SetErrorMode(oldMode) |
165 ctypes.windll.kernel32.SetErrorMode(oldMode) |
142 else: |
166 else: |
143 # we are on a Linux or macOS platform |
167 # we are on a Linux or macOS platform |
144 for mountCommand in ['mount', '/sbin/mount', '/usr/sbin/mount']: |
168 for mountCommand in ["mount", "/sbin/mount", "/usr/sbin/mount"]: |
145 try: |
169 try: |
146 mountOutput = check_output(mountCommand).splitlines() |
170 mountOutput = check_output(mountCommand).splitlines() |
147 mountedVolumes = [x.split()[2] for x in mountOutput] |
171 mountedVolumes = [x.split()[2] for x in mountOutput] |
148 for volume in mountedVolumes: |
172 for volume in mountedVolumes: |
149 if volume.endswith(b'CIRCUITPY'): |
173 if volume.endswith(b"CIRCUITPY"): |
150 deviceDirectory = volume.decode('utf-8') |
174 deviceDirectory = volume.decode("utf-8") |
151 break |
175 break |
152 if deviceDirectory: |
176 if deviceDirectory: |
153 break |
177 break |
154 except FileNotFoundError: |
178 except FileNotFoundError: |
155 pass |
179 pass |