diff options
author | Walter Bender <walter@sugarlabs.org> | 2010-03-02 08:23:29 (GMT) |
---|---|---|
committer | Walter Bender <walter@sugarlabs.org> | 2010-03-02 08:23:29 (GMT) |
commit | 11e88c07cfa97933ac17dddbabb7e8bce1fbb07a (patch) | |
tree | 4e54d7f203b5ae983f7b28780f2cfac8c83c77c4 | |
parent | 391fb28b9b6d01679c10c8f978baf560003b8014 (diff) |
moving color to canvas
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | icons/debugoff.svg | 12 | ||||
-rw-r--r-- | icons/debugon.svg | 12 | ||||
-rw-r--r-- | icons/eraseroff.svg | 10 | ||||
-rw-r--r-- | icons/eraseron.svg | 10 | ||||
-rw-r--r-- | icons/stopitoff.svg | 2 | ||||
-rw-r--r-- | sprites.py | 3 | ||||
-rw-r--r-- | tacanvas.py | 38 | ||||
-rw-r--r-- | talogo.py | 24 | ||||
-rw-r--r-- | tamyblock.py | 4 | ||||
-rw-r--r-- | tawindow.py | 9 |
11 files changed, 63 insertions, 62 deletions
@@ -18,6 +18,7 @@ o labels on coordinate-grid overlays o more complete support in non-Sugar environments o new (and improved) sample code + o Logo code for project added to View Source * completed a major refactoring of the code o 90% smaller download bundle-size diff --git a/icons/debugoff.svg b/icons/debugoff.svg index c5a3bc4..cf70e7e 100644 --- a/icons/debugoff.svg +++ b/icons/debugoff.svg @@ -113,27 +113,27 @@ id="path3258" style="fill:none;stroke:#ffffff;stroke-width:0.75545591;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> <path - d="M 26.988213,20.231746 25.8722,15.229742 22.062204,17.274526" + d="M 26.988213,20.231746 L 25.8722,15.229742 22.062204,17.274526" id="path3260" style="fill:none;stroke:#ffffff;stroke-width:1.51091182px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> <path - d="m 33.361036,23.684723 3.584614,-0.929858 2.882681,3.70167" + d="m 33.361036,23.684723 l 3.584614,-0.929858 2.882681,3.70167" id="path3262" style="fill:none;stroke:#ffffff;stroke-width:1.51091182px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> <path - d="m 23.851158,22.042526 -1.097622,-3.067217 -8.164934,2.756268" + d="m 23.851158,22.042526 l -1.097622,-3.067217 -8.164934,2.756268" id="path3264" style="fill:none;stroke:#ffffff;stroke-width:1.51091182px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> <path - d="m 33.777334,27.207476 3.47402,-0.42778 0.497902,7.4182" + d="m 33.777334,27.207476 l 3.47402,-0.42778 0.497902,7.4182" id="path3266" style="fill:none;stroke:#ffffff;stroke-width:1.51091182px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> <path - d="M 20.388485,25.668558 19.349188,23.00868 12.485021,29.515384" + d="M 20.388485,25.668558 L 19.349188,23.00868 12.485021,29.515384" id="path3268" style="fill:none;stroke:#ffffff;stroke-width:1.51091182px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> <path - d="m 32.410841,31.851473 2.920057,-0.91739 -2.027798,9.412169" + d="m 32.410841,31.851473 l 2.920057,-0.91739 -2.027798,9.412169" id="path3270" style="fill:none;stroke:#ffffff;stroke-width:1.51091182px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> </g> diff --git a/icons/debugon.svg b/icons/debugon.svg index 5cc7762..6232a99 100644 --- a/icons/debugon.svg +++ b/icons/debugon.svg @@ -118,27 +118,27 @@ id="path3258" style="fill:none;stroke:#000000;stroke-width:0.75545591;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> <path - d="M 26.988213,20.231746 25.8722,15.229742 22.062204,17.274526" + d="M 26.988213,20.231746 L 25.8722,15.229742 22.062204,17.274526" id="path3260" style="fill:none;stroke:#000000;stroke-width:1.51091182px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> <path - d="m 33.361036,23.684723 3.584614,-0.929858 2.882681,3.70167" + d="m 33.361036,23.684723 l 3.584614,-0.929858 2.882681,3.70167" id="path3262" style="fill:none;stroke:#000000;stroke-width:1.51091182px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> <path - d="m 23.851158,22.042526 -1.097622,-3.067217 -8.164934,2.756268" + d="m 23.851158,22.042526 l -1.097622,-3.067217 -8.164934,2.756268" id="path3264" style="fill:none;stroke:#000000;stroke-width:1.51091182px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> <path - d="m 33.777334,27.207476 3.47402,-0.42778 0.497902,7.4182" + d="m 33.777334,27.207476 l 3.47402,-0.42778 0.497902,7.4182" id="path3266" style="fill:none;stroke:#000000;stroke-width:1.51091182px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> <path - d="M 20.388485,25.668558 19.349188,23.00868 12.485021,29.515384" + d="M 20.388485,25.668558 L 19.349188,23.00868 12.485021,29.515384" id="path3268" style="fill:none;stroke:#000000;stroke-width:1.51091182px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> <path - d="m 32.410841,31.851473 2.920057,-0.91739 -2.027798,9.412169" + d="m 32.410841,31.851473 l 2.920057,-0.91739 -2.027798,9.412169" id="path3270" style="fill:none;stroke:#000000;stroke-width:1.51091182px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> </g> diff --git a/icons/eraseroff.svg b/icons/eraseroff.svg index 9f466ce..5ced823 100644 --- a/icons/eraseroff.svg +++ b/icons/eraseroff.svg @@ -11,23 +11,23 @@ <defs id="defs5" /> <path - d="m 36.61535,26.125 0,-8.375 12.5,-13.5 -1.5,10.5 -11,11.375 z" + d="m 36.61535,26.125 l 0,-8.375 12.5,-13.5 -1.5,10.5 -11,11.375 z" id="path2394" style="fill:#c44000;fill-opacity:1;stroke:#a00000;stroke-width:1.5;stroke-linecap:butt;stroke-linejoin:round;stroke-opacity:1;stroke-dasharray:none" /> <path - d="m 15.61535,17.75 13.5,-13.5 20,0 -12.5,13.5 -21,0 z" + d="m 15.61535,17.75 l 13.5,-13.5 20,0 -12.5,13.5 -21,0 z" id="path2390" style="fill:#c44000;fill-opacity:1;stroke:#a00000;stroke-width:1.5;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> <path - d="m 23.416068,38.75 2.692998,-10 10.506284,-11 0,8.375 -13.199282,12.625 z" + d="m 23.416068,38.75 l 2.692998,-10 10.506284,-11 0,8.375 -13.199282,12.625 z" id="path2392" style="fill:#c4a000;fill-opacity:1;stroke:#a00000;stroke-width:1.5;stroke-linejoin:round;stroke-opacity:1;stroke-dasharray:none" /> <path - d="m 4.5650808,28.75 11.0502692,-11 21,0 -10.86535,11 -21.1849192,0 z" + d="m 4.5650808,28.75 l 11.0502692,-11 21,0 -10.86535,11 -21.1849192,0 z" id="path2388" style="fill:#c4a000;fill-opacity:1;stroke:#a00000;stroke-width:1.5;stroke-linejoin:round;stroke-opacity:1;stroke-dasharray:none" /> <path - d="m 0.88464991,38.75 3.59066429,-10 21.1849188,0 -2.603231,10 -22.17235209,0 z" + d="m 0.88464991,38.75 l 3.59066429,-10 21.1849188,0 -2.603231,10 -22.17235209,0 z" id="path2384" style="fill:#e0d000;fill-opacity:1;stroke:#a00000;stroke-width:1.5;stroke-linejoin:round;stroke-opacity:1;stroke-dasharray:none" /> </svg> diff --git a/icons/eraseron.svg b/icons/eraseron.svg index ca884df..27a5ffd 100644 --- a/icons/eraseron.svg +++ b/icons/eraseron.svg @@ -15,23 +15,23 @@ id="g3589" style="fill:#404040;fill-opacity:1;stroke:#ffffff;stroke-width:2;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"> <path - d="M 36,25.875 36,17.5 48.5,4 47,14.5 36,25.875 z" + d="M 36,25.875 L 36,17.5 48.5,4 47,14.5 36,25.875 z" id="path2394" style="fill:#404040;fill-opacity:1;stroke:#ffffff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> <path - d="M 15,17.5 28.5,4 48.5,4 36,17.5 l -21,0 z" + d="M 15,17.5 L 28.5,4 48.5,4 36,17.5 l -21,0 z" id="path2390" style="fill:#404040;fill-opacity:1;stroke:#ffffff;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> <path - d="M 22.800718,38.5 25.493716,28.5 36,17.5 36,25.875 22.800718,38.5 z" + d="M 22.800718,38.5 L 25.493716,28.5 36,17.5 36,25.875 22.800718,38.5 z" id="path2392" style="fill:#404040;fill-opacity:1;stroke:#ffffff;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> <path - d="M 3.9497307,28.5 15,17.5 l 21,0 -10.86535,11 -21.1849193,0 z" + d="M 3.9497307,28.5 L 15,17.5 l 21,0 -10.86535,11 -21.1849193,0 z" id="path2388" style="fill:#404040;fill-opacity:1;stroke:#ffffff;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> <path - d="m 0.26929982,38.5 3.59066428,-10 21.1849189,0 -2.603231,10 -22.17235218,0 z" + d="m 0.26929982,38.5 l 3.59066428,-10 21.1849189,0 -2.603231,10 -22.17235218,0 z" id="path2384" style="fill:#404040;fill-opacity:1;stroke:#ffffff;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> </g> diff --git a/icons/stopitoff.svg b/icons/stopitoff.svg index 7379bee..de041ea 100644 --- a/icons/stopitoff.svg +++ b/icons/stopitoff.svg @@ -11,7 +11,7 @@ <defs id="defs5" /> <path - d="M 26.896078,11.635294 15.157342,23.955503 -1.8549019,24.366666 -14.175111,12.62793 -14.586274,-4.3843137 -2.8475378,-16.704523 14.164706,-17.115686 26.484915,-5.3769496 26.896078,11.635294 z" + d="M 26.896078,11.635294 L 15.157342,23.955503 -1.8549019,24.366666 -14.175111,12.62793 -14.586274,-4.3843137 -2.8475378,-16.704523 14.164706,-17.115686 26.484915,-5.3769496 26.896078,11.635294 z" transform="matrix(0.8982409,0.027775,-0.02744374,0.9090831,16.347508,18.533176)" id="path3158" style="fill:none;stroke:#ffffff;stroke-width:3.31833673;stroke-opacity:1" /> @@ -34,7 +34,7 @@ class Sprite manages individual sprites within the collection. Example usage: # Import the classes into your program. - from sprites import Sprites Sprite + from sprites import Sprites, Sprite # Create a new sprite collection for a gtk Drawing Area. my_drawing_area = gtk.DrawingArea() @@ -364,3 +364,4 @@ class Sprite: except IndexError: print "Index Error: %d %d" % (len(array), offset) return (-1,-1,-1,-1) + diff --git a/tacanvas.py b/tacanvas.py index 77e42ad..2ce5106 100644 --- a/tacanvas.py +++ b/tacanvas.py @@ -76,9 +76,15 @@ class TurtleGraphics: self.canvas.type = 'canvas' self.canvas.set_layer(CANVAS_LAYER) self.gc = self.canvas.images[0].new_gc() + self.cm = self.gc.get_colormap() + self.fgrgb = [255,0,0] + self.fgcolor = self.cm.alloc_color('red') + self.bgrgb = [255,248,222] + self.bgcolor = self.cm.alloc_color('#fff8de') + self.textsize = 48 + self.textcolor = self.cm.alloc_color('blue') self.tw.active_turtle.show() self.shade = 0 - self.bgcolor = self.tw.bgcolor self.svg = SVG() self.svg.set_fill_color('none') self.tw.svg_string = '' @@ -86,7 +92,7 @@ class TurtleGraphics: def clearscreen(self): rect = gtk.gdk.Rectangle(0, 0, self.width, self.height) - self.gc.set_foreground(self.tw.bgcolor) + self.gc.set_foreground(self.bgcolor) self.canvas.images[0].draw_rectangle(self.gc, True, *rect) self.invalt(0, 0, self.width, self.height) self.setpensize(5) @@ -110,7 +116,7 @@ class TurtleGraphics: def forward(self, n): n *= self.tw.coord_scale - self.gc.set_foreground(self.tw.fgcolor) + self.gc.set_foreground(self.fgcolor) oldx, oldy = self.xcor, self.ycor try: self.xcor += n*sin(self.heading*DEGTOR) @@ -144,7 +150,7 @@ class TurtleGraphics: self.turn_turtle() def arc(self, a, r): - self.gc.set_foreground(self.tw.fgcolor) + self.gc.set_foreground(self.fgcolor) r *= self.tw.coord_scale try: if a<0: @@ -265,10 +271,8 @@ class TurtleGraphics: oldc, olds = self.color,self.shade self.setcolor(c); self.setshade(s) rect = gtk.gdk.Rectangle(0,0,self.width,self.height) - self.gc.set_foreground(self.tw.fgcolor) - self.bgcolor = "#%02x%02x%02x" % (self.tw.rgb[0], - self.tw.rgb[1], - self.tw.rgb[2]) + self.gc.set_foreground(self.fgcolor) + self.bgrgb = self.fgrgb[:] self.canvas.images[0].draw_rectangle(self.gc, True, *rect) self.invalt(0,0,self.width,self.height) self.setcolor(oldc); self.setshade(olds) @@ -280,18 +284,18 @@ class TurtleGraphics: rgb = color_table[wrap100(self.color)] r,g,b = (rgb>>8)&0xff00,rgb&0xff00,(rgb<<8)&0xff00 r,g,b = calc_shade(r,sh),calc_shade(g,sh),calc_shade(b,sh) - self.tw.rgb = [r>>8,g>>8,b>>8] - self.tw.fgcolor = self.tw.cm.alloc_color(r,g,b) - self.svg.set_stroke_color("#%02x%02x%02x" % (self.tw.rgb[0], - self.tw.rgb[1], - self.tw.rgb[2])) + self.fgrgb = [r>>8,g>>8,b>>8] + self.fgcolor = self.cm.alloc_color(r,g,b) + self.svg.set_stroke_color("#%02x%02x%02x" % (self.fgrgb[0], + self.fgrgb[1], + self.fgrgb[2])) def set_textcolor(self): sh = (wrap100(self.shade)-50)/50.0 rgb = color_table[wrap100(self.tcolor)] r,g,b = (rgb>>8)&0xff00,rgb&0xff00,(rgb<<8)&0xff00 r,g,b = calc_shade(r,sh),calc_shade(g,sh),calc_shade(b,sh) - self.tw.textcolor = self.tw.cm.alloc_color(r,g,b) + self.tw.textcolor = self.cm.alloc_color(r,g,b) def setpen(self,bool): self.pendown = bool @@ -379,6 +383,6 @@ class TurtleGraphics: return self.svg.calc_w_h(False) self.tw.svg_string = "%s%s%s%s" % (self.svg.header(True), - self.svg.background(self.bgcolor), - self.tw.svg_string, - self.svg.footer()) + self.svg.background("#%02x%02x%02x" %\ + (self.bgrgb[0], self.bgrgb[1], self.bgrgb[2])), + self.tw.svg_string, self.svg.footer()) @@ -1016,7 +1016,7 @@ class LogoCode: for s in sarray: self.tw.canvas.setxy(x, y) self.show(s) - y -= int(self.tw.textsize*self.tw.lead) + y -= int(self.tw.canvas.textsize*self.tw.lead) def set_scale(self, x): self.scale = x @@ -1041,16 +1041,18 @@ class LogoCode: self.play_sound(string) else: if center: - y -= self.tw.textsize + y -= self.tw.canvas.textsize self.tw.canvas.draw_text(string, x, y, - int(self.tw.textsize*self.scale/100), + int(self.tw.canvas.textsize*\ + self.scale/100), self.tw.canvas.width-x) elif type(string) == float or type(string) == int: string = round_int(string) if center: - y -= self.tw.textsize + y -= self.tw.canvas.textsize self.tw.canvas.draw_text(string, x, y, - int(self.tw.textsize*self.scale/100), + int(self.tw.canvas.textsize*\ + self.scale/100), self.tw.canvas.width-x) # Image only (at current x,y) @@ -1172,7 +1174,7 @@ class LogoCode: y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) # save the text size so we can restore it later - save_text_size = self.tw.textsize + save_text_size = self.tw.canvas.textsize # set title text self.tw.canvas.settextsize(self.title_height) self.show(title) @@ -1201,7 +1203,7 @@ class LogoCode: y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) # save the text size so we can restore it later - save_text_size = self.tw.textsize + save_text_size = self.tw.canvas.textsize # set title text self.tw.canvas.settextsize(self.title_height) self.show(title) @@ -1236,7 +1238,7 @@ class LogoCode: y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) # save the text size so we can restore it later - save_text_size = self.tw.textsize + save_text_size = self.tw.canvas.textsize # set title text self.tw.canvas.settextsize(self.title_height) self.show(sarray[0]) @@ -1258,7 +1260,7 @@ class LogoCode: y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) # save the text size so we can restore it later - save_text_size = self.tw.textsize + save_text_size = self.tw.canvas.textsize # set title text self.tw.canvas.settextsize(self.title_height) self.show(title) @@ -1293,7 +1295,7 @@ class LogoCode: y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) # save the text size so we can restore it later - save_text_size = self.tw.textsize + save_text_size = self.tw.canvas.textsize # set title text self.tw.canvas.settextsize(self.title_height) self.show(title) @@ -1327,7 +1329,7 @@ class LogoCode: y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) # save the text size so we can restore it later - save_text_size = self.tw.textsize + save_text_size = self.tw.canvas.textsize # set title text self.tw.canvas.settextsize(self.title_height) self.show(title) diff --git a/tamyblock.py b/tamyblock.py index 6627066..a90995a 100644 --- a/tamyblock.py +++ b/tamyblock.py @@ -51,7 +51,7 @@ def myblock(lc, x): # while b > 255: # b -= 256 # rgb = "#%02x%02x%02x" % (r,g,b) - # lc.tw.fgcolor = lc.tw.cm.alloc_color(rgb) + # lc.tw.canvas.fgcolor = lc.tw.canvas.cm.alloc_color(rgb) # return ########################################################################### @@ -120,7 +120,7 @@ def myblock(lc, x): # b = int((val*(100-x) + lc.tw.rgb[2]*x)/100) # reallocate current color # rgb = "#%02x%02x%02x" % (r,g,b) - # lc.tw.fgcolor = lc.tw.cm.alloc_color(rgb) + # lc.tw.canvas.fgcolor = lc.tw.canvas.cm.alloc_color(rgb) # return ########################################################################### diff --git a/tawindow.py b/tawindow.py index b249f18..456f91d 100644 --- a/tawindow.py +++ b/tawindow.py @@ -124,13 +124,6 @@ class TurtleArtWindow(): self.scale = 1.0 self.block_scale = BLOCK_SCALE self.trash_scale = 0.5 - self.cm = self.gc.get_colormap() - self.rgb = [255,0,0] - self.bgcolor = self.cm.alloc_color('#fff8de') - self.msgcolor = self.cm.alloc_color('black') - self.fgcolor = self.cm.alloc_color('red') - self.textcolor = self.cm.alloc_color('blue') - self.textsize = 48 self.myblock = None self.nop = 'nop' self.loaded = 0 @@ -2637,7 +2630,7 @@ class TurtleArtWindow(): dsobject.metadata['title'] = name dsobject.metadata['icon-color'] = profile.get_color().to_string() if svg: - dsobject.metadata['mime_type'] = 'image/svg' + dsobject.metadata['mime_type'] = 'image/svg+xml' else: dsobject.metadata['mime_type'] = 'image/png' dsobject.set_file_path(file_path) |