Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0.4, 2.0.5, and 2.1

stable setup, hgqt: build Qt translation resource and load it if frozen

It switches QTranslator's load path to :/translations if frozen.
And add 'setup.py build_qt --frozen' option to build translation resource.

Changeset 9ccf60504e07

Parent e44f6f508a07

by Yuya Nishihara

Changes to 4 files · Browse files at 9ccf60504e07 Showing diff from parent e44f6f508a07 Diff from another changeset...

Change 1 of 3 Show Entire File setup.py Stacked
 
13
14
15
 
 
16
17
18
 
110
111
112
113
114
 
 
 
115
116
117
 
118
119
120
 
186
187
188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
190
191
192
193
194
 
 
195
196
197
 
13
14
15
16
17
18
19
20
 
112
113
114
 
 
115
116
117
118
119
120
121
122
123
124
 
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
@@ -13,6 +13,8 @@
 import shutil  import subprocess  import cgi +import tempfile +import re  from fnmatch import fnmatch  from distutils import log  from distutils.core import setup, Command @@ -110,11 +112,13 @@
 class build_qt(Command):   description = "build PyQt GUIs (.ui) and resources (.qrc)"   user_options = [('force', 'f', 'forcibly compile everything' - ' (ignore file timestamps)')] - boolean_options = ('force',) + ' (ignore file timestamps)'), + ('frozen', None, 'include resources for frozen exe')] + boolean_options = ('force', 'frozen')     def initialize_options(self):   self.force = None + self.frozen = False     def finalize_options(self):   self.set_undefined_options('build', ('force', 'force')) @@ -186,12 +190,33 @@
  finally:   os.unlink(qrc_file)   + def _build_translations(self, basepath): + """Build translations_rc.py which inclues qt_xx.qm""" + from PyQt4.QtCore import QLibraryInfo + trpath = unicode(QLibraryInfo.location(QLibraryInfo.TranslationsPath)) + d = tempfile.mkdtemp() + try: + for e in os.listdir(trpath): + if re.match(r'qt_[a-z]{2}(_[A-Z]{2})?\.ts$', e): + r = os.system('lrelease "%s" -qm "%s"' + % (os.path.join(trpath, e), + os.path.join(d, e[:-3] + '.qm'))) + if r > 0: + self.warn('Unable to generate Qt message file' + ' from %s' % e) + self.build_rc(os.path.join(basepath, 'translations_rc.py'), + d, '/translations') + finally: + shutil.rmtree(d) +   def run(self):   self._wrapuic()   basepath = join(os.path.dirname(__file__), 'tortoisehg', 'hgqt')   self.build_rc(os.path.join(basepath, 'icons_rc.py'),   os.path.join(os.path.dirname(__file__), 'icons'),   '/icons') + if self.frozen: + self._build_translations(basepath)   for dirpath, _, filenames in os.walk(basepath):   for filename in filenames:   if filename.endswith('.ui'):
Change 1 of 1 Show Entire File thg Stacked
 
43
44
45
 
46
47
48
 
43
44
45
46
47
48
49
@@ -43,6 +43,7 @@
 demandimport.ignore.append('win32com.shell')  demandimport.ignore.append('tortoisehg.util.config')  demandimport.ignore.append('icons_rc') +demandimport.ignore.append('translations_rc')  demandimport.enable()  from mercurial import ui as uimod, util  from tortoisehg.util.hgversion import hgversion, checkhgversion
 
1
2
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
@@ -1,2 +1,8 @@
 # load icon resources  import icons_rc + +# load Qt translations for frozen environment +try: + import translations_rc +except ImportError: + pass
 
394
395
396
397
 
 
 
 
398
399
400
 
394
395
396
 
397
398
399
400
401
402
403
@@ -394,7 +394,10 @@
   def gettranslationpath():   """Return path to Qt's translation file (.qm)""" - return QLibraryInfo.location(QLibraryInfo.TranslationsPath) + if getattr(sys, 'frozen', False): + return ':/translations' + else: + return QLibraryInfo.location(QLibraryInfo.TranslationsPath)    def CommonMsgBox(icon, title, main, text='', buttons=QMessageBox.Ok,   labels=[], parent=None, defaultbutton=None):