Salome HOME
add the template command
[tools/sat.git] / data / templates / Application / config / splash_generator / splash.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3
4 # This script can be used to generate resources (splash screen, logo app and about screen)
5 # to customize a SALOME application.
6
7 import os, sys
8 try:
9     import Image
10     import ImageDraw
11     import ImageFont
12 except ImportError, exc:
13     print
14     print "** Error in %s" % os.path.realpath(__file__)
15     print "This script requires the Image, ImageDraw and ImageFont libraries"
16     print exc
17     sys.exit(1)
18
19 # splash screen
20 C_FONT_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'xirod.ttf')
21 C_SPLASH_WIDTH = 600
22 C_SPLASH_HEIGHT = 300
23 C_SPLASH_COLOR = (100, 155, 100)
24 C_LOGO_COLOR = "rgb(0, 0, 0)"
25 C_BORDER = 10
26
27 ##
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')
32
33     font48 = ImageFont.truetype(C_FONT_PATH, 48)
34     font20 = ImageFont.truetype(C_FONT_PATH, 20)
35
36     # create the splash screen
37     im = Image.new("RGBA", (C_SPLASH_WIDTH, C_SPLASH_HEIGHT), C_SPLASH_COLOR)
38     draw = ImageDraw.Draw(im)
39     
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)
45
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)
49
50     # add the version if any
51     if len(version) > 0:
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)
54
55     del draw
56     im.save(os.path.join(dest, 'splash.png'), "PNG")
57     im.save(os.path.join(dest, 'about.png'), "PNG")
58
59 ##
60 # create the application logo
61 def generate_logo(dest, appname):
62     uname = unicode(appname, 'UTF-8')
63
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)
69     del draw
70
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)
74     del draw
75     im.save(os.path.join(dest, 'applogo.png'), "PNG")
76
77
78 if __name__ == "__main__":
79
80     if len(sys.argv) < 3:
81         print "usage: %s <dest> <name> [<version>]" % sys.argv[0]
82         sys.exit(1)
83
84     dest = sys.argv[1]
85     appname = sys.argv[2]
86     version = ""
87     if len(sys.argv) > 3: version = sys.argv[3]
88     
89     generate_splash(dest, appname, version)
90     generate_logo(dest, appname)