Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2013-12-13 22:51:54 (GMT)
committer Walter Bender <walter@sugarlabs.org>2013-12-13 22:51:54 (GMT)
commit3d4c26ccfd8fc851b8dd34dab753d3dc70ea8160 (patch)
tree3e0188fb9c2123968d5fd8c9e43f648d8dd5d480 /TurtleArt
parentad5db297b65e5bf1894066b1d1474d6a3f465f5c (diff)
194.4v194.4
Diffstat (limited to 'TurtleArt')
-rw-r--r--TurtleArt/tablock.py3
-rw-r--r--TurtleArt/tacanvas.py6
-rw-r--r--TurtleArt/taconstants.py5
-rw-r--r--TurtleArt/taexportpython.py28
-rw-r--r--TurtleArt/talogo.py68
-rwxr-xr-xTurtleArt/tasprite_factory.py12
-rw-r--r--TurtleArt/tawindow.py63
7 files changed, 114 insertions, 71 deletions
diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py
index 3b9650f..402de33 100644
--- a/TurtleArt/tablock.py
+++ b/TurtleArt/tablock.py
@@ -1088,7 +1088,8 @@ class Block:
self.svg.docks[4][1], ']']]
def _make_clamp_style_until(self, svg, extend_x=0, extend_y=4):
- self.svg.expand(self.dx + self.ex + extend_x, self.ey + extend_y)
+ self.svg.expand(self.dx + self.ex + extend_x, self.ey + extend_y,
+ 0, self.ey2)
self.svg.set_slot(True)
self.svg.set_tab(True)
self.svg.set_boolean(True)
diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.py
index 4bac442..f37a3a4 100644
--- a/TurtleArt/tacanvas.py
+++ b/TurtleArt/tacanvas.py
@@ -305,10 +305,14 @@ class TurtleGraphics:
''' Draw text '''
def _draw_text(cr, label, x, y, size, width, scale, heading, rgb):
+ import textwrap
+ final_scale = int(size * scale) * pango.SCALE
+ label = str(label)
+ label = '\n'.join(textwrap.wrap(label, int(width / scale)))
cc = pangocairo.CairoContext(cr)
pl = cc.create_layout()
fd = pango.FontDescription('Sans')
- fd.set_size(int(size * scale) * pango.SCALE)
+ fd.set_size(final_scale)
pl.set_font_description(fd)
if isinstance(label, (str, unicode)):
pl.set_text(label.replace('\0', ' '))
diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py
index 75288c1..3e92956 100644
--- a/TurtleArt/taconstants.py
+++ b/TurtleArt/taconstants.py
@@ -341,8 +341,6 @@ VOICES = {'af': 'afrikaans', 'cy': 'welsh-test', 'el': 'greek',
MACROS = {
'ifthenelse': # Because it is too big to fit on the palette
[[0, 'ifelse', 0, 0, [None, None, None, None, None]]],
- 'untilmacro': # Because it is too big to fit on the palette
- [[0, 'until', 0, 0, [None, None, None, None]]],
'kbinput':
[[0, 'until', 0, 0, [None, 1, 4, None]],
[1, 'greater2', 0, 0, [0, 2, 3, None]],
@@ -544,4 +542,7 @@ MACROS = {
[25, 'description', 0, 0, [24, None]]],
'reskin':
[[0, 'skin', 0, 0, [None, 1, None]],
+ [1, 'journal', 0, 0, [0, None]]],
+ 'loadheapfromjournal':
+ [[0, 'loadheap', 0, 0, [None, 1, None]],
[1, 'journal', 0, 0, [0, None]]]}
diff --git a/TurtleArt/taexportpython.py b/TurtleArt/taexportpython.py
index 9135302..60bf0c1 100644
--- a/TurtleArt/taexportpython.py
+++ b/TurtleArt/taexportpython.py
@@ -45,18 +45,22 @@ _ALTERNATIVE_INSTALL_PATH = \
'/usr/local/share/sugar/activities/TurtleArt.activity'
import os, sys
-if os.path.exists('../TurtleBlocks.activity'):
- sys.path.insert(0, '../TurtleBlocks.activity')
-elif os.path.exists(os.path.join(os.path.expanduser('~'), 'Activities',
- 'TurtleBlocks.activity')):
- sys.path.insert(0, os.path.join(os.path.expanduser('~'), 'Activities',
- 'TurtleBlocks.activity'))
-elif os.path.exists(_INSTALL_PATH):
- sys.path.insert(0, _INSTALL_PATH)
-elif os.path.exists(_ALTERNATIVE_INSTALL_PATH):
- sys.path.insert(0, _ALTERNATIVE_INSTALL_PATH)
-else:
- print 'This code require the TurtleBlocks activity to be installed.'
+paths = []
+paths.append('../%s.activity')
+paths.append(os.path.expanduser('~') + '/Activities/%s.activity')
+paths.append('/usr/share/sugar/activities/%s.activity')
+paths.append('/usr/local/share/sugar/activities/%s.activity')
+
+flag = False
+for path in paths:
+ for activity in ['TurtleBlocks', 'TurtleBots']:
+ p = path % activity
+ if os.path.exists(p):
+ flag = True
+ sys.path.insert(0, p)
+
+if not flag:
+ print 'This code require the Turtle Blocks/Bots activity to be installed.'
exit(1)
from time import *
diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py
index 5380137..5792043 100644
--- a/TurtleArt/talogo.py
+++ b/TurtleArt/talogo.py
@@ -835,24 +835,35 @@ class LogoCode:
name = float(name)
return 'stack3' + str(name)
- def load_heap(self, path):
+ def load_heap(self, obj):
""" Load FILO from file """
if self.tw.running_sugar:
- # Choose a datastore object and push data to heap (Sugar only)
- chooser_dialog(self.tw.parent, path, self.push_file_data_to_heap)
+ # Is the object a dsobject?
+ if isinstance(obj, Media) and obj.value:
+ from sugar.datastore import datastore
+ try:
+ dsobject = datastore.get(obj.value)
+ except:
+ debug_output("Couldn't find dsobject %s" %
+ (obj.value), self.tw.running_sugar)
+ if dsobject is not None:
+ self.push_file_data_to_heap(dsobject)
+ # Or is it a path?
+ elif os.path.exists(obj):
+ self.push_file_data_to_heap(None, path=obj)
+ else:
+ # Finally try choosing a datastore object
+ chooser_dialog(self.tw.parent, obj,
+ self.push_file_data_to_heap)
else:
- if not os.path.exists(path):
- path, self.tw.load_save_folder = get_load_name(
+ # If you cannot find the file, open a chooser.
+ if not os.path.exists(obj):
+ obj, self.tw.load_save_folder = get_load_name(
'.*', self.tw.load_save_folder)
- if path is None:
- return
+ if obj is not None:
+ self.push_file_data_to_heap(None, path=obj)
- data = data_from_file(path)
- if data is not None:
- for val in data:
- self.heap.append(val)
-
- def save_heap(self, path):
+ def save_heap(self, obj):
""" save FILO to file """
if self.tw.running_sugar:
from sugar import profile
@@ -861,22 +872,23 @@ class LogoCode:
# Save JSON-encoded heap to temporary file
heap_file = os.path.join(get_path(activity, 'instance'),
- str(path) + '.txt')
+ 'heap.txt')
data_to_file(self.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'
+ # Write to an existing or new dsobject
+ if isinstance(obj, Media) and obj.value:
+ dsobject = datastore.get(obj.value)
+ else:
+ dsobject = datastore.create()
+ dsobject.metadata['title'] = str(obj)
+ 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
+ heap_file = obj
data_to_file(self.heap, heap_file)
def get_heap(self):
@@ -1172,9 +1184,15 @@ class LogoCode:
int(self.tw.canvas.textsize * self.scale / 100.),
self.tw.canvas.width - x)
- def push_file_data_to_heap(self, dsobject):
+ def push_file_data_to_heap(self, dsobject, path=None):
""" push contents of a data store object (assuming json encoding) """
- data = data_from_file(dsobject.file_path)
+ if dsobject:
+ data = data_from_file(dsobject.file_path)
+ elif path is not None:
+ data = data_from_file(path)
+ else:
+ data = None
+ debug_output("No file to open", self.tw.running_sugar)
if data is not None:
for val in data:
self.heap.append(val)
diff --git a/TurtleArt/tasprite_factory.py b/TurtleArt/tasprite_factory.py
index 7f9494c..8360dbb 100755
--- a/TurtleArt/tasprite_factory.py
+++ b/TurtleArt/tasprite_factory.py
@@ -634,22 +634,12 @@ stroke-width="3.5" fill="%s" stroke="none" />\n' % (self._stroke)
svg += self._inverse_corner(1, 1, 90, 0, 0)
svg += self._do_slot()
svg += self._rline_to(self._radius, 0)
- if self._second_clamp:
- svg += self._corner(-1, 1)
- svg += self.line_to(xx, self._y)
- svg += self._rline_to(-self._expand_x, 0)
- svg += self._do_tab()
- svg += self._inverse_corner(-1, 1, 90, 0, 0)
- svg += self._rline_to(0, self._expand_y2)
- svg += self._inverse_corner(1, 1, 90, 0, 0)
- svg += self._do_slot()
- svg += self._rline_to(self._radius, 0)
if self._innie[0] is True:
svg += self._do_innie()
else:
self.margins[2] = \
int((self._x - self._stroke_width + 0.5) * self._scale)
- svg += self._rline_to(0, self._radius * 3)
+ svg += self._rline_to(0, self._radius + self._expand_y2)
if self._bool is True:
svg += self._do_boolean()
svg += self._corner(-1, 1)
diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py
index 2f0a036..4584726 100644
--- a/TurtleArt/tawindow.py
+++ b/TurtleArt/tawindow.py
@@ -2554,10 +2554,14 @@ before making changes to your program'))
continue
if blk.name in EXPANDABLE_FLOW:
if blk.name in block_styles['clamp-style-1arg'] or \
- blk.name in block_styles['clamp-style-boolean'] or \
- blk.name in block_styles['clamp-style-until']:
+ blk.name in block_styles['clamp-style-boolean']:
if blk.connections[2] is not None:
self._resize_clamp(blk, blk.connections[2])
+ elif blk.name in block_styles['clamp-style-until']:
+ if blk.connections[2] is not None:
+ self._resize_clamp(blk, blk.connections[2])
+ if blk.connections[1] is not None:
+ self._resize_clamp(blk, blk.connections[1], dockn=1)
elif blk.name in block_styles['clamp-style']:
if blk.connections[1] is not None:
self._resize_clamp(blk, blk.connections[1])
@@ -3392,12 +3396,18 @@ before making changes to your program'))
if best_destination.name in \
block_styles['clamp-style-1arg'] or \
best_destination.name in \
- block_styles['clamp-style-boolean'] or \
- best_destination.name in \
- block_styles['clamp-style-until']:
+ block_styles['clamp-style-boolean']:
if best_destination_dockn == 2:
self._resize_clamp(best_destination,
self.drag_group[0])
+ elif best_destination.name in \
+ block_styles['clamp-style-until']:
+ if best_destination_dockn == 2:
+ self._resize_clamp(best_destination,
+ self.drag_group[0])
+ elif best_destination_dockn == 1:
+ self._resize_clamp(best_destination,
+ self.drag_group[0], dockn=1)
elif best_destination.name in block_styles['clamp-style'] or \
best_destination.name in \
block_styles['clamp-style-collapsible']:
@@ -3496,16 +3506,18 @@ before making changes to your program'))
self._cascade_expandable(blk2)
elif c is not None and blk2.name in EXPANDABLE_FLOW:
if blk2.name in block_styles['clamp-style-1arg'] or \
- blk2.name in block_styles['clamp-style-boolean'] or \
- blk2.name in block_styles['clamp-style-until']:
+ blk2.name in block_styles['clamp-style-boolean']:
if c == 2:
- self._resize_clamp(blk2, None, c)
+ self._resize_clamp(blk2, None, dockn=c)
+ elif blk2.name in block_styles['clamp-style-until']:
+ if c in [1, 2]:
+ self._resize_clamp(blk2, None, dockn=c)
elif blk2.name in block_styles['clamp-style'] or \
blk2.name in block_styles['clamp-style-collapsible']:
if c == 1:
self._resize_clamp(blk2, None)
elif blk2.name in block_styles['clamp-style-else']:
- if c == 2 or c == 3:
+ if c in [2, 3]:
self._resize_clamp(blk2, None, dockn=c)
while blk3 is not None and blk3.connections[dockn] is not None:
self._resize_clamp(blk3, blk3.connections[dockn], dockn=dockn)
@@ -3521,22 +3533,35 @@ before making changes to your program'))
y1 = blk.docks[-1][3]
if blk.name in block_styles['clamp-style-else'] and dockn == 3:
blk.reset_y2()
+ elif blk.name in block_styles['clamp-style-until'] and dockn == 1:
+ blk.reset_y2()
else:
blk.reset_y()
dy = 0
# Calculate height of drag group
- while gblk is not None:
- delta = int((gblk.docks[-1][3] - gblk.docks[0][3]) / gblk.scale)
- if delta == 0:
- dy += 21 # Fixme: don't hardcode size of stop action block
- else:
- dy += delta
- gblk = gblk.connections[-1]
- # Clamp has room for one 'standard' block by default
- if dy > 0:
- dy -= 21 # Fixme: don't hardcode
+ if blk.name in block_styles['clamp-style-until'] and dockn == 1:
+ if gblk is not None:
+ dy = int(gblk.spr.rect.height / gblk.scale)
+ # Room for part of one 'standard' boolean by default
+ if dy > 0:
+ dy -= 25 # Fixme: don't hardcode size of slot
+ if dy < 0:
+ dy = 0
+ else:
+ while gblk is not None:
+ delta = int((gblk.docks[-1][3] - gblk.docks[0][3]) / gblk.scale)
+ if delta == 0:
+ dy += 21 # Fixme: don't hardcode size of slot
+ else:
+ dy += delta
+ gblk = gblk.connections[-1]
+ # Clamp has room for one 'standard' block by default
+ if dy > 0:
+ dy -= 21 # Fixme: don't hardcode size of slot
if blk.name in block_styles['clamp-style-else'] and dockn == 3:
blk.expand_in_y2(dy)
+ elif blk.name in block_styles['clamp-style-until'] and dockn == 1:
+ blk.expand_in_y2(dy)
else:
blk.expand_in_y(dy)
y2 = blk.docks[-1][3]