diff options
-rwxr-xr-x | MANIFEST | 2 | ||||
-rwxr-xr-x | TurtleArtActivity.py | 19 | ||||
-rwxr-xr-x | samples/candyvortex.png | bin | 98971 -> 92624 bytes | |||
-rwxr-xr-x | samples/candyvortex.ta | 4 | ||||
-rwxr-xr-x | samples/colors.png | bin | 95221 -> 89789 bytes | |||
-rwxr-xr-x | samples/colors.ta | 2 | ||||
-rwxr-xr-x | samples/flower.png | bin | 152107 -> 151215 bytes | |||
-rwxr-xr-x | samples/flower.ta | 4 | ||||
-rwxr-xr-x | samples/rainbow.png | bin | 51398 -> 47957 bytes | |||
-rwxr-xr-x | samples/rainbow.ta | 2 | ||||
-rwxr-xr-x | samples/shades.png | bin | 65541 -> 59890 bytes | |||
-rwxr-xr-x | samples/shades.ta | 2 | ||||
-rwxr-xr-x | samples/square.png | bin | 5223 -> 4801 bytes | |||
-rwxr-xr-x | samples/squares.png | bin | 42674 -> 41829 bytes | |||
-rwxr-xr-x | samples/xo-man.png | bin | 0 -> 79523 bytes | |||
-rwxr-xr-x | samples/xo-man.ta | 602 | ||||
-rwxr-xr-x | setup.py | 2 | ||||
-rwxr-xr-x | ta.py | 19 | ||||
-rwxr-xr-x | turtlesetup.py | 358 |
19 files changed, 817 insertions, 199 deletions
@@ -189,3 +189,5 @@ samples/squares.png samples/squares.ta samples/squiral.png samples/squiral.ta +samples/xo-man.png +samples/xo-man.ta diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py index 7869e4a..3c40d89 100755 --- a/TurtleArtActivity.py +++ b/TurtleArtActivity.py @@ -1,18 +1,27 @@ import ta +import pygtk +pygtk.require('2.0') +import gtk from sugar.activity import activity class TurtleArtActivity(activity.Activity): def __init__(self, handle): - activity.Activity.__init__(self, handle) - self.connect('destroy', self._cleanup_cb) + super(TurtleArtActivity,self).__init__(handle) self.gamename = 'turtleart' self.set_title("TurtleArt") + toolbar = activity.ActivityToolbar(self) + toolbar.show() + self.set_toolbox(toolbar) + + self.connect('destroy', self._cleanup_cb) +# self.connect('focus_in_event', self._focus_in) +# self.connect('focus_out_event', self._focus_out) - self.connect('focus_in_event', self._focus_in) - self.connect('focus_out_event', self._focus_out) - ta.init(self, activity.get_bundle_path()) + canvas = gtk.EventBox() + self.set_canvas(canvas) + ta.init(canvas, activity.get_bundle_path(),self) def _cleanup_cb(self, data=None): diff --git a/samples/candyvortex.png b/samples/candyvortex.png Binary files differindex 89aec32..908b90e 100755 --- a/samples/candyvortex.png +++ b/samples/candyvortex.png diff --git a/samples/candyvortex.ta b/samples/candyvortex.ta index 30e67af..1f7748e 100755 --- a/samples/candyvortex.ta +++ b/samples/candyvortex.ta @@ -136,8 +136,8 @@ p46 F0.0 F0.0 F10.0 -F8.1910046234551999 -F17.372816552336076 +F190.8089953765448 +F981.62718344766392 F11.0 tp47 a.
\ No newline at end of file diff --git a/samples/colors.png b/samples/colors.png Binary files differindex 2891ba7..0cb4cf6 100755 --- a/samples/colors.png +++ b/samples/colors.png diff --git a/samples/colors.ta b/samples/colors.ta index 7ab30e8..cedbb95 100755 --- a/samples/colors.ta +++ b/samples/colors.ta @@ -118,7 +118,7 @@ p39 F0.0 F0.0 F0.0 -F40.0 +F359.0 I50 F15.0 tp40 diff --git a/samples/flower.png b/samples/flower.png Binary files differindex 9977d3a..f8dfd33 100755 --- a/samples/flower.png +++ b/samples/flower.png diff --git a/samples/flower.ta b/samples/flower.ta index c4b9009..fd9d2d1 100755 --- a/samples/flower.ta +++ b/samples/flower.ta @@ -281,8 +281,8 @@ p94 F1.3812950783176348e-11 F-7.4464878707658499e-11 F0.0 -F99.333333333333329 -F1.0 +F99.666666666666671 +F-199.0 I5 tp95 a.
\ No newline at end of file diff --git a/samples/rainbow.png b/samples/rainbow.png Binary files differindex 213b204..4abea6a 100755 --- a/samples/rainbow.png +++ b/samples/rainbow.png diff --git a/samples/rainbow.ta b/samples/rainbow.ta index 7730a7a..26d635e 100755 --- a/samples/rainbow.ta +++ b/samples/rainbow.ta @@ -187,7 +187,7 @@ p63 F0.0 F0.0 F0.0 -F99.277777777777771 +F99.722222222222229 I50 F15.0 tp64 diff --git a/samples/shades.png b/samples/shades.png Binary files differindex 7e7e504..ca59fce 100755 --- a/samples/shades.png +++ b/samples/shades.png diff --git a/samples/shades.ta b/samples/shades.ta index 90dd90f..c6e6790 100755 --- a/samples/shades.ta +++ b/samples/shades.ta @@ -188,7 +188,7 @@ F0.0 F0.0 F0.0 F50.0 -F-0.44444444444445708 +F199.44444444444446 F15.0 tp64 a.
\ No newline at end of file diff --git a/samples/square.png b/samples/square.png Binary files differindex 91d4509..848de15 100755 --- a/samples/square.png +++ b/samples/square.png diff --git a/samples/squares.png b/samples/squares.png Binary files differindex 94d9461..ca854d0 100755 --- a/samples/squares.png +++ b/samples/squares.png diff --git a/samples/xo-man.png b/samples/xo-man.png Binary files differnew file mode 100755 index 0000000..a75f159 --- /dev/null +++ b/samples/xo-man.png diff --git a/samples/xo-man.ta b/samples/xo-man.ta new file mode 100755 index 0000000..7ecff69 --- /dev/null +++ b/samples/xo-man.ta @@ -0,0 +1,602 @@ +(lp0 +(I0 +S'hat1' +p1 +I837 +I133 +(lp2 +NaI1 +atp3 +a(I1 +S'left' +p4 +I849 +I183 +(lp5 +I0 +aI2 +aI3 +atp6 +a(I2 +(S'number' +p7 +S'45' +p8 +tp9 +I923 +I192 +(lp10 +I1 +aNatp11 +a(I3 +S'repeat' +p12 +I849 +I222 +(lp13 +I1 +aI4 +aI5 +aI9 +atp14 +a(I4 +(g7 +S'4' +p15 +tp16 +I935 +I231 +(lp17 +I3 +aNatp18 +a(I5 +S'forward' +p19 +I944 +I271 +(lp20 +I3 +aI48 +aI6 +atp21 +a(I6 +S'back' +p22 +I944 +I310 +(lp23 +I5 +aI49 +aI7 +atp24 +a(I7 +g4 +I944 +I349 +(lp25 +I6 +aI8 +aNatp26 +a(I8 +(g7 +S'90' +p27 +tp28 +I1018 +I358 +(lp29 +I7 +aNatp30 +a(I9 +S'vspace' +p31 +I849 +I312 +(lp32 +I3 +aI10 +atp33 +a(I10 +S'right' +p34 +I849 +I381 +(lp35 +I9 +aI11 +aI12 +atp36 +a(I11 +(g7 +S'45' +p37 +tp38 +I923 +I390 +(lp39 +I10 +aNatp40 +a(I12 +S'penup' +p41 +I849 +I420 +(lp42 +I10 +aI13 +atp43 +a(I13 +g19 +I849 +I459 +(lp44 +I12 +aI50 +aI14 +atp45 +a(I14 +S'pendown' +p46 +I849 +I498 +(lp47 +I13 +aI15 +atp48 +a(I15 +S'setpensize' +p49 +I849 +I537 +(lp50 +I14 +aI16 +aI19 +atp51 +a(I16 +S'pensize' +p52 +I923 +I554 +(lp53 +I15 +aI17 +atp54 +a(I17 +S'plus' +p55 +I1016 +I546 +(lp56 +I16 +aI18 +atp57 +a(I18 +(g7 +S'35' +p58 +tp59 +I1055 +I554 +(lp60 +I17 +aNatp61 +a(I19 +g19 +I849 +I591 +(lp62 +I15 +aI20 +aI21 +atp63 +a(I20 +(g7 +S'1' +p64 +tp65 +I923 +I600 +(lp66 +I19 +aNatp67 +a(I21 +g41 +I849 +I630 +(lp68 +I19 +aI22 +atp69 +a(I22 +g22 +I849 +I669 +(lp70 +I21 +aI51 +aI23 +atp71 +a(I23 +g46 +I849 +I708 +(lp72 +I22 +aI24 +atp73 +a(I24 +g49 +I849 +I747 +(lp74 +I23 +aI25 +aNatp75 +a(I25 +g52 +I923 +I764 +(lp76 +I24 +aI26 +atp77 +a(I26 +S'minus' +p78 +I1016 +I756 +(lp79 +I25 +aI27 +atp80 +a(I27 +(g7 +S'35' +p81 +tp82 +I1055 +I764 +(lp83 +I26 +aNatp84 +a(I28 +S'setcolor' +p85 +I87 +I546 +(lp86 +I46 +aI29 +aI34 +atp87 +a(I29 +(g7 +S'0' +p88 +tp89 +I161 +I563 +(lp90 +I28 +aI30 +atp91 +a(I30 +g55 +I254 +I555 +(lp92 +I29 +aI31 +atp93 +a(I31 +S'random' +p94 +I293 +I544 +(lp95 +I30 +aI32 +aI33 +aNatp96 +a(I32 +(g7 +g88 +tp97 +I321 +I563 +(lp98 +I31 +aNatp99 +a(I33 +(g7 +S'100' +p100 +tp101 +I443 +I563 +(lp102 +I31 +aNatp103 +a(I34 +g49 +I87 +I600 +(lp104 +I28 +aI35 +aI36 +atp105 +a(I35 +(g7 +S'40' +p106 +tp107 +I161 +I617 +(lp108 +I34 +aNatp109 +a(I36 +S'stack1' +p110 +I87 +I654 +(lp111 +I34 +aI37 +atp112 +a(I37 +g85 +I87 +I693 +(lp113 +I36 +aI38 +aI41 +atp114 +a(I38 +S'color' +p115 +I161 +I710 +(lp116 +I37 +aI39 +atp117 +a(I39 +g55 +I254 +I702 +(lp118 +I38 +aI40 +atp119 +a(I40 +(g7 +S'10' +p120 +tp121 +I293 +I710 +(lp122 +I39 +aNatp123 +a(I41 +g49 +I87 +I747 +(lp124 +I37 +aI42 +aI45 +atp125 +a(I42 +g52 +I161 +I764 +(lp126 +I41 +aI43 +atp127 +a(I43 +g78 +I254 +I756 +(lp128 +I42 +aI44 +atp129 +a(I44 +(g7 +S'25' +p130 +tp131 +I293 +I764 +(lp132 +I43 +aNatp133 +a(I45 +g110 +I87 +I801 +(lp134 +I41 +aNatp135 +a(I46 +S'hat2' +p136 +I75 +I496 +(lp137 +NaI28 +atp138 +a(I47 +S'xcor' +p139 +I316 +I329 +(lp140 +NaNatp141 +a(I48 +(g7 +S'75' +p142 +tp143 +I1018 +I280 +(lp144 +I5 +aNatp145 +a(I49 +(g7 +S'75' +p146 +tp147 +I1018 +I319 +(lp148 +I6 +aNatp149 +a(I50 +(g7 +S'90' +p150 +tp151 +I923 +I468 +(lp152 +I13 +aNatp153 +a(I51 +(g7 +S'91' +p154 +tp155 +I923 +I678 +(lp156 +I22 +aNatp157 +a(I52 +S'clean' +p158 +I305 +I33 +(lp159 +NaI53 +atp160 +a(I53 +S'forever' +p161 +I305 +I72 +(lp162 +I52 +aI54 +aNatp163 +a(I54 +g41 +I386 +I86 +(lp164 +I53 +aI55 +atp165 +a(I55 +S'setxy' +p166 +I386 +I125 +(lp167 +I54 +aI56 +aI59 +aI62 +atp168 +a(I56 +g94 +I460 +I115 +(lp169 +I55 +aI57 +aI58 +aNatp170 +a(I57 +(g7 +S'-600' +p171 +tp172 +I488 +I134 +(lp173 +I56 +aNatp174 +a(I58 +(g7 +S'600' +p175 +tp176 +I610 +I134 +(lp177 +I56 +aNatp178 +a(I59 +g94 +I460 +I152 +(lp179 +I55 +aI60 +aI61 +aNatp180 +a(I60 +(g7 +S'-450' +p181 +tp182 +I488 +I171 +(lp183 +I59 +aNatp184 +a(I61 +(g7 +S'450' +p185 +tp186 +I610 +I171 +(lp187 +I59 +aNatp188 +a(I62 +g46 +I386 +I201 +(lp189 +I55 +aI63 +atp190 +a(I63 +S'stack2' +p191 +I386 +I240 +(lp192 +I62 +aNatp193 +a(I-1 +S'turtle' +p194 +F71.033008588991066 +F309.03300858899104 +F45.0 +F99.0 +I50 +F15.0 +tp195 +a.
\ No newline at end of file @@ -1,3 +1,3 @@ #!/usr/bin/env python from sugar.activity import bundlebuilder -bundlebuilder.start() +bundlebuilder.start("TurtleArt") @@ -13,7 +13,7 @@ import logo import turtle WIDTH=1200 -HEIGHT=900 +HEIGHT=825 DEGTOR = 2*pi/360 @@ -479,28 +479,33 @@ def project_flap_pressed(spr,x,y): # Startup # -def init(top_window, path): +def init(top_window, path, parentwindow=None): global gc, area, category_spr, bgcolor,turtlecanvas, select_mask global status_spr, turtle_spr, selbuttons, hidden_palette_icon, project_flap global base_path, load_save_folder window = top_window base_path = path + if parentwindow is None: + parentwindow = top_window # remove any children of the window that Sugar may have added - for widget in window.get_children(): window.remove(widget) + #for widget in window.get_children(): window.remove(widget) - window.set_title("TurteArt") + #window.set_title("TurteArt") window.connect("destroy", lambda w: gtk.main_quit()) + window.set_flags(gtk.CAN_FOCUS) window.set_size_request(WIDTH, HEIGHT) window.add_events(gtk.gdk.BUTTON_PRESS_MASK) window.add_events(gtk.gdk.BUTTON_RELEASE_MASK) window.add_events(gtk.gdk.POINTER_MOTION_MASK) + parentwindow.add_events(gtk.gdk.KEY_PRESS_MASK) window.connect("expose-event", expose_cb) window.connect("button-press-event", buttonpress_cb) window.connect("button-release-event", buttonrelease_cb) window.connect("motion-notify-event", move_cb) - window.connect("key_press_event", keypress_cb) + parentwindow.connect("key_press_event", keypress_cb) window.show() + parentwindow.show_all() area = window.window cursor_pix = gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'arrow.gif')) cursor = gtk.gdk.Cursor(area.get_display(), cursor_pix, 10, 0) @@ -516,12 +521,12 @@ def init(top_window, path): # who.setlayer(700) - turtlecanvas = Sprite(0,0,gtk.gdk.Pixmap(area,1200,900,-1)) + turtlecanvas = Sprite(0,0,gtk.gdk.Pixmap(area,WIDTH,HEIGHT,-1)) turtlecanvas.type = 'canvas' turtlecanvas.setlayer(600) select_mask = Sprite(100,100,gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'masknumber.gif'))) select_mask.type = 'selectmask' - status_spr = Sprite(0,865,gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'status.gif')),True) + status_spr = Sprite(0,790,gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'status.gif')),True) status_spr.type = 'status' status_spr.setlayer(400) turtle.shapelist = [gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'shapes','t'+str(i)+'.gif')) diff --git a/turtlesetup.py b/turtlesetup.py index 6525a1c..be38afa 100755 --- a/turtlesetup.py +++ b/turtlesetup.py @@ -1,179 +1,179 @@ -import pygtk
-pygtk.require('2.0')
-import gtk
-import gobject
-import os
-#import os.path
-
-from sprites import *
-
-selectors = (
- ('turtle', 37,
- (('clean','clean','noarg'),
- ('forward','forward','onearg',100),
- ('back','back','onearg',100),
- ('left','left','onearg',90),
- ('right','right','onearg',90),
- ('arc','arc','twoargs',90,100),
- ('setxy','setxy','twoargs',0,0),
- ('seth','seth','onearg',0),
- ('xcor','xcor','num'),
- ('ycor','ycor','num'),
- ('heading','heading','num'))),
- ('pen', 30,
- (('penup','penup','noarg'),
- ('pendown','pendown','noarg'),
- ('setpensize','setpensize','1arg',5),
- ('setcolor','setcolor','1arg',0),
- ('setshade','setshade','1arg',50),
- ('fillscreen','fillscreen','twoargs',60,80),
- ('pensize','pensize','num'),
- ('color','color','num'),
- ('shade','shade','num'))),
- ('numbers', 55,
- (('number','','num'),
- ('plus','+','ari'),
- ('minus','-','ari'),
- ('product','*','ari'),
- ('division','/','ari'),
- ('remainder','%','ari2'),
- ('random','random','random',0,100),
- ('greater','greater?','comp'),
- ('less','less?','comp'),
- ('equal','equal?','comp'),
- ('and','and','and'),
- ('or','or','and'),
- ('not','not','not'),
- ('print','print','onearg'))),
- ('flow', 30,
- (('wait','wait','onearg',10),
- ('forever','forever','forever'),
- ('repeat','repeat','repeat',4),
- ('if','if','if'),
- ('stopstack','stopstack','stop'),
- ('ifelse','ifelse','ifelse'),
- ('hspace','nop','hspace'),
- ('vspace','nop','vspace'))),
- ('myblocks', 46,
- (('hat1','nop','start'),
- ('stack1','stack1','noarg'),
- ('hat2','nop','start'),
- ('stack2','stack2','noarg'),
- ('storeinbox1','storeinbox1','1arg'),
- ('box1','box1','num'),
- ('storeinbox2','storeinbox2','1arg'),
- ('box2','box2','num'))))
-
-toolbaritems = (
-# ('new',0,20),('open',70,20), ('save',70,20),
- ('hideshow',700, 850),('eraser',54,850), ('stopit',54,850))
-# ('hideshow',200, 2),('eraser',54,3), ('stopit',54,2))
-
-dockdetails = {
- 'noarg': (('flow',True,37,5),('flow',False,37,44)),
- 'onearg': (('flow',True,37,5),('num',False,74,21),('flow',False,37,44)),
- '1arg': (('flow',True,37,5),('num',False,74,29),('flow',False,37,59)),
- 'twoargs': (('flow',True,37,5),('num',False,74,21),('num',False,74,58),('flow',False,37,81)),
- 'forever': (('flow',True,37,5),('flow',False,118,19,'['),('unavailable',False,0,0,']')),
- 'repeat': (('flow',True,37,5),('num',False,86,21),('flow',False,132,54,'['),('flow',False,37,95,']')),
- 'num': (('num',True,0,12),('numend',False,105,12)),
- 'if': (('flow',True,37,5),('logi+',False,80,31),('flow',False,132,79,'['),('flow',False,37,120,']')),
- 'ifelse': (('flow',True,37,5),('logi+',False,80,31),('flow',False,132,79,'['),('flow',False,217,79,']['),('flow',False,37,120,']')),
- 'ari': (('numend',True,12,20),('num',False,39,20)),
- 'ari2': (('numend',True,12,20),('num',False,51,20)),
- 'stop': (('flow',True,37,5),('unavailable',False,0,0)),
- 'comp': (('logi+',True,0,21,'('),('num',False,32,21),('num',False,181,21),('logi-',False,320,21,')')),
- 'random': (('num',True,0,31,'('),('num',False,28,31),('num',False,150,31),('numend',False,279,31,')')),
- 'and': (('logi-',True,28,24),('logi+',False,64,24)),
- 'vspace': (('flow',True,37,5),('flow',False,37,74)),
- 'hspace': (('flow',True,37,14),('flow',False,128,13)),
- 'not': (('logi+',True,0,24),('unavailable',False,0,0),('logi+',False,55,24)),
- 'start': (('start',True,50,0),('flow',False,49,55))
-}
-
-protodict = {}
-toolsprs = {}
-base_path = None
-
-class BlockProto:
- def __init__(self,name):
- self.name = name
-
-
-def setup_selectors(path):
- global base_path
- base_path = path
- y = 25
- categories = []
- for s in selectors:
- name,dy,blockdescriptions = s
- cat = setup_selector(name,y, blockdescriptions)
- y += dy*3/2
- categories.append(cat)
- category_spr = Sprite(0, 0, categories[0].group)
- category_spr.type = 'category'
- category_spr.setlayer(660)
- return category_spr, categories, categories[0]
-
-def setup_selector(name,y,blockdescriptions):
- offshape = gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'palette',name+'off.gif'))
- onshape = gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'palette',name+'on.gif'))
- who = Sprite(140,y,offshape)
- who.setlayer(800)
- who.offshape = offshape
- who.onshape = onshape
- who.group = gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, name,name+'group.gif'))
- maskname = os.path.join(base_path, name,name+'mask.gif')
- if os.access(maskname, os.F_OK):
- who.mask = gtk.gdk.pixbuf_new_from_file(maskname)
- else: who.mask = None
- who.type = 'selbutton'
- protos = []
- for b in blockdescriptions:
- bname,primname,docktype = b[0:3]
- image = gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, name, bname+'.gif'))
- proto = BlockProto(bname)
- proto.image = image
- proto.primname=primname
- proto.defaults=b[3:]
- if docktype in dockdetails: proto.docks=dockdetails[docktype]
- else: proto.docks = docktype
- protodict[bname] = proto
- protos.append(proto)
- who.blockprotos = protos
- return who
-
-def setup_toolbar():
- x,y = 330,0
- for s in toolbaritems:
- name,dx,dy= s
- x += dx
- setup_tool(x,y + dy,name)
- return
-
-def setup_tool(x,y,name):
- offshape = gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'toolbar',name+'off.gif'))
- onshape = gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'toolbar',name+'on.gif'))
- who = Sprite(x,y,offshape)
- who.setlayer(800)
- who.offshape = offshape
- who.onshape = onshape
- who.type = 'tool'
- who.blocktype = name
- toolsprs[name] = who
-
-def setup_project_flap():
- project_flap = {
- 'closed': gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'toolbar','project-.gif')),
- 'open': gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'toolbar','project.gif')),
- 'mask': gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'toolbar','projectmask.gif'))}
-# who = Sprite(720,0,project_flap['closed'])
- who = Sprite(888,0,project_flap['closed'])
- who.type = 'project_flap'
- who.setlayer(800)
- return project_flap
-
-def blockproto(name): return protodict[name]
-
-def toolsprite(name): return toolsprs[name]
-
+import pygtk +pygtk.require('2.0') +import gtk +import gobject +import os +#import os.path + +from sprites import * + +selectors = ( + ('turtle', 37, + (('clean','clean','noarg'), + ('forward','forward','onearg',100), + ('back','back','onearg',100), + ('left','left','onearg',90), + ('right','right','onearg',90), + ('arc','arc','twoargs',90,100), + ('setxy','setxy','twoargs',0,0), + ('seth','seth','onearg',0), + ('xcor','xcor','num'), + ('ycor','ycor','num'), + ('heading','heading','num'))), + ('pen', 30, + (('penup','penup','noarg'), + ('pendown','pendown','noarg'), + ('setpensize','setpensize','1arg',5), + ('setcolor','setcolor','1arg',0), + ('setshade','setshade','1arg',50), + ('fillscreen','fillscreen','twoargs',60,80), + ('pensize','pensize','num'), + ('color','color','num'), + ('shade','shade','num'))), + ('numbers', 55, + (('number','','num'), + ('plus','+','ari'), + ('minus','-','ari'), + ('product','*','ari'), + ('division','/','ari'), + ('remainder','%','ari2'), + ('random','random','random',0,100), + ('greater','greater?','comp'), + ('less','less?','comp'), + ('equal','equal?','comp'), + ('and','and','and'), + ('or','or','and'), + ('not','not','not'), + ('print','print','onearg'))), + ('flow', 30, + (('wait','wait','onearg',10), + ('forever','forever','forever'), + ('repeat','repeat','repeat',4), + ('if','if','if'), + ('stopstack','stopstack','stop'), + ('ifelse','ifelse','ifelse'), + ('hspace','nop','hspace'), + ('vspace','nop','vspace'))), + ('myblocks', 46, + (('hat1','nop','start'), + ('stack1','stack1','noarg'), + ('hat2','nop','start'), + ('stack2','stack2','noarg'), + ('storeinbox1','storeinbox1','1arg'), + ('box1','box1','num'), + ('storeinbox2','storeinbox2','1arg'), + ('box2','box2','num')))) + +toolbaritems = ( +# ('new',0,20),('open',70,20), ('save',70,20), + ('hideshow',700, 775),('eraser',54,775), ('stopit',54,775)) +# ('hideshow',200, 2),('eraser',54,3), ('stopit',54,2)) + +dockdetails = { + 'noarg': (('flow',True,37,5),('flow',False,37,44)), + 'onearg': (('flow',True,37,5),('num',False,74,21),('flow',False,37,44)), + '1arg': (('flow',True,37,5),('num',False,74,29),('flow',False,37,59)), + 'twoargs': (('flow',True,37,5),('num',False,74,21),('num',False,74,58),('flow',False,37,81)), + 'forever': (('flow',True,37,5),('flow',False,118,19,'['),('unavailable',False,0,0,']')), + 'repeat': (('flow',True,37,5),('num',False,86,21),('flow',False,132,54,'['),('flow',False,37,95,']')), + 'num': (('num',True,0,12),('numend',False,105,12)), + 'if': (('flow',True,37,5),('logi+',False,80,31),('flow',False,132,79,'['),('flow',False,37,120,']')), + 'ifelse': (('flow',True,37,5),('logi+',False,80,31),('flow',False,132,79,'['),('flow',False,217,79,']['),('flow',False,37,120,']')), + 'ari': (('numend',True,12,20),('num',False,39,20)), + 'ari2': (('numend',True,12,20),('num',False,51,20)), + 'stop': (('flow',True,37,5),('unavailable',False,0,0)), + 'comp': (('logi+',True,0,21,'('),('num',False,32,21),('num',False,181,21),('logi-',False,320,21,')')), + 'random': (('num',True,0,31,'('),('num',False,28,31),('num',False,150,31),('numend',False,279,31,')')), + 'and': (('logi-',True,28,24),('logi+',False,64,24)), + 'vspace': (('flow',True,37,5),('flow',False,37,74)), + 'hspace': (('flow',True,37,14),('flow',False,128,13)), + 'not': (('logi+',True,0,24),('unavailable',False,0,0),('logi+',False,55,24)), + 'start': (('start',True,50,0),('flow',False,49,55)) +} + +protodict = {} +toolsprs = {} +base_path = None + +class BlockProto: + def __init__(self,name): + self.name = name + + +def setup_selectors(path): + global base_path + base_path = path + y = 25 + categories = [] + for s in selectors: + name,dy,blockdescriptions = s + cat = setup_selector(name,y, blockdescriptions) + y += dy*3/2 + categories.append(cat) + category_spr = Sprite(0, 0, categories[0].group) + category_spr.type = 'category' + category_spr.setlayer(660) + return category_spr, categories, categories[0] + +def setup_selector(name,y,blockdescriptions): + offshape = gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'palette',name+'off.gif')) + onshape = gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'palette',name+'on.gif')) + who = Sprite(140,y,offshape) + who.setlayer(800) + who.offshape = offshape + who.onshape = onshape + who.group = gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, name,name+'group.gif')) + maskname = os.path.join(base_path, name,name+'mask.gif') + if os.access(maskname, os.F_OK): + who.mask = gtk.gdk.pixbuf_new_from_file(maskname) + else: who.mask = None + who.type = 'selbutton' + protos = [] + for b in blockdescriptions: + bname,primname,docktype = b[0:3] + image = gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, name, bname+'.gif')) + proto = BlockProto(bname) + proto.image = image + proto.primname=primname + proto.defaults=b[3:] + if docktype in dockdetails: proto.docks=dockdetails[docktype] + else: proto.docks = docktype + protodict[bname] = proto + protos.append(proto) + who.blockprotos = protos + return who + +def setup_toolbar(): + x,y = 330,0 + for s in toolbaritems: + name,dx,dy= s + x += dx + setup_tool(x,y + dy,name) + return + +def setup_tool(x,y,name): + offshape = gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'toolbar',name+'off.gif')) + onshape = gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'toolbar',name+'on.gif')) + who = Sprite(x,y,offshape) + who.setlayer(800) + who.offshape = offshape + who.onshape = onshape + who.type = 'tool' + who.blocktype = name + toolsprs[name] = who + +def setup_project_flap(): + project_flap = { + 'closed': gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'toolbar','project-.gif')), + 'open': gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'toolbar','project.gif')), + 'mask': gtk.gdk.pixbuf_new_from_file(os.path.join(base_path, 'toolbar','projectmask.gif'))} +# who = Sprite(720,0,project_flap['closed']) + who = Sprite(888,0,project_flap['closed']) + who.type = 'project_flap' + who.setlayer(800) + return project_flap + +def blockproto(name): return protodict[name] + +def toolsprite(name): return toolsprs[name] + |