4 # This script can be used to generate resources (splash screen, logo app and about screen)
5 # to customize a SALOME application.
12 except ImportError, exc:
14 print "** Error in %s" % os.path.realpath(__file__)
15 print "This script requires the Image, ImageDraw and ImageFont libraries"
20 C_FONT_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'xirod.ttf')
23 C_SPLASH_COLOR = (100, 155, 100)
24 C_LOGO_COLOR = "rgb(0, 0, 0)"
28 # create the splash screen and the about logo.
29 def generate_splash(dest, appname, version):
30 uname = unicode(appname, 'UTF-8')
31 uversion = unicode(version, 'UTF-8')
33 font48 = ImageFont.truetype(C_FONT_PATH, 48)
34 font20 = ImageFont.truetype(C_FONT_PATH, 20)
36 # create the splash screen
37 im = Image.new("RGBA", (C_SPLASH_WIDTH, C_SPLASH_HEIGHT), C_SPLASH_COLOR)
38 draw = ImageDraw.Draw(im)
40 # add the name of the application
41 iw, ih = draw.textsize(uname, font=font48)
42 x = (C_SPLASH_WIDTH - iw) / 2.0 # horizontal center
43 y = (C_SPLASH_HEIGHT - ih) / 2.0 # vertical center
44 draw.text((x, y), uname, font=font48)
46 # add powered by SALOME
47 iw, ih = draw.textsize("Powered by SALOME", font=font20)
48 draw.text((C_BORDER, C_SPLASH_HEIGHT - C_BORDER - ih), "Powered by SALOME", font=font20)
50 # add the version if any
52 iw, ih = draw.textsize(uversion, font=font20)
53 draw.text((C_SPLASH_WIDTH - C_BORDER - iw, C_SPLASH_HEIGHT - C_BORDER - ih), uversion, font=font20)
56 im.save(os.path.join(dest, 'splash.png'), "PNG")
57 im.save(os.path.join(dest, 'about.png'), "PNG")
60 # create the application logo
61 def generate_logo(dest, appname):
62 uname = unicode(appname, 'UTF-8')
64 # evaluate size before deleting draw
65 im = Image.new("RGBA", (20, 20), (0, 0, 0, 0))
66 draw = ImageDraw.Draw(im)
67 font = ImageFont.truetype(C_FONT_PATH, 18)
68 iw, ih = draw.textsize(uname, font=font)
71 im = Image.new("RGBA", (iw + 5, 20), (0, 0, 0, 0))
72 draw = ImageDraw.Draw(im)
73 draw.text((0, 0), uname, font=font, fill=C_LOGO_COLOR)
75 im.save(os.path.join(dest, 'applogo.png'), "PNG")
78 if __name__ == "__main__":
81 print "usage: %s <dest> <name> [<version>]" % sys.argv[0]
87 if len(sys.argv) > 3: version = sys.argv[3]
89 generate_splash(dest, appname, version)
90 generate_logo(dest, appname)