You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit be78ffc
Browse filesBrowse the repository at this point in the historyBrowse files
// Call the web_editor function to start the editor running.
220
+
web_editor({
221
+
'translate': {
222
+
'code_snippets': {
223
+
'title': 'Code Snippets',
224
+
'description': "Code snippets are short blocks of code to re-use in your own programs. There are snippets for most common things you'll want to do using MicroPython.",
225
+
'instructions': "Select one of the snippets below, or type the snippet's trigger then tap the TAB key.",
226
+
'trigger_heading': 'trigger',
227
+
'description_heading': 'description',
228
+
'docs': 'create a comment to describe your code',
229
+
'wh': 'while some condition is True, keep looping over some code',
230
+
'with': 'do some stuff with something assigned to a name',
231
+
'cl': 'create a new class that defines the behaviour of a new type of object',
232
+
'def': 'define a named function that takes some arguments and optionally add a description',
233
+
'if': 'if some condition is True, do something',
234
+
'ei': 'else if some other condition is True, do something',
235
+
'el': 'else do some other thing',
236
+
'for': 'for each item in a collection of items do something with each item',
237
+
'try': 'try doing something and handle exceptions (errors)'
238
+
},
239
+
'share': {
240
+
'title': 'Share Code',
241
+
'description': 'This link points to your code:',
242
+
},
243
+
'alerts': {
244
+
'download': 'Safari has a bug that means your work will be downloaded as an un-named file. Please rename it to something ending in .hex. Alternatively, use a browser such as Firefox or Chrome. They do not suffer from this bug.',
245
+
'save': 'Safari has a bug that means your work will be downloaded as an un-named file. Please rename it to something ending in .py. Alternatively, use a browser such as Firefox or Chrome. They do not suffer from this bug.',
246
+
'length': 'Oops! Your script is to long given the limited memory on the device.'
247
+
},
248
+
'confirms': {
249
+
'quit': "Some of your changes have not been saved. Quit anyway?",
250
+
'blocks': "You have unsaved code. Using blocks will change your code. You may lose your changes. Do you want to continue?"
Copy file name to clipboardExpand all lines: python-main.js
+43-24Lines changed: 43 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/*
2
-
0.0.7
2
+
0.0.8
3
3
4
4
A simple editor that targets MicroPython for the BBC micro:bit.
5
5
@@ -89,7 +89,10 @@ function pythonEditor(id) {
89
89
for(vari=0;i<script.length;++i){
90
90
data[4+i]=script.charCodeAt(i);
91
91
}
92
-
// TODO check data.length < 0x2000
92
+
// check data.length < 0x2000
93
+
if(data.length>8192){
94
+
thrownewRangeError('Too long');
95
+
}
93
96
// convert to .hex format
94
97
varaddr=0x3e000;// magic start address in flash
95
98
varchunk=newUint8Array(5+16);
@@ -172,7 +175,7 @@ the editor to the DOM (web-page).
172
175
173
176
See the comments in-line for more information.
174
177
*/
175
-
functionweb_editor(){
178
+
functionweb_editor(config){
176
179
177
180
// Indicates if there are unsaved changes to the content of the editor.
178
181
vardirty=false;
@@ -227,6 +230,20 @@ function web_editor() {
227
230
setFontSize(fontSize);
228
231
};
229
232
233
+
// Checks for feature flags in the config object and shows/hides UI
234
+
// elements as required.
235
+
functionsetupFeatureFlags(){
236
+
if(config.flags.blocks){
237
+
$("#command-blockly").removeClass('hidden');
238
+
}
239
+
if(config.flags.snippets){
240
+
$("#command-snippet").removeClass('hidden');
241
+
}
242
+
if(config.flags.share){
243
+
$("#command-share").removeClass('hidden');
244
+
}
245
+
};
246
+
230
247
// This function is called by TouchDevelop to cause the editor to be initialised. It sets things up so the user sees their code or, in the case of a new program, uses some sane defaults.
231
248
functionsetupEditor(message){
232
249
// Setup the Ace editor.
@@ -247,12 +264,7 @@ function web_editor() {
247
264
EDITOR.setCode(message.code);
248
265
}else{
249
266
// A sane default starting point for a new script.
250
-
EDITOR.setCode("# Add your Python code here. E.g.\n"+
alert("Safari has a bug that means your work will be downloaded as an un-named file. Please rename it to something ending in .hex. Alternatively, use a browser such as Firefox or Chrome. They do not suffer from this bug.");
alert("Safari has a bug that means your work will be downloaded as an un-named file. Please rename it to something ending in .py. Alternatively, use a browser such as Firefox or Chrome. They do not suffer from this bug.");
0 commit comments