diff options
author | Emiliano Pastorino <epastorino@plan.ceibal.edu.uy> | 2011-03-23 12:30:00 (GMT) |
---|---|---|
committer | Emiliano Pastorino <epastorino@plan.ceibal.edu.uy> | 2011-03-23 12:30:00 (GMT) |
commit | d7d10290da2811d80a7e7885ed8c70b7aa59a260 (patch) | |
tree | e76d0f1eae75b7ef06d7b73eb1af2f9b4f7b4ad8 | |
parent | 8bfacef788c7a5f71db4e75c52b055a53769fc27 (diff) | |
parent | d4ca05eb702dd15adba170dc1f18a78fb00656d9 (diff) |
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | TurtleArt/tajail.py | 8 | ||||
-rw-r--r-- | samples/timer.ta | 82 |
3 files changed, 93 insertions, 3 deletions
@@ -21,7 +21,7 @@ BUG FIXES * Fixed regression with camera_plugin after refactoring (#2689) * Fixed problem with saving/loading extra turtles when nick changes (#2441) -PYTHON CODE FLAG DAY +PYTHON CODE CHANGE * Userdefined code gets TurtleWindow instance rather than LogoCode instance as first argument. This change was made in order to better @@ -31,7 +31,9 @@ PYTHON CODE FLAG DAY directly, e.g., tw. To reference lc, use tw.lc. Also note that the push_mouse_event.py sample has changed. The x,y position of the mouse is now always pushed to the stack, whether or not the mouse - button is pressed. + button is pressed. Under most circumstances, Turtle Art will detect + when myblock is looking for lc rather than tw and it will pass the + correct argument. 106 diff --git a/TurtleArt/tajail.py b/TurtleArt/tajail.py index c8cea7f..3fcf997 100644 --- a/TurtleArt/tajail.py +++ b/TurtleArt/tajail.py @@ -25,6 +25,7 @@ from math import * def myfunc(f, args): + ''' Run inline Python code ''' # check to make sure no import calls are made if len(args) == 1: myf = 'def f(x): return ' + f.replace('import', '') @@ -44,10 +45,15 @@ def myfunc(f, args): def myfunc_import(parent, f, x): + ''' Run Python code imported from Journal ''' + if 'def myblock(lc,' in f: + base_class = parent.tw.lc # pre-v107, we passed lc + else: + base_class = parent.tw # as of v107, we pass tw userdefined = {} try: exec f in globals(), userdefined - return userdefined['myblock'](parent.tw, x) + return userdefined['myblock'](base_class, x) except: traceback.print_exc() return None diff --git a/samples/timer.ta b/samples/timer.ta new file mode 100644 index 0000000..cb691ec --- /dev/null +++ b/samples/timer.ta @@ -0,0 +1,82 @@ +[[0, ["fillscreen", 0], 753, 146, [12, 2, 1, 4]], +[1, ["number", 80], 839, 188, [0, null]], +[2, "red", 839, 146, [0, null]], +[3, "white", 831, 230, [4, null]], +[4, "setcolor", 753, 230, [0, 3, 71]], +[5, "white", 843, 407, [7, null]], +[6, "blue", 835, 491, [9, null]], +[7, ["fillscreen", 0], 757, 407, [11, 5, 8, 9]], +[8, ["number", 80], 843, 449, [7, null]], +[9, "setcolor", 757, 491, [7, 6, 74]], +[10, ["start", 2.0], 194, 74, [null, 80]], +[11, "hat1", 757, 365, [null, 7]], +[12, "hat2", 753, 104, [null, 0]], +[13, "show", 258, 760, [68, 77, 79]], +[14, "setscale", 194, 158, [80, 15, 44]], +[15, ["number", 330], 273, 158, [14, null]], +[16, ["userdefined", "pysamples/push_time.py"], 892, 673, [41, 17, 18]], +[17, ["number", 100], 950, 673, [16, null]], +[18, ["storein", 0], 892, 715, [16, 24, 20, 21]], +[19, ["string", "h"], 961, 883, [23, null]], +[20, "pop", 961, 757, [18, null]], +[21, ["storein", 0], 892, 799, [18, 22, 34, 23]], +[22, ["string", "m"], 961, 799, [21, null]], +[23, ["storein", 0], 892, 883, [21, 19, 35, 25]], +[24, ["string", "s"], 961, 715, [18, null]], +[25, "storeinbox1", 892, 967, [23, 30, null]], +[26, "box", 1119, 967, [28, 27, null]], +[27, ["string", "h"], 1174, 967, [26, null]], +[28, ["product2", 0], 1065, 967, [30, 26, 29]], +[29, ["number", 3600], 1119, 1009, [28, null]], +[30, ["plus2", 20], 1011, 967, [25, 28, 32]], +[31, ["product2", 0], 1119, 1049, [32, 36, 33]], +[32, ["plus2", 20], 1065, 1049, [30, 31, 38]], +[33, ["number", 60], 1173, 1091, [31, null]], +[34, "pop", 961, 841, [21, null]], +[35, "pop", 961, 925, [23, null]], +[36, "box", 1173, 1049, [31, 37, null]], +[37, ["string", "m"], 1228, 1049, [36, null]], +[38, "box", 1119, 1131, [32, 39, null]], +[39, ["string", "s"], 1174, 1131, [38, null]], +[40, "box1", 313, 242, [43, null]], +[41, "hat", 892, 623, [null, 42, 16]], +[42, ["string", "time"], 950, 631, [41, null]], +[43, "storeinbox2", 194, 242, [44, 40, 46]], +[44, "stack", 194, 200, [14, 45, 43]], +[45, ["string", "time"], 252, 200, [44, null]], +[46, "stack1", 194, 284, [43, 47]], +[47, "forever", 194, 326, [46, 53, null]], +[48, ["vspace", 40], 258, 470, [58, 66]], +[49, "wait", 258, 844, [79, 50, null]], +[50, ["number", 10], 316, 844, [49, null]], +[51, "box2", 459, 470, [55, null]], +[52, "box1", 435, 428, [55, null]], +[53, "stack", 258, 344, [47, 54, 58]], +[54, ["string", "time"], 316, 344, [53, null]], +[55, ["minus2", 0], 381, 428, [56, 52, 51]], +[56, ["division2", 20], 327, 428, [58, 55, 57]], +[57, ["number", 60], 405, 510, [56, null]], +[58, ["storein", 0], 258, 386, [53, 59, 56, 48]], +[59, ["string", "elapsed"], 327, 386, [58, null]], +[60, ["greater2", 0], 320, 558, [66, 62, 61, null]], +[61, ["number", 20], 390, 600, [60, null]], +[62, "box", 366, 558, [60, 63, null]], +[63, ["string", "elapsed"], 421, 558, [62, null]], +[64, "stack2", 334, 702, [67, null]], +[65, "stack1", 386, 660, [66, null]], +[66, "ifelse", 258, 592, [48, 60, 67, 65, 68]], +[67, ["vspace", 0], 334, 660, [66, 64]], +[68, ["vspace", 20], 258, 678, [66, 13]], +[69, "box", 397, 802, [77, 70, null]], +[70, ["string", "elapsed"], 452, 802, [69, null]], +[71, ["setxy2", 0], 753, 272, [4, 72, 73, null]], +[72, ["number", -100], 811, 272, [71, null]], +[73, ["number", 200], 811, 314, [71, null]], +[74, ["setxy2", 0], 757, 533, [9, 75, 76, null]], +[75, ["number", -100], 815, 533, [74, null]], +[76, ["number", 200], 815, 575, [74, null]], +[77, ["myfunc1arg", 0], 316, 760, [13, 78, 69, null]], +[78, ["string", "int(x)"], 397, 760, [77, null]], +[79, ["vspace", 0], 258, 802, [13, 49]], +[80, "hideblocks", 194, 116, [10, 14]], +[-1, ["turtle", "Yertle"], -100.0, 200.0, 0, 70, 50, 5]]
\ No newline at end of file |