From 9029e2150656225fbca1e237f6f8292ada6150ff Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Fri, 18 Oct 2013 19:20:41 +0000 Subject: more changes for v192 --- (limited to 'plugins') diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py index 3cb4fb9..e31cb27 100644 --- a/plugins/turtle_blocks_extras/turtle_blocks_extras.py +++ b/plugins/turtle_blocks_extras/turtle_blocks_extras.py @@ -36,7 +36,8 @@ from TurtleArt.taconstants import (DEFAULT_SCALE, ICON_SIZE, CONSTANTS, MACROS, COLORDICT) from TurtleArt.tautils import (round_int, debug_output, get_path, data_to_string, find_group, image_to_base64, - hat_on_top, listify, data_from_file) + hat_on_top, listify, data_from_file, + data_to_file, chooser_dialog, get_load_name) from TurtleArt.tajail import (myfunc, myfunc_import) @@ -396,6 +397,7 @@ to the stack')) palette.add_block('see', style='box-style', label=_('turtle sees'), + value_block=True, prim_name='see', help_string=_('returns the color that the turtle \ "sees"')) @@ -487,6 +489,28 @@ make "tmp first :taheap\nmake "taheap butfirst :taheap\noutput :tmp\nend\n') self.tw.lc.def_prim('isheapempty', 0, lambda self: primitive_dictionary['isheapempty']()) + primitive_dictionary['saveheap'] = self._prim_save_heap + palette.add_block('saveheap', + style='basic-style-1arg', + label=_('save heap to file'), + default=_('filename'), + prim_name='saveheap', + help_string=_('saves FILO (first-in \ +last-out heap) to a file')) + self.tw.lc.def_prim('saveheap', 1, + lambda self, x: primitive_dictionary['saveheap'](x)) + + primitive_dictionary['loadheap'] = self._prim_load_heap + palette.add_block('loadheap', + style='basic-style-1arg', + label=_('load heap from file'), + default=_('filename'), + prim_name='loadheap', + help_string=_('loads FILO (first-in \ +last-out heap) from a file')) + self.tw.lc.def_prim('loadheap', 1, + lambda self, x: primitive_dictionary['loadheap'](x)) + primitive_dictionary['isheapempty2'] = self._prim_is_heap_empty_bool palette.add_block('isheapempty2', style='boolean-block-style', @@ -540,6 +564,14 @@ bottom of the screen')) self.tw.lc.def_prim('int', 1, lambda self, x: primitive_dictionary['int'](x)) + palette.add_block('polar', + style='basic-style-extended-vertical', + label=_('polar'), + prim_name='polar', + help_string=_('displays polar coordinates')) + self.tw.lc.def_prim('polar', 0, + lambda self: self.tw.set_polar(True)) + primitive_dictionary['myfunction'] = self._prim_myfunction palette.add_block('myfunc1arg', style='number-style-var-arg', @@ -581,6 +613,14 @@ advanced multi-variable math equations, e.g., sin(x+y+z)')) lambda self, f, x, y, z: primitive_dictionary['myfunction'](f, [x, y, z])) + palette.add_block('cartesian', + style='basic-style-extended-vertical', + label=_('Cartesian'), + prim_name='cartesian', + help_string=_('displays Cartesian coordinates')) + self.tw.lc.def_prim('cartesian', 0, + lambda self: self.tw.set_cartesian(True)) + primitive_dictionary['userdefined'] = self._prim_myblock palette.add_block('userdefined', style='basic-style-var-arg', @@ -634,21 +674,52 @@ module found in the Journal')) MEDIA_SHAPES.append('pythonoff') MEDIA_SHAPES.append('pythonon') - palette.add_block('cartesian', - style='basic-style-extended-vertical', - label=_('Cartesian'), - prim_name='cartesian', - help_string=_('displays Cartesian coordinates')) - self.tw.lc.def_prim('cartesian', 0, - lambda self: self.tw.set_cartesian(True)) + primitive_dictionary['loadblock'] = self._prim_load_block + palette.add_block('loadblock', + style='basic-style-var-arg', + label=_('load'), + prim_name='loadblock', + default=_('forward'), + help_string=_('loads a block')) + self.tw.lc.def_prim('loadblock', 1, + lambda self, x: + primitive_dictionary['loadblock'](x)) - palette.add_block('polar', - style='basic-style-extended-vertical', - label=_('polar'), - prim_name='polar', - help_string=_('displays polar coordinates')) - self.tw.lc.def_prim('polar', 0, - lambda self: self.tw.set_polar(True)) + palette.add_block('loadblock2arg', + style='basic-style-var-arg', + hidden=True, + label=_('load'), + prim_name='loadblock2', + string_or_number=True, + default=[_('forward'), 100], + help_string=_('loads a block')) + self.tw.lc.def_prim('loadblock2', 2, + lambda self, x, y: + primitive_dictionary['loadblock']([x, y])) + + palette.add_block('loadblock3arg', + style='basic-style-var-arg', + hidden=True, + label=_('load'), + string_or_number=True, + prim_name='loadblock3', + default=[_('setxy'), 0, 0], + help_string=_('loads a block')) + self.tw.lc.def_prim('loadblock3', 3, + lambda self, x, y, z: + primitive_dictionary['loadblock']([x, y, z])) + + primitive_dictionary['loadpalette'] = self._prim_load_palette + palette.add_block('loadpalette', + style='basic-style-1arg', + string_or_number=True, + label=_('select palette'), + prim_name='loadpalette', + default=_('turtle'), + help_string=_('selects a palette')) + self.tw.lc.def_prim('loadpalette', 1, + lambda self, x: + primitive_dictionary['loadpalette'](x)) palette.add_block('addturtle', style='basic-style-1arg', @@ -729,53 +800,6 @@ module found in the Journal')) special_name=_('top'), help_string=_('top of a collapsed stack')) - primitive_dictionary['loadblock'] = self._prim_load_block - palette.add_block('loadblock', - style='basic-style-var-arg', - label=_('load'), - prim_name='loadblock', - default=_('forward'), - help_string=_('loads a block')) - self.tw.lc.def_prim('loadblock', 1, - lambda self, x: - primitive_dictionary['loadblock'](x)) - - palette.add_block('loadblock2arg', - style='basic-style-var-arg', - hidden=True, - label=_('load'), - prim_name='loadblock2', - string_or_number=True, - default=[_('forward'), 100], - help_string=_('loads a block')) - self.tw.lc.def_prim('loadblock2', 2, - lambda self, x, y: - primitive_dictionary['loadblock']([x, y])) - - palette.add_block('loadblock3arg', - style='basic-style-var-arg', - hidden=True, - label=_('load'), - string_or_number=True, - prim_name='loadblock3', - default=[_('setxy'), 0, 0], - help_string=_('loads a block')) - self.tw.lc.def_prim('loadblock3', 3, - lambda self, x, y, z: - primitive_dictionary['loadblock']([x, y, z])) - - primitive_dictionary['loadpalette'] = self._prim_load_palette - palette.add_block('loadpalette', - style='basic-style-1arg', - string_or_number=True, - label=_('select palette'), - prim_name='loadpalette', - default=_('turtle'), - help_string=_('selects a palette')) - self.tw.lc.def_prim('loadpalette', 1, - lambda self, x: - primitive_dictionary['loadpalette'](x)) - def _portfolio_palette(self): debug_output('creating %s palette' % _('portfolio'), self.tw.running_sugar) @@ -1217,6 +1241,58 @@ Journal objects')) else: self.tw.showlabel('print', str(self.tw.lc.heap)) + def _prim_load_heap(self, path): + """ Load FILO from file """ + if type(path) == float: + path = '' + if self.tw.running_sugar: + # Choose a datastore object and push data to heap (Sugar only) + chooser_dialog(self.tw.parent, path, + self.tw.lc.push_file_data_to_heap) + else: + if not os.path.exists(path): + path, tw.load_save_folder = get_load_name( + '.*', self.tw.load_save_folder) + if path is None: + return + + data = data_from_file(path) + if data is not None: + for val in data: + self.tw.lc.heap.append(val) + + if len(self.tw.lc.heap) > 0: + self.tw.lc.update_label_value('pop', self.tw.lc.heap[-1]) + + def _prim_save_heap(self, path): + """ save FILO to file """ + # TODO: add GNOME save + + if self.tw.running_sugar: + from sugar import profile + from sugar.datastore import datastore + from sugar.activity import activity + + # Save JSON-encoded heap to temporary file + heap_file = os.path.join(get_path(activity, 'instance'), + str(path) + '.txt') + data_to_file(self.tw.lc.heap, heap_file) + + # Create a datastore object + dsobject = datastore.create() + + # Write any metadata (specifically set the title of the file + # and specify that this is a plain text file). + dsobject.metadata['title'] = str(path) + dsobject.metadata['icon-color'] = profile.get_color().to_string() + dsobject.metadata['mime_type'] = 'text/plain' + dsobject.set_file_path(heap_file) + datastore.write(dsobject) + dsobject.destroy() + else: + heap_file = path + data_to_file(self.tw.lc.heap, heap_file) + def _prim_push(self, val): """ Push value onto FILO """ self.tw.lc.heap.append(val) -- cgit v0.9.1