1 # Copyright (C) 2009, David Aguilar <davvid@gmail.com>
2 """Provides the cola QApplication subclass"""
3 # style note: we use camelCase here since we're masquerading a Qt class
7 from PyQt4
import QtCore
8 from PyQt4
import QtGui
10 from cola
import utils
11 from cola
import resources
13 class ColaApplication(object):
14 """The main cola application
16 ColaApplication handles i18n of user-visible data
19 def __init__(self
, argv
, locale
=None, gui
=True):
20 """Initialize our QApplication for translation
22 # monkey-patch Qt's app translate() to handle .po files
24 self
._app
= QtGui
.QApplication(argv
)
25 self
._app
.setWindowIcon(QtGui
.QIcon(resources
.icon('git.svg')))
26 self
._translate
_base
= QtGui
.QApplication
.translate
27 QtGui
.QApplication
.translate
= self
.translate
29 self
._app
= QtCore
.QCoreApplication(argv
)
30 self
._translate
_base
= QtCore
.QCoreApplication
.translate
31 QtCore
.QCoreApplication
.translate
= self
.translate
33 # Find the current language settings and apply them
35 locale
= str(QtCore
.QLocale().system().name())
37 qmfile
= utils
.qm_for_locale(locale
)
38 if os
.path
.exists(qmfile
):
39 translator
= QtCore
.QTranslator(self
._app
)
40 translator
.load(qmfile
)
41 self
._app
.installTranslator(translator
)
43 def translate(self
, context
, *args
):
44 """Supports @@noun/@@verb and context-less translation
46 # We set the context to '' to properly handle .qm files
47 trtxt
= unicode(self
._translate
_base
('', *args
))
48 if trtxt
[-6:-4] == '@@': # handle @@verb / @@noun
52 def activeWindow(self
):
53 """Wrap activeWindow()"""
54 return self
._app
.activeWindow()
58 return self
._app
.exec_()
60 def setStyleSheet(self
, txt
):
61 """Wrap setStyleSheet(txt)"""
62 return self
._app
.setStyleSheet(txt
)