diff options
author | Marion <marion.zepf@gmail.com> | 2013-09-06 12:30:22 (GMT) |
---|---|---|
committer | Marion <marion.zepf@gmail.com> | 2013-09-06 12:30:22 (GMT) |
commit | 73c40f3f55f8055fa8d8acf20ab5f4b7328f7b89 (patch) | |
tree | 6b513c2c9e6f1ab5c86d86b9f9c63dea6eef9cef | |
parent | 440b2fd29dd1bce06678e9f2d774ee5e443cad96 (diff) |
add Primitives for the 'chr' and 'int' blocks
-rw-r--r-- | plugins/turtle_blocks_extras/turtle_blocks_extras.py | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py index 08e00bc..dca52a5 100644 --- a/plugins/turtle_blocks_extras/turtle_blocks_extras.py +++ b/plugins/turtle_blocks_extras/turtle_blocks_extras.py @@ -39,7 +39,8 @@ from TurtleArt.tautils import (round_int, debug_output, get_path, hat_on_top, listify, data_from_file) from TurtleArt.tajail import (myfunc, myfunc_import) from TurtleArt.taprimitive import (ArgSlot, ConstantArg, Primitive) -from TurtleArt.tatype import (TYPE_BOOL, TYPE_OBJECT, TYPE_STRING) +from TurtleArt.tatype import (TYPE_BOOL, TYPE_CHAR, TYPE_INT, TYPE_NUMBER, + TYPE_OBJECT, TYPE_STRING) def _num_type(x): @@ -558,23 +559,25 @@ bottom of the screen')) lambda self, x: primitive_dictionary['print'](x, False)) - primitive_dictionary['chr'] = self._prim_chr palette.add_block('chr', style='number-style-1arg', label='chr', prim_name='chr', help_string=_('Python chr operator')) self.tw.lc.def_prim('chr', 1, - lambda self, x: primitive_dictionary['chr'](x)) + Primitive(chr, return_type=TYPE_CHAR, + arg_descs=[ArgSlot(TYPE_INT)])) - primitive_dictionary['int'] = self._prim_int palette.add_block('int', style='number-style-1arg', label='int', prim_name='int', help_string=_('Python int operator')) self.tw.lc.def_prim('int', 1, - lambda self, x: primitive_dictionary['int'](x)) + # leave over the actual work to the type system, and just demand + # that the argument be converted to an integer + Primitive(Primitive.identity, return_type=TYPE_INT, + arg_descs=[ArgSlot(TYPE_INT)])) primitive_dictionary['myfunction'] = self._prim_myfunction palette.add_block('myfunc1arg', @@ -1459,22 +1462,6 @@ Journal objects')) self.tw.activity.stop_turtle_button.set_icon("stopiton") self.tw.activity.stop_turtle_button.set_tooltip(_('Stop turtle')) - def _prim_chr(self, x): - """ Chr conversion """ - try: - return chr(int(x)) - except ValueError: - self.tw.lc.stop_logo() - raise logoerror("#notanumber") - - def _prim_int(self, x): - """ Int conversion """ - try: - return int(x) - except ValueError: - self.tw.lc.stop_logo() - raise logoerror("#notanumber") - def _prim_load_block(self, blkname): ''' Load a block on to the canvas ''' # Place the block at the active turtle (x, y) and move the turtle |