From dff1f20e0b04084d4a72ef70b31ec9917aada539 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sun, 21 Feb 2010 13:29:25 +0000 Subject: adding Cartesian, polar blocks --- diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py index d5a126e..b0023bd 100644 --- a/TurtleArtActivity.py +++ b/TurtleArtActivity.py @@ -396,27 +396,16 @@ class TurtleArtActivity(activity.Activity): Display coordinate grids """ def _do_cartesian_cb(self, button): - if self.tw.cartesian is True: - if self.tw.coord_scale == 1: - self.tw.overlay_shapes['Cartesian_labeled'].hide() - else: - self.tw.overlay_shapes['Cartesian'].hide() - self.tw.cartesian = False + if self.tw.cartesian: + self.tw.set_cartesian(False) else: - if self.tw.coord_scale == 1: - self.tw.overlay_shapes['Cartesian_labeled'].set_layer( - OVERLAY_LAYER) - else: - self.tw.overlay_shapes['Cartesian'].set_layer(OVERLAY_LAYER) - self.tw.cartesian = True + self.tw.set_cartesian(True) def _do_polar_cb(self, button): - if self.tw.polar is True: - self.tw.overlay_shapes['polar'].hide() - self.tw.polar = False + if self.tw.polar: + self.tw.set_polar(False) else: - self.tw.overlay_shapes['polar'].set_layer(OVERLAY_LAYER) - self.tw.polar = True + self.tw.set_polar(True) """ Rescale coordinate system to 100 == height/2 or 100 == 100 pixels (default) @@ -427,7 +416,7 @@ class TurtleArtActivity(activity.Activity): self.rescale_button.set_icon("contract-coordinates") self.rescale_button.set_tooltip(_('Rescale coordinates down')) self.tw.eraser_button() - if self.tw.cartesian is True: + if self.tw.cartesian: self.tw.overlay_shapes['Cartesian_labeled'].hide() self.tw.overlay_shapes['Cartesian'].set_layer(OVERLAY_LAYER) else: @@ -435,7 +424,7 @@ class TurtleArtActivity(activity.Activity): self.rescale_button.set_icon("expand-coordinates") self.rescale_button.set_tooltip(_('Rescale coordinates up')) self.tw.eraser_button() - if self.tw.cartesian is True: + if self.tw.cartesian: self.tw.overlay_shapes['Cartesian'].hide() self.tw.overlay_shapes['Cartesian_labeled'].set_layer( OVERLAY_LAYER) @@ -522,7 +511,7 @@ class TurtleArtActivity(activity.Activity): self.event_received_cb) # now that we have the tube, we can ask for an initialization - if self.waiting_for_blocks is True: + if self.waiting_for_blocks: self._send_event("i") """ @@ -559,7 +548,7 @@ class TurtleArtActivity(activity.Activity): self.tw.key_press(False,keyname,False) elif text[0] == 'i': # request for current state # sharer should send current state to joiner - if self.initiating is True: + if self.initiating: _logger.debug("serialize the project and send to joiner") text = data_to_string(self.tw.assemble_data_to_save(True, True)) self._send_event("I:" + text) @@ -923,7 +912,7 @@ class TurtleArtActivity(activity.Activity): _logger.debug("and creating a tamyblock.py Journal entry") # Make sure there is a copy of tamyblock.py in the Journal - if newversion is True: + if newversion: dsobject = datastore.create() dsobject.metadata['title'] = 'tamyblock.py' dsobject.metadata['icon-color'] = \ diff --git a/taconstants.py b/taconstants.py index 8549796..1d2e116 100644 --- a/taconstants.py +++ b/taconstants.py @@ -125,7 +125,7 @@ PALETTES = [['clean', 'forward', 'back', 'show', 'left', 'right', 'storein', 'start'], ['kbinput', 'push', 'printheap', 'keyboard', 'pop', 'clearheap', 'myfunc', 'nop', 'addturtle', 'comment', 'print', 'width', - 'height','sandwichtop', 'sandwichbottom'], + 'height','sandwichtop', 'sandwichbottom', 'cartesian', 'polar'], ['journal', 'audio', 'description', 'savepix', 'hideblocks', 'showblocks', 'fullscreen', 'picturelist', 'picture1x1a', 'picture1x1', 'picture2x2', 'picture2x1', 'picture1x2'], @@ -162,7 +162,7 @@ BASIC_STYLE_HEAD_1ARG = ['hat'] BASIC_STYLE_TAIL = ['stopstack', 'empty'] BASIC_STYLE = ['clean', 'penup', 'pendown', 'stack1', 'stack2', 'vspace', 'hideblocks', 'showblocks', 'clearheap', 'printheap', 'kbinput', - 'fullscreen', 'sandwichcollapsed'] + 'fullscreen', 'sandwichcollapsed', 'cartesian', 'polar'] BASIC_STYLE_EXTENDED = ['picturelist', 'picture1x1', 'picture2x2', 'picture2x1', 'picture1x2', 'picture1x1a'] BASIC_STYLE_1ARG = ['forward', 'back', 'left', 'right', 'seth', 'show', @@ -176,9 +176,9 @@ BOX_STYLE = ['number', 'xcor', 'ycor', 'heading', 'pensize', 'color', 'shade', 'red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple', 'titlex', 'titley', 'leftx', 'topy', 'rightx', 'bottomy'] BOX_STYLE_MEDIA = ['description', 'audio', 'journal'] -NUMBER_STYLE = ['plus2', 'product2'] -NUMBER_STYLE_VAR_ARG = ['myfunc'] -NUMBER_STYLE_BLOCK = ['random', 'myfunc2'] +NUMBER_STYLE = ['plus2', 'product2', 'myfunc'] +NUMBER_STYLE_VAR_ARG = ['myfunc2'] +NUMBER_STYLE_BLOCK = ['random'] NUMBER_STYLE_PORCH = ['minus2', 'division2', 'remainder2'] NUMBER_STYLE_1ARG = ['sqrt', 'identity2'] NUMBER_STYLE_1STRARG = ['box'] @@ -241,6 +241,7 @@ BLOCK_NAMES = { 'box':[_('box')], 'box1':[_('box 1')], 'box2':[_('box 2')], + 'cartesian':[_('Cartesian')], 'clean':[_(' clean ')], 'clearheap':[_('empty heap')], 'color':[_('color')], @@ -292,6 +293,7 @@ BLOCK_NAMES = { 'picture2x1':[' '], 'picture1x2':[' '], 'plus2':['+'], + 'polar':[_('polar')], 'pop':[_('pop')], 'printheap':[_('show heap')], 'print':[_('print')], @@ -370,6 +372,7 @@ PRIMITIVES = { 'box1':'box1', 'box2':'box2', 'box':'box', + 'cartesian':'cartesian', 'clean':'clean', 'clearheap':'clearheap', 'color':'color', @@ -411,6 +414,7 @@ PRIMITIVES = { 'pensize':'pensize', 'penup':'penup', 'plus2':'plus', + 'polar':'polar', 'pop':'pop', 'printheap':'printheap', 'print':'print', @@ -630,6 +634,7 @@ HELP_STRINGS = { 'box1':_("Variable 1 (numeric value)"), 'box2':_("Variable 2 (numeric value)"), 'box':_("named variable (numeric value)"), + 'cartesian':_("displays Cartesian coordinates"), 'clean':_("clears the screen and reset the turtle"), 'clearheap':_("emptys FILO (first-in-last-out heap)"), 'color':_("holds current pen color (can be used in place of a number block)"), @@ -685,6 +690,7 @@ HELP_STRINGS = { 'picture2x2':_("presentation template: select four Journal objects"), 'picturelist':_("presentation template: list of bullets"), 'plus2':_("adds two alphanumeric inputs"), + 'polar':_("displays polar coordinates"), 'pop':_("pops value off FILO (first-in last-out heap)"), 'portfolio':_("palette of presentation templates"), 'print':_("prints value in status block at bottom of the screen"), diff --git a/talogo.py b/talogo.py index 55b9b73..cb2d86e 100644 --- a/talogo.py +++ b/talogo.py @@ -280,6 +280,7 @@ class LogoCode: 'box2':[0, lambda self: self.boxes['box2']], 'bullet':[1, self.prim_bullet, True], 'bulletlist':[1, self.prim_list, True], + 'cartesian':[0, lambda self: self.tw.set_cartesian(True)], 'clean':[0, lambda self: self.prim_clear()], 'clearheap':[0, lambda self: self.empty_heap()], 'color':[0, lambda self: self.tw.canvas.color], @@ -311,7 +312,7 @@ class LogoCode: 'minus':[2, lambda self,x,y: taminus(x,y)], 'mod':[2, lambda self,x,y: tamod(x,y)], 'myfunc':[1, self.prim_myfunc, True], - 'myfunction':[1, lambda self, x: self.myfunction(x)], + 'myfunction':[2, lambda self, f, x: self.myfunction(f, x)], 'nop':[0, lambda self: None], 'nop1':[0, lambda self: None], 'nop2':[0, lambda self: None], @@ -323,6 +324,7 @@ class LogoCode: 'pensize':[0, lambda self: self.tw.canvas.pensize], 'penup':[0, lambda self: self.tw.canvas.setpen(False)], 'plus':[2, lambda self,x,y: taplus(x,y)], + 'polar':[0, lambda self: self.tw.set_polar(True)], 'pop':[0, lambda self: self.prim_pop()], 'print':[1, lambda self,x: self.prim_print(x, False)], 'printheap':[0, lambda self: self.prim_print_heap()], @@ -829,8 +831,8 @@ class LogoCode: self.ireturn() yield True - def myfunction(self, list): - y = myfunc(list[0], list[1:]) + def myfunction(self, f, x): + y = myfunc(f, [x]) if y == None: raise logoerror("#syntaxerror") stop_logo(self.tw) diff --git a/tawindow.py b/tawindow.py index 6a585ad..b650e31 100644 --- a/tawindow.py +++ b/tawindow.py @@ -310,8 +310,9 @@ class TurtleArtWindow(): self._resize_skin(blk) self.nop = 'pythonloaded' + """ - Enter fulscreen mode + Enter fullscreen mode """ def set_fullscreen(self): if self.running_sugar: @@ -319,6 +320,35 @@ class TurtleArtWindow(): self.activity.recenter() """ + Turn on/off Cartesian coordinates + """ + def set_cartesian(self, flag): + if flag: + if self.coord_scale == 1: + self.overlay_shapes['Cartesian_labeled'].set_layer( + OVERLAY_LAYER) + else: + self.overlay_shapes['Cartesian'].set_layer(OVERLAY_LAYER) + self.cartesian = True + else: + if self.coord_scale == 1: + self.overlay_shapes['Cartesian_labeled'].hide() + else: + self.overlay_shapes['Cartesian'].hide() + self.cartesian = False + + """ + Turn on/off polar coordinates + """ + def set_polar(self, flag): + if flag: + self.overlay_shapes['polar'].set_layer(OVERLAY_LAYER) + self.polar = True + else: + self.overlay_shapes['polar'].hide() + self.polar = False + + """ Hide/show button """ def hideshow_button(self): -- cgit v0.9.1