views.main: Remove tooltip from the status view too
[git-cola.git] / cola / app.py
blob4a44106dc5c2955381c2d3323272f7c9a2880641
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
5 import os
7 from PyQt4 import QtCore
8 from PyQt4 import QtGui
10 from cola import utils
11 from cola import resources
12 from cola import i18n
14 _app = None
15 def instance(argv):
16 global _app
17 if not _app:
18 _app = QtGui.QApplication(argv)
19 return _app
22 class ColaApplication(object):
23 """The main cola application
25 ColaApplication handles i18n of user-visible data
26 """
28 def __init__(self, argv, locale=None, gui=True):
29 """Initialize our QApplication for translation
30 """
31 if locale:
32 os.environ['LANG'] = locale
33 i18n.install()
35 # monkey-patch Qt's translate() to use our translate()
36 if gui:
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
41 else:
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):
47 """
48 Translate strings with gettext
50 Supports @@noun/@@verb specifiers.
52 """
53 trtxt = i18n.gettext(txt)
54 if trtxt[-6:-4] == '@@': # handle @@verb / @@noun
55 trtxt = trtxt[:-6]
56 return trtxt
58 def activeWindow(self):
59 """Wrap activeWindow()"""
60 return self._app.activeWindow()
62 def exec_(self):
63 """Wrap exec_()"""
64 return self._app.exec_()
66 def setStyleSheet(self, txt):
67 """Wrap setStyleSheet(txt)"""
68 return self._app.setStyleSheet(txt)