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
18 _app
= QtGui
.QApplication(argv
)
22 class ColaApplication(object):
23 """The main cola application
25 ColaApplication handles i18n of user-visible data
28 def __init__(self
, argv
, locale
=None, gui
=True):
29 """Initialize our QApplication for translation
32 os
.environ
['LANG'] = locale
35 # monkey-patch Qt's translate() to use our translate()
37 self
._app
= instance(argv
)
38 self
._app
.setWindowIcon(QtGui
.QIcon(resources
.icon('git.svg')))
39 self
._translate
_base
= QtGui
.QApplication
.translate
40 QtGui
.QApplication
.translate
= self
.translate
42 self
._app
= QtCore
.QCoreApplication(argv
)
43 self
._translate
_base
= QtCore
.QCoreApplication
.translate
44 QtCore
.QCoreApplication
.translate
= self
.translate
46 def translate(self
, context
, txt
):
48 Translate strings with gettext
50 Supports @@noun/@@verb specifiers.
53 trtxt
= i18n
.gettext(txt
)
54 if trtxt
[-6:-4] == '@@': # handle @@verb / @@noun
58 def activeWindow(self
):
59 """Wrap activeWindow()"""
60 return self
._app
.activeWindow()
64 return self
._app
.exec_()
66 def setStyleSheet(self
, txt
):
67 """Wrap setStyleSheet(txt)"""
68 return self
._app
.setStyleSheet(txt
)