[gcompris/gcomprixogoo] Imported latest version of the gimp plugin from the master branch.
- From: Bruno Coudoin <bcoudoin src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gcompris/gcomprixogoo] Imported latest version of the gimp plugin from the master branch.
- Date: Sun, 7 Feb 2010 02:02:19 +0000 (UTC)
commit 63f505be0ad6660bd20db131a98c45e368f2582c
Author: Bruno Coudoin <bruno coudoin free fr>
Date: Sun Feb 7 03:00:59 2010 +0100
Imported latest version of the gimp plugin from the master branch.
tools/gcompris_shapegame.py | 106 ++++++++++++++++++++++++++++---------------
1 files changed, 69 insertions(+), 37 deletions(-)
---
diff --git a/tools/gcompris_shapegame.py b/tools/gcompris_shapegame.py
index d57d1d1..f49d9da 100644
--- a/tools/gcompris_shapegame.py
+++ b/tools/gcompris_shapegame.py
@@ -1,10 +1,10 @@
#!/usr/bin/python
#
-# Copyright (C) 2006, 2008 Miguel DE IZARRA
+# Copyright (C) 2006 Miguel DE IZARRA
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@@ -13,8 +13,7 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#######################################################################
#
@@ -22,31 +21,36 @@
#
# Require: gimp-python
#
-# To install, copy this script in ~/.gimp-2.2/plug-ins/ and set it executable
+# To install, copy this script in ~/.gimp-2.2/plug-ins/ (and make it is executable)
# cp gcompris_shapegame.py ~/.gimp-2.2/plug-ins/
# chmod +x ~/.gimp-2.2/plug-ins/gcompris_shapegame.py
#
#######################################################################
#
-# To use Puzzle :
+# To create a Puzzle:
# 1. Open an image in Gimp
-# 2. Menu Python-Fu -> Gcompris -> Puzzle
-# 3. Choice number of tile horizontaly, verticaly and type of puzzle
+# 2. Save the image
+# 3. Menu Python-Fu -> GCompris -> Puzzle
+# 4. Choice number of tile horizontaly, verticaly and type of puzzle
+# 5. The resulting data are saved under the location of the original image.
+# 6. Move the data under /usr/share/gcompris/boards/<paintings>
#
#######################################################################
#
-# To use Geography :
+# To create a Geography map:
# 1. Open a map in Gimp
# 2. Save the image in Gimp Format (.xcf) to preserve channels
# 3. For each region:
# a. Select individual region
# b. Save selection to channel
-# c. Rename channel with the name of the region
-# (You create a channel for each regions)
+# c. Rename channel in the name of region
+# (You can create a channel for Foreign regions)
# 4. Menu Python-Fu -> GCompris -> Geography
# a. Choice output directory and title (default based on image name)
# b. Set the border size between regions (depend on the original map)
# c. Choice if borders between region should be show
+# 5. The resulting data are saved under the location of the original image.
+# 6. Move the data under /usr/share/gcompris/boards/<geography>
#
# We can change color of a region by opening region file in gimp,
# and fill it by a new color.
@@ -59,7 +63,11 @@ from random import randint
def gcompris_init(img):
if len(img.layers) > 1:
- gimp.message("Error : There is too many layers")
+ gimp.message("Error : There too many layers")
+ return False
+
+ if not img.filename:
+ gimp.message("Error : save the image first (in Gimp .xcf format)")
return False
# resize the image
@@ -69,7 +77,9 @@ def gcompris_init(img):
pdb.gimp_image_scale(img, new_w, new_h)
return True
-def gcompris_puzzle(img, sdrawable, x, y, dossier, title, puzzle_type):
+def gcompris_puzzle(img, sdrawable, x, y, activity_name,
+ folder, title, puzzle_type,
+ level, sublevel):
""" Create file png and board.xml from current image """
def puzzle_layer(img, ptype, x, y):
@@ -95,6 +105,10 @@ def gcompris_puzzle(img, sdrawable, x, y, dossier, title, puzzle_type):
if not gcompris_init(img):
return
+ # Default values
+ if(not activity_name):
+ activity_name = "paintings"
+
# Init
bg_layer = img.active_layer
pdb.gimp_selection_none(img)
@@ -122,29 +136,39 @@ def gcompris_puzzle(img, sdrawable, x, y, dossier, title, puzzle_type):
d_title["<name>"] = title
shapebg = dict(name=1, pixmapfile="skin:gcompris-shapelabel.png",
type="SHAPE_BACKGROUND", x=405, y=495, position=0)
- gcompris_layer_to_board(layerlist, "paintings", dossier, d_title, shapebg, None)
+
+ gcompris_layer_to_board(layerlist, activity_name, folder, d_title, shapebg, None,
+ level, sublevel)
register(
"gcompris_puzzle",
- "Make Puzzle for gcompris ",
- "Make Puzzle for gcompris ",
+ "Make Puzzle for GCompris ",
+ "Make Puzzle for GCompris ",
"Miguel de Izarra",
"Miguel de Izarra",
"2006",
- "<Image>/Python-Fu/Gcompris/Puzzle",
+ "<Image>/Python-Fu/GCompris/Puzzle",
"RGB*, GRAY*",
[
(PF_SPINNER, "x", "Number of tiles across", 3, (2, 9, 1) ),
(PF_SPINNER, "y", "Number of tiles down", 3, (2, 9, 1) ),
- (PF_STRING, "dossier", "relative output directory (default = image name)", ""),
+ (PF_STRING, "activity_name", "Name of the activity (default = painting)", ""),
+ (PF_STRING, "folder", "Relative output directory (default = image name)", ""),
(PF_STRING, "title", "GCompris puzzle title", ""),
- (PF_SPINNER, "type", "Type of puzzle (0 Normal 1 Rectangle)", 0, (0, 1, 1) )
+ (PF_SPINNER, "type", "Type of puzzle (0 Normal 1 Rectangle)", 0, (0, 1, 1) ),
+ (PF_SPINNER, "level", "The level in the activity", 1, (1, 9, 1) ),
+ (PF_SPINNER, "sublevel", "The sub level in the activity", 1, (1, 20, 1) )
],
[],
gcompris_puzzle)
-def gcompris_geography(img, sdrawable, dossier, title, bordersize, keepLimit):
+def gcompris_geography(img, sdrawable, activity_name,
+ folder, title, bordersize, keepLimit, level, sublevel):
"""Create file for the geography activity from the current image """
+ # Default values
+ if(not activity_name):
+ activity_name = "geography"
+
if not gcompris_init(img):
return
if len(img.channels) == 0:
@@ -205,7 +229,7 @@ def gcompris_geography(img, sdrawable, dossier, title, bordersize, keepLimit):
gimp.set_foreground(58, 68, 219)
gimp.set_background(94, 146, 229)
pdb.gimp_edit_blend(layer_map, 0, 0, 0, 50, 0, 0, False, False, 0, 0,
- True, 0, 0, img.width, img.height)
+ True, 0, 0, img.width, img.height)
# Water 2
pdb.gimp_selection_load(earth)
@@ -214,7 +238,7 @@ def gcompris_geography(img, sdrawable, dossier, title, bordersize, keepLimit):
gimp.set_foreground(110, 123, 215)
gimp.set_background(137, 173, 225)
pdb.gimp_edit_blend(layer_map, 0, 0, 0, 25, 0, 0, False, False, 0, 0,
- True, 0, 0, img.width, img.height)
+ True, 0, 0, img.width, img.height)
# Remove tmp channel
img.remove_channel(earth)
@@ -225,13 +249,14 @@ def gcompris_geography(img, sdrawable, dossier, title, bordersize, keepLimit):
pdb.gimp_selection_none(img)
shape = dict()
- shape["sound"] = os.path.join("sounds", "$LOCALE", "geography", dossier, "%n.ogg")
+ shape["sound"] = os.path.join("sounds", "$LOCALE", "geography", folder, "%n.ogg")
shape["<tooltip>"] = "%n"
title_d = dict(x=600, y=495, justification="GTK_JUSTIFY_CENTER")
title_d["<name>"] = title
layer_map.name = "background"
- gcompris_layer_to_board(layerlist, "geography", dossier, title_d, layer_map, shape)
+ gcompris_layer_to_board(layerlist, activity_name, folder, title_d, layer_map, shape,
+ level, sublevel)
register(
"gcompris_geography",
@@ -240,26 +265,32 @@ register(
"Miguel de Izarra",
"Miguel de Izarra",
"2006",
- "<Image>/Python-Fu/Gcompris/Geography",
+ "<Image>/Python-Fu/GCompris/Geography",
"RGB*, GRAY*",
[
- (PF_STRING, "dossier", "relative output directory (default = image name)", ""),
+ (PF_STRING, "activity_name", "Name of the activity (default = geography)", ""),
+ (PF_STRING, "folder", "Relative output directory (default = image name)", ""),
(PF_STRING, "title", "GCompris puzzle title", ""),
- (PF_SPINNER, "bordersize", "the Size of border between country", 1, (1, 20, 1) ),
- (PF_TOGGLE, "keepLimit", "Keep limit between country", False)
+ (PF_SPINNER, "bordersize", "The Size of border between country", 1, (1, 20, 1) ),
+ (PF_TOGGLE, "keepLimit", "Keep limit between country", False),
+ (PF_SPINNER, "level", "The level in the activity", 1, (1, 100, 1) ),
+ (PF_SPINNER, "sublevel", "The sub level in the activity", 1, (1, 20, 1) ),
],
[],
gcompris_geography)
-def gcompris_layer_to_board(layerlist, activity, subdir, title, background, shape):
+def gcompris_layer_to_board(layerlist, activity, subdir, title, background, shape,
+ level, sublevel):
""" Create png file and board.xml for gcompris
layerlist : the list of layer to process
- activity : gcompris activity name
- subdir : sub directory in which png file and board.xml will be put
+ activity : gcompris activity name in which boardx_y.xml will be put
+ subdir : sub directory in which png files will be put
title : a dictionnary with name and value of properties of element <title>
background : a dictionnary with name and value of properties of the Shape Background
or a background Layer
shape : a dictonnary of extra properties of each shape. In values, "%n" replace the layer name / filename
+ level : The level in the activity
+ sublevel : The sub level in the activity
"""
def realbasename(f):
"""Return the basename without extension"""
@@ -291,16 +322,16 @@ def gcompris_layer_to_board(layerlist, activity, subdir, title, background, shap
filename = img.filename
if not subdir:
subdir = realbasename(img.filename)
- out_dir = os.path.join(os.path.dirname(filename), subdir)
+ out_dir = os.path.join(os.path.dirname(filename), activity, subdir)
if not os.path.isdir(out_dir):
if os.path.exists(out_dir):
os.remove(out_dir)
- os.mkdir(out_dir)
+ os.makedirs(out_dir)
- out_xml = os.path.join(out_dir, "board.xml")
+ out_xml = os.path.join(out_dir, "..", "board%d_%d.xml" % (level, sublevel))
xml = file(out_xml, "w")
xml.write("""<?xml version="1.0" encoding="UTF-8"?>
-<ShapeGame><!-- Created with GcomprisShapegame gimp script -->\n""")
+<ShapeGame><!-- Created with GComprisShapegame gimp script -->\n""")
if title:
xml.write(dict_to_str("title", title))
@@ -313,9 +344,10 @@ def gcompris_layer_to_board(layerlist, activity, subdir, title, background, shap
deltax, deltay = (800-width)/2, (520-height)/2
for tile_layer in layerlist:
- tile_filename = tile_layer.name+".png"
+ tile_filename = tile_layer.name.lower().replace(' ', '_')+".png"
tile_filename_long = os.path.join(out_dir, tile_filename)
- pdb.file_png_save(img, tile_layer, tile_filename_long, tile_filename_long, 0, 0, 0, 0, 0, 0, 0)
+ pdb.file_png_save(img, tile_layer, tile_filename_long, tile_filename,
+ 0, 0, 0, 0, 0, 0, 0)
if shape:
shape_dict = dict(shape)
for key, value in shape_dict.iteritems():
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]