1232 |
1232 |
1233 print("All dependencies ok.") |
1233 print("All dependencies ok.") |
1234 print() |
1234 print() |
1235 |
1235 |
1236 |
1236 |
|
1237 def __pyName(py_dir, py_file): |
|
1238 """ |
|
1239 Local function to create the Python source file name for the compiled |
|
1240 .ui file. |
|
1241 |
|
1242 @param py_dir suggested name of the directory (string) |
|
1243 @param py_file suggested name for the compile source file (string) |
|
1244 @return tuple of directory name (string) and source file name (string) |
|
1245 """ |
|
1246 return py_dir, "Ui_{0}".format(py_file) |
|
1247 |
|
1248 |
1237 def compileUiFiles(): |
1249 def compileUiFiles(): |
1238 """ |
1250 """ |
1239 Compile the .ui files to Python sources. |
1251 Compile the .ui files to Python sources. |
1240 """ # __IGNORE_WARNING__ |
1252 """ |
1241 global sourceDir |
1253 global sourceDir |
1242 try: |
1254 if pyqtVariant == "PyQt4": |
1243 if pyqtVariant == "PyQt4": |
1255 from PyQt4.uic import compileUiDir |
1244 from PyQt4.uic import compileUiDir |
1256 else: |
1245 else: |
1257 from PyQt5.uic import compileUiDir |
1246 from PyQt5.uic import compileUiDir |
1258 compileUiDir(sourceDir, True, __pyName) |
1247 except ImportError: |
|
1248 if pyqtVariant == "PyQt4": |
|
1249 from PyQt4.uic import compileUi |
|
1250 else: |
|
1251 from PyQt5.uic import compileUi |
|
1252 |
|
1253 def compileUiDir(dir, recurse=False, # __IGNORE_WARNING__ |
|
1254 map=None, **compileUi_args): |
|
1255 """ |
|
1256 Creates Python modules from Qt Designer .ui files in a directory or |
|
1257 directory tree. |
|
1258 |
|
1259 Note: This function is a modified version of the one found in |
|
1260 PyQt5. |
|
1261 |
|
1262 @param dir Name of the directory to scan for files whose name ends |
|
1263 with '.ui'. By default the generated Python module is created |
|
1264 in the same directory ending with '.py'. |
|
1265 @param recurse flag indicating that any sub-directories should be |
|
1266 scanned. |
|
1267 @param map an optional callable that is passed the name of the |
|
1268 directory containing the '.ui' file and the name of the Python |
|
1269 module that will be created. The callable should return a |
|
1270 tuple of the name of the directory in which the Python module |
|
1271 will be created and the (possibly modified) name of the module. |
|
1272 @param compileUi_args any additional keyword arguments that are |
|
1273 passed to the compileUi() function that is called to create |
|
1274 each Python module. |
|
1275 """ |
|
1276 def compile_ui(ui_dir, ui_file): |
|
1277 """ |
|
1278 Local function to compile a single .ui file. |
|
1279 |
|
1280 @param ui_dir directory containing the .ui file (string) |
|
1281 @param ui_file file name of the .ui file (string) |
|
1282 """ |
|
1283 # Ignore if it doesn't seem to be a .ui file. |
|
1284 if ui_file.endswith('.ui'): |
|
1285 py_dir = ui_dir |
|
1286 py_file = ui_file[:-3] + '.py' |
|
1287 |
|
1288 # Allow the caller to change the name of the .py file or |
|
1289 # generate it in a different directory. |
|
1290 if map is not None: |
|
1291 py_dir, py_file = list(map(py_dir, py_file)) |
|
1292 |
|
1293 # Make sure the destination directory exists. |
|
1294 try: |
|
1295 os.makedirs(py_dir) |
|
1296 except: |
|
1297 pass |
|
1298 |
|
1299 ui_path = os.path.join(ui_dir, ui_file) |
|
1300 py_path = os.path.join(py_dir, py_file) |
|
1301 |
|
1302 ui_file = open(ui_path, 'r') |
|
1303 py_file = open(py_path, 'w') |
|
1304 |
|
1305 try: |
|
1306 compileUi(ui_file, py_file, **compileUi_args) |
|
1307 finally: |
|
1308 ui_file.close() |
|
1309 py_file.close() |
|
1310 |
|
1311 if recurse: |
|
1312 for root, _, files in os.walk(dir): |
|
1313 for ui in files: |
|
1314 compile_ui(root, ui) |
|
1315 else: |
|
1316 for ui in os.listdir(dir): |
|
1317 if os.path.isfile(os.path.join(dir, ui)): |
|
1318 compile_ui(dir, ui) |
|
1319 |
|
1320 def pyName(py_dir, py_file): |
|
1321 """ |
|
1322 Local function to create the Python source file name for the compiled |
|
1323 .ui file. |
|
1324 |
|
1325 @param py_dir suggested name of the directory (string) |
|
1326 @param py_file suggested name for the compile source file (string) |
|
1327 @return tuple of directory name (string) and source file name (string) |
|
1328 """ |
|
1329 return py_dir, "Ui_{0}".format(py_file) |
|
1330 |
|
1331 compileUiDir(sourceDir, True, pyName) |
|
1332 |
1259 |
1333 |
1260 |
1334 def prepareInfoFile(fileName): |
1261 def prepareInfoFile(fileName): |
1335 """ |
1262 """ |
1336 Function to prepare an Info.py file when installing from source. |
1263 Function to prepare an Info.py file when installing from source. |