Numworks Epsilon  1.4.1
Graphing Calculator Operating System
python_toolbox.cpp
Go to the documentation of this file.
1 #include "python_toolbox.h"
2 #include "../shared/toolbox_helpers.h"
3 #include <assert.h>
4 extern "C" {
5 #include <string.h>
6 #include <ctype.h>
7 }
8 
9 namespace Code {
10 
11 static constexpr int catalogChildrenCount = 94;
12 static constexpr int MathModuleChildrenCount = 43;
13 static constexpr int KandinskyModuleChildrenCount = 7;
14 static constexpr int CMathModuleChildrenCount = 13;
15 static constexpr int RandomModuleChildrenCount = 10;
16 static constexpr int conditionsChildrenCount = 9;
17 static constexpr int forLoopChildrenCount = 4;
18 static constexpr int functionsChildrenCount = 2;
19 static constexpr int ifStatementChildrenCount = 5;
20 static constexpr int loopsAndTestsChildrenCount = 4;
21 static constexpr int menuChildrenCount = 4;
22 static constexpr int modulesChildrenCount = 4;
23 static constexpr int whileLoopChildrenCount = 1;
24 
25 
26 const ToolboxMessageTree forLoopChildren[forLoopChildrenCount] = {
27  ToolboxMessageTree(I18n::Message::ForInRange1ArgLoopWithArg, I18n::Message::Default, I18n::Message::ForInRange1ArgLoop),
28  ToolboxMessageTree(I18n::Message::ForInRange2ArgsLoopWithArg, I18n::Message::Default, I18n::Message::ForInRange2ArgsLoop),
29  ToolboxMessageTree(I18n::Message::ForInRange3ArgsLoopWithArg, I18n::Message::Default, I18n::Message::ForInRange3ArgsLoop),
30  ToolboxMessageTree(I18n::Message::ForInListLoopWithArg, I18n::Message::Default, I18n::Message::ForInListLoop)};
31 
32 const ToolboxMessageTree ifStatementChildren[ifStatementChildrenCount] = {
33  ToolboxMessageTree(I18n::Message::IfElseStatementWithArg, I18n::Message::Default, I18n::Message::IfElseStatement),
34  ToolboxMessageTree(I18n::Message::IfThenStatementWithArg, I18n::Message::Default, I18n::Message::IfThenStatement),
35  ToolboxMessageTree(I18n::Message::IfElifElseStatementWithArg, I18n::Message::Default, I18n::Message::IfElifElseStatement),
36  ToolboxMessageTree(I18n::Message::IfAndIfElseStatementWithArg, I18n::Message::Default, I18n::Message::IfAndIfElseStatement),
37  ToolboxMessageTree(I18n::Message::IfOrIfElseStatementWithArg, I18n::Message::Default, I18n::Message::IfOrIfElseStatement)};
38 
39 const ToolboxMessageTree whileLoopChildren[whileLoopChildrenCount] = {
40  ToolboxMessageTree(I18n::Message::WhileLoopWithArg, I18n::Message::Default, I18n::Message::WhileLoop)};
41 
42 const ToolboxMessageTree conditionsChildren[conditionsChildrenCount] = {
43  ToolboxMessageTree(I18n::Message::EqualityConditionWithArg, I18n::Message::Default, I18n::Message::EqualityCondition),
44  ToolboxMessageTree(I18n::Message::NonEqualityConditionWithArg, I18n::Message::Default, I18n::Message::NonEqualityCondition),
45  ToolboxMessageTree(I18n::Message::SuperiorStrictConditionWithArg, I18n::Message::Default, I18n::Message::SuperiorStrictCondition),
46  ToolboxMessageTree(I18n::Message::InferiorStrictConditionWithArg, I18n::Message::Default, I18n::Message::InferiorStrictCondition),
47  ToolboxMessageTree(I18n::Message::SuperiorConditionWithArg, I18n::Message::Default, I18n::Message::SuperiorCondition),
48  ToolboxMessageTree(I18n::Message::InferiorConditionWithArg, I18n::Message::Default, I18n::Message::InferiorCondition),
49  ToolboxMessageTree(I18n::Message::ConditionAnd, I18n::Message::Default, I18n::Message::ConditionAnd),
50  ToolboxMessageTree(I18n::Message::ConditionOr, I18n::Message::Default, I18n::Message::ConditionOr),
51  ToolboxMessageTree(I18n::Message::ConditionNot, I18n::Message::Default, I18n::Message::ConditionNot)};
52 
53 const ToolboxMessageTree loopsAndTestsChildren[loopsAndTestsChildrenCount] = {
54  ToolboxMessageTree(I18n::Message::ForLoopMenu, I18n::Message::Default, I18n::Message::Default, forLoopChildren, forLoopChildrenCount),
55  ToolboxMessageTree(I18n::Message::IfStatementMenu, I18n::Message::Default, I18n::Message::Default, ifStatementChildren, ifStatementChildrenCount),
56  ToolboxMessageTree(I18n::Message::WhileLoopMenu, I18n::Message::Default, I18n::Message::Default, whileLoopChildren, whileLoopChildrenCount),
57  ToolboxMessageTree(I18n::Message::ConditionsMenu, I18n::Message::Default, I18n::Message::Default, conditionsChildren, conditionsChildrenCount)};
58 
59 const ToolboxMessageTree MathModuleChildren[MathModuleChildrenCount] = {
60  ToolboxMessageTree(I18n::Message::PythonCommandImportMath, I18n::Message::PythonImportMath, I18n::Message::PythonCommandImportMath),
61  ToolboxMessageTree(I18n::Message::PythonCommandImportFromMath, I18n::Message::PythonImportFromMath, I18n::Message::PythonCommandImportFromMath),
62  ToolboxMessageTree(I18n::Message::PythonCommandMathFunction, I18n::Message::PythonMathFunction, I18n::Message::PythonCommandMathFunctionWithoutArg),
63  ToolboxMessageTree(I18n::Message::PythonCommandConstantE, I18n::Message::PythonConstantE, I18n::Message::PythonCommandConstantE),
64  ToolboxMessageTree(I18n::Message::PythonCommandConstantPi, I18n::Message::PythonConstantPi, I18n::Message::PythonCommandConstantPi),
65  ToolboxMessageTree(I18n::Message::PythonCommandSqrt, I18n::Message::PythonSqrt, I18n::Message::PythonCommandSqrt),
66  ToolboxMessageTree(I18n::Message::PythonCommandPower, I18n::Message::PythonPower, I18n::Message::PythonCommandPower),
67  ToolboxMessageTree(I18n::Message::PythonCommandExp, I18n::Message::PythonExp, I18n::Message::PythonCommandExp),
68  ToolboxMessageTree(I18n::Message::PythonCommandExpm1, I18n::Message::PythonExpm1, I18n::Message::PythonCommandExpm1),
69  ToolboxMessageTree(I18n::Message::PythonCommandLog, I18n::Message::PythonLog, I18n::Message::PythonCommandLog),
70  ToolboxMessageTree(I18n::Message::PythonCommandLog2, I18n::Message::PythonLog2, I18n::Message::PythonCommandLog2),
71  ToolboxMessageTree(I18n::Message::PythonCommandLog10, I18n::Message::PythonLog10, I18n::Message::PythonCommandLog10),
72  ToolboxMessageTree(I18n::Message::PythonCommandCosh, I18n::Message::PythonCosh, I18n::Message::PythonCommandCosh),
73  ToolboxMessageTree(I18n::Message::PythonCommandSinh, I18n::Message::PythonSinh, I18n::Message::PythonCommandSinh),
74  ToolboxMessageTree(I18n::Message::PythonCommandTanh, I18n::Message::PythonTanh, I18n::Message::PythonCommandTanh),
75  ToolboxMessageTree(I18n::Message::PythonCommandAcosh, I18n::Message::PythonAcosh, I18n::Message::PythonCommandAcosh),
76  ToolboxMessageTree(I18n::Message::PythonCommandAsinh, I18n::Message::PythonAsinh, I18n::Message::PythonCommandAsinh),
77  ToolboxMessageTree(I18n::Message::PythonCommandAtanh, I18n::Message::PythonAtanh, I18n::Message::PythonCommandAtanh),
78  ToolboxMessageTree(I18n::Message::PythonCommandCos, I18n::Message::PythonCos, I18n::Message::PythonCommandCos),
79  ToolboxMessageTree(I18n::Message::PythonCommandSin, I18n::Message::PythonSin, I18n::Message::PythonCommandSin),
80  ToolboxMessageTree(I18n::Message::PythonCommandTan, I18n::Message::PythonTan, I18n::Message::PythonCommandTan),
81  ToolboxMessageTree(I18n::Message::PythonCommandAcos, I18n::Message::PythonAcos, I18n::Message::PythonCommandAcos),
82  ToolboxMessageTree(I18n::Message::PythonCommandAsin, I18n::Message::PythonAsin, I18n::Message::PythonCommandAsin),
83  ToolboxMessageTree(I18n::Message::PythonCommandAtan, I18n::Message::PythonAtan, I18n::Message::PythonCommandAtan),
84  ToolboxMessageTree(I18n::Message::PythonCommandAtan2, I18n::Message::PythonAtan2, I18n::Message::PythonCommandAtan2),
85  ToolboxMessageTree(I18n::Message::PythonCommandCeil, I18n::Message::PythonCeil, I18n::Message::PythonCommandCeil),
86  ToolboxMessageTree(I18n::Message::PythonCommandCopySign, I18n::Message::PythonCopySign, I18n::Message::PythonCommandCopySign),
87  ToolboxMessageTree(I18n::Message::PythonCommandFabs, I18n::Message::PythonFabs, I18n::Message::PythonCommandFabs),
88  ToolboxMessageTree(I18n::Message::PythonCommandFloor, I18n::Message::PythonFloor, I18n::Message::PythonCommandFloor),
89  ToolboxMessageTree(I18n::Message::PythonCommandFmod, I18n::Message::PythonFmod, I18n::Message::PythonCommandFmod),
90  ToolboxMessageTree(I18n::Message::PythonCommandFrExp, I18n::Message::PythonFrExp, I18n::Message::PythonCommandFrExp),
91  ToolboxMessageTree(I18n::Message::PythonCommandLdexp, I18n::Message::PythonLdexp, I18n::Message::PythonCommandLdexp),
92  ToolboxMessageTree(I18n::Message::PythonCommandModf, I18n::Message::PythonModf, I18n::Message::PythonCommandModf),
93  ToolboxMessageTree(I18n::Message::PythonCommandIsFinite, I18n::Message::PythonIsFinite, I18n::Message::PythonCommandIsFinite),
94  ToolboxMessageTree(I18n::Message::PythonCommandIsInfinite, I18n::Message::PythonIsInfinite, I18n::Message::PythonCommandIsInfinite),
95  ToolboxMessageTree(I18n::Message::PythonCommandIsNaN, I18n::Message::PythonIsNaN, I18n::Message::PythonCommandIsNaN),
96  ToolboxMessageTree(I18n::Message::PythonCommandTrunc, I18n::Message::PythonTrunc, I18n::Message::PythonCommandTrunc),
97  ToolboxMessageTree(I18n::Message::PythonCommandRadians, I18n::Message::PythonRadians, I18n::Message::PythonCommandRadians),
98  ToolboxMessageTree(I18n::Message::PythonCommandDegrees, I18n::Message::PythonDegrees, I18n::Message::PythonCommandDegrees),
99  ToolboxMessageTree(I18n::Message::PythonCommandErf, I18n::Message::PythonErf, I18n::Message::PythonCommandErf),
100  ToolboxMessageTree(I18n::Message::PythonCommandErfc, I18n::Message::PythonErfc, I18n::Message::PythonCommandErfc),
101  ToolboxMessageTree(I18n::Message::PythonCommandGamma, I18n::Message::PythonGamma, I18n::Message::PythonCommandGamma),
102  ToolboxMessageTree(I18n::Message::PythonCommandLgamma, I18n::Message::PythonLgamma, I18n::Message::PythonCommandLgamma)};
103 
104 const ToolboxMessageTree KandinskyModuleChildren[KandinskyModuleChildrenCount] = {
105  ToolboxMessageTree(I18n::Message::PythonCommandImportKandinsky, I18n::Message::PythonImportKandinsky, I18n::Message::PythonCommandImportKandinsky),
106  ToolboxMessageTree(I18n::Message::PythonCommandImportFromKandinsky, I18n::Message::PythonImportFromKandinsky, I18n::Message::PythonCommandImportFromKandinsky),
107  ToolboxMessageTree(I18n::Message::PythonCommandKandinskyFunction, I18n::Message::PythonKandinskyFunction, I18n::Message::PythonCommandKandinskyFunctionWithoutArg),
108  ToolboxMessageTree(I18n::Message::PythonCommandGetPixel, I18n::Message::PythonGetPixel, I18n::Message::PythonCommandGetPixel),
109  ToolboxMessageTree(I18n::Message::PythonCommandSetPixel, I18n::Message::PythonSetPixel, I18n::Message::PythonCommandSetPixel),
110  ToolboxMessageTree(I18n::Message::PythonCommandColor, I18n::Message::PythonColor, I18n::Message::PythonCommandColor),
111  ToolboxMessageTree(I18n::Message::PythonCommandDrawString, I18n::Message::PythonDrawString, I18n::Message::PythonCommandDrawString)};
112 
113 const ToolboxMessageTree RandomModuleChildren[RandomModuleChildrenCount] = {
114  ToolboxMessageTree(I18n::Message::PythonCommandImportRandom, I18n::Message::PythonImportRandom, I18n::Message::PythonCommandImportRandom),
115  ToolboxMessageTree(I18n::Message::PythonCommandImportFromRandom, I18n::Message::PythonImportFromRandom, I18n::Message::PythonCommandImportFromRandom),
116  ToolboxMessageTree(I18n::Message::PythonCommandRandomFunction, I18n::Message::PythonRandomFunction, I18n::Message::PythonCommandRandomFunctionWithoutArg),
117  ToolboxMessageTree(I18n::Message::PythonCommandGetrandbits, I18n::Message::PythonGetrandbits, I18n::Message::PythonCommandGetrandbits),
118  ToolboxMessageTree(I18n::Message::PythonCommandSeed, I18n::Message::PythonSeed, I18n::Message::PythonCommandSeed),
119  ToolboxMessageTree(I18n::Message::PythonCommandRandrange, I18n::Message::PythonRandrange, I18n::Message::PythonCommandRandrange),
120  ToolboxMessageTree(I18n::Message::PythonCommandRandint, I18n::Message::PythonRandint, I18n::Message::PythonCommandRandint),
121  ToolboxMessageTree(I18n::Message::PythonCommandChoice, I18n::Message::PythonChoice, I18n::Message::PythonCommandChoice),
122  ToolboxMessageTree(I18n::Message::PythonCommandRandom, I18n::Message::PythonRandom, I18n::Message::PythonCommandRandom),
123  ToolboxMessageTree(I18n::Message::PythonCommandUniform, I18n::Message::PythonUniform, I18n::Message::PythonCommandUniform)
124 };
125 
126 const ToolboxMessageTree CMathModuleChildren[CMathModuleChildrenCount] = {
127  ToolboxMessageTree(I18n::Message::PythonCommandImportCmath, I18n::Message::PythonImportCmath, I18n::Message::PythonCommandImportCmath),
128  ToolboxMessageTree(I18n::Message::PythonCommandImportFromCmath, I18n::Message::PythonImportFromCmath, I18n::Message::PythonCommandImportFromCmath),
129  ToolboxMessageTree(I18n::Message::PythonCommandCmathFunction, I18n::Message::PythonCmathFunction, I18n::Message::PythonCommandCmathFunctionWithoutArg),
130  ToolboxMessageTree(I18n::Message::PythonCommandConstantE, I18n::Message::PythonConstantE, I18n::Message::PythonCommandConstantE),
131  ToolboxMessageTree(I18n::Message::PythonCommandConstantPi, I18n::Message::PythonConstantPi, I18n::Message::PythonCommandConstantPi),
132  ToolboxMessageTree(I18n::Message::PythonCommandPhase, I18n::Message::PythonPhase, I18n::Message::PythonCommandPhase),
133  ToolboxMessageTree(I18n::Message::PythonCommandPolar, I18n::Message::PythonPolar, I18n::Message::PythonCommandPolar),
134  ToolboxMessageTree(I18n::Message::PythonCommandRect, I18n::Message::PythonRect, I18n::Message::PythonCommandRect),
135  ToolboxMessageTree(I18n::Message::PythonCommandExpComplex, I18n::Message::PythonExp, I18n::Message::PythonCommandExp),
136  ToolboxMessageTree(I18n::Message::PythonCommandLogComplex, I18n::Message::PythonLog, I18n::Message::PythonCommandLog),
137  ToolboxMessageTree(I18n::Message::PythonCommandSqrtComplex, I18n::Message::PythonSqrt, I18n::Message::PythonCommandSqrt),
138  ToolboxMessageTree(I18n::Message::PythonCommandCosComplex, I18n::Message::PythonCos, I18n::Message::PythonCommandCos),
139  ToolboxMessageTree(I18n::Message::PythonCommandSinComplex, I18n::Message::PythonSin, I18n::Message::PythonCommandSin)};
140 
141 const ToolboxMessageTree modulesChildren[modulesChildrenCount] = {
142  ToolboxMessageTree(I18n::Message::MathModule, I18n::Message::Default, I18n::Message::Default, MathModuleChildren, MathModuleChildrenCount),
143  ToolboxMessageTree(I18n::Message::CmathModule, I18n::Message::Default, I18n::Message::Default, CMathModuleChildren, CMathModuleChildrenCount),
144  ToolboxMessageTree(I18n::Message::RandomModule, I18n::Message::Default, I18n::Message::Default, RandomModuleChildren, RandomModuleChildrenCount),
145  ToolboxMessageTree(I18n::Message::KandinskyModule, I18n::Message::Default, I18n::Message::Default, KandinskyModuleChildren, KandinskyModuleChildrenCount)};
146 
147 const ToolboxMessageTree catalogChildren[catalogChildrenCount] = {
148  ToolboxMessageTree(I18n::Message::PythonCommandPound, I18n::Message::PythonPound, I18n::Message::PythonCommandPound),
149  ToolboxMessageTree(I18n::Message::PythonCommandPercent, I18n::Message::PythonPercent, I18n::Message::PythonCommandPercent),
150  ToolboxMessageTree(I18n::Message::PythonCommand1J, I18n::Message::Python1J, I18n::Message::PythonCommand1J),
151  ToolboxMessageTree(I18n::Message::PythonCommandLF, I18n::Message::PythonLF, I18n::Message::PythonCommandLF),
152  ToolboxMessageTree(I18n::Message::PythonCommandTab, I18n::Message::PythonTab, I18n::Message::PythonCommandTab),
153  ToolboxMessageTree(I18n::Message::PythonCommandAmpersand, I18n::Message::PythonAmpersand, I18n::Message::PythonCommandAmpersand),
154  ToolboxMessageTree(I18n::Message::PythonCommandSymbolExp, I18n::Message::PythonSymbolExp, I18n::Message::PythonCommandSymbolExp),
155  ToolboxMessageTree(I18n::Message::PythonCommandVerticalBar, I18n::Message::PythonVerticalBar, I18n::Message::PythonCommandVerticalBar),
156  ToolboxMessageTree(I18n::Message::PythonCommandSingleQuote, I18n::Message::PythonSingleQuote, I18n::Message::PythonCommandSingleQuote),
157  ToolboxMessageTree(I18n::Message::PythonCommandAbs, I18n::Message::PythonAbs, I18n::Message::PythonCommandAbs),
158  ToolboxMessageTree(I18n::Message::PythonCommandAcos, I18n::Message::PythonAcos, I18n::Message::PythonCommandAcos),
159  ToolboxMessageTree(I18n::Message::PythonCommandAcosh, I18n::Message::PythonAcosh, I18n::Message::PythonCommandAcosh),
160  ToolboxMessageTree(I18n::Message::PythonCommandAsin, I18n::Message::PythonAsin, I18n::Message::PythonCommandAsin),
161  ToolboxMessageTree(I18n::Message::PythonCommandAsinh, I18n::Message::PythonAsinh, I18n::Message::PythonCommandAsinh),
162  ToolboxMessageTree(I18n::Message::PythonCommandAtan, I18n::Message::PythonAtan, I18n::Message::PythonCommandAtan),
163  ToolboxMessageTree(I18n::Message::PythonCommandAtan2, I18n::Message::PythonAtan2, I18n::Message::PythonCommandAtan2),
164  ToolboxMessageTree(I18n::Message::PythonCommandAtanh, I18n::Message::PythonAtanh, I18n::Message::PythonCommandAtanh),
165  ToolboxMessageTree(I18n::Message::PythonCommandBin, I18n::Message::PythonBin, I18n::Message::PythonCommandBin),
166  ToolboxMessageTree(I18n::Message::PythonCommandCeil, I18n::Message::PythonCeil, I18n::Message::PythonCommandCeil),
167  ToolboxMessageTree(I18n::Message::PythonCommandChoice, I18n::Message::PythonChoice, I18n::Message::PythonCommandChoice),
168  ToolboxMessageTree(I18n::Message::PythonCommandCmathFunction, I18n::Message::PythonCmathFunction, I18n::Message::PythonCommandCmathFunctionWithoutArg),
169  ToolboxMessageTree(I18n::Message::PythonCommandColor, I18n::Message::PythonColor, I18n::Message::PythonCommandColor),
170  ToolboxMessageTree(I18n::Message::PythonCommandComplex, I18n::Message::PythonComplex, I18n::Message::PythonCommandComplex),
171  ToolboxMessageTree(I18n::Message::PythonCommandCopySign, I18n::Message::PythonCopySign, I18n::Message::PythonCommandCopySign),
172  ToolboxMessageTree(I18n::Message::PythonCommandCos, I18n::Message::PythonCos, I18n::Message::PythonCommandCos),
173  ToolboxMessageTree(I18n::Message::PythonCommandCosh, I18n::Message::PythonCosh, I18n::Message::PythonCommandCosh),
174  ToolboxMessageTree(I18n::Message::PythonCommandDegrees, I18n::Message::PythonDegrees, I18n::Message::PythonCommandDegrees),
175  ToolboxMessageTree(I18n::Message::PythonCommandDivMod, I18n::Message::PythonDivMod, I18n::Message::PythonCommandDivMod),
176  ToolboxMessageTree(I18n::Message::PythonCommandDrawString, I18n::Message::PythonDrawString, I18n::Message::PythonCommandDrawString),
177  ToolboxMessageTree(I18n::Message::PythonCommandConstantE, I18n::Message::PythonConstantE, I18n::Message::PythonCommandConstantE),
178  ToolboxMessageTree(I18n::Message::PythonCommandErf, I18n::Message::PythonErf, I18n::Message::PythonCommandErf),
179  ToolboxMessageTree(I18n::Message::PythonCommandErfc, I18n::Message::PythonErfc, I18n::Message::PythonCommandErfc),
180  ToolboxMessageTree(I18n::Message::PythonCommandExp, I18n::Message::PythonExp, I18n::Message::PythonCommandExp),
181  ToolboxMessageTree(I18n::Message::PythonCommandExpm1, I18n::Message::PythonExpm1, I18n::Message::PythonCommandExpm1),
182  ToolboxMessageTree(I18n::Message::PythonCommandFabs, I18n::Message::PythonFabs, I18n::Message::PythonCommandFabs),
183  ToolboxMessageTree(I18n::Message::PythonCommandFloor, I18n::Message::PythonFloor, I18n::Message::PythonCommandFloor),
184  ToolboxMessageTree(I18n::Message::PythonCommandFmod, I18n::Message::PythonFmod, I18n::Message::PythonCommandFmod),
185  ToolboxMessageTree(I18n::Message::PythonCommandFrExp, I18n::Message::PythonFrExp, I18n::Message::PythonCommandFrExp),
186  ToolboxMessageTree(I18n::Message::PythonCommandImportFromCmath, I18n::Message::PythonImportFromCmath, I18n::Message::PythonCommandImportFromCmath),
187  ToolboxMessageTree(I18n::Message::PythonCommandImportFromKandinsky, I18n::Message::PythonImportFromKandinsky, I18n::Message::PythonCommandImportFromKandinsky),
188  ToolboxMessageTree(I18n::Message::PythonCommandImportFromMath, I18n::Message::PythonImportFromMath, I18n::Message::PythonCommandImportFromMath),
189  ToolboxMessageTree(I18n::Message::PythonCommandImportFromRandom, I18n::Message::PythonImportFromRandom, I18n::Message::PythonCommandImportFromRandom),
190  ToolboxMessageTree(I18n::Message::PythonCommandGamma, I18n::Message::PythonGamma, I18n::Message::PythonCommandGamma),
191  ToolboxMessageTree(I18n::Message::PythonCommandGetPixel, I18n::Message::PythonGetPixel, I18n::Message::PythonCommandGetPixel),
192  ToolboxMessageTree(I18n::Message::PythonCommandGetrandbits, I18n::Message::PythonGetrandbits, I18n::Message::PythonCommandGetrandbits),
193  ToolboxMessageTree(I18n::Message::PythonCommandHex, I18n::Message::PythonHex, I18n::Message::PythonCommandHex),
194  ToolboxMessageTree(I18n::Message::PythonCommandImportCmath, I18n::Message::PythonImportCmath, I18n::Message::PythonCommandImportCmath),
195  ToolboxMessageTree(I18n::Message::PythonCommandImportKandinsky, I18n::Message::PythonImportKandinsky, I18n::Message::PythonCommandImportKandinsky),
196  ToolboxMessageTree(I18n::Message::PythonCommandImportMath, I18n::Message::PythonImportMath, I18n::Message::PythonCommandImportMath),
197  ToolboxMessageTree(I18n::Message::PythonCommandImportRandom, I18n::Message::PythonImportRandom, I18n::Message::PythonCommandImportRandom),
198  ToolboxMessageTree(I18n::Message::PythonCommandInput, I18n::Message::PythonInput, I18n::Message::PythonCommandInput),
199  ToolboxMessageTree(I18n::Message::PythonCommandInt, I18n::Message::PythonInt, I18n::Message::PythonCommandInt),
200  ToolboxMessageTree(I18n::Message::PythonCommandIsFinite, I18n::Message::PythonIsFinite, I18n::Message::PythonCommandIsFinite),
201  ToolboxMessageTree(I18n::Message::PythonCommandIsInfinite, I18n::Message::PythonIsInfinite, I18n::Message::PythonCommandIsInfinite),
202  ToolboxMessageTree(I18n::Message::PythonCommandIsNaN, I18n::Message::PythonIsNaN, I18n::Message::PythonCommandIsNaN),
203  ToolboxMessageTree(I18n::Message::PythonCommandKandinskyFunction, I18n::Message::PythonKandinskyFunction, I18n::Message::PythonCommandKandinskyFunctionWithoutArg),
204  ToolboxMessageTree(I18n::Message::PythonCommandLdexp, I18n::Message::PythonLdexp, I18n::Message::PythonCommandLdexp),
205  ToolboxMessageTree(I18n::Message::PythonCommandLength, I18n::Message::PythonLength, I18n::Message::PythonCommandLength),
206  ToolboxMessageTree(I18n::Message::PythonCommandLgamma, I18n::Message::PythonLgamma, I18n::Message::PythonCommandLgamma),
207  ToolboxMessageTree(I18n::Message::PythonCommandLog, I18n::Message::PythonLog, I18n::Message::PythonCommandLog),
208  ToolboxMessageTree(I18n::Message::PythonCommandLog10, I18n::Message::PythonLog10, I18n::Message::PythonCommandLog10),
209  ToolboxMessageTree(I18n::Message::PythonCommandLog2, I18n::Message::PythonLog2, I18n::Message::PythonCommandLog2),
210  ToolboxMessageTree(I18n::Message::PythonCommandMathFunction, I18n::Message::PythonMathFunction, I18n::Message::PythonCommandMathFunctionWithoutArg),
211  ToolboxMessageTree(I18n::Message::PythonCommandMax, I18n::Message::PythonMax, I18n::Message::PythonCommandMax),
212  ToolboxMessageTree(I18n::Message::PythonCommandMin, I18n::Message::PythonMin, I18n::Message::PythonCommandMin),
213  ToolboxMessageTree(I18n::Message::PythonCommandModf, I18n::Message::PythonModf, I18n::Message::PythonCommandModf),
214  ToolboxMessageTree(I18n::Message::PythonCommandOct, I18n::Message::PythonOct, I18n::Message::PythonCommandOct),
215  ToolboxMessageTree(I18n::Message::PythonCommandPhase, I18n::Message::PythonPhase, I18n::Message::PythonCommandPhase),
216  ToolboxMessageTree(I18n::Message::PythonCommandConstantPi, I18n::Message::PythonConstantPi, I18n::Message::PythonCommandConstantPi),
217  ToolboxMessageTree(I18n::Message::PythonCommandPolar, I18n::Message::PythonPolar, I18n::Message::PythonCommandPolar),
218  ToolboxMessageTree(I18n::Message::PythonCommandPower, I18n::Message::PythonPower, I18n::Message::PythonCommandPower),
219  ToolboxMessageTree(I18n::Message::PythonCommandPrint, I18n::Message::PythonPrint, I18n::Message::PythonCommandPrint),
220  ToolboxMessageTree(I18n::Message::PythonCommandRadians, I18n::Message::PythonRadians, I18n::Message::PythonCommandRadians),
221  ToolboxMessageTree(I18n::Message::PythonCommandRandint, I18n::Message::PythonRandint, I18n::Message::PythonCommandRandint),
222  ToolboxMessageTree(I18n::Message::PythonCommandRandom, I18n::Message::PythonRandom, I18n::Message::PythonCommandRandom),
223  ToolboxMessageTree(I18n::Message::PythonCommandRandomFunction, I18n::Message::PythonRandomFunction, I18n::Message::PythonCommandRandomFunctionWithoutArg),
224  ToolboxMessageTree(I18n::Message::PythonCommandRandrange, I18n::Message::PythonRandrange, I18n::Message::PythonCommandRandrange),
225  ToolboxMessageTree(I18n::Message::PythonCommandRangeStartStop, I18n::Message::PythonRangeStartStop, I18n::Message::PythonCommandRangeStartStop),
226  ToolboxMessageTree(I18n::Message::PythonCommandRangeStop, I18n::Message::PythonRangeStop, I18n::Message::PythonCommandRangeStop),
227  ToolboxMessageTree(I18n::Message::PythonCommandRect, I18n::Message::PythonRect, I18n::Message::PythonCommandRect),
228  ToolboxMessageTree(I18n::Message::PythonCommandRound, I18n::Message::PythonRound, I18n::Message::PythonCommandRound),
229  ToolboxMessageTree(I18n::Message::PythonCommandSetPixel, I18n::Message::PythonSetPixel, I18n::Message::PythonCommandSetPixel),
230  ToolboxMessageTree(I18n::Message::PythonCommandSeed, I18n::Message::PythonSeed, I18n::Message::PythonCommandSeed),
231  ToolboxMessageTree(I18n::Message::PythonCommandSin, I18n::Message::PythonSin, I18n::Message::PythonCommandSin),
232  ToolboxMessageTree(I18n::Message::PythonCommandSinh, I18n::Message::PythonSinh, I18n::Message::PythonCommandSinh),
233  ToolboxMessageTree(I18n::Message::PythonCommandSorted, I18n::Message::PythonSorted, I18n::Message::PythonCommandSorted),
234  ToolboxMessageTree(I18n::Message::PythonCommandSqrt, I18n::Message::PythonSqrt, I18n::Message::PythonCommandSqrt),
235  ToolboxMessageTree(I18n::Message::PythonCommandSum, I18n::Message::PythonSum, I18n::Message::PythonCommandSum),
236  ToolboxMessageTree(I18n::Message::PythonCommandTan, I18n::Message::PythonTan, I18n::Message::PythonCommandTan),
237  ToolboxMessageTree(I18n::Message::PythonCommandTanh, I18n::Message::PythonTanh, I18n::Message::PythonCommandTanh),
238  ToolboxMessageTree(I18n::Message::PythonCommandTrunc, I18n::Message::PythonTrunc, I18n::Message::PythonCommandTrunc),
239  ToolboxMessageTree(I18n::Message::PythonCommandUniform, I18n::Message::PythonUniform, I18n::Message::PythonCommandUniform),
240  ToolboxMessageTree(I18n::Message::PythonCommandImag, I18n::Message::PythonImag, I18n::Message::PythonCommandImagWithoutArg),
241  ToolboxMessageTree(I18n::Message::PythonCommandReal, I18n::Message::PythonReal, I18n::Message::PythonCommandRealWithoutArg)
242 };
243 
244 const ToolboxMessageTree functionsChildren[functionsChildrenCount] = {
245  ToolboxMessageTree(I18n::Message::PythonCommandDefWithArg, I18n::Message::Default, I18n::Message::PythonCommandDef),
246  ToolboxMessageTree(I18n::Message::PythonCommandReturn, I18n::Message::Default, I18n::Message::PythonCommandReturn)};
247 
248 const ToolboxMessageTree menu[menuChildrenCount] = {
249  ToolboxMessageTree(I18n::Message::LoopsAndTests, I18n::Message::Default, I18n::Message::Default, loopsAndTestsChildren, loopsAndTestsChildrenCount),
250  ToolboxMessageTree(I18n::Message::Modules, I18n::Message::Default, I18n::Message::Default, modulesChildren, modulesChildrenCount),
251  ToolboxMessageTree(I18n::Message::Catalog, I18n::Message::Default, I18n::Message::Default, catalogChildren, catalogChildrenCount),
252  ToolboxMessageTree(I18n::Message::Functions, I18n::Message::Default, I18n::Message::Default, functionsChildren, functionsChildrenCount)};
253 
254 const ToolboxMessageTree toolboxModel = ToolboxMessageTree(I18n::Message::Toolbox, I18n::Message::Default, I18n::Message::Default, menu, menuChildrenCount);
255 
256 
258  Toolbox(nullptr, I18n::translate(rootModel()->label()))
259 {
260 }
261 
263  if (Toolbox::handleEvent(event)) {
264  return true;
265  }
266  if (event.hasText() && strlen(event.text()) == 1) {
267  scrollToLetter(event.text()[0]);
268  return true;
269  }
270  return false;
271 }
272 
274  if (typeAtLocation(0, j) == Toolbox::LeafCellType && m_messageTreeModel->label() == I18n::Message::IfStatementMenu) {
275  /* To get the exact height needed for each cell, we have to compute its
276  * text size, which means scan the text char by char to look for '\n'
277  * chars. This is very costly and ruins the speed performance when
278  * scrolling at the bottom of a long table: to compute a position on the
279  * kth row, we call cumulatedHeightFromIndex(k), which calls rowHeight k
280  * times.
281  * We thus decided to compute the real height only for the ifStatement
282  * children of the toolbox, which is the only menu that has special height
283  * rows. */
284  const ToolboxMessageTree * messageTree = static_cast<const ToolboxMessageTree *>(m_messageTreeModel->children(j));
285  return KDText::stringSize(I18n::translate(messageTree->label()), k_fontSize).height() + 2*Metric::TableCellLabelTopMargin + (messageTree->text() == I18n::Message::Default ? 0 : Toolbox::rowHeight(j));
286  }
287  return Toolbox::rowHeight(j);
288 }
289 
290 bool PythonToolbox::selectLeaf(ToolboxMessageTree * selectedMessageTree) {
292  ToolboxMessageTree * node = selectedMessageTree;
293  const char * editedText = I18n::translate(node->insertedText());
294  char strippedEditedText[strlen(editedText)+1];
296  TextInput * textInput = static_cast<TextInput *>(sender());
297  textInput->handleEventWithText(strippedEditedText, true);
299  return true;
300 }
301 
303  return &toolboxModel;
304 }
305 
307  assert(index >= 0 && index < k_maxNumberOfDisplayedRows);
308  return &m_leafCells[index];
309 }
310 
312  assert(index >= 0 && index < k_maxNumberOfDisplayedRows);
313  return &m_nodeCells[index];
314 }
315 
318 }
319 
320 void PythonToolbox::scrollToLetter(char letter) {
321  char lowerLetter = tolower(letter);
322  // We look for a child MessageTree that starts with the wanted letter.
323  for (int i = 0; i < m_messageTreeModel->numberOfChildren(); i++) {
324  char currentFirstLetterLowered = tolower(I18n::translate(m_messageTreeModel->children(i)->label())[0]);
325  if (currentFirstLetterLowered == lowerLetter) {
326  scrollToAndSelectChild(i);
327  return;
328  }
329  }
330  // We did not find a child MessageTree that starts with the wanted letter.
331  // We scroll to the first child MessageTree that starts with a letter higher
332  // than the wanted letter.
333  for (int i = 0; i < m_messageTreeModel->numberOfChildren(); i++) {
334  char currentFirstLetterLowered = tolower(I18n::translate(m_messageTreeModel->children(i)->label())[0]);
335  if (currentFirstLetterLowered >= lowerLetter && currentFirstLetterLowered <= 'z') {
336  scrollToAndSelectChild(i);
337  return;
338  }
339  }
340 }
341 
342 void PythonToolbox::scrollToAndSelectChild(int i) {
343  assert(i >=0 && i<m_messageTreeModel->numberOfChildren());
347 }
348 
349 }
350 
const ToolboxMessageTree modulesChildren[modulesChildrenCount]
const ToolboxMessageTree catalogChildren[catalogChildrenCount]
Definition: i18n.h:6
bool selectLeaf(ToolboxMessageTree *selectedMessageTree) override
const ToolboxMessageTree functionsChildren[functionsChildrenCount]
#define assert(e)
Definition: assert.h:9
const ToolboxMessageTree CMathModuleChildren[CMathModuleChildrenCount]
const ToolboxMessageTree MathModuleChildren[MathModuleChildrenCount]
int typeAtLocation(int i, int j) override
Definition: toolbox.cpp:179
SelectableTableView m_selectableTableView
Definition: toolbox.h:81
int16_t KDCoordinate
Definition: coordinate.h:6
const ToolboxMessageTree loopsAndTestsChildren[loopsAndTestsChildrenCount]
static KDSize stringSize(const char *text, FontSize size=FontSize::Large)
Definition: text.cpp:6
bool handleEvent(Ion::Events::Event event) override
Definition: toolbox.cpp:103
const ToolboxMessageTree toolboxModel
bool selectCellAtLocation(int i, int j, bool setFirstResponder=true)
virtual void scrollToCell(int i, int j)
Definition: table_view.cpp:26
MessageTableCellWithChevron * nodeCellAtIndex(int index) override
int numberOfChildren() const
Definition: message_tree.cpp:3
virtual bool handleEventWithText(const char *text, bool indenting=false)=0
const ToolboxMessageTree * rootModel() override
const ToolboxMessageTree whileLoopChildren[whileLoopChildrenCount]
MessageTableCellWithMessage * leafCellAtIndex(int index) override
enum Message uint16_t enum Language uint16_t const char * translate(Message m, Language l=(Language) 0)
Definition: i18n.cpp:5
bool hasText() const
Definition: events.cpp:122
Definition: app.cpp:7
void TextToInsertForCommandMessage(I18n::Message message, char *buffer)
size_t strlen(const char *s)
Definition: strlen.c:3
static constexpr int k_maxNumberOfDisplayedRows
I18n::Message label() const
Definition: message_tree.cpp:7
const ToolboxMessageTree forLoopChildren[forLoopChildrenCount]
static constexpr KDCoordinate TableCellLabelTopMargin
Definition: metric.h:18
virtual Responder * sender()
Definition: toolbox.cpp:238
const ToolboxMessageTree conditionsChildren[conditionsChildrenCount]
ToolboxMessageTree * m_messageTreeModel
Definition: toolbox.h:84
const char * text() const
Definition: events.cpp:61
const ToolboxMessageTree ifStatementChildren[ifStatementChildrenCount]
static constexpr int LeafCellType
Definition: toolbox.h:69
I18n::Message insertedText() const
int maxNumberOfDisplayedRows() override
KDCoordinate rowHeight(int j) override
const ToolboxMessageTree KandinskyModuleChildren[KandinskyModuleChildrenCount]
const ToolboxMessageTree menu[menuChildrenCount]
bool handleEvent(Ion::Events::Event event) override
I18n::Message text() const
constexpr Event Toolbox
Definition: events.h:75
const MessageTree * children(int index) const override
App * app()
Definition: responder.cpp:77
void dismissModalViewController()
Definition: app.cpp:93
virtual KDCoordinate rowHeight(int j) override
Definition: toolbox.cpp:124
const ToolboxMessageTree RandomModuleChildren[RandomModuleChildrenCount]
int tolower(int c)
Definition: ctype.c:15
constexpr KDCoordinate height() const
Definition: size.h:11