doc: Add git-cola-1.3.7 release notes
[git-cola.git] / cola / app.py
blobde93021ec0249df55edabbf2e7e2aaeacd95fa75
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
13 class ColaApplication(object):
14 """The main cola application
16 ColaApplication handles i18n of user-visible data
17 """
19 def __init__(self, argv, locale=None, gui=True):
20 """Initialize our QApplication for translation
21 """
22 # monkey-patch Qt's app translate() to handle .po files
23 if gui:
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
28 else:
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
34 if not locale:
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
45 """
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
49 trtxt = trtxt[:-6]
50 return trtxt
52 def activeWindow(self):
53 """Wrap activeWindow()"""
54 return self._app.activeWindow()
56 def exec_(self):
57 """Wrap exec_()"""
58 return self._app.exec_()
60 def setStyleSheet(self, txt):
61 """Wrap setStyleSheet(txt)"""
62 return self._app.setStyleSheet(txt)