@@ -47,7 +47,14 @@ def initialize_blockly( blockly_id='blocklyDiv', toolbox_id='toolbox', on_change
4747 v .setAttribute ('name' , input ['name' ])
4848 e .appendChild (v )
4949 nb = document .createElement ('block' )
50- nb .setAttribute ('type' , 'logic_null' )
50+ if input ['default_value' ] is not None :
51+ nb .setAttribute ('type' , 'math_number' ) ## TODO support other types
52+ t = document .createElement ('title' )
53+ t .setAttribute ('name' , 'NUM' )
54+ t .appendChild ( document .createTextNode (input ['default_value' ]) )
55+ nb .appendChild (t )
56+ else :
57+ nb .setAttribute ('type' , 'logic_null' )
5158 v .appendChild (nb )
5259 i += 1
5360
@@ -116,15 +123,23 @@ def setup(self, block_name=None, title=None, color=None, category=None):
116123 def javascript_callback (self , jsfunc ):
117124 print '@callback' , jsfunc
118125 self .set_external_function ( jsfunc .NAME , javascript = True )
119- with javascript : arr = jsfunc .args_signature
120- for i in range (arr .length ): self .add_input_value ( arr [i ] )
126+ with javascript :
127+ arr = jsfunc .args_signature
128+ defs = jsfunc .kwargs_signature
129+ for i in range (arr .length ):
130+ name = arr [i ]
131+ self .add_input_value ( name , default_value = defs [name ] )
121132 return jsfunc
122133
123134 def callback (self , jsfunc ): ## decorator
124135 print '@callback' , jsfunc
125136 self .set_external_function ( jsfunc .NAME )
126- with javascript : arr = jsfunc .args_signature
127- for i in range (arr .length ): self .add_input_value ( arr [i ] )
137+ with javascript :
138+ arr = jsfunc .args_signature
139+ defs = jsfunc .kwargs_signature
140+ for i in range (arr .length ):
141+ name = arr [i ]
142+ self .add_input_value ( name , default_value = defs [name ] )
128143 return jsfunc
129144
130145 def set_on_click_callback (self , callback ):
@@ -154,15 +169,15 @@ def make_statement(self, stack_input=None, stack_output=None):
154169 self .stack_output = stack_output
155170 self .is_statement = True
156171
157- def add_input_value (self , name = None , type = None , title = None ):
172+ def add_input_value (self , name = None , type = None , title = None , default_value = None ):
158173 if name is None : raise TypeError
159174 elif type == 'Number' : pass
160175 elif type == 'String' : pass
161176 elif type == 'Array' : pass
162177 #else: raise TypeError
163178 if title is None : title = name
164179 self .input_values .append (
165- {'name' :name , 'type' :type , 'title' :title }
180+ {'name' :name , 'type' :type , 'title' :title , 'default_value' : default_value }
166181 )
167182
168183 def add_input_statement (self , name = None , title = None , callback = None ):
0 commit comments