4 # This script can be used to generate resources (splash screen, logo app and about screen)
5 # to customize a SALOME application.
11 __LANG__ = os.environ["LANG"] # original locale
13 __LANG__ = "en_US.utf8" #default
16 "This script requires the Image, ImageDraw and ImageFont libraries":
17 "Ce script a besoin de Image, ImageDraw et ImageFont python librairies",
18 "WARNING: automatic filter application name for resources:":
19 "ATTENTION: filtre automatique sur le nom de l'application pour les ressources:",
20 "generate": "génération de",
21 "in directory": "dans le répertoire",
22 "Generate resources for": "Génération des ressources pour",
26 """very easy very locale standalone translation"""
38 except ImportError, exc:
40 print "ERROR: " + os.path.realpath(__file__)
41 print _loc("This script requires the Image, ImageDraw and ImageFont libraries")
47 C_FONT_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'xirod.ttf')
50 C_SPLASH_COLOR = (100, 120, 160)
51 C_SPLASH_TEXT_COLOR = "rgb(255, 250, 250)"
52 C_SHADOW_COLOR = "rgb(0, 0, 0)"
53 C_LOGO_COLOR = "rgb(200, 200, 200)"
57 C_SHADOW_Y = C_SHADOW_X
60 # create the splash screen and the about logo.
61 def generate_splash(dest, appname, version, subtext=None):
63 subtext="Powered by SALOME"
64 uname = unicode(appname, 'UTF-8')
65 uversion = unicode(version, 'UTF-8')
67 fontbig = ImageFont.truetype(C_FONT_PATH, 44)
68 fontsmall = ImageFont.truetype(C_FONT_PATH, 16)
70 # create the splash screen
71 # 12 characters are maximum for for C_SPLASH_WIDTH
73 WIDTH = C_SPLASH_WIDTH
75 WIDTH=C_SPLASH_WIDTH*nbcar/12 #a little more
77 WIDTH = 1024 #but not too big
78 #im = Image.new("RGBA", (WIDTH, C_SPLASH_HEIGHT), C_SPLASH_COLOR)
79 d0 = os.path.dirname(os.path.realpath(__file__))
80 f0 = os.path.join(d0,"Salome6_splash_fond.png")
81 #print "cvw splash2.py",f0
83 im = im.resize((WIDTH, C_SPLASH_HEIGHT))
84 draw = ImageDraw.Draw(im)
86 # add the name of the application
87 iw, ih = draw.textsize(uname, font=fontbig)
88 x = (WIDTH - iw) / 2.0 # horizontal center
89 y = (C_SPLASH_HEIGHT - ih) / 2.0 # vertical center
90 draw.text((x+C_SHADOW_X, y+C_SHADOW_Y), uname, font=fontbig, fill=C_SHADOW_COLOR)
91 draw.text((x, y), uname, font=fontbig, fill=C_SPLASH_TEXT_COLOR)
93 # add powered by SALOME
94 iw, ih = draw.textsize(subtext, font=fontsmall)
95 draw.text((C_BORDER_X+C_SHADOW_X, C_SPLASH_HEIGHT+C_SHADOW_Y-C_BORDER_Y-ih),
96 subtext, font=fontsmall, fill=C_SHADOW_COLOR)
97 draw.text((C_BORDER_X, C_SPLASH_HEIGHT-C_BORDER_Y-ih),
98 subtext, font=fontsmall, fill=C_SPLASH_TEXT_COLOR)
100 # add the version if any
102 iw, ih = draw.textsize(uversion, font=fontsmall)
103 draw.text((WIDTH+C_SHADOW_X-C_BORDER_X-iw, C_SPLASH_HEIGHT+C_SHADOW_Y-C_BORDER_Y-ih),
104 uversion, font=fontsmall, fill=C_SHADOW_COLOR)
105 draw.text((WIDTH-C_BORDER_X-iw, C_SPLASH_HEIGHT-C_BORDER_Y-ih),
106 uversion, font=fontsmall, fill=C_SPLASH_TEXT_COLOR)
109 d1 = os.path.join(dest, 'icon_splash.png')
111 d2 = os.path.join(dest, 'icon_about.png')
113 print _loc("in directory"), os.getcwd()
114 print _loc("generate"), d1
115 print _loc("generate"), d2
118 # create the application logo
119 def generate_logo(dest, appname):
120 uname = unicode(appname, 'UTF-8')
122 # evaluate size before deleting draw
123 im = Image.new("RGBA", (20, 20), (0, 0, 0, 0))
124 draw = ImageDraw.Draw(im)
125 font = ImageFont.truetype(C_FONT_PATH, 18)
126 iw, ih = draw.textsize(uname, font=font)
129 im = Image.new("RGBA", (iw + 5, 20), (0, 0, 0, 0))
130 draw = ImageDraw.Draw(im)
131 draw.text((0+1, 0), uname, font=font, fill=C_SHADOW_COLOR)
132 draw.text((0, -1), uname, font=font, fill=C_LOGO_COLOR)
134 d1 = os.path.join(dest, 'icon_applogo.png')
136 print _loc("generate"), d1
138 def filter_appname(appname):
139 name = appname.upper() # xirod seems not have lower character
140 for i in ["_APPLICATION","_APPLI","_APP"]:
146 for i in ["APPLICATION_","APPLI_","APP_"]:
154 if __name__ == "__main__":
155 if len(sys.argv) < 3:
156 print "usage: %s <dest> <name> [<version>] [<subtext>]" % sys.argv[0]
160 appname = sys.argv[2]
163 if len(sys.argv) > 3: version = sys.argv[3]
164 if len(sys.argv) > 4: subtext = sys.argv[4]
167 print _loc("Generate resources for"), appname
168 name = filter_appname(appname)
170 print _loc("WARNING: automatic filter application name for resources:"),
171 print "'%s' -> '%s'" % (appname, name)
173 generate_splash(dest, name, version, subtext)
174 generate_logo(dest, name)