-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlaunch.py
109 lines (85 loc) · 3.16 KB
/
launch.py
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
################
# #
# George Dietz #
# CEBM@Brown #
# #
################
import os
import sys
import time
from PyQt4 import QtGui
from PyQt4.Qt import QPixmap, QSplashScreen, QThread
import python_to_R
import main_form
import ome_globals
def load_R_libraries(app, splash=None):
''' Loads the R libraries while updating the splash screen'''
python_to_R.get_R_libpaths() # print the lib paths
rloader = python_to_R.RlibLoader()
splash.showMessage("Loading metafor\n....")
app.processEvents()
rloader.load_metafor()
splash.showMessage("Loading openmetar\n........")
app.processEvents()
rloader.load_openmetar()
splash.showMessage("Loading openmee\n............")
app.processEvents()
rloader.load_openmeer()
splash.showMessage("Loading igraph\n............")
app.processEvents()
rloader.load_igraph()
splash.showMessage("Loading grid\n................")
app.processEvents()
rloader.load_grid()
splash.showMessage("Loading APE\n................")
app.processEvents()
rloader.load_ape()
splash.showMessage("Loading mice\n................")
app.processEvents()
rloader.load_mice()
def start(open_file_path=None, reset_settings=False):
###### Setup directories ######
app = QtGui.QApplication(sys.argv)
app.setApplicationName(ome_globals.PROGRAM_NAME)
app.setOrganizationName(ome_globals.ORGANIZATION_NAME)
# Make working directory for python and R and sets up r_tmp (where R does
# its calculations. Also clears r_tmp
## N.B. This MUST come after setting the app name and stuff in order for the
# paths and subsequent calls to get_base_path() to work correctly
python_to_R.setup_directories()
if reset_settings:
ome_globals.reset_settings()
splash_pixmap = QPixmap(":/splash/splash.png")
splash = QSplashScreen(splash_pixmap)
splash.show()
splash_starttime = time.time()
load_R_libraries(app, splash)
# Show splash screen for at least ome_globals.SPLASH_DISPLAY_TIME seconds
time_elapsed = time.time() - splash_starttime
print("It took %s seconds to load the R libraries" % str(time_elapsed))
if time_elapsed < ome_globals.SPLASH_DISPLAY_TIME: # seconds
print("Going to sleep for %f seconds" % float(ome_globals.SPLASH_DISPLAY_TIME-time_elapsed))
QThread.sleep(int(ome_globals.SPLASH_DISPLAY_TIME-time_elapsed))
print("woke up")
# create and show the main window
form = main_form.MainForm()
form.show()
#form.raise_()
if open_file_path:
form.open(open_file_path)
# Close the splash screen
splash.finish(form)
sys.exit(app.exec_())
def clear_r_tmp():
r_tmp_dir = os.path.join(ome_globals.get_base_path(), "r_tmp")
print("Clearing %s" % r_tmp_dir)
for file_p in os.listdir(r_tmp_dir):
file_path = os.path.join(r_tmp_dir, file_p)
try:
if os.path.isfile(file_path):
print("deleting %s" % file_path)
os.unlink(file_path) # same as remove
except Exception, e:
print e
if __name__ == "__main__":
start()