13
from qt import QTranslator, QMimeSourceFactory, \
14
QTextCodec, SIGNAL, SLOT
13
from PyQt4.QtCore import QTranslator, QTextCodec, QLocale, QDir, \
14
SIGNAL, SLOT, QLibraryInfo
15
from PyQt4.QtGui import QApplication
16
17
from KdeQt.KQApplication import KQApplication
20
21
from UI.Info import Version
22
from eric3config import getConfig
25
from eric4config import getConfig
25
28
def makeAppInfo(argv, name, arg, description, options = []):
86
Copyright (c) 2002-2007 Detlev Offenbach <detlev@die-offenbachs.de>
89
Copyright (c) 2002 - 2007 Detlev Offenbach <detlev@die-offenbachs.de>
87
90
This is free software; see LICENSE.GPL for copying conditions.
88
91
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
89
92
PARTICULAR PURPOSE.""" % appinfo
127
130
loaded = trans.load(tn, dir)
131
134
print "Warning: translation file '" + tn + "'could not be loaded."
132
135
print "Using default."
136
def initializeMimeSourceFactory():
139
def initializeResourceSearchPath():
138
141
Function to initialize the default mime source factory.
140
defaultFactory = QMimeSourceFactory.defaultFactory()
141
143
defaultIconPath = os.path.join(getConfig('ericIconDir'), "default")
142
144
iconPaths = Preferences.getIcons("Path")
143
145
for iconPath in iconPaths:
144
defaultFactory.addFilePath(iconPath)
146
if not iconPath.isEmpty():
147
UI.PixmapCache.addSearchPath(iconPath)
145
148
if not defaultIconPath in iconPaths:
146
defaultFactory.addFilePath(defaultIconPath)
149
UI.PixmapCache.addSearchPath(defaultIconPath)
149
151
# the translator must not be deleted, therefore we save them here
150
152
loaded_translators = {}
152
def loadTranslators(qtDir, app, translationFiles = ()):
154
def loadTranslators(qtTransDir, app, translationFiles = ()):
154
156
Function to load all required translations.
156
@param qtDir directory of the Qt installation (string)
158
@param qtTransDir directory of the Qt translations files (string)
157
159
@param app reference to the application object (QApplication)
158
160
@param translationFiles tuple of additional translations to
159
161
be loaded (tuple of strings)
160
162
@return the requested locale (string)
162
translations = ("qt", "eric3") + translationFiles
164
translations = ("qt", "eric4") + translationFiles
163
165
loc = Preferences.getUILanguage()
167
169
if loc == "System":
168
loc = str(QTextCodec.locale())
170
loc = str(QLocale.system().name())
170
172
dirs = [getConfig('ericTranslationsDir'), Utilities.getConfigDir()]
171
if qtDir is not None:
172
dirs.append(os.path.join(qtDir, "translations"))
173
if qtTransDir is not None:
174
dirs.append(qtTransDir)
174
176
for tf in ["%s_%s" % (tr, loc) for tr in translations]:
175
177
translator, ok = loadTranslatorForLocale(dirs, tf)
186
188
Function to start up an application that doesn't need a specialized start up.
188
This function is used by all of eric3's helper programs.
190
This function is used by all of eric4's helper programs.
190
192
@param argv list of commandline parameters (list of strings)
191
193
@param appinfo dictionary describing the application
204
206
ddindex = handleArgs(argv, appinfo)
205
207
app = KQApplication(argv, kqOptions)
207
qtDir = Preferences.getQtDir()
208
if qtDir is not None:
209
if Preferences.getQt("ExportQtDir"):
210
os.environ["QTDIR"] = qtDir
211
initializeMimeSourceFactory()
209
qt4Dir = Preferences.getQt4Dir()
211
if Preferences.getQt("ExportQt4Dir"):
212
os.environ["QT4DIR"] = str(qt4Dir)
213
initializeResourceSearchPath()
214
QApplication.setWindowIcon(UI.PixmapCache.getIcon("eric.png"))
213
216
sys.setappdefaultencoding(str(Preferences.getSystem("StringEncoding")))
217
loadTranslators(qtDir, app)
219
QTextCodec.setCodecForCStrings(QTextCodec.codecForName(str(Preferences.getSystem("StringEncoding"))))
221
w = mwFactory(argv, qtDir)
220
qt4TransDir = Preferences.getQt4TranslationsDir()
222
qt4TransDir = QLibraryInfo.location(QLibraryInfo.TranslationsPath)
223
loadTranslators(qt4TransDir, app)
225
QTextCodec.setCodecForCStrings(\
226
QTextCodec.codecForName(str(Preferences.getSystem("StringEncoding")))
229
w = mwFactory(argv, qt4Dir)
223
230
app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
226
return app.exec_loop()