forked from open-cogsci/OpenSesame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opensesame
executable file
·116 lines (104 loc) · 4 KB
/
opensesame
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python
#-*- coding:utf-8 -*-
"""
This file is part of OpenSesame.
OpenSesame is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenSesame is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenSesame. If not, see <http://www.gnu.org/licenses/>.
"""
if __name__ == u'__main__':
# Make sure the multiprocessing part of OS plays well with py2exe/py2app
# Has no effect if program is run straight from cli interpreter
# First, load a minimum number of modules and show an empty app window.
# This gives the user the feeling of a snappy response.
import os, sys, platform
# Support for multiprocessing when packaged
# In OS X the multiprocessing module is horribly broken, but a fixed
# version has been released as the 'billiard' module
if platform.system() == 'Darwin':
from billiard import freeze_support, forking_enable
forking_enable(0)
else:
from multiprocessing import freeze_support
freeze_support()
# Change the working directory on Windows. Depending on whether the
# application has been frozen by py2exe or not we need to use a different
# method of deducing the name to the main script.
# See also http://www.py2exe.org/index.cgi/HowToDetermineIfRunningFromExe
if os.name == u'nt':
import imp
if (hasattr(sys, u'frozen') or hasattr(sys, u'importers') or \
imp.is_frozen(u'__main__')):
path = os.path.dirname(sys.executable)
else:
path = os.path.dirname(__file__)
if path != '':
os.chdir(path)
if path not in sys.path:
sys.path.append(path)
from libopensesame.misc import resource, filesystem_encoding, \
parse_environment_file
parse_environment_file()
# Change Qt API
import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
# Register PyQt4 plugin folder
from PyQt4.QtCore import QCoreApplication
if os.path.exists(u'PyQt4_plugins'):
QCoreApplication.addLibraryPath(u'PyQt4_plugins')
# Load debug package (this must be after the working directory change)
from libopensesame import debug
# Do the basic window initialization
from PyQt4.QtGui import QApplication
app = QApplication(sys.argv)
from libqtopensesame.qtopensesame import qtopensesame
opensesame = qtopensesame(app)
app.processEvents()
# Import the remaining modules
from PyQt4.QtCore import QObject, QLocale, QTranslator
from libopensesame.py3compat import *
import os.path
# Load the locale for UI translation. The locale can be specified on the
# command line using the --locale parameter
locale = str(QLocale().system().name())
for i in range(len(sys.argv)-1):
if sys.argv[i] == '--locale':
locale = sys.argv[i+1]
qm = resource(os.path.join(u'locale', locale) + u'.qm')
if qm is not None:
debug.msg(u'installing %s translator' % qm)
translator = QTranslator()
translator.load(qm)
app.installTranslator(translator)
else:
debug.msg(u'no translator found for %s' % locale)
# Now that the window is shown, load the remaining modules and resume the
# GUI initialization.
opensesame.resume_init()
# Open an experiment if it has been specified as a command line argument
# and suppress the new wizard in that case.
import os.path
if len(sys.argv) >= 2 and os.path.isfile(sys.argv[1]):
start_new_tab = False
path = sys.argv[1]
path = safe_decode(path, enc=filesystem_encoding(), errors=u'ignore')
opensesame.open_file(path=path)
else:
start_new_tab = True
if start_new_tab:
opensesame.ui.tabwidget.open_start_new(start=True, switch=False)
opensesame.restore_window_state()
opensesame.refresh()
opensesame.show()
# Added for OS X, otherwise Window will not appear
opensesame.raise_()
# Exit using the application exit status
sys.exit(app.exec_())