1 # This file is part of MyPaint.
2 # Copyright (C) 2007-2009 by Martin Renold <martinxyz@gmx.ch>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
10 This script does all the platform dependent stuff. Its main task is
11 to figure out where the python modules are.
18 lib_shared='share/mypaint/'
19 # note: some distros use lib64 instead, they have to edit this...
20 lib_compiled='lib/mypaint/'
22 arg0 = sys.argv[0].decode(sys.getfilesystemencoding())
23 scriptdir=os.path.dirname(arg0)
25 # this script is installed as $prefix/bin. We just need $prefix to continue.
26 #pwd=os.getcwd() # why????
27 #dir_install=os.path.normpath(join(pwd,scriptdir)) # why????
28 dir_install=scriptdir # same, except maybe if scriptdir is relative...
30 if os.path.basename(dir_install) == 'bin':
31 prefix=os.path.dirname(dir_install)
32 assert isinstance(prefix, unicode)
33 libpath=join(prefix, lib_shared)
34 libpath_compiled = join(prefix, lib_compiled)
35 sys.path.insert(0, libpath)
36 sys.path.insert(0, libpath_compiled)
37 localepath = join(prefix, 'share/locale')
38 elif sys.platform == 'win32':
40 # this is py2exe point of view, all executables in root of installdir
41 # all path must be normalized to absolute path
42 libpath = os.path.abspath(os.path.dirname(os.path.realpath(arg0)))
43 sys.path.insert(0, libpath)
44 localepath = join(libpath,'share/locale')
46 # we are not installed
51 assert isinstance(libpath, unicode)
53 try: # just for a nice error message
54 from lib import mypaintlib
57 print "We are not correctly installed or compiled!"
58 print 'script: "%s"' % arg0
60 print 'deduced prefix: "%s"' % prefix
61 print 'lib_shared: "%s"' % libpath
62 print 'lib_compiled: "%s"' % libpath_compiled
67 if not os.path.isdir(join(datapath, 'brushes')):
68 print 'Default brush collection not found! It should have been here:'
72 homepath = os.path.expanduser(u'~')
74 confpath = join(prefix, 'UserData')
76 confpath = join(homepath, '.mypaint/')
78 assert isinstance(datapath, unicode)
79 assert isinstance(confpath, unicode)
80 return datapath, confpath, localepath
83 # This helps on slow PCs where the python overhead dominates.
84 # (30% higher framerate measured on 533MHz CPU; startup slowdown below 20%)
85 # Note: python -O -O does not help.
86 if os.name in ('nt', 'ce'):
87 # reported to be broken on Windows
91 if sys.platform == 'win32':
92 if psyco.hexversion >= 0x020000f0 :
94 print 'Psyco being used'
96 print "Need at least psyco 2.0 to run"
99 print 'Psyco being used'
103 if __name__ == '__main__':
106 datapath, confpath, localepath = get_paths()
108 # must be done before importing any translated python modules
109 # (to get global strings translated, especially brushsettings.py)
111 if sys.platform == 'win32':
113 os.environ['LANG'] = locale.getdefaultlocale()[0]
114 gettext.bindtextdomain("mypaint", localepath)
115 gettext.textdomain("mypaint")
118 main.main(datapath, confpath)