diff options
author | Walter Bender <walter@walter-laptop.(none)> | 2010-01-11 20:37:35 (GMT) |
---|---|---|
committer | Walter Bender <walter@walter-laptop.(none)> | 2010-01-11 20:37:35 (GMT) |
commit | db3d25f9db71f6332336b851098e50ee9bc2b2c3 (patch) | |
tree | 1a3d8528daf2a1b4a6f394e8f0639bdce5a2fafe /card.py | |
parent | e1590f9e97b69e61182ccdc543288795a80d3d2d (diff) |
fileless svg generation
Diffstat (limited to 'card.py')
-rw-r--r-- | card.py | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -32,14 +32,12 @@ from sprites import * # if shape == SELECTMASK then generate special card-selected overlay # class Card: - def __init__(self, sprites, path, cardtype, width, height, attributes): + def __init__(self, sprites, svg_string, attributes): if attributes[0] == SELECTMASK: - self.spr = Sprite(sprites, 0, 0, - self.load_image(path, "selected", width, height)) + self.spr = Sprite(sprites, 0, 0, svg_str_to_pixbuf(svg_string)) self.index = SELECTMASK elif attributes[0] == MATCHMASK: - self.spr = Sprite(sprites, 0, 0, - self.load_image(path, "match", width, height)) + self.spr = Sprite(sprites, 0, 0, svg_str_to_pixbuf(svg_string)) self.index = MATCHMASK else: self.shape = attributes[0] @@ -50,10 +48,7 @@ class Card: self.color*NUMBER*FILLS+\ self.num*FILLS+\ self.fill - self.spr = Sprite(sprites, 0, 0, - self.load_image(path, cardtype+"-"+\ - str(self.index), - width, height)) + self.spr = Sprite(sprites, 0, 0, svg_str_to_pixbuf(svg_string)) def show_card(self): self.spr.set_layer(2000) @@ -62,7 +57,12 @@ class Card: def hide_card(self): self.spr.hide() - def load_image(self, path, file, w, h): - return gtk.gdk.pixbuf_new_from_file_at_size( - os.path.join(path, file+".svg"), int(w), int(h)) - +# +# Load pixbuf from SVG string +# +def svg_str_to_pixbuf(svg_string): + pl = gtk.gdk.PixbufLoader('svg') + pl.write(svg_string) + pl.close() + pixbuf = pl.get_pixbuf() + return pixbuf |