diff options
author | Ignacio RodrÃguez <ignacio@sugarlabs.org> | 2014-01-04 15:18:53 (GMT) |
---|---|---|
committer | Ignacio RodrÃguez <ignacio@sugarlabs.org> | 2014-01-04 15:18:53 (GMT) |
commit | b048c6a8f46f14efd80b7af2685d87668407f762 (patch) | |
tree | 715b0c9a4a78ad76ea980c0561c7a11d40ed0927 | |
parent | 37484f777f97d3d87314a8434a3a33c44dccaa65 (diff) |
use art4apps for images.
-rw-r--r-- | game.py | 47 |
1 files changed, 39 insertions, 8 deletions
@@ -20,14 +20,17 @@ from random import uniform from gettext import gettext as _ +_HAVE_ARTS4APPS = True +try: + from art4apps import Art4Apps +except ImportError: + _HAVE_ARTS4APPS = False + import logging _logger = logging.getLogger('search-activity') -try: - from sugar3.graphics import style - GRID_CELL_SIZE = style.GRID_CELL_SIZE -except ImportError: - GRID_CELL_SIZE = 0 +from sugar3.graphics import style +GRID_CELL_SIZE = style.GRID_CELL_SIZE from sprites import Sprites, Sprite @@ -63,7 +66,16 @@ class Game(): self._timeout_id = None # Find the image files - self._PATHS = glob.glob(os.path.join(self._path, 'images', '*.svg')) + if not _HAVE_ARTS4APPS: + self._PATHS = glob.glob(os.path.join(self._path, 'images', '*.svg')) + else: + art = Art4Apps() + images = art.get_words() + self._PATHS = [] + for image in images: + filepath = art.get_image_filename(image) + if os.path.exists(filepath): + self._PATHS.append(filepath) # Generate the sprites we'll need... self._sprites = Sprites(self._canvas) @@ -73,6 +85,10 @@ class Game(): for x in range(3): xoffset = int((self._width - 3 * self._dot_size - \ 2 * self._space) / 2.) + + if _HAVE_ARTS4APPS: + self._colors[0] = "#F05D5D" + self._dots.append( Sprite(self._sprites, xoffset + x * (self._dot_size + self._space), @@ -151,6 +167,16 @@ class Game(): return [dot % 3, int(dot / 3)] def __draw_cb(self, canvas, cr): + if _HAVE_ARTS4APPS: + square = Gdk.Rectangle() + square.x = 0 + square.y = 0 + square.width = Gdk.Screen.width() + square.height = Gdk.Screen.height() + Gdk.cairo_set_source_color(cr, Gdk.color_parse('white')) + Gdk.cairo_rectangle(cr, square) + cr.fill() + self._sprites.redraw_sprites(cr=cr) def __expose_cb(self, win, event): @@ -204,8 +230,13 @@ class Game(): for line in fd: svg_string += line.replace('#000000', color) fd.close() - pixbuf = svg_str_to_pixbuf(svg_string, w=self._dot_size, - h = self._dot_size) + if _HAVE_ARTS4APPS: + filepath = self._PATHS[image] + pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(filepath, + self._dot_size, self._dot_size) + else: + pixbuf = svg_str_to_pixbuf(svg_string, w=self._dot_size, + h = self._dot_size) else: if color in self._dot_cache: return self._dot_cache[color] |