1360 """ |
1360 """ |
1361 global configDir |
1361 global configDir |
1362 configDir = os.path.expanduser(d) |
1362 configDir = os.path.expanduser(d) |
1363 |
1363 |
1364 |
1364 |
|
1365 ################################################################################ |
|
1366 # functions for environment handling |
|
1367 ################################################################################ |
|
1368 |
|
1369 |
|
1370 def getEnvironmentEntry(key, default=None): |
|
1371 """ |
|
1372 Module function to get an environment entry. |
|
1373 |
|
1374 @param key key of the requested environment entry (string) |
|
1375 @param default value to be returned, if the environment doesn't contain |
|
1376 the requested entry (string) |
|
1377 @return the requested entry or the default value, if the entry wasn't |
|
1378 found (string or None) |
|
1379 """ |
|
1380 filter = QRegExp("^{0}[ \t]*=".format(key)) |
|
1381 if isWindowsPlatform(): |
|
1382 filter.setCaseSensitivity(Qt.CaseInsensitive) |
|
1383 |
|
1384 entries = [e for e in QProcess.systemEnvironment() if filter.indexIn(e) != -1] |
|
1385 if not entries: |
|
1386 return default |
|
1387 |
|
1388 # if there are multiple entries, just consider the first one |
|
1389 ename, val = entries[0].split("=", 1) |
|
1390 return val.strip() |
|
1391 |
|
1392 |
|
1393 def hasEnvironmentEntry(key): |
|
1394 """ |
|
1395 Module function to check, if the environment contains an entry. |
|
1396 |
|
1397 @param key key of the requested environment entry (string) |
|
1398 @return flag indicating the presence of the requested entry (boolean) |
|
1399 """ |
|
1400 filter = QRegExp("^{0}[ \t]*=".format(key)) |
|
1401 if isWindowsPlatform(): |
|
1402 filter.setCaseSensitivity(Qt.CaseInsensitive) |
|
1403 |
|
1404 entries = [e for e in QProcess.systemEnvironment() if filter.indexIn(e) != -1] |
|
1405 return len(entries) > 0 |
|
1406 |
|
1407 ################################################################################ |
|
1408 # Qt utility functions below |
|
1409 ################################################################################ |
|
1410 |
|
1411 |
|
1412 def generateQtToolName(toolname): |
|
1413 """ |
|
1414 Module function to generate the executable name for a Qt tool like designer. |
|
1415 |
|
1416 @param toolname base name of the tool (string) |
|
1417 @return the Qt tool name without extension (string) |
|
1418 """ |
|
1419 return "{0}{1}{2}".format(Preferences.getQt("QtToolsPrefix4"), |
|
1420 toolname, |
|
1421 Preferences.getQt("QtToolsPostfix4") |
|
1422 ) |
|
1423 |
|
1424 |
|
1425 def getQtMacBundle(toolname): |
|
1426 """ |
|
1427 Module function to determine the correct Mac OS X bundle name for Qt tools. |
|
1428 |
|
1429 @param toolname plain name of the tool (e.g. "designer") (string) |
|
1430 @return bundle name of the Qt tool (string) |
|
1431 """ |
|
1432 qtDir = Preferences.getQt("Qt4Dir") |
|
1433 bundles = [ |
|
1434 os.path.join(qtDir, 'bin', generateQtToolName(toolname.capitalize())) + ".app", |
|
1435 os.path.join(qtDir, 'bin', generateQtToolName(toolname)) + ".app", |
|
1436 os.path.join(qtDir, generateQtToolName(toolname.capitalize())) + ".app", |
|
1437 os.path.join(qtDir, generateQtToolName(toolname)) + ".app", |
|
1438 ] |
|
1439 for bundle in bundles: |
|
1440 if os.path.exists(bundle): |
|
1441 return bundle |
|
1442 return "" |
|
1443 |
|
1444 |
|
1445 def prepareQtMacBundle(toolname, version, args): |
|
1446 """ |
|
1447 Module function for starting Qt tools that are Mac OS X bundles. |
|
1448 |
|
1449 @param toolname plain name of the tool (e.g. "designer") (string) |
|
1450 @param version indication for the requested version (Qt 4) (integer) |
|
1451 @param args name of input file for tool, if any (list of strings) |
|
1452 @return command-name and args for QProcess (tuple) |
|
1453 """ |
|
1454 if version != 4: |
|
1455 return ("", []) |
|
1456 |
|
1457 fullBundle = getQtMacBundle(toolname) |
|
1458 if fullBundle == "": |
|
1459 return ("", []) |
|
1460 |
|
1461 newArgs = [] |
|
1462 newArgs.append("-a") |
|
1463 newArgs.append(fullBundle) |
|
1464 if args: |
|
1465 newArgs.append("--args") |
|
1466 newArgs += args |
|
1467 |
|
1468 return ("open", newArgs) |
|
1469 |
|
1470 ################################################################################ |
|
1471 # Qt utility functions below |
|
1472 ################################################################################ |
|
1473 |
|
1474 |
|
1475 def generatePySideToolPath(toolname): |
|
1476 """ |
|
1477 Module function to generate the executable path for a PySide tool. |
|
1478 |
|
1479 @param toolname base name of the tool (string or QString) |
|
1480 @return the PySide tool path with extension (string) |
|
1481 """ |
|
1482 if isWindowsPlatform(): |
|
1483 try: |
|
1484 # step 1: try Python3 variant of PySide |
|
1485 import PySide # __IGNORE_EXCEPTION__ |
|
1486 del PySide |
|
1487 prefix = sys.prefix |
|
1488 except ImportError: |
|
1489 # step 2: check for a Python2 variant |
|
1490 prefix = os.path.dirname(Preferences.getDebugger("PythonInterpreter")) |
|
1491 if toolname == "pyside-uic": |
|
1492 return os.path.join(prefix, "Scripts", toolname + '.exe') |
|
1493 else: |
|
1494 return os.path.join(prefix, "Lib", "site-packages", "PySide", |
|
1495 toolname + ".exe") |
|
1496 else: |
|
1497 return toolname |
|
1498 |
|
1499 |
1365 def checkPyside(): |
1500 def checkPyside(): |
1366 """ |
1501 """ |
1367 Module function to check the presence of PySide. |
1502 Module function to check the presence of PySide. |
1368 |
1503 |
1369 @return flag indicating the presence of PySide (boolean) |
1504 @return flag indicating the presence of PySide (boolean) |
1390 if proc.exitCode() == 0: |
1525 if proc.exitCode() == 0: |
1391 return True |
1526 return True |
1392 |
1527 |
1393 return False |
1528 return False |
1394 |
1529 |
1395 |
|
1396 ################################################################################ |
|
1397 # functions for environment handling |
|
1398 ################################################################################ |
|
1399 |
|
1400 |
|
1401 def getEnvironmentEntry(key, default=None): |
|
1402 """ |
|
1403 Module function to get an environment entry. |
|
1404 |
|
1405 @param key key of the requested environment entry (string) |
|
1406 @param default value to be returned, if the environment doesn't contain |
|
1407 the requested entry (string) |
|
1408 @return the requested entry or the default value, if the entry wasn't |
|
1409 found (string or None) |
|
1410 """ |
|
1411 filter = QRegExp("^{0}[ \t]*=".format(key)) |
|
1412 if isWindowsPlatform(): |
|
1413 filter.setCaseSensitivity(Qt.CaseInsensitive) |
|
1414 |
|
1415 entries = [e for e in QProcess.systemEnvironment() if filter.indexIn(e) != -1] |
|
1416 if not entries: |
|
1417 return default |
|
1418 |
|
1419 # if there are multiple entries, just consider the first one |
|
1420 ename, val = entries[0].split("=", 1) |
|
1421 return val.strip() |
|
1422 |
|
1423 |
|
1424 def hasEnvironmentEntry(key): |
|
1425 """ |
|
1426 Module function to check, if the environment contains an entry. |
|
1427 |
|
1428 @param key key of the requested environment entry (string) |
|
1429 @return flag indicating the presence of the requested entry (boolean) |
|
1430 """ |
|
1431 filter = QRegExp("^{0}[ \t]*=".format(key)) |
|
1432 if isWindowsPlatform(): |
|
1433 filter.setCaseSensitivity(Qt.CaseInsensitive) |
|
1434 |
|
1435 entries = [e for e in QProcess.systemEnvironment() if filter.indexIn(e) != -1] |
|
1436 return len(entries) > 0 |
|
1437 |
|
1438 ################################################################################ |
|
1439 # Qt utility functions below |
|
1440 ################################################################################ |
|
1441 |
|
1442 |
|
1443 def generateQtToolName(toolname): |
|
1444 """ |
|
1445 Module function to generate the executable name for a Qt tool like designer. |
|
1446 |
|
1447 @param toolname base name of the tool (string) |
|
1448 @return the Qt tool name without extension (string) |
|
1449 """ |
|
1450 return "{0}{1}{2}".format(Preferences.getQt("QtToolsPrefix4"), |
|
1451 toolname, |
|
1452 Preferences.getQt("QtToolsPostfix4") |
|
1453 ) |
|
1454 |
|
1455 |
|
1456 def getQtMacBundle(toolname): |
|
1457 """ |
|
1458 Module function to determine the correct Mac OS X bundle name for Qt tools. |
|
1459 |
|
1460 @param toolname plain name of the tool (e.g. "designer") (string) |
|
1461 @return bundle name of the Qt tool (string) |
|
1462 """ |
|
1463 qtDir = Preferences.getQt("Qt4Dir") |
|
1464 bundles = [ |
|
1465 os.path.join(qtDir, 'bin', generateQtToolName(toolname.capitalize())) + ".app", |
|
1466 os.path.join(qtDir, 'bin', generateQtToolName(toolname)) + ".app", |
|
1467 os.path.join(qtDir, generateQtToolName(toolname.capitalize())) + ".app", |
|
1468 os.path.join(qtDir, generateQtToolName(toolname)) + ".app", |
|
1469 ] |
|
1470 for bundle in bundles: |
|
1471 if os.path.exists(bundle): |
|
1472 return bundle |
|
1473 return "" |
|
1474 |
|
1475 |
|
1476 def prepareQtMacBundle(toolname, version, args): |
|
1477 """ |
|
1478 Module function for starting Qt tools that are Mac OS X bundles. |
|
1479 |
|
1480 @param toolname plain name of the tool (e.g. "designer") (string) |
|
1481 @param version indication for the requested version (Qt 4) (integer) |
|
1482 @param args name of input file for tool, if any (list of strings) |
|
1483 @return command-name and args for QProcess (tuple) |
|
1484 """ |
|
1485 if version != 4: |
|
1486 return ("", []) |
|
1487 |
|
1488 fullBundle = getQtMacBundle(toolname) |
|
1489 if fullBundle == "": |
|
1490 return ("", []) |
|
1491 |
|
1492 newArgs = [] |
|
1493 newArgs.append("-a") |
|
1494 newArgs.append(fullBundle) |
|
1495 if args: |
|
1496 newArgs.append("--args") |
|
1497 newArgs += args |
|
1498 |
|
1499 return ("open", newArgs) |
|
1500 |
|
1501 ################################################################################ |
|
1502 # Qt utility functions below |
|
1503 ################################################################################ |
|
1504 |
|
1505 |
|
1506 def generatePySideToolPath(toolname): |
|
1507 """ |
|
1508 Module function to generate the executable path for a PySide tool. |
|
1509 |
|
1510 @param toolname base name of the tool (string or QString) |
|
1511 @return the PySide tool path with extension (string) |
|
1512 """ |
|
1513 if isWindowsPlatform(): |
|
1514 prefix = os.path.dirname(Preferences.getDebugger("PythonInterpreter")) |
|
1515 if toolname == "pyside-uic": |
|
1516 return os.path.join(prefix, "Scripts", toolname + '.exe') |
|
1517 else: |
|
1518 return os.path.join(prefix, "Lib", "site-packages", "PySide", |
|
1519 toolname + ".exe") |
|
1520 else: |
|
1521 return toolname |
|
1522 |
|
1523 ################################################################################ |
1530 ################################################################################ |
1524 # Other utility functions below |
1531 # Other utility functions below |
1525 ################################################################################ |
1532 ################################################################################ |
1526 |
1533 |
1527 |
1534 |