~ubuntu-branches/ubuntu/karmic/eric/karmic

« back to all changes in this revision

Viewing changes to eric/Utilities/Startup.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2008-01-28 18:02:25 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080128180225-6nrox6yrworh2c4v
Tags: 4.0.4-1ubuntu1
* Add python-qt3 to build-depends becuase that's where Ubuntu puts 
  pyqtconfig
* Change maintainer to MOTU

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
import os
11
11
import sys
12
12
 
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
15
16
 
16
17
from KdeQt.KQApplication import KQApplication
17
18
 
19
20
import Utilities
20
21
from UI.Info import Version
21
22
 
22
 
from eric3config import getConfig
 
23
import UI.PixmapCache
 
24
 
 
25
from eric4config import getConfig
23
26
 
24
27
 
25
28
def makeAppInfo(argv, name, arg, description, options = []):
83
86
 
84
87
%(description)s
85
88
 
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
100
103
        the application, that all additional option don't belong to
101
104
        the application.
102
105
    """
103
 
    ddindex = 30000     # arbitrariely large number
 
106
    ddindex = 30000     # arbitrarily large number
104
107
    args = {
105
108
        "--version": version,
106
109
        "--help": usage,
126
129
    for dir in dirs:
127
130
        loaded = trans.load(tn, dir)
128
131
        if loaded:
129
 
            return (trans, 1)
 
132
            return (trans, True)
130
133
            
131
134
    print "Warning: translation file '" + tn + "'could not be loaded."
132
135
    print "Using default."
133
 
    return (None, 0)
134
 
 
135
 
 
136
 
def initializeMimeSourceFactory():
 
136
    return (None, False)
 
137
 
 
138
 
 
139
def initializeResourceSearchPath():
137
140
    """
138
141
    Function to initialize the default mime source factory.
139
142
    """
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)
147
 
 
 
149
        UI.PixmapCache.addSearchPath(defaultIconPath)
148
150
 
149
151
# the translator must not be deleted, therefore we save them here
150
152
loaded_translators = {}
151
153
 
152
 
def loadTranslators(qtDir, app, translationFiles = ()):
 
154
def loadTranslators(qtTransDir, app, translationFiles = ()):
153
155
    """
154
156
    Function to load all required translations.
155
157
    
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)
161
163
    """
162
 
    translations = ("qt", "eric3") + translationFiles
 
164
    translations = ("qt", "eric4") + translationFiles
163
165
    loc = Preferences.getUILanguage()
164
166
    if loc is None:
165
167
        return
166
168
 
167
169
    if loc == "System":
168
 
        loc = str(QTextCodec.locale())
 
170
        loc = str(QLocale.system().name())
169
171
    if loc != "C":
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)
173
175
 
174
176
        for tf in ["%s_%s" % (tr, loc) for tr in translations]:
175
177
            translator, ok = loadTranslatorForLocale(dirs, tf)
185
187
    """
186
188
    Function to start up an application that doesn't need a specialized start up.
187
189
    
188
 
    This function is used by all of eric3's helper programs.
 
190
    This function is used by all of eric4's helper programs.
189
191
    
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)
206
208
 
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()
 
210
    if qt4Dir:
 
211
        if Preferences.getQt("ExportQt4Dir"):
 
212
            os.environ["QT4DIR"] = str(qt4Dir)
 
213
    initializeResourceSearchPath()
 
214
    QApplication.setWindowIcon(UI.PixmapCache.getIcon("eric.png"))
212
215
    try:
213
216
        sys.setappdefaultencoding(str(Preferences.getSystem("StringEncoding")))
214
217
    except:
215
218
        pass
216
 
 
217
 
    loadTranslators(qtDir, app)
218
 
    
219
 
    QTextCodec.setCodecForCStrings(QTextCodec.codecForName(str(Preferences.getSystem("StringEncoding"))))
220
 
    
221
 
    w = mwFactory(argv, qtDir)
222
 
    app.setMainWidget(w)
 
219
    
 
220
    qt4TransDir = Preferences.getQt4TranslationsDir()
 
221
    if not qt4TransDir:
 
222
        qt4TransDir = QLibraryInfo.location(QLibraryInfo.TranslationsPath)
 
223
    loadTranslators(qt4TransDir, app)
 
224
    
 
225
    QTextCodec.setCodecForCStrings(\
 
226
        QTextCodec.codecForName(str(Preferences.getSystem("StringEncoding")))
 
227
    )
 
228
    
 
229
    w = mwFactory(argv, qt4Dir)
223
230
    app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
224
231
    w.show()
225
232
    
226
 
    return app.exec_loop()
 
233
    return app.exec_()