|
1 #!/usr/bin/env python3 |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # Copyright (c) 2009 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
5 # |
|
6 |
|
7 """ |
|
8 Script for eric6 to compile all .ui files to Python source. |
|
9 """ |
|
10 |
|
11 from __future__ import unicode_literals, print_function |
|
12 |
|
13 import sys |
|
14 |
|
15 # step 1: determine PyQt variant, preferring PyQt5 |
|
16 try: |
|
17 import PyQt5 # __IGNORE_WARNING__ |
|
18 pyqtVariant = "PyQt5" |
|
19 except ImportError: |
|
20 import PyQt4 # __IGNORE_WARNING__ |
|
21 pyqtVariant = "PyQt4" |
|
22 |
|
23 # step 2: compile the UI files |
|
24 if pyqtVariant == "PyQt4": |
|
25 from PyQt4.uic import compileUiDir |
|
26 else: |
|
27 from PyQt5.uic import compileUiDir |
|
28 |
|
29 |
|
30 def __pyName(py_dir, py_file): |
|
31 """ |
|
32 Local function to create the Python source file name for the compiled |
|
33 .ui file. |
|
34 |
|
35 @param py_dir suggested name of the directory (string) |
|
36 @param py_file suggested name for the compile source file (string) |
|
37 @return tuple of directory name (string) and source file name (string) |
|
38 """ |
|
39 return py_dir, "Ui_{0}".format(py_file) |
|
40 |
|
41 |
|
42 def compileUiFiles(): |
|
43 """ |
|
44 Compile the .ui files to Python sources. |
|
45 """ |
|
46 compileUiDir("eric6", True, __pyName) |
|
47 |
|
48 |
|
49 def main(argv): |
|
50 """ |
|
51 The main function of the script. |
|
52 |
|
53 @param argv the list of command line arguments. |
|
54 """ |
|
55 # Compile .ui files |
|
56 print("Compiling user interface files...") |
|
57 compileUiFiles() |
|
58 |
|
59 |
|
60 if __name__ == "__main__": |
|
61 try: |
|
62 main(sys.argv) |
|
63 except SystemExit: |
|
64 raise |
|
65 except Exception: |
|
66 print( |
|
67 "\nAn internal error occured. Please report all the output of the" |
|
68 " program, \nincluding the following traceback, to" |
|
69 " eric-bugs@eric-ide.python-projects.org.\n") |
|
70 raise |
|
71 |
|
72 # |
|
73 # eflag: noqa = M801 |