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 from cola
.decorators
import memoize
18 return QtGui
.QApplication(list(argv
))
21 class ColaApplication(object):
22 """The main cola application
24 ColaApplication handles i18n of user-visible data
27 def __init__(self
, argv
, locale
=None, gui
=True):
28 """Initialize our QApplication for translation
31 os
.environ
['LANG'] = locale
34 # monkey-patch Qt's translate() to use our translate()
36 self
._app
= instance(tuple(argv
))
37 self
._app
.setWindowIcon(QtGui
.QIcon(resources
.icon('git.svg')))
38 self
._translate
_base
= QtGui
.QApplication
.translate
39 QtGui
.QApplication
.translate
= self
.translate
41 self
._app
= QtCore
.QCoreApplication(argv
)
42 self
._translate
_base
= QtCore
.QCoreApplication
.translate
43 QtCore
.QCoreApplication
.translate
= self
.translate
45 def translate(self
, context
, txt
):
47 Translate strings with gettext
49 Supports @@noun/@@verb specifiers.
52 trtxt
= i18n
.gettext(txt
)
53 if trtxt
[-6:-4] == '@@': # handle @@verb / @@noun
57 def activeWindow(self
):
58 """Wrap activeWindow()"""
59 return self
._app
.activeWindow()
63 return self
._app
.exec_()
65 def setStyleSheet(self
, txt
):
66 """Wrap setStyleSheet(txt)"""
67 return self
._app
.setStyleSheet(txt
)