Skip to content

Commit 2f9e29b

Browse files
author
hartsantler
committed
THREE.js with GoogleBlockly editor prototype.
1 parent b604f0f commit 2f9e29b

6 files changed

Lines changed: 418 additions & 7 deletions

File tree

bindings/ace.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# PythonJS binding for Ace Editor http://ace.c9.io/
2+
# by Brett Hartshorn - copyright 2013
3+
# License: "New BSD"
4+
5+
class AceEditor:
6+
def __init__(self, div_id='editor', mode='python', theme=None):
7+
with javascript: self[...] = ace.edit( div_id )
8+
if mode: self.setMode( mode )
9+
if theme: self.setTheme( theme )
10+
11+
def setMode(self, mode):
12+
with javascript:
13+
self[...].getSession().setMode( 'ace/mode/'+mode )
14+
15+
def setTheme(self, name='monokai'):
16+
with javascript:
17+
self[...].setTheme( 'ace/theme/'+name)
18+
19+
def setValue(self, txt):
20+
with javascript:
21+
self[...].setValue( txt )
22+
23+
def getValue(self):
24+
with javascript:
25+
return self[...].getValue()
26+
27+

bindings/blockly.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ def initialize_blockly( blockly_id='blocklyDiv', toolbox_id='toolbox', on_change
1212
defaults = []
1313
cats = {}
1414
for block_name in BlocklyBlockGenerators.keys():
15+
b = BlocklyBlockGenerators[ block_name ]
1516
e = document.createElement('block')
1617
e.setAttribute('type', block_name)
1718

18-
b = BlocklyBlockGenerators[ block_name ]
1919
if b.category:
2020
if b.category in cats:
2121
cats[ b.category ].appendChild( e )
@@ -28,6 +28,19 @@ def initialize_blockly( blockly_id='blocklyDiv', toolbox_id='toolbox', on_change
2828
else:
2929
defaults.append( e )
3030

31+
i = 0
32+
#for i in range(len(b.input_values)): ## TODO check why this got broken
33+
while i < len(b.input_values):
34+
input = b.input_values[i]
35+
v = document.createElement('value')
36+
v.setAttribute('name', input['name'])
37+
e.appendChild(v)
38+
nb = document.createElement('block')
39+
nb.setAttribute('type', 'logic_null')
40+
v.appendChild(nb)
41+
i += 1
42+
43+
3144
if len(defaults):
3245
cat = document.createElement('category')
3346
cat.setAttribute('name', 'Callbacks')
@@ -226,7 +239,7 @@ def generator(block):
226239
code += a + ';'
227240

228241
if is_statement:
229-
return code ## statements can directly return
242+
return code + ';' ## statements can directly return
230243
else:
231244
return [ code, Blockly.Python.ORDER_NONE ] ## return Array
232245

@@ -239,13 +252,13 @@ class StatementBlock( BlocklyBlock ):
239252
'''
240253
A statement-block has a previous and/or next statement notch: stack_input and/or stack_output
241254
'''
242-
def __init__(self, name, title=None, stack_input=False, stack_output=False, color=150, category=None):
255+
def __init__(self, name, title=None, stack_input=False, stack_output=False, color=170, category=None):
243256
self.setup( name, title=title, color=color, category=category )
244257
self.make_statement( stack_input=stack_input, stack_output=stack_output)
245258

246259

247260
class ValueBlock( BlocklyBlock ):
248-
def __init__(self, name, title=None, output=None, color=120, category=None):
261+
def __init__(self, name, title=None, output='*', color=100, category=None):
249262
if output is None: raise TypeError
250263
self.setup( name, title=title, color=color, category=category )
251264
self.set_output( output )

bindings/three.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# THREE.js wrapper for PythonScript
1+
# THREE.js wrapper for PythonJS
22
# by Brett Hartshorn - copyright 2013
33
# License: "New BSD"
44

pythonjs/python_to_pythonjs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,9 @@ def visit_Assign(self, node):
824824
elif type == 'dict':
825825
self._global_typed_dicts[ target.id ] = set()
826826

827-
writer.write('%s = %s ## global type: %s' % (target.id, node_value, type))
827+
writer.write('%s = %s' % (target.id, node_value))
828828
else:
829-
writer.write('%s = %s ## type: %s' % (target.id, node_value, type))
829+
writer.write('%s = %s' % (target.id, node_value))
830830
else:
831831
writer.write('%s = %s' % (target.id, node_value))
832832

tests/server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ def get(self, path=None):
257257
'ace.js': os.path.expanduser( '~/ace-builds/src-noconflict/ace.js'),
258258
'theme-monokai.js':os.path.expanduser( '~/ace-builds/src-noconflict/theme-monokai.js'),
259259
'mode-python.js':os.path.expanduser( '~/ace-builds/src-noconflict/mode-python.js'),
260+
'mode-javascript.js':os.path.expanduser( '~/ace-builds/src-noconflict/mode-javascript.js'),
261+
'worker-javascript.js':os.path.expanduser( '~/ace-builds/src-noconflict/worker-javascript.js'),
260262
},
261263
)
262264

0 commit comments

Comments
 (0)