diff options
-rw-r--r-- | TurtleArt/tabasics.py | 132 | ||||
-rw-r--r-- | TurtleArt/taconstants.py | 4 | ||||
-rw-r--r-- | TurtleArtActivity.py | 95 | ||||
-rw-r--r-- | plugins/turtle_blocks_extras/turtle_blocks_extras.py | 16 |
4 files changed, 131 insertions, 116 deletions
diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py index f92123b..9a921b4 100644 --- a/TurtleArt/tabasics.py +++ b/TurtleArt/tabasics.py @@ -67,7 +67,7 @@ from gettext import gettext as _ from tapalette import (make_palette, define_logo_function) from talogo import (primitive_dictionary, logoerror) from tautils import (convert, chr_to_ord, round_int, strtype) -from taconstants import (COLORDICT, CONSTANTS) +from taconstants import (LOGOCOLORDICT, COLORDICT, CONSTANTS) def _color_to_num(c): @@ -187,8 +187,8 @@ degrees)')) self.tw.lc.def_prim('arc', 2, lambda self, x, y: primitive_dictionary['arc']( self.tw.canvas.arc, x, y)) - define_logo_function('taarc', 'to taarc :a :r\rrepeat round :a \ -[right 1 forward (0.0175 * :r)]\rend\r') + define_logo_function('taarc', 'to taarc :a :r\nrepeat round :a \ +[right 1 forward (0.0175 * :r)]\nend\n') palette.add_block('setxy2', style='basic-style-2arg', @@ -201,7 +201,7 @@ degrees)')) self.tw.lc.def_prim('setxy2', 2, lambda self, x, y: primitive_dictionary['move']( self.tw.canvas.setxy, x, y)) - define_logo_function('tasetxy', 'to tasetxy :x :y\rsetxy :x :y\rend\r') + define_logo_function('tasetxy', 'to tasetxy :x :y\nsetxy :x :y\nend\n') primitive_dictionary['set'] = self._prim_set palette.add_block('seth', @@ -267,8 +267,8 @@ turtle (can be used in place of a number block)'), self.tw.lc.def_prim('setxy', 2, lambda self, x, y: primitive_dictionary['move']( self.tw.canvas.setxy, x, y, pendown=False)) - define_logo_function('tasetxypenup', 'to tasetxypenup :x :y\rpenup\r\ -setxy :x :y\rpendown\rend\r') + define_logo_function('tasetxypenup', 'to tasetxypenup :x :y\npenup\n\ +setxy :x :y\npendown\nend\n') def _pen_palette(self): """ The basic Turtle Art pen palette """ @@ -302,7 +302,7 @@ shade)')) lambda self, x, y, z: self.tw.canvas.fillscreen_with_gray(x, y, z)) define_logo_function('tasetbackground', 'to tasetbackground :color \ -:shade\rtasetshade :shade\rsetbackground :color\rend\r') +:shade\ntasetshade :shade\nsetbackground :color\nend\n') palette.add_block('setcolor', style='basic-style-1arg', @@ -396,8 +396,8 @@ turtle')) self.tw.lc.def_prim('setpensize', 1, lambda self, x: primitive_dictionary['set']( 'pensize', self.tw.canvas.setpensize, x)) - define_logo_function('tasetpensize', 'to tasetpensize :a\rsetpensize \ -round :a\rend\r') + define_logo_function('tasetpensize', 'to tasetpensize :a\nsetpensize \ +round :a\nend\n') palette.add_block('startfill', style='basic-style-extended-vertical', @@ -426,8 +426,8 @@ in place of a number block)'), prim_name='pensize', logo_command='pensize') self.tw.lc.def_prim('pensize', 0, lambda self: self.tw.canvas.pensize) - define_logo_function('tapensize', 'to tapensize\routput first round \ -pensize\rend\r') + define_logo_function('tapensize', 'to tapensize\noutput first round \ +pensize\nend\n') def _color_palette(self): """ The basic Turtle Art color palette """ @@ -475,51 +475,51 @@ turtle')) # In order to map Turtle Art colors to the standard UCB Logo palette, # we need to define a somewhat complex set of functions. define_logo_function('tacolor', '\ -to tasetpalette :i :r :g :b :myshade \r\ -make "s ((:myshade - 50) / 50) \r\ -ifelse lessp :s 0 [ \r\ -make "s (1 + (:s *0.8)) \r\ -make "r (:r * :s) \r\ -make "g (:g * :s) \r\ -make "b (:b * :s) \r\ +to tasetpalette :i :r :g :b :myshade \n\ +make "s ((:myshade - 50) / 50) \n\ +ifelse lessp :s 0 [ \n\ +make "s (1 + (:s *0.8)) \n\ +make "r (:r * :s) \n\ +make "g (:g * :s) \n\ +make "b (:b * :s) \n\ ] [ \ -make "s (:s * 0.9) \r\ -make "r (:r + ((99-:r) * :s)) \r\ -make "g (:g + ((99-:g) * :s)) \r\ -make "b (:b + ((99-:b) * :s)) \r\ +make "s (:s * 0.9) \n\ +make "r (:r + ((99-:r) * :s)) \n\ +make "g (:g + ((99-:g) * :s)) \n\ +make "b (:b + ((99-:b) * :s)) \n\ ] \ -setpalette :i (list :r :g :b) \r\ -end \r\ +setpalette :i (list :r :g :b) \n\ +end \n\ \ -to rgb :myi :mycolors :myshade \r\ -make "myr first :mycolors \r\ -make "mycolors butfirst :mycolors \r\ -make "myg first :mycolors \r\ -make "mycolors butfirst :mycolors \r\ -make "myb first :mycolors \r\ -make "mycolors butfirst :mycolors \r\ -tasetpalette :myi :myr :myg :myb :myshade \r\ -output :mycolors \r\ -end \r\ +to rgb :myi :mycolors :myshade \n\ +make "myr first :mycolors \n\ +make "mycolors butfirst :mycolors \n\ +make "myg first :mycolors \n\ +make "mycolors butfirst :mycolors \n\ +make "myb first :mycolors \n\ +make "mycolors butfirst :mycolors \n\ +tasetpalette :myi :myr :myg :myb :myshade \n\ +output :mycolors \n\ +end \n\ \ -to processcolor :mycolors :myshade \r\ -if emptyp :mycolors [stop] \r\ -make "i :i + 1 \r\ -processcolor (rgb :i :mycolors :myshade) :myshade \r\ -end \r\ +to processcolor :mycolors :myshade \n\ +if emptyp :mycolors [stop] \n\ +make "i :i + 1 \n\ +processcolor (rgb :i :mycolors :myshade) :myshade \n\ +end \n\ \ -to tasetshade :shade \r\ -make "myshade modulo :shade 200 \r\ -if greaterp :myshade 99 [make "myshade (199-:myshade)] \r\ -make "i 7 \r\ -make "mycolors :colors \r\ -processcolor :mycolors :myshade \r\ -end \r\ +to tasetshade :shade \n\ +make "myshade modulo :shade 200 \n\ +if greaterp :myshade 99 [make "myshade (199-:myshade)] \n\ +make "i 7 \n\ +make "mycolors :colors \n\ +processcolor :mycolors :myshade \n\ +end \n\ \ -to tasetpencolor :c \r\ -make "color (modulo (round :c) 100) \r\ -setpencolor :color + 8 \r\ -end \r\ +to tasetpencolor :c \n\ +make "color (modulo (round :c) 100) \n\ +setpencolor :color + 8 \n\ +end \n\ \ make "colors [ \ 99 0 0 99 5 0 99 10 0 99 15 0 99 20 0 \ @@ -541,9 +541,9 @@ make "colors [ \ 50 0 99 55 0 99 60 0 99 65 0 99 70 0 99 \ 75 0 99 80 0 99 85 0 99 90 0 99 95 0 99 \ 99 0 99 99 0 90 99 0 80 99 0 70 99 0 60 \ -99 0 50 99 0 40 99 0 30 99 0 20 99 0 10] \r\ -make "shade 50 \r\ -tasetshade :shade \r') +99 0 50 99 0 40 99 0 30 99 0 20 99 0 10] \n\ +make "shade 50 \n\ +tasetshade :shade \n') def _numbers_palette(self): """ The basic Turtle Art numbers palette """ @@ -575,8 +575,8 @@ tasetshade :shade \r') top numeric input')) self.tw.lc.def_prim( 'minus', 2, lambda self, x, y: primitive_dictionary['minus'](x, y)) - define_logo_function('taminus', 'to taminus :y :x\routput sum :x \ -minus :y\rend\r') + define_logo_function('taminus', 'to taminus :y :x\noutput sum :x \ +minus :y\nend\n') primitive_dictionary['product'] = self._prim_product palette.add_block('product2', @@ -648,8 +648,8 @@ minimum (top) and maximum (bottom) values')) self.tw.lc.def_prim( 'random', 2, lambda self, x, y: primitive_dictionary['random']( x, y)) - define_logo_function('tarandom', 'to tarandom :min :max\r \ -output (random (:max - :min)) + :min\rend\r') + define_logo_function('tarandom', 'to tarandom :min :max\n \ +output (random (:max - :min)) + :min\nend\n') palette.add_block('number', style='box-style', @@ -838,7 +838,7 @@ boolean operators from Numbers palette')) style='basic-style-head', label=_('start'), prim_name='start', - logo_command='to start\r', + logo_command='to start\n', help_string=_('connects action to toolbar run \ buttons')) self.tw.lc.def_prim('start', 0, @@ -951,7 +951,7 @@ variable')) style='basic-style-head', label=_('action 1'), prim_name='nop1', - logo_command='to stack1\r', + logo_command='to stack1\n', help_string=_('top of Action 1 stack')) self.tw.lc.def_prim('nop1', 0, lambda self: None) @@ -960,7 +960,7 @@ variable')) style='basic-style-head', label=_('action 2'), prim_name='nop2', - logo_command='to stack2\r', + logo_command='to stack2\n', help_string=_('top of Action 2 stack')) self.tw.lc.def_prim('nop2', 0, lambda self: None) @@ -1382,7 +1382,13 @@ variable')) def _make_constant(self, palette, block_name, label, constant): """ Factory for constant blocks """ - palette.add_block(block_name, style='box-style', - label=label, prim_name=block_name, - logo_command=block_name) + if constant in LOGOCOLORDICT: + value = str(LOGOCOLORDICT[constant]) + else: + value = constant + palette.add_block(block_name, + style='box-style', + label=label, + prim_name=block_name, + logo_command=value) self.tw.lc.def_prim(block_name, 0, lambda self: constant) diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py index 1fb979a..4961b24 100644 --- a/TurtleArt/taconstants.py +++ b/TurtleArt/taconstants.py @@ -92,6 +92,10 @@ COLORDICT = {'_black': [None, 0, 0], '_white': [None, 100, 0], '_cyan': [50, 50, 100], '_blue': [70, 50, 100], '_purple': [90, 50, 100]} +LOGOCOLORDICT = {'_black': 0, '_white': 1, '_red': 2, '_orange': 3, + '_yellow': 3, '_green': 4, '_cyan': 5, '_blue': 6, + '_purple': 7} + # Blocks that are expandable EXPANDABLE_STYLE = ['boolean-style', 'compare-porch-style', 'compare-style', diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py index 4cd1e80..6acea2d 100644 --- a/TurtleArtActivity.py +++ b/TurtleArtActivity.py @@ -57,12 +57,12 @@ import gconf from gettext import gettext as _ from TurtleArt.tapalette import (palette_names, help_strings, help_palettes, - help_windows) + help_windows) from TurtleArt.taconstants import (BLOCK_SCALE, XO1, XO15, XO175, XO30, XO4, MIMETYPE) from TurtleArt.taexportlogo import save_logo from TurtleArt.tautils import (data_to_file, data_to_string, data_from_string, - get_path, chooser, get_hardware) + get_path, chooser, get_hardware) from TurtleArt.tawindow import TurtleArtWindow from TurtleArt.tacollaboration import Collaboration @@ -199,10 +199,10 @@ class TurtleArtActivity(activity.Activity): def _load_ta_project(self, dsobject): ''' Load a TA project from the datastore. ''' try: - _logger.debug('Opening %s ' % dsobject.file_path) + _logger.debug('Opening %s ' % (dsobject.file_path)) self.read_file(dsobject.file_path, run_it=False, plugin=False) except: - _logger.debug("Couldn't open %s" % dsobject.file_path) + _logger.debug("Couldn't open %s" % (dsobject.file_path)) def do_load_ta_plugin_cb(self, button): ''' Load a plugin from the Journal. ''' @@ -216,7 +216,7 @@ class TurtleArtActivity(activity.Activity): def _load_ta_plugin(self, dsobject): ''' Load a TA plugin from the datastore. ''' - _logger.debug('Opening %s ' % dsobject.file_path) + _logger.debug('Opening %s ' % (dsobject.file_path)) self.read_file(dsobject.file_path, run_it=False, plugin=True) def do_load_python_cb(self, button): @@ -531,7 +531,7 @@ class TurtleArtActivity(activity.Activity): def is_fullscreen(self): ''' Are we in fullscreen mode (toolbars hidden)? ''' - # Fixme: this should be a exposed as a window property, not private + # Fixme: this should be a exposed as a window property, not private return self._is_fullscreen def toolbars_expanded(self, palette=False): @@ -577,13 +577,13 @@ class TurtleArtActivity(activity.Activity): edit_toolbar = gtk.Toolbar() self.edit_toolbar_button = ToolbarButton(label=_('Edit'), - page=edit_toolbar, - icon_name='toolbar-edit') + page=edit_toolbar, + icon_name='toolbar-edit') self._view_toolbar = gtk.Toolbar() self.view_toolbar_button = ToolbarButton(label=_('View'), - page=self._view_toolbar, - icon_name='toolbar-view') + page=self._view_toolbar, + icon_name='toolbar-view') self._palette_toolbar = gtk.Toolbar() self.palette_toolbar_button = ToolbarButton( page=self._palette_toolbar, icon_name='palette') @@ -802,7 +802,7 @@ class TurtleArtActivity(activity.Activity): add_paragraph(help_box, _('Metric coordinates'), icon='view-metric') add_paragraph(help_box, _('Rescale coordinates up'), - icon='expand-coordinates') + icon='expand-coordinates') add_paragraph(help_box, _('Grow blocks'), icon='resize+') add_paragraph(help_box, _('Shrink blocks'), icon='resize-') add_paragraph(help_box, _('Turn off hover help'), icon='help-off') @@ -872,35 +872,38 @@ class TurtleArtActivity(activity.Activity): palette_group = None else: palette_group = self.palette_buttons[0] - _logger.debug('palette_buttons.append %s', palette_name) - self.palette_buttons.append(self._radio_button_factory( + _logger.debug('palette_buttons.append %s', (palette_name)) + self.palette_buttons.append( + self._radio_button_factory( palette_name + 'off', None, self.do_palette_buttons_cb, i, help_strings[palette_name], palette_group)) - self._overflow_buttons.append(self._add_button( - palette_name + 'off', - None, - self.do_palette_buttons_cb, - None, - arg=i)) + self._overflow_buttons.append( + self._add_button( + palette_name + 'off', + None, + self.do_palette_buttons_cb, + None, + arg=i)) # And we need an extra button for the overflow self._overflow_palette_button = self._radio_button_factory( - 'overflow', - None, - self._overflow_palette_cb, - None, - _('Palettes'), - palette_group) + 'overflow', + None, + self._overflow_palette_cb, + None, + _('Palettes'), + palette_group) def _overflow_palette_cb(self, button): _logger.debug('overflow palette cb') if self._overflow_palette: if not self._overflow_palette.is_up(): - self._overflow_palette.popup(immediate=True, - state=self._overflow_palette.SECONDARY) + self._overflow_palette.popup( + immediate=True, + state=self._overflow_palette.SECONDARY) else: self._overflow_palette.popdown(immediate=True) return @@ -931,8 +934,11 @@ class TurtleArtActivity(activity.Activity): 'filesaveoff', _('Save snapshot'), self.do_keep_cb, None, button_box) self.samples_button2, self.samples_label2 = \ - self._add_button_and_label('ta-open', _('Load example'), - self.do_samples_cb, None, button_box) + self._add_button_and_label('ta-open', + _('Load example'), + self.do_samples_cb, + None, + button_box) self.load_ta_project, label = self._add_button_and_label( 'load-from-journal', _('Load project'), @@ -1040,8 +1046,8 @@ class TurtleArtActivity(activity.Activity): self.set_canvas(self.fixed) self.vbox = gtk.VBox(False, 0) self.vbox.set_size_request(gtk.gdk.screen_width(), - gtk.gdk.screen_height() - \ - 2 * style.GRID_CELL_SIZE) + gtk.gdk.screen_height() - + 2 * style.GRID_CELL_SIZE) self.sw = gtk.ScrolledWindow() # self.set_canvas(self.sw) self.vbox.pack_end(self.sw, True, True) @@ -1139,7 +1145,7 @@ class TurtleArtActivity(activity.Activity): self.metadata['turtle blocks'] = ''.join(self.tw.used_block_list) self.metadata['public'] = data_to_string(['activity count', 'turtle blocks']) - _logger.debug('Wrote to file: %s' % file_path) + _logger.debug('Wrote to file: %s' % (file_path)) def _load_a_plugin(self, tmp_dir): ''' Load a plugin from the Journal and initialize it ''' @@ -1193,8 +1199,8 @@ Plugin section of plugin.info file.') self.tw.load_media_shapes() for i, palette_name in enumerate(palette_name_list): if create_palette[i]: - _logger.debug('Creating plugin palette %s (%d)' % ( - palette_name.strip(), i)) + _logger.debug('Creating plugin palette %s (%d)' % + (palette_name.strip(), i)) j = len(self.palette_buttons) self.palette_buttons.append( self._radio_button_factory( @@ -1221,11 +1227,10 @@ skipping insert') # We need to change the index associated with the # Trash Palette Button. j = len(palette_names) - self.palette_buttons[palette_names.index( - palette_name.strip())].connect( + pidx = palette_names.index(palette_name.strip()) + self.palette_buttons[pidx].connect( 'clicked', self.do_palette_buttons_cb, j - 1) - self._overflow_buttons[palette_names.index( - palette_name.strip())].connect( + self._overflow_buttons[pidx].connect( 'clicked', self.do_palette_buttons_cb, j - 1) _logger.debug('reinitializing palette toolbar') self._setup_palette_toolbar() @@ -1286,17 +1291,17 @@ in order to use the plugin.')) subprocess.call(['cp', file_path, tmpfile]) status = subprocess.call(['gunzip', tmpfile]) if status == 0: - _logger.debug('tarfile.open %s' % tmpfile[:3]) + _logger.debug('tarfile.open %s' % (tmpfile[:3])) tar_fd = tarfile.open(tmpfile[:-3], 'r') else: - _logger.debug('tarfile.open %s' % tmpfile) + _logger.debug('tarfile.open %s' % (tmpfile)) tar_fd = tarfile.open(tmpfile, 'r') except: - _logger.debug('tarfile.open %s' % file_path) + _logger.debug('tarfile.open %s' % (file_path)) tar_fd = tarfile.open(file_path, 'r') tmp_dir = tempfile.mkdtemp() - _logger.debug('tmp_dir %s' % tmp_dir) + _logger.debug('tmp_dir %s' % (tmp_dir)) try: tar_fd.extractall(tmp_dir) @@ -1308,11 +1313,11 @@ in order to use the plugin.')) if os.path.exists(turtle_code): self.tw.load_files(turtle_code, run_it) else: - _logger.debug('load a plugin from %s' % tmp_dir) + _logger.debug('load a plugin from %s' % (tmp_dir)) self._load_a_plugin(tmp_dir) except: - _logger.debug('Could not extract files from %s.' % ( - file_path)) + _logger.debug('Could not extract files from %s.' % + (file_path)) finally: if not plugin: shutil.rmtree(tmp_dir) diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py index 6b0f3ce..84c7287 100644 --- a/plugins/turtle_blocks_extras/turtle_blocks_extras.py +++ b/plugins/turtle_blocks_extras/turtle_blocks_extras.py @@ -474,8 +474,8 @@ program started')) last-out heap)')) self.tw.lc.def_prim('push', 1, lambda self, x: primitive_dictionary['push'](x)) - define_logo_function('tapush', 'to tapush :foo\rmake "taheap fput \ -:foo :taheap\rend\rmake "taheap []\r') + define_logo_function('tapush', 'to tapush :foo\nmake "taheap fput \ +:foo :taheap\nend\nmake "taheap []\n') primitive_dictionary['printheap'] = self._prim_printheap palette.add_block('printheap', @@ -487,8 +487,8 @@ last-out heap)')) last-out heap)')) self.tw.lc.def_prim('printheap', 0, lambda self: primitive_dictionary['printheap']()) - define_logo_function('taprintheap', 'to taprintheap \rprint :taheap\r\ -end\r') + define_logo_function('taprintheap', 'to taprintheap \nprint :taheap\n\ +end\n') primitive_dictionary['clearheap'] = self._prim_emptyheap palette.add_block('clearheap', @@ -500,8 +500,8 @@ end\r') heap)')) self.tw.lc.def_prim('clearheap', 0, lambda self: primitive_dictionary['clearheap']()) - define_logo_function('taclearheap', 'to taclearheap\rmake "taheap []\r\ -end\r') + define_logo_function('taclearheap', 'to taclearheap\nmake "taheap []\n\ +end\n') primitive_dictionary['pop'] = self._prim_pop palette.add_block('pop', @@ -515,8 +515,8 @@ end\r') last-out heap)')) self.tw.lc.def_prim('pop', 0, lambda self: primitive_dictionary['pop']()) - define_logo_function('tapop', 'to tapop\rif emptyp :taheap [stop]\r\ -make "tmp first :taheap\rmake "taheap butfirst :taheap\routput :tmp\rend\r') + define_logo_function('tapop', 'to tapop\nif emptyp :taheap [stop]\n\ +make "tmp first :taheap\nmake "taheap butfirst :taheap\noutput :tmp\nend\n') primitive_dictionary['isheapempty'] = self._prim_is_heap_empty palette.add_block('isheapempty', |