src/eric7/SystemUtilities/QtUtilities.py

Mon, 16 Oct 2023 19:41:27 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 16 Oct 2023 19:41:27 +0200
branch
eric7
changeset 10250
09b42174e077
parent 10249
77b4c59c76d9
child 10431
64157aeb0312
permissions
-rw-r--r--

QtUtilities.py
- Extended the search for the 'bin' directory in the 'getQtBinariesPath()' function.

9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
9653
e67609152c5e Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9625
diff changeset
3 # Copyright (c) 2022 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing Qt/PyQt/PySide related utility functions.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import contextlib
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import functools
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import os
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 import sys
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 import sysconfig
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from PyQt6.QtCore import QT_VERSION, QDir, QLibraryInfo, QProcess
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 from eric7.EricWidgets.EricApplication import ericApp
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from eric7.SystemUtilities import FileSystemUtilities, OSUtilities, PythonUtilities
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 try:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 from eric7.eric7config import getConfig
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 except ImportError:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 from eric7config import getConfig
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 ###############################################################################
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 ## Qt utility functions below
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 ###############################################################################
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 def qVersionTuple():
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 Module function to get the Qt version as a tuple.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @return Qt version as a tuple
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @rtype tuple of int
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 return (
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 (QT_VERSION & 0xFF0000) >> 16,
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 (QT_VERSION & 0xFF00) >> 8,
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 QT_VERSION & 0xFF,
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 )
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 def generateQtToolName(toolname):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 Module function to generate the executable name for a Qt tool like
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 designer.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 @param toolname base name of the tool (string)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 @return the Qt tool name without extension (string)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 from eric7 import Preferences
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 return "{0}{1}{2}".format(
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 Preferences.getQt("QtToolsPrefix"),
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 toolname,
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 Preferences.getQt("QtToolsPostfix"),
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 )
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 def getQtBinariesPath(libexec=False):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 Module function to get the path of the Qt binaries.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 @param libexec flag indicating to get the path of the executable library
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 (defaults to False)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 @type bool (optional)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @return path of the Qt binaries
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 @rtype str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 from eric7 import Preferences
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 binPath = ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 # step 1: check, if the user has configured a tools path
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 qtToolsDir = Preferences.getQt("QtToolsDir")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 if qtToolsDir:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 if libexec:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 binPath = os.path.join(qtToolsDir, "..", "libexec")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 if not os.path.exists(binPath):
10249
77b4c59c76d9 QtUtilities.py
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10158
diff changeset
82 binPath = os.path.join(qtToolsDir, "libexec")
77b4c59c76d9 QtUtilities.py
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10158
diff changeset
83 if not os.path.exists(binPath):
77b4c59c76d9 QtUtilities.py
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10158
diff changeset
84 binPath = qtToolsDir
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 else:
10250
09b42174e077 QtUtilities.py
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10249
diff changeset
86 binPath = os.path.join(qtToolsDir, "bin")
09b42174e077 QtUtilities.py
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10249
diff changeset
87 if not os.path.exists(binPath):
09b42174e077 QtUtilities.py
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10249
diff changeset
88 binPath = qtToolsDir
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 if not os.path.exists(binPath):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 binPath = ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 # step 2: try the qt6_applications package
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 if not binPath:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 with contextlib.suppress(ImportError):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 # if qt6-applications is not installed just go to the next step
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 import qt6_applications # __IGNORE_WARNING_I10__
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 if libexec:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 binPath = os.path.join(
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 os.path.dirname(qt6_applications.__file__), "Qt", "libexec"
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 )
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 if not os.path.exists(binPath):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 binPath = os.path.join(
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 os.path.dirname(qt6_applications.__file__), "Qt", "bin"
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 )
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 else:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 binPath = os.path.join(
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 os.path.dirname(qt6_applications.__file__), "Qt", "bin"
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 )
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 if not os.path.exists(binPath):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 binPath = ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 # step3: determine via QLibraryInfo
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 if not binPath:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 binPath = (
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 QLibraryInfo.path(QLibraryInfo.LibraryPath.LibraryExecutablesPath)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 if libexec
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 else QLibraryInfo.path(QLibraryInfo.LibraryPath.BinariesPath)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 )
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 # step 4: determine from used Python interpreter (designer is test object)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 if not binPath:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 program = "designer"
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 if OSUtilities.isWindowsPlatform():
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 program += ".exe"
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 progPath = os.path.join(PythonUtilities.getPythonScriptsDirectory(), program)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 if os.path.exists(progPath):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 binPath = PythonUtilities.getPythonScriptsDirectory()
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 return QDir.toNativeSeparators(binPath)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 def getQtMacBundle(toolname):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 Module function to determine the correct Mac OS X bundle name for Qt tools.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 @param toolname plain name of the tool (e.g. "designer") (string)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 @return bundle name of the Qt tool (string)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 qtDir = getQtBinariesPath()
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 bundles = [
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 os.path.join(qtDir, "bin", generateQtToolName(toolname.capitalize())) + ".app",
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 os.path.join(qtDir, "bin", generateQtToolName(toolname)) + ".app",
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 os.path.join(qtDir, generateQtToolName(toolname.capitalize())) + ".app",
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 os.path.join(qtDir, generateQtToolName(toolname)) + ".app",
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 ]
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 if toolname == "designer":
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 # support the standalone Qt Designer installer from
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 # https://build-system.fman.io/qt-designer-download
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 designer = "Qt Designer.app"
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 bundles.extend(
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 [
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 os.path.join(qtDir, "bin", designer),
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 os.path.join(qtDir, designer),
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 ]
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 )
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 for bundle in bundles:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 if os.path.exists(bundle):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 return bundle
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 return ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 def prepareQtMacBundle(toolname, args):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 Module function for starting Qt tools that are Mac OS X bundles.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 @param toolname plain name of the tool (e.g. "designer")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 @type str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 @param args name of input file for tool, if any
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 @type list of str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 @return command-name and args for QProcess
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 @rtype tuple of (str, list of str)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 fullBundle = getQtMacBundle(toolname)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 if fullBundle == "":
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 return ("", [])
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 newArgs = []
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 newArgs.append("-a")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 newArgs.append(fullBundle)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 if args:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 newArgs.append("--args")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 newArgs += args
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 return ("open", newArgs)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188
10158
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
189 def hasQtDesigner():
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
190 """
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
191 Function to check for the availabilility of Qt-Designer tool.
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
192
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
193 @return flag indicating the availability of the Qt-Designer tool
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
194 @rtype bool
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
195 """
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
196 if OSUtilities.isWindowsPlatform():
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
197 designerExe = os.path.join(
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
198 getQtBinariesPath(),
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
199 "{0}.exe".format(generateQtToolName("designer")),
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
200 )
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
201 elif OSUtilities.isMacPlatform():
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
202 designerExe = getQtMacBundle("designer")
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
203 else:
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
204 designerExe = os.path.join(
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
205 getQtBinariesPath(),
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
206 generateQtToolName("designer"),
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
207 )
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
208 return os.path.exists(designerExe)
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
209
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
210
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
211 def hasQtLinguist():
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
212 """
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
213 Function to check for the availabilility of Qt-Linguist tool.
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
214
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
215 @return flag indicating the availability of the Qt-Linguist tool
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
216 @rtype bool
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
217 """
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
218 if OSUtilities.isWindowsPlatform():
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
219 linguistExe = os.path.join(
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
220 getQtBinariesPath(),
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
221 "{0}.exe".format(generateQtToolName("linguist")),
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
222 )
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
223 elif OSUtilities.isMacPlatform():
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
224 linguistExe = getQtMacBundle("linguist")
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
225 else:
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
226 linguistExe = os.path.join(
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
227 getQtBinariesPath(),
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
228 generateQtToolName("linguist"),
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
229 )
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
230 return os.path.exists(linguistExe)
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
231
b5aadedf4214 Made the enabled state of the "Open in Qt-Designer" and "Open in Qt-Linguist" context menu entries dependent of the availability of these tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
232
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 ###############################################################################
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 ## PyQt utility functions below
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 ###############################################################################
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 def getPyQt6ModulesDirectory():
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 Function to determine the path to PyQt6 modules directory.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 @return path to the PyQt6 modules directory
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 @rtype str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 pyqtPath = os.path.join(sysconfig.get_path("platlib"), "PyQt6")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 if os.path.exists(pyqtPath):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 return pyqtPath
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 return ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 def getPyQtToolsPath(version=5):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 Module function to get the path of the PyQt tools.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 @param version PyQt major version
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 @type int
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 @return path to the PyQt tools
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 @rtype str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 from eric7 import Preferences
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 from eric7.EricWidgets.EricApplication import ericApp
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 toolsPath = ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 # step 1: check, if the user has configured a tools path
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 if version == 5:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 toolsPath = Preferences.getQt("PyQtToolsDir")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 venvName = Preferences.getQt("PyQtVenvName")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 elif version == 6:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 toolsPath = Preferences.getQt("PyQt6ToolsDir")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 venvName = Preferences.getQt("PyQt6VenvName")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 # step 2: determine from used Python interpreter (pylupdate is test object)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 if not toolsPath:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 program = "pylupdate{0}".format(version)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 if venvName:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 venvManager = ericApp().getObject("VirtualEnvManager")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 dirName = venvManager.getVirtualenvDirectory(venvName)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 else:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 dirName = os.path.dirname(sys.executable)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 if OSUtilities.isWindowsPlatform():
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 program += ".exe"
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 if os.path.exists(os.path.join(dirName, program)):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 toolsPath = dirName
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 elif os.path.exists(os.path.join(dirName, "Scripts", program)):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 toolsPath = os.path.join(dirName, "Scripts")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 else:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 if os.path.exists(os.path.join(dirName, program)):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 toolsPath = dirName
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 elif os.path.exists(os.path.join(dirName, "bin", program)):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 toolsPath = os.path.join(dirName, "bin")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 return toolsPath
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 def generatePyQtToolPath(toolname, alternatives=None):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 Module function to generate the executable path for a PyQt tool.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 @param toolname base name of the tool
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 @type str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 @param alternatives list of alternative tool names to try
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 @type list of str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 @return executable path name of the tool
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 @rtype str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 pyqtVariant = int(toolname[-1])
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 pyqtToolsPath = getPyQtToolsPath(pyqtVariant)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 if pyqtToolsPath:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 exe = os.path.join(pyqtToolsPath, toolname)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 if OSUtilities.isWindowsPlatform():
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 exe += ".exe"
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 else:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 if OSUtilities.isWindowsPlatform():
9625
2c760cdc6b64 Fixed an issue causing an exception on Windows platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
317 exe = FileSystemUtilities.getWindowsExecutablePath(toolname)
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 else:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 exe = toolname
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 if not FileSystemUtilities.isinpath(exe) and alternatives:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 ex_ = generatePyQtToolPath(alternatives[0], alternatives[1:])
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 if FileSystemUtilities.isinpath(ex_):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 exe = ex_
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 return exe
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 ###############################################################################
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 ## PySide2/PySide6 utility functions below
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 ###############################################################################
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 def generatePySideToolPath(toolname, variant=2):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 Module function to generate the executable path for a PySide2/PySide6 tool.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 @param toolname base name of the tool
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 @type str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 @param variant indicator for the PySide variant
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 @type int or str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 @return the PySide2/PySide6 tool path with extension
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 @rtype str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 from eric7 import Preferences
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 if OSUtilities.isWindowsPlatform():
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 hasPyside = checkPyside(variant)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 if not hasPyside:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 return ""
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 venvName = Preferences.getQt("PySide{0}VenvName".format(variant))
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 if not venvName:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 venvName = Preferences.getDebugger("Python3VirtualEnv")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 interpreter = (
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 ericApp().getObject("VirtualEnvManager").getVirtualenvInterpreter(venvName)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 )
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 if interpreter == "" or not FileSystemUtilities.isinpath(interpreter):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 interpreter = PythonUtilities.getPythonExecutable()
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 prefix = os.path.dirname(interpreter)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 if not prefix.endswith("Scripts"):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 prefix = os.path.join(prefix, "Scripts")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 return os.path.join(prefix, toolname + ".exe")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 else:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 # step 1: check, if the user has configured a tools path
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 path = Preferences.getQt("PySide{0}ToolsDir".format(variant))
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 if path:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 return os.path.join(path, toolname)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 # step 2: determine from used Python interpreter
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 dirName = os.path.dirname(sys.executable)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 if os.path.exists(os.path.join(dirName, toolname)):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 return os.path.join(dirName, toolname)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 return toolname
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 @functools.lru_cache()
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 def checkPyside(variant=2):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 Module function to check the presence of PySide2/PySide6.
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 @param variant indicator for the PySide variant
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 @type int or str
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 @return flags indicating the presence of PySide2/PySide6
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 @rtype bool
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 """
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 from eric7 import Preferences
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 venvName = Preferences.getQt("PySide{0}VenvName".format(variant))
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 if not venvName:
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 venvName = Preferences.getDebugger("Python3VirtualEnv")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 interpreter = (
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 ericApp().getObject("VirtualEnvManager").getVirtualenvInterpreter(venvName)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 )
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 if interpreter == "" or not FileSystemUtilities.isinpath(interpreter):
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 interpreter = PythonUtilities.getPythonExecutable()
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 checker = os.path.join(getConfig("ericDir"), "SystemUtilities", "PySideImporter.py")
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 args = [checker, "--variant={0}".format(variant)]
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 proc = QProcess()
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 proc.setProcessChannelMode(QProcess.ProcessChannelMode.MergedChannels)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 proc.start(interpreter, args)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 finished = proc.waitForFinished(30000)
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 return finished and proc.exitCode() == 0

eric ide

mercurial