compileUiFiles.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2525
8b507a9a2d40
parent 2969
0e1af1313b8b
child 3058
0a02c433f52d
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
1 #!/usr/bin/env python 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 # Copyright (c) 2009 - 2013 Detlev Offenbach <detlev@die-offenbachs.de> 4 # Copyright (c) 2009 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
5 # 5 #
6 6
15 15
16 16
17 def compileUiFiles(): 17 def compileUiFiles():
18 """ 18 """
19 Compile the .ui files to Python sources. 19 Compile the .ui files to Python sources.
20 """ 20 """ # __IGNORE_WARNING__
21 try: 21 try:
22 from PyQt4.uic import compileUiDir 22 from PyQt4.uic import compileUiDir
23 except ImportError: 23 except ImportError:
24 from PyQt4.uic import compileUi 24 from PyQt4.uic import compileUi
25 25
26 def compileUiDir(dir, recurse = False, map = None, # __IGNORE_WARNING__ 26 def compileUiDir(dir, recurse=False, # __IGNORE_WARNING__
27 ** compileUi_args): 27 map=None, **compileUi_args):
28 """ 28 """
29 Creates Python modules from Qt Designer .ui files in a directory or 29 Creates Python modules from Qt Designer .ui files in a directory or
30 directory tree. 30 directory tree.
31 31
32 Note: This function is a modified version of the one found in PyQt4. 32 Note: This function is a modified version of the one found in
33 PyQt4.
33 34
34 @param dir Name of the directory to scan for files whose name ends with 35 @param dir Name of the directory to scan for files whose name ends
35 '.ui'. By default the generated Python module is created in the same 36 with '.ui'. By default the generated Python module is created
36 directory ending with '.py'. 37 in the same directory ending with '.py'.
37 @param recurse flag indicating that any sub-directories should be scanned. 38 @param recurse flag indicating that any sub-directories should be
38 @param map an optional callable that is passed the name of the directory 39 scanned.
39 containing the '.ui' file and the name of the Python module that will be 40 @param map an optional callable that is passed the name of the
40 created. The callable should return a tuple of the name of the directory 41 directory containing the '.ui' file and the name of the Python
41 in which the Python module will be created and the (possibly modified) 42 module that will be created. The callable should return a tuple
42 name of the module. 43 of the name of the directory in which the Python module will be
43 @param compileUi_args any additional keyword arguments that are passed to 44 created and the (possibly modified) name of the module.
44 the compileUi() function that is called to create each Python module. 45 @param compileUi_args any additional keyword arguments that are
46 passed to the compileUi() function that is called to create
47 each Python module.
45 """ 48 """
46 def compile_ui(ui_dir, ui_file): 49 def compile_ui(ui_dir, ui_file):
47 """ 50 """
48 Local function to compile a single .ui file. 51 Local function to compile a single .ui file.
49 52
53 # Ignore if it doesn't seem to be a .ui file. 56 # Ignore if it doesn't seem to be a .ui file.
54 if ui_file.endswith('.ui'): 57 if ui_file.endswith('.ui'):
55 py_dir = ui_dir 58 py_dir = ui_dir
56 py_file = ui_file[:-3] + '.py' 59 py_file = ui_file[:-3] + '.py'
57 60
58 # Allow the caller to change the name of the .py file or generate 61 # Allow the caller to change the name of the .py file or
59 # it in a different directory. 62 # generate it in a different directory.
60 if map is not None: 63 if map is not None:
61 py_dir, py_file = list(map(py_dir, py_file)) 64 py_dir, py_file = list(map(py_dir, py_file))
62 65
63 # Make sure the destination directory exists. 66 # Make sure the destination directory exists.
64 try: 67 try:
87 if os.path.isfile(os.path.join(dir, ui)): 90 if os.path.isfile(os.path.join(dir, ui)):
88 compile_ui(dir, ui) 91 compile_ui(dir, ui)
89 92
90 def pyName(py_dir, py_file): 93 def pyName(py_dir, py_file):
91 """ 94 """
92 Local function to create the Python source file name for the compiled .ui file. 95 Local function to create the Python source file name for the compiled
96 .ui file.
93 97
94 @param py_dir suggested name of the directory (string) 98 @param py_dir suggested name of the directory (string)
95 @param py_file suggested name for the compile source file (string) 99 @param py_file suggested name for the compile source file (string)
96 @return tuple of directory name (string) and source file name (string) 100 @return tuple of directory name (string) and source file name (string)
97 """ 101 """
115 try: 119 try:
116 main(sys.argv) 120 main(sys.argv)
117 except SystemExit: 121 except SystemExit:
118 raise 122 raise
119 except: 123 except:
120 print("""An internal error occured. Please report all the output of the program, 124 print("""
125 An internal error occured. Please report all the output of the program,
121 including the following traceback, to eric5-bugs@eric-ide.python-projects.org. 126 including the following traceback, to eric5-bugs@eric-ide.python-projects.org.
122 """) 127 """)
123 raise 128 raise

eric ide

mercurial