OSDN Git Service

windows: locale and icon fix attempts
[mypaint-anime/master.git] / mypaint.py
1 # This file is part of MyPaint.
2 # Copyright (C) 2007-2009 by Martin Renold <martinxyz@gmx.ch>
3 #
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.
8
9 """
10 This script does all the platform dependent stuff. Its main task is
11 to figure out where the python modules are.
12 """
13 import sys, os
14
15 def get_paths():
16     join = os.path.join
17
18     lib_shared='share/mypaint/'
19     # note: some distros use lib64 instead, they have to edit this...
20     lib_compiled='lib/mypaint/'
21
22     scriptdir=os.path.dirname(sys.argv[0])
23
24     # this script is installed as $prefix/bin. We just need $prefix to continue.
25     #pwd=os.getcwd() # why????
26     #dir_install=os.path.normpath(join(pwd,scriptdir)) # why????
27     dir_install=scriptdir # same, except maybe if scriptdir is relative...
28
29     if os.path.basename(dir_install) == 'bin':
30         prefix=os.path.dirname(dir_install)
31         libpath=join(prefix, lib_shared)
32         libpath_compiled = join(prefix, lib_compiled)
33         sys.path.insert(0, libpath)
34         sys.path.insert(0, libpath_compiled)
35         localepath = join(prefix, 'share/locale')
36     else:
37         # we are not installed
38         prefix=None
39         libpath='.'
40         localepath = 'po'
41
42     try: # just for a nice error message
43         from lib import mypaintlib
44     except ImportError:
45         print
46         print "We are not correctly installed or compiled!"
47         print 'script: "%s"' % sys.argv[0]
48         if prefix:
49             print 'deduced prefix: "%s"' % prefix
50             print 'lib_shared: "%s"' % libpath
51             print 'lib_compiled: "%s"' % libpath_compiled
52         print
53         raise
54
55     datapath = libpath
56     if not os.path.isdir(join(datapath, 'brushes')):
57         print 'Default brush collection not found! It should have been here:'
58         print datapath
59         raise sys.exit(1)
60
61     homepath =  os.path.expanduser('~')
62     if homepath == '~':
63         confpath = join(prefix, 'UserData')
64     else:
65         confpath = join(homepath, '.mypaint/')
66
67     return datapath, confpath, localepath
68
69 def psyco_opt():
70     # This helps on slow PCs where the python overhead dominates.
71     # (30% higher framerate measured on 533MHz CPU; startup slowdown below 20%)
72     # Note: python -O -O does not help.
73     if os.name in ('nt', 'ce'):
74         # reported to be broken on Windows
75         return
76     try:
77         import psyco
78         psyco.full()
79         print 'Psyco being used'
80     except ImportError:
81         pass
82
83 if __name__ == '__main__':
84     psyco_opt()
85
86     datapath, confpath, localepath = get_paths()
87
88     # must be done before importing any translated python modules
89     # (to get global strings translated, especially brushsettings.py)
90     import gettext
91     if sys.platform == 'win32':
92         import locale
93         os.environ['LANG'] = locale.getdefaultlocale()[0]
94     gettext.bindtextdomain("mypaint", localepath)
95     gettext.textdomain("mypaint")
96
97     from gui import main
98     main.main(datapath, confpath)