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 from lib import helpers
73 homepath = helpers.expanduser_unicode(u'~')
75 confpath = join(prefix, 'UserData')
77 confpath = join(homepath, '.mypaint/')
78 #Workaround before glib.get_user_config_dir() fixed in upstream
79 if sys.platform == 'win32':
82 HKCU = _winreg.ConnectRegistry(None, _winreg.HKEY_CURRENT_USER)
83 ShellKey = _winreg.OpenKey(HKCU, r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
84 localappdatapath = _winreg.QueryValueEx(ShellKey, "Local AppData")[0]
85 confpath = join(localappdatapath, 'mypaint/')
87 print "Can't retrive Local Application Data Path from registry"
89 assert isinstance(datapath, unicode)
90 assert isinstance(confpath, unicode)
91 return datapath, confpath, localepath
94 # This helps on slow PCs where the python overhead dominates.
95 # (30% higher framerate measured on 533MHz CPU; startup slowdown below 20%)
96 # Note: python -O -O does not help.
97 if os.name in ('nt', 'ce'):
98 # reported to be broken on Windows
102 if sys.platform == 'win32':
103 if psyco.hexversion >= 0x020000f0 :
105 print 'Psyco being used'
107 print "Need at least psyco 2.0 to run"
110 print 'Psyco being used'
114 if __name__ == '__main__':
117 datapath, confpath, localepath = get_paths()
119 # must be done before importing any translated python modules
120 # (to get global strings translated, especially brushsettings.py)
122 if sys.platform == 'win32':
124 os.environ['LANG'] = locale.getdefaultlocale()[0]
125 gettext.bindtextdomain("mypaint", localepath)
126 gettext.textdomain("mypaint")
129 main.main(datapath, confpath)