forked from jjgomera/pychemqt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pychemqt.py
executable file
·150 lines (123 loc) · 5.6 KB
/
pychemqt.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
import urllib2
import shutil
if sys.version_info[0] == 2:
from ConfigParser import ConfigParser
else:
from configparser import ConfigParser
from PyQt4 import QtCore, QtGui
path = os.path.dirname(os.path.realpath(sys.argv[0]))
sys.path.append(path)
conf_dir = os.path.expanduser('~') + os.sep+".pychemqt"+os.sep
os.environ["pychemqt"] = path + os.path.sep
app = QtGui.QApplication(sys.argv)
app.setOrganizationName("pychemqt")
app.setOrganizationDomain("pychemqt")
app.setApplicationName("pychemqt")
# Translation
locale = QtCore.QLocale.system().name()
myTranslator = QtCore.QTranslator()
if myTranslator.load("pychemqt_" + locale, os.environ["pychemqt"] + "i18n"):
app.installTranslator(myTranslator)
qtTranslator = QtCore.QTranslator()
if qtTranslator.load("qt_" + locale,
QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)):
app.installTranslator(qtTranslator)
# Check external modules
from tools.dependences import optional_modules
for module, use in optional_modules:
try:
__import__(module)
os.environ[module] = "True"
except ImportError:
print(QtGui.QApplication.translate("pychemqt", "%s don't found, %s"
% (module, use)).toUtf8())
os.environ[module] = ""
class SplashScreen(QtGui.QSplashScreen):
"""Clase que crea una ventana de splash"""
def __init__(self):
QtGui.QSplashScreen.__init__(self,
QtGui.QPixmap(os.environ["pychemqt"] + "/images/splash.jpg"))
self.show()
QtGui.QApplication.flush()
def showMessage(self, msg):
"""Método para mostrar mensajes en la parte inferior de la ventana de
splash"""
labelAlignment = QtCore.Qt.Alignment(QtCore.Qt.AlignBottom |
QtCore.Qt.AlignRight |
QtCore.Qt.AlignAbsolute)
QtGui.QSplashScreen.showMessage(self, msg, labelAlignment,
QtGui.QColor(QtCore.Qt.white))
QtGui.QApplication.processEvents()
def clearMessage(self):
QtGui.QSplashScreen.clearMessage(self)
QtGui.QApplication.processEvents()
splash = SplashScreen()
# Check config files
splash.showMessage(QtGui.QApplication.translate("pychemqt",
"Checking config files..."))
from lib import firstrun
if not os.path.isdir(conf_dir):
os.mkdir(conf_dir)
if not os.path.isfile(conf_dir + "pychemqtrc"):
Preferences = firstrun.Preferences()
Preferences.write(open(conf_dir + "pychemqtrc", "w"))
# FIXME: Hasta que no sepa como prescindir de este archivo sera necesario
if not os.path.isfile(conf_dir + "pychemqtrc_temporal"):
Config = firstrun.config()
Config.write(open(conf_dir + "pychemqtrc_temporal", "w"))
splash.showMessage(QtGui.QApplication.translate("pychemqt",
"Checking cost index..."))
if not os.path.isfile(conf_dir + "CostIndex.dat"):
with open(os.environ["pychemqt"] + "dat/costindex.dat") as cost_index:
lista = cost_index.readlines()[-1][:-1].split(" ")
with open(conf_dir + "CostIndex.dat", "w") as archivo:
for data in lista:
archivo.write(data + os.linesep)
splash.showMessage(QtGui.QApplication.translate("pychemqt",
"Checking currency data"))
if not os.path.isfile(conf_dir+"moneda.dat"):
from lib.firstrun import getrates
try:
getrates(conf_dir+"moneda.dat")
except urllib2.URLError:
origen = os.environ["pychemqt"]+"dat"+os.sep+"moneda.dat"
shutil.copy(origen, conf_dir+"moneda.dat")
print(QtGui.QApplication.translate("pychemqt",
"Internet connection error, using archived currency rates"))
splash.showMessage(QtGui.QApplication.translate("pychemqt",
"Checking custom database..."))
from lib.sql import createDatabase
# Import internal libraries
splash.showMessage(QtGui.QApplication.translate("pychemqt",
"Importing libraries..."))
from UI import texteditor, newComponent, flujo, charts, plots, viewComponents
from UI.widgets import createAction, ClickableLabel, TreeEquipment
from lib.config import conf_dir, getComponents
from lib.project import Project
from lib.EoS import K, H
from lib import unidades
splash.showMessage(QtGui.QApplication.translate("pychemqt",
"Importing equipments..."))
from equipment import *
splash.showMessage(QtGui.QApplication.translate("pychemqt", "Importing tools..."))
from tools import UI_confComponents, UI_confTransport, UI_confThermo, UI_confUnits, UI_confResolution, UI_databank, UI_unitConverter, UI_steamTables, UI_psychrometry
from UI.conversor_unidades import moneda
splash.showMessage(QtGui.QApplication.translate("pychemqt", "Loading main window..."))
from UI.mainWindow import UI_pychemqt
pychemqt = UI_pychemqt()
splash.showMessage(QtGui.QApplication.translate("pychemqt", "Loading project files..."))
if pychemqt.Preferences.getboolean("General", 'Load_Last_Project'):
filename = pychemqt.settings.value("LastFile").toStringList()
for file in sys.argv[1:]:
filename.append(file)
for fname in filename:
if fname and QtCore.QFile.exists(fname):
splash.showMessage(QtGui.QApplication.translate("pychemqt", "Loading project files...")+"\n"+fname)
pychemqt.fileOpen(fname)
splash.finish(pychemqt)
pychemqt.show()
sys.exit(app.exec_())