Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt
diff options
context:
space:
mode:
authorPootle daemon <pootle@pootle.sugarlabs.org>2012-03-24 04:31:42 (GMT)
committer Pootle daemon <pootle@pootle.sugarlabs.org>2012-03-24 04:31:42 (GMT)
commit2de03de0d162804617c8c7900b4b96003af32b27 (patch)
tree853fa7ac8afd652c647bd0d81ed115750fb0e388 /TurtleArt
parentaf980cf67accf15284231b4bcad18c1ee6f3d87a (diff)
parent155970b44c67a5113dba0b62514b2379b0788a7c (diff)
Merge branch 'master' of git.sugarlabs.org:turtleart/mainline
Diffstat (limited to 'TurtleArt')
-rw-r--r--TurtleArt/taconstants.py2
-rw-r--r--TurtleArt/tapalette.py109
-rw-r--r--TurtleArt/tawindow.py31
3 files changed, 96 insertions, 46 deletions
diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py
index 74291fc..efdc1e8 100644
--- a/TurtleArt/taconstants.py
+++ b/TurtleArt/taconstants.py
@@ -143,7 +143,7 @@ OVERLAY_SHAPES = ['Cartesian', 'Cartesian_labeled', 'polar', 'metric']
STATUS_SHAPES = ['status', 'info', 'nostack', 'dupstack', 'noinput',
'emptyheap', 'emptybox', 'nomedia', 'nocode', 'overflowerror',
'negroot', 'syntaxerror', 'nofile', 'nojournal', 'zerodivide',
- 'notanumber', 'incompatible']
+ 'notanumber', 'incompatible', 'help']
#
# Emulate Sugar toolbar when running from outside of Sugar
diff --git a/TurtleArt/tapalette.py b/TurtleArt/tapalette.py
index be9d999..da80386 100644
--- a/TurtleArt/tapalette.py
+++ b/TurtleArt/tapalette.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-#Copyright (c) 2011 Walter Bender
+#Copyright (c) 2011,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
@@ -19,6 +19,8 @@
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
+help_palettes = {}
+help_windows = {}
palette_names = []
palette_blocks = []
block_colors = []
@@ -75,6 +77,12 @@ block_styles = {'basic-style': [],
'portfolio-style-2x1': [],
'portfolio-style-1x2': []}
+
+import gtk
+
+from sugar.graphics.icon import Icon
+from sugar.graphics import style
+
from taconstants import EXPANDABLE_STYLE
from tautils import debug_output
@@ -94,10 +102,25 @@ class Palette():
self._special_name = _(name)
self._colors = colors
self._help = None
+ self._max_text_width = int(gtk.gdk.screen_width() / 3) - 20
- '''
- self._fd = open('/home/walter/Desktop/turtleblocks/doc/%s-palette.page' % (name), 'a')
- '''
+ # Prepare a vbox for the help palette
+ if not (self._name in help_palettes):
+ self._help_box = gtk.VBox()
+ self._help_box.set_homogeneous(False)
+ help_palettes[self._name] = self._help_box
+ else:
+ self._help_box = help_palettes[self._name]
+
+ help_windows[self._name] = gtk.ScrolledWindow()
+ help_windows[self._name].set_size_request(
+ int(gtk.gdk.screen_width() / 3),
+ gtk.gdk.screen_height() - style.GRID_CELL_SIZE * 3)
+ help_windows[self._name].set_policy(
+ gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+ help_windows[self._name].add_with_viewport(
+ help_palettes[self._name])
+ help_palettes[self._name].show()
def add_palette(self, position=None):
if self._name is None:
@@ -117,28 +140,6 @@ class Palette():
palette_names.insert(i, self._name)
palette_blocks.insert(i, [])
block_colors.insert(i, self._colors)
-
- '''
- self._fd.write('<page xmlns="http://projectmallard.org/1.0/"\n\
- type="guide"\n\
- id="%s-palette"\n\
- xmlns:its="http://www.w3.org/2005/11/its"\n\
- its:version="1.0">\n\
-<info>\n\
- <link type="guide" xref="index"/>\n\
- <link type="topic" xref="palettes"/>\n\
- <its:rules version="1.0">\n\
- <its:translateRule selector="//path | //cmd" translate="no"/>\n\
- </its:rules>\n\
-</info>\n\
-<title>The %s Palette</title>\n\
-<p>\n\
-%s\n\
-</p>\n\
-<terms>\n\
-' % (self._name, self._name, self._help))
- '''
-
else:
# debug_output('Palette %s already defined' % (self._name))
return
@@ -150,8 +151,48 @@ 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('<b>%s</b>' % 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):
self._help = help
+ if hasattr(self, '_help_box'):
+ self.add_section(self._help, icon=self._name + 'off')
def set_special_name(self, name):
self._special_name = name
@@ -178,6 +219,14 @@ class Palette():
block.set_logo_command(logo_command)
if help_string is not None:
block.set_help(help_string)
+ if not hidden:
+ if special_name is None:
+ if type(label) == list:
+ self.add_paragraph('%s: %s' % (label[0], help_string))
+ else:
+ self.add_paragraph('%s: %s' % (label, help_string))
+ else:
+ self.add_paragraph('%s: %s' % (special_name, help_string))
if colors is not None:
block.set_colors(colors)
block.set_value_block(value_block)
@@ -187,14 +236,6 @@ class Palette():
block.set_hidden()
block.add_block()
- '''
- self._fd.write(' <item>\n\
- <title>%s</title>\n\
- <p>%s</p>\n\
- </item>\n\
-' % (block_name, help_string))
- '''
-
def make_palette(palette_name, colors=None, help_string=None, position=None):
""" Palette helper function """
if colors is None:
diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py
index b324c7b..e5984d2 100644
--- a/TurtleArt/tawindow.py
+++ b/TurtleArt/tawindow.py
@@ -124,6 +124,9 @@ class TurtleArtWindow():
self.height = gtk.gdk.screen_height()
self.rect = gtk.gdk.Rectangle(0, 0, 0, 0)
+ self.no_help = False
+ self.last_label = None
+
self.keypress = ''
self.keyvalue = 0
self.dead_key = ''
@@ -651,6 +654,10 @@ class TurtleArtWindow():
p[0].move((x + p[0].save_xy[0], y + p[0].save_xy[1]))
if p[1] is not None:
p[1].move((x + p[1].save_xy[0], y + p[1].save_xy[1]))
+
+ self.status_spr.move((x + self.status_spr.save_xy[0],
+ y + self.status_spr.save_xy[1]))
+
# To do: set save_xy for blocks in Trash
for blk in self.trash_stack:
for gblk in find_group(blk):
@@ -1729,6 +1736,8 @@ class TurtleArtWindow():
def _do_show_popup(self, block_name):
""" Fetch the help text and display it. """
+ if self.no_help:
+ return 0
if block_name in special_names:
special_block_name = special_names[block_name]
elif block_name in block_names:
@@ -1738,18 +1747,13 @@ class TurtleArtWindow():
else:
special_block_name = _(block_name)
if block_name in help_strings:
- if special_block_name == '':
- label = help_strings[block_name]
- else:
- label = special_block_name + ": " + help_strings[block_name]
+ label = help_strings[block_name]
else:
label = special_block_name
- if self.running_sugar:
- self.activity.hover_help_label.set_text(label)
- self.activity.hover_help_label.show()
- else:
- if self.interactive_mode:
- self.parent.set_title(_("Turtle Art") + " — " + label)
+ if self.last_label == label:
+ return 0
+ self.showlabel('help', label=label)
+ self.last_label = label
return 0
def _buttonrelease_cb(self, win, event):
@@ -3073,7 +3077,12 @@ class TurtleArtWindow():
if shp == 'info':
self.status_spr.move((PALETTE_WIDTH, self.height - 400))
else:
- self.status_spr.move((PALETTE_WIDTH, self.height - 200))
+ # Adjust vertical position based on scrolled window adjustment
+ if self.running_sugar:
+ self.status_spr.move((0, self.height - 200 + \
+ self.activity.sw.get_vadjustment().get_value()))
+ elif self.interactive_mode:
+ self.status_spr.move((0, self.height - 100))
def calc_position(self, template):
""" Relative placement of portfolio objects (deprecated) """