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
    elif sys.platform == 'win32':
37
        prefix=None
38
        # this is py2exe point of view, all executables in root of installdir
39
        # all path must be normalized to absolute path
40
        libpath = os.path.abspath(os.path.dirname(os.path.realpath(sys.argv[0])))
41
        sys.path.insert(0, libpath)
42
        localepath = join(libpath,'share/locale')
43
    else:
44
        # we are not installed
45
        prefix=None
46
        libpath='.'
47
        localepath = 'po'
48
49
    try: # just for a nice error message
50
        from lib import mypaintlib
51
    except ImportError:
52
        print
53
        print "We are not correctly installed or compiled!"
54
        print 'script: "%s"' % sys.argv[0]
55
        if prefix:
56
            print 'deduced prefix: "%s"' % prefix
57
            print 'lib_shared: "%s"' % libpath
58
            print 'lib_compiled: "%s"' % libpath_compiled
59
        print
60
        raise
61
62
    datapath = libpath
63
    if not os.path.isdir(join(datapath, 'brushes')):
64
        print 'Default brush collection not found! It should have been here:'
65
        print datapath
66
        raise sys.exit(1)
67
68
    homepath =  os.path.expanduser('~')
69
    if homepath == '~':
70
        confpath = join(prefix, 'UserData')
71
    else:
72
        confpath = join(homepath, '.mypaint/')
73
74
    return datapath, confpath, localepath
75
76
def psyco_opt():
77
    # This helps on slow PCs where the python overhead dominates.
78
    # (30% higher framerate measured on 533MHz CPU; startup slowdown below 20%)
79
    # Note: python -O -O does not help.
80
    if os.name in ('nt', 'ce'):
81
        # reported to be broken on Windows
82
        return
83
    try:
84
        import psyco
85
        if sys.platform == 'win32':
86
            if psyco.hexversion >= 0x020000f0 :
87
                psyco.full()
88
                print 'Psyco being used'
89
            else:
90
                print "Need at least psyco 2.0 to run"
91
        else:
92
            psyco.full()
93
            print 'Psyco being used'
94
    except ImportError:
95
        pass
96
97
if __name__ == '__main__':
98
    psyco_opt()
99
100
    datapath, confpath, localepath = get_paths()
101
102
    # must be done before importing any translated python modules
103
    # (to get global strings translated, especially brushsettings.py)
104
    import gettext
105
    if sys.platform == 'win32':
106
        import locale
107
        os.environ['LANG'] = locale.getdefaultlocale()[0]
108
    gettext.bindtextdomain("mypaint", localepath)
109
    gettext.textdomain("mypaint")
110
111
    from gui import main
112
    main.main(datapath, confpath)