eric6/MicroPython/MicrobitDevices.py

branch
micropython
changeset 7059
a8fad276cbd5
child 7065
e3d04faced34
equal deleted inserted replaced
7058:bdd583f96e96 7059:a8fad276cbd5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the device interface class for BBC micro:bit boards.
8 """
9
10 from __future__ import unicode_literals
11
12 from .MicroPythonDevices import MicroPythonDevice
13 from .MicroPythonReplWidget import HAS_QTCHART
14
15
16 class MicrobitDevice(MicroPythonDevice):
17 """
18 Class implementing the device for BBC micro:bit boards.
19 """
20 def __init__(self, microPythonWidget, parent=None):
21 """
22 Constructor
23
24 @param microPythonWidget reference to the main MicroPython widget
25 @type MicroPythonReplWidget
26 @param parent reference to the parent object
27 @type QObject
28 """
29 super(MicrobitDevice, self).__init__(microPythonWidget, parent)
30
31 self.__replActive = False
32 self.__fileManagerActive = False
33 self.__plotterActive = False
34
35 def setButtons(self):
36 """
37 Public method to enable the supported action buttons.
38 """
39 super(MicrobitDevice, self).setButtons()
40 self.microPython.setActionButtons(
41 repl=True, files=True, chart=HAS_QTCHART)
42
43 def forceInterrupt(self):
44 """
45 Public method to determine the need for an interrupt when opening the
46 serial connection.
47
48 @return flag indicating an interrupt is needed
49 @rtype bool
50 """
51 return True
52
53 def canStartRepl(self):
54 """
55 Public method to determine, if a REPL can be started.
56
57 @return tuple containing a flag indicating it is safe to start a REPL
58 and a reason why it cannot.
59 @rtype tuple of (bool, str)
60 """
61 if self.__fileManagerActive:
62 return False, self.tr("The REPL and the file manager use the same"
63 " USB serial connection. Only one can be"
64 " active at any time. Toggle the file"
65 " manager off and try again.")
66 else:
67 return True, ""
68
69 def setRepl(self, on):
70 """
71 Public method to set the REPL status and dependent status.
72
73 @param on flag indicating the active status
74 @type bool
75 """
76 self.__replActive = on
77 self.microPython.setActionButtons(files=not on)
78
79 def canStartPlotter(self):
80 """
81 Public method to determine, if a Plotter can be started.
82
83 @return tuple containing a flag indicating it is safe to start a
84 Plotter and a reason why it cannot.
85 @rtype tuple of (bool, str)
86 """
87 if self.__fileManagerActive:
88 return False, self.tr("The Plotter and the file manager use the"
89 " same USB serial connection. Only one can"
90 " be active at any time. Toggle the file"
91 " manager off and try again.")
92 else:
93 return True, ""
94
95 def setPlotter(self, on):
96 """
97 Public method to set the Plotter status and dependent status.
98
99 @param on flag indicating the active status
100 @type bool
101 """
102 self.__plotterActive = on
103 self.microPython.setActionButtons(files=not on)
104
105 # TODO: not yet implemented
106 def canStartFileManager(self):
107 """
108 Public method to determine, if a File Manager can be started.
109
110 @return tuple containing a flag indicating it is safe to start a
111 File Manager and a reason why it cannot.
112 @rtype tuple of (bool, str)
113 """
114 return False, self.tr("File Manager is not supported by this device.")
115
116 # TODO: not yet implemented
117 def setFileManager(self, on):
118 """
119 Public method to set the File Manager status and dependent status.
120
121 @param on flag indicating the active status
122 @type bool
123 """
124 pass

eric ide

mercurial