2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 # Options of this script
27 def profileQuickStartParser() :
29 parser = optparse.OptionParser( usage = "usage: python app-quickstart.py [options]" )
31 parser.add_option('-p',
33 metavar="</Path/to/the/sources/of/application>",
38 help="Where the application's sources will be generated. [Default : '.']")
40 parser.add_option('-m',
42 metavar="<module1,module2,...>",
47 help="List of the application's modules. [Default : KERNEL,GUI]")
49 parser.add_option('-n',
54 help="Name of the application")
56 parser.add_option('-v',
62 help="Version of the application. [Default : 1.0]")
64 parser.add_option('-s',
70 help="Slogan of the application.")
72 parser.add_option('-f',
76 help="Overwrites existing sources")
82 #Create the splash screen
83 def profileGenerateSplash( resources_dir, appname, version, subtext ):
88 uname = unicode(appname, 'UTF-8')
89 uversion = unicode(version, 'UTF-8')
92 fontbig = ImageFont.truetype( os.path.join( resources_dir, 'Anita semi square.ttf' ), 64)
93 fontsmall = ImageFont.truetype( os.path.join( resources_dir, 'Anita semi square.ttf' ), 20)
94 textColor = "rgb(255, 250, 250)"
95 shadowColor = "rgb(0, 0, 0)"
101 width = min( width*nbcar/12, 1024) #a little more
108 # load background image
109 f0 = os.path.join( resources_dir, "background.png" )
111 im = im.resize( ( width, height ) )
112 draw = ImageDraw.Draw(im)
114 # add the name of the application
115 iw, ih = draw.textsize(uname, font=fontbig)
116 x = (width - iw) / 2.0 # horizontal center
117 y = (height - ih) / 2.0 # vertical center
118 draw.text((x+shadowX, y+shadowY), uname, font=fontbig, fill=shadowColor)
119 draw.text((x, y), uname, font=fontbig, fill=textColor)
123 iw, ih = draw.textsize(subtext, font=fontsmall)
124 draw.text((borderX+shadowX, height+shadowY-borderY-ih),
125 subtext, font=fontsmall, fill=shadowColor)
126 draw.text((borderX, height-borderY-ih),
127 subtext, font=fontsmall, fill=textColor)
129 # add the version if any
131 iw, ih = draw.textsize(uversion, font=fontsmall)
132 draw.text((width+shadowX-borderX-iw, height+shadowY-borderY-ih),
133 uversion, font=fontsmall, fill=shadowColor)
134 draw.text((width-borderX-iw, height-borderY-ih),
135 uversion, font=fontsmall, fill=textColor)
141 #Create the application logo
142 def profileGenerateLogo( appname, font ):
146 uname = unicode(appname, 'UTF-8')
148 # evaluate size before deleting draw
149 im = Image.new( "RGBA", (1, 1), (0, 0, 0, 0) )
150 draw = ImageDraw.Draw( im )
152 im = Image.new( "RGBA", draw.textsize( uname, font=font ), (0, 0, 0, 0) )
153 draw = ImageDraw.Draw(im)
154 draw.text( (0+1, 0), uname, font=font, fill="rgb(0, 0, 0)" )
155 draw.text( (0, -1), uname, font=font, fill="rgb(191, 191, 191)" )
161 #Replace strings in the template
162 def profileReplaceStrings( src, dst, options ) :
163 with open( dst, "wt" ) as fout:
164 with open( src, "rt" ) as fin:
166 l = line.replace( '[LIST_OF_MODULES]', options.modules )
167 l = l.replace( '[VERSION]', options.version )
168 l = l.replace( '[SLOGAN]', options.slogan )
169 l = l.replace( '[NAME_OF_APPLICATION]', options.name.upper() )
170 l = l.replace( '<Name_of_Application>', options.name )
171 l = l.replace( '(name_of_application)', options.name.lower() )
175 #Generation of a template profile sources
176 def profileGenerateSources( options, args ) :
178 #Set name of several directories
179 app_dir = options.prefix
180 app_resources_dir = os.path.join( app_dir, "resources" )
181 kernel_root_dir = os.environ["KERNEL_ROOT_DIR"]
182 bin_salome_dir = os.path.join( kernel_root_dir, "bin", "salome" )
183 kernel_resources_dir = os.path.join( kernel_root_dir, "share", "salome", "resources", "kernel" )
184 template_dir = os.path.join( kernel_resources_dir, "app-template" )
186 #Check if the directory of the sources already exists and delete it
187 if os.path.exists( app_dir ) :
188 if not options.force :
189 print "Directory %s already exists." %app_dir
190 print "Use option --force to overwrite it."
193 shutil.rmtree( app_dir )
195 #Copy template directory
197 for root, dirs, files in os.walk( template_dir ) :
198 dst_dir = root.replace( template_dir, app_dir )
200 os.mkdir( os.path.join( dst_dir, d ) )
202 profileReplaceStrings( os.path.join( root, f ), os.path.join( dst_dir, f ), options )
204 #Complete source directory
205 contextFiles = [ "salomeContext.py", "salomeContextUtils.py", "parseConfigFile.py" ]
206 for f in contextFiles :
207 shutil.copy( os.path.join( bin_salome_dir, f ), os.path.join( app_dir, "src" ) )
209 #Search for python modules Image, ImageDraw and ImageFont
212 imp.find_module('Image')
213 imp.find_module('ImageDraw')
214 imp.find_module('ImageFont')
219 #Generate logo and splash
220 logo_destination = os.path.join( app_resources_dir, 'app_logo.png')
221 splash_destination = os.path.join( app_resources_dir, 'splash.png')
222 about_destination = os.path.join( app_resources_dir, 'about.png')
225 font = ImageFont.truetype( os.path.join( kernel_resources_dir, "Anita semi square.ttf" ) , 18 )
227 #Generate and save logo
228 app_logo = profileGenerateLogo( options.name, font )
229 app_logo.save( logo_destination, "PNG" )
231 #Generate and splash screen and about image
233 subtext = options.slogan
235 subtext = "Powered by SALOME"
236 im = profileGenerateSplash( kernel_resources_dir, options.name, options.version, subtext )
237 im.save( splash_destination, "PNG" )
238 im.save( about_destination, "PNG" )
240 gui_resources_dir = os.path.join( os.environ["GUI_ROOT_DIR"], "share", "salome", "resources", "gui" )
241 logo_name = os.path.join( gui_resources_dir, "icon_applogo.png" )
242 if os.path.exists( logo_name ) :
243 shutil.copy( logo_name, logo_destination )
244 about_name = os.path.join( gui_resources_dir, "icon_about.png" )
245 if os.path.exists( about_name ) :
246 shutil.copy( about_name, about_destination )
247 shutil.copy( about_name, splash_destination )
250 print "Sources of %s were generated in %s." %( options.name, app_dir )
253 # -----------------------------------------------------------------------------
255 if __name__ == '__main__':
256 #Get options and args
257 (options, args) = profileQuickStartParser().parse_args()
259 #Check name of the application
260 if not options.name :
261 raise RuntimeError( "A name must be given to the application. Please use option --name." )
263 #Check if the prefix's parent is a directory
264 if not os.path.isdir( os.path.dirname( options.prefix ) ) :
265 raise RuntimeError( "%s is not a directory." % os.path.dirname( options.prefix ) )
267 #Generate sources of the profile
268 profileGenerateSources( options, args )