Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarion <marion.zepf@gmail.com>2013-09-12 21:32:19 (GMT)
committer Marion <marion.zepf@gmail.com>2013-09-12 21:32:19 (GMT)
commit88eb04055b4d15c8d9b45b245bbedd5ff4b42af7 (patch)
tree7aa5b3d38b43781865b2346514f522d0bcf3b121
parentbc3fc71b15786accf3ebd725374625cbb2ef2b1e (diff)
add Primitive for the 'print' block
-rw-r--r--TurtleArt/tawindow.py45
-rw-r--r--plugins/turtle_blocks_extras/turtle_blocks_extras.py47
2 files changed, 45 insertions, 47 deletions
diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py
index ea7bf05..f386b68 100644
--- a/TurtleArt/tawindow.py
+++ b/TurtleArt/tawindow.py
@@ -58,7 +58,7 @@ from taconstants import (HORIZONTAL_PALETTE, VERTICAL_PALETTE, BLOCK_SCALE,
PYTHON_SKIN, PALETTE_HEIGHT, STATUS_LAYER, OLD_DOCK,
EXPANDABLE_ARGS, XO1, XO15, XO175, XO30, XO4, TITLEXY,
CONTENT_ARGS, CONSTANTS, EXPAND_SKIN, PROTO_LAYER,
- EXPANDABLE_FLOW, SUFFIX, TMP_SVG_PATH)
+ EXPANDABLE_FLOW, SUFFIX, TMP_SVG_PATH, Color)
from tapalette import (palette_names, palette_blocks, expandable_blocks,
block_names, content_blocks, default_values,
special_names, block_styles, help_strings,
@@ -67,7 +67,7 @@ from tapalette import (palette_names, palette_blocks, expandable_blocks,
palette_init_on_start)
from talogo import (LogoCode, primitive_dictionary, logoerror)
from tacanvas import TurtleGraphics
-from tablock import (Blocks, Block)
+from tablock import (Blocks, Block, media_blocks_dictionary)
from taturtle import (Turtles, Turtle)
from tautils import (magnitude, get_load_name, get_save_name, data_from_file,
data_to_file, round_int, get_id, get_pixbuf_from_journal,
@@ -4316,6 +4316,47 @@ before making changes to your Turtle Blocks program'))
elif self.interactive_mode:
self.parent.set_title(text)
+ def print_(self, n, flag):
+ """ Print object n to the bar at the bottom of the screen """
+ if flag and (self.hide or self.step_time == 0):
+ return
+ if isinstance(n, list):
+ self.showlabel('print', n)
+ elif isinstance(n, Color):
+ if n.color is None:
+ self.showlabel('print', '%s %d, %s %d' %
+ (_('shade'), n.shade,
+ _('gray'), n.gray))
+ else:
+ self.showlabel('print', '%s %d, %s %d, %s %d' %
+ (_('color'), n.color,
+ _('shade'), n.shade,
+ _('gray'), n.gray))
+ elif isinstance(n, basestring):
+ if n[0:6] == 'media_' and \
+ n[6:].lower not in media_blocks_dictionary:
+ try:
+ if self.running_sugar:
+ from sugar.datastore import datastore
+ try:
+ dsobject = datastore.get(n[6:])
+ except:
+ debug_output("Couldn't open %s" % (n[6:]),
+ self.running_sugar)
+ self.showlabel('print', dsobject.metadata['title'])
+ dsobject.destroy()
+ else:
+ self.showlabel('print', n[6:])
+ except IOError:
+ self.showlabel('print', n)
+ else:
+ self.showlabel('print', n)
+ elif isinstance(n, int):
+ self.showlabel('print', n)
+ else:
+ self.showlabel(
+ 'print',
+ str(round_int(n)).replace('.', self.decimal_point))
def showlabel(self, shp, label=''):
''' Display a message on a status block '''
diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py
index c909803..22bae62 100644
--- a/plugins/turtle_blocks_extras/turtle_blocks_extras.py
+++ b/plugins/turtle_blocks_extras/turtle_blocks_extras.py
@@ -553,7 +553,6 @@ make "tmp first :taheap\nmake "taheap butfirst :taheap\noutput :tmp\nend\n')
arg_descs=[ConstantArg(
Primitive(self.tw.lc.get_heap, return_type=TYPE_BOOL))]))
- primitive_dictionary['print'] = self._prim_print
palette.add_block('comment',
style='basic-style-1arg',
label=_('comment'),
@@ -573,8 +572,8 @@ make "tmp first :taheap\nmake "taheap butfirst :taheap\noutput :tmp\nend\n')
help_string=_('prints value in status block at \
bottom of the screen'))
self.tw.lc.def_prim('print', 1,
- lambda self, x:
- primitive_dictionary['print'](x, False))
+ Primitive(self.tw.print_,
+ arg_descs=[ArgSlot(TYPE_OBJECT), ConstantArg(False)]))
palette.add_block('chr',
style='number-style-1arg',
@@ -1146,48 +1145,6 @@ Journal objects'))
else:
self.tw.lc.update_label_value('pop', self.tw.lc.heap[-1])
- def _prim_print(self, n, flag):
- """ Print object n """
- if flag and (self.tw.hide or self.tw.step_time == 0):
- return
- if isinstance(n, list):
- self.tw.showlabel('print', n)
- elif isinstance(n, Color):
- if n.color is None:
- self.tw.showlabel('print', '%s %d, %s %d' %
- (_('shade'), n.shade,
- _('gray'), n.gray))
- else:
- self.tw.showlabel('print', '%s %d, %s %d, %s %d' %
- (_('color'), n.color,
- _('shade'), n.shade,
- _('gray'), n.gray))
- elif isinstance(n, basestring):
- if n[0:6] == 'media_' and \
- n[6:].lower not in media_blocks_dictionary:
- try:
- if self.tw.running_sugar:
- from sugar.datastore import datastore
- try:
- dsobject = datastore.get(n[6:])
- except:
- debug_output("Couldn't open %s" % (n[6:]),
- self.tw.running_sugar)
- self.tw.showlabel('print', dsobject.metadata['title'])
- dsobject.destroy()
- else:
- self.tw.showlabel('print', n[6:])
- except IOError:
- self.tw.showlabel('print', n)
- else:
- self.tw.showlabel('print', n)
- elif isinstance(n, int):
- self.tw.showlabel('print', n)
- else:
- self.tw.showlabel(
- 'print',
- str(round_int(n)).replace('.', self.tw.decimal_point))
-
def _prim_printheap(self):
""" Display contents of heap """
heap_as_string = str(self.tw.lc.heap)