From 8ddffb2383528f8ff55b727cf04d637df9573f6e Mon Sep 17 00:00:00 2001 From: Pootle daemon Date: Thu, 29 Mar 2012 04:31:39 +0000 Subject: Merge branch 'master' of git.sugarlabs.org:turtleart/mainline --- (limited to 'TurtleArt') diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py index 6bbaf69..0cfb242 100644 --- a/TurtleArt/taconstants.py +++ b/TurtleArt/taconstants.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -#Copyright (c) 2010-11 Walter Bender +#Copyright (c) 2010-12 Walter Bender #Permission is hereby granted, free of charge, to any person obtaining a copy #of this software and associated documentation files (the "Software"), to deal diff --git a/TurtleArt/tapalette.py b/TurtleArt/tapalette.py index 86a3bda..7678f7e 100644 --- a/TurtleArt/tapalette.py +++ b/TurtleArt/tapalette.py @@ -86,6 +86,8 @@ from sugar.graphics import style from taconstants import EXPANDABLE_STYLE from tautils import debug_output +from util.helpbutton import add_section, add_paragraph + from gettext import gettext as _ help_strings = { @@ -150,49 +152,11 @@ class Palette(): else: help_strings[self._name] = '' - def add_section(self, section_text, icon=None): - ''' Add a section to the help palette. From helpbutton.py by - Gonzalo Odiard ''' - hbox = gtk.HBox() - label = gtk.Label() - label.set_use_markup(True) - label.set_markup('%s' % section_text) - label.set_line_wrap(True) - label.set_size_request(self._max_text_width, -1) - hbox.add(label) - if icon is not None: - _icon = Icon(icon_name=icon) - hbox.add(_icon) - label.set_size_request(self._max_text_width - 20, -1) - else: - label.set_size_request(self._max_text_width, -1) - - hbox.show_all() - self._help_box.pack_start(hbox, False, False, padding=5) - - def add_paragraph(self, text, icon=None): - ''' Add an entry to the help palette. From helpbutton.py by - Gonzalo Odiard ''' - hbox = gtk.HBox() - label = gtk.Label(text) - label.set_justify(gtk.JUSTIFY_LEFT) - label.set_line_wrap(True) - hbox.add(label) - if icon is not None: - _icon = Icon(icon_name=icon) - hbox.add(_icon) - label.set_size_request(self._max_text_width - 20, -1) - else: - label.set_size_request(self._max_text_width, -1) - - hbox.show_all() - self._help_box.pack_start(hbox, False, False, padding=5) - def set_help(self, help): if self._help is None: self._help = help if hasattr(self, '_help_box'): - self.add_section(self._help, icon=self._name + 'off') + add_section(self._help_box, self._help, icon=self._name + 'off') def set_special_name(self, name): self._special_name = name @@ -229,9 +193,10 @@ class Palette(): else: first_arg = special_name if first_arg is None or first_arg == '' or first_arg == ' ': - self.add_paragraph('%s' % (help_string)) + add_paragraph(self._help_box, '%s' % (help_string)) else: - self.add_paragraph('%s: %s' % (first_arg, help_string)) + add_paragraph(self._help_box, '%s: %s' % (first_arg, + help_string)) if colors is not None: block.set_colors(colors) block.set_value_block(value_block) diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index 499eefb..e28984b 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -630,6 +630,7 @@ class TurtleArtWindow(): self.show_toolbar_palette(n) self.palette_button[self.orientation].set_layer(TAB_LAYER) self.palette_button[2].set_layer(TAB_LAYER) + self._display_palette_shift_button(n) if self.activity is None or not self.activity.has_toolbarbox: self.toolbar_spr.set_layer(CATEGORY_LAYER) self.palette = True @@ -639,6 +640,8 @@ class TurtleArtWindow(): self._hide_toolbar_palette() self.palette_button[self.orientation].hide() self.palette_button[2].hide() + self.palette_button[3].hide() + self.palette_button[4].hide() if self.activity is None or not self.activity.has_toolbarbox: self.toolbar_spr.hide() self.palette = False @@ -716,6 +719,25 @@ class TurtleArtWindow(): if blk.name in BLOCKS_WITH_SKIN: self._resize_skin(blk) + def _shift_toolbar_palette(self, n): + ''' Shift blocks on specified palette ''' + x, y = self.palette_sprs[n][self.orientation].get_xy() + w, h = self.palette_sprs[n][self.orientation].get_dimensions() + bx, by = self.palettes[n][0].spr.get_xy() + if self.orientation == 0: + dx = w - self.width + dy = 0 + if bx - x > 0: + dx *= -1 + else: + dx = 0 + dy = h - self.height + ICON_SIZE + if by - y > 0: + dy *= -1 + for blk in self.palettes[n]: + if blk.get_visibility(): + blk.spr.move_relative((dx, dy)) + def show_toolbar_palette(self, n, init_only=False, regenerate=False, show=True): """ Show the toolbar palettes, creating them on init_only """ @@ -756,6 +778,7 @@ class TurtleArtWindow(): # Show the palette with the current orientation. if self.palette_sprs[n][self.orientation] is not None: self.palette_sprs[n][self.orientation].set_layer(CATEGORY_LAYER) + self._display_palette_shift_button(n) # Create 'proto' blocks for each palette entry self._create_proto_blocks(n) @@ -785,6 +808,20 @@ class TurtleArtWindow(): self.selected_palette = save_selected self.previous_palette = save_previous + def _display_palette_shift_button(self, n): + ''' Palettes too wide (or tall) for the screen get a shift button ''' + if self.palette_sprs[n][self.orientation].type == \ + 'category-shift-horizontal': + self.palette_button[3].set_layer(CATEGORY_LAYER) + self.palette_button[4].hide() + elif self.palette_sprs[n][self.orientation].type == \ + 'category-shift-vertical': + self.palette_button[3].hide() + self.palette_button[4].set_layer(CATEGORY_LAYER) + else: + self.palette_button[3].hide() + self.palette_button[4].hide() + def _create_the_selectors(self): ''' Create the palette selector buttons: only when running old-style Sugar toolbars or from GNOME ''' @@ -861,6 +898,21 @@ class TurtleArtWindow(): self.palette_button[2].type = 'palette' self.palette_button[2].set_layer(TAB_LAYER) + # Create the palette shift buttons + dims = self.palette_button[0].get_dimensions() + self.palette_button.append(Sprite(self.sprite_list, 0, + self.toolbar_offset + dims[1], svg_str_to_pixbuf(svg_from_file( + "%s/images/palettehshift.svg" % (self.path))))) + self.palette_button.append(Sprite(self.sprite_list, dims[0], + self.toolbar_offset, svg_str_to_pixbuf(svg_from_file( + "%s/images/palettevshift.svg" % (self.path))))) + self.palette_button[3].name = _('shift') + self.palette_button[4].name = _('shift') + self.palette_button[3].type = 'palette' + self.palette_button[4].type = 'palette' + self.palette_button[3].hide() + self.palette_button[4].hide() + def _create_proto_blocks(self, n): ''' Create the protoblocks that will populate a palette. ''' # Reload the palette, but reuse the existing blocks @@ -1048,6 +1100,7 @@ class TurtleArtWindow(): self.palette_button[2].move_relative( (self.activity.hadj_value, self.activity.vadj_value)) self.palette_sprs[n][self.orientation].set_layer(CATEGORY_LAYER) + self._display_palette_shift_button(n) def _make_palette_spr(self, n, x, y, w, h, regenerate=False): ''' Make the background for the palette. ''' @@ -1063,7 +1116,16 @@ class TurtleArtWindow(): if self.running_sugar and not self.hw in [XO1]: self.palette_sprs[n][self.orientation].move_relative( (self.activity.hadj_value, self.activity.vadj_value)) - self.palette_sprs[n][self.orientation].type = 'category' + if self.orientation == 0 and w > self.width: + debug_output('setting to shiftable horizontal', True) + self.palette_sprs[n][self.orientation].type = \ + 'category-shift-horizontal' + elif self.orientation == 1 and h > self.height - ICON_SIZE: + debug_output('setting to shiftable vertical', True) + self.palette_sprs[n][self.orientation].type = \ + 'category-shift-vertical' + else: + self.palette_sprs[n][self.orientation].type = 'category' if n == palette_names.index('trash'): svg = SVG() self.palette_sprs[n][self.orientation].set_shape( @@ -1186,7 +1248,8 @@ class TurtleArtWindow(): if hasattr(spr, 'type'): if spr.type == 'selector': self._select_category(spr) - elif spr.type == 'category': + elif spr.type in ['category', 'category-shift-horizontal', + 'category-shift-vertical']: if hide_button_hit(spr, x, y): self.hideshow_palette(False) elif spr.type == 'palette': @@ -1210,6 +1273,8 @@ class TurtleArtWindow(): self.activity.palette_buttons[i].set_icon( palette_names[i] + 'on') self.show_palette(i) + elif spr.name == _('shift'): + self._shift_toolbar_palette(self.selected_palette) else: self.orientation = 1 - self.orientation self.palette_button[self.orientation].set_layer(TAB_LAYER) -- cgit v0.9.1