eric6/Globals/__init__.py

Sat, 27 Jul 2019 15:40:51 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Jul 2019 15:40:51 +0200
branch
micropython
changeset 7085
328f0f44aa95
parent 6942
2602857055c5
child 7192
a22eee00b052
permissions
-rw-r--r--

Globals: changed format of the data size output and added branch for TiB.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6630
diff changeset
3 # Copyright (c) 2006 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module defining common data to be used by all modules.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
4343
afe0da217745 Added the '--settings=' command line switch to store the settings files in a non-standard directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4241
diff changeset
10 #
afe0da217745 Added the '--settings=' command line switch to store the settings files in a non-standard directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4241
diff changeset
11 # Note: Do not import any eric stuff in here!!!!!!!
afe0da217745 Added the '--settings=' command line switch to store the settings files in a non-standard directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4241
diff changeset
12 #
afe0da217745 Added the '--settings=' command line switch to store the settings files in a non-standard directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4241
diff changeset
13
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3060
diff changeset
14 from __future__ import unicode_literals
6630
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
15 try:
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
16 str = unicode # __IGNORE_EXCEPTION__
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
17 except NameError:
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
18 pass
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
19
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 import sys
1162
ab292b7f4f8a Added code to search for a Python2 interpreter in some known places. If none is found, the user can configure it on the Debugger, Python config page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
21 import os
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
22 import re
6474
72c063cc730b Globals.__init__: fixed an issue that caused startup issues on Windows if both _eric6 and .eric6 were existing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6366
diff changeset
23 import shutil
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
25 from PyQt5.QtCore import QDir, QLibraryInfo, QByteArray, QCoreApplication, \
6630
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
26 QT_VERSION_STR, QT_VERSION, QProcess, qVersion
2087
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
27
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 # names of the various settings objects
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
29 settingsNameOrganization = "Eric6"
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
30 settingsNameGlobal = "eric6"
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
31 settingsNameRecent = "eric6recent"
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 # key names of the various recent entries
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 recentNameMultiProject = "MultiProjects"
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 recentNameProject = "Projects"
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 recentNameFiles = "Files"
4695
9dc08852de25 Added a 'Recent Files' menu to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4686
diff changeset
37 recentNameHexFiles = "HexFiles"
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1162
diff changeset
38 recentNameHosts = "Hosts6"
6034
4f88f70d2cd4 Added the capability to remember the most recently used file names and conditions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5859
diff changeset
39 recentNameBreakpointFiles = "BreakPointFiles"
4f88f70d2cd4 Added the capability to remember the most recently used file names and conditions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5859
diff changeset
40 recentNameBreakpointConditions = "BreakPointConditions"
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
2087
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
42 configDir = None
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
43
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
44
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 def isWindowsPlatform():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 Function to check, if this is a Windows platform.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @return flag indicating Windows platform (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
6289
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
51 return sys.platform.startswith(("win", "cygwin"))
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
52
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
53
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
54 def isMacPlatform():
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
55 """
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
56 Function to check, if this is a Mac platform.
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
57
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
58 @return flag indicating Mac platform (boolean)
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
59 """
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
60 return sys.platform == "darwin"
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
61
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
62
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
63 def isLinuxPlatform():
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
64 """
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
65 Function to check, if this is a Linux platform.
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
66
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
67 @return flag indicating Linux platform (boolean)
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
68 """
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
69 return sys.platform.startswith("linux")
1162
ab292b7f4f8a Added code to search for a Python2 interpreter in some known places. If none is found, the user can configure it on the Debugger, Python config page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
70
ab292b7f4f8a Added code to search for a Python2 interpreter in some known places. If none is found, the user can configure it on the Debugger, Python config page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
71
6289
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
72 def desktopName():
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
73 """
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
74 Function to determine the name of the desktop environment used
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
75 (Linux only).
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
76
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
77 @return name of the desktop environment
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
78 @rtype str
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
79 """
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
80 if not isLinuxPlatform():
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
81 return ""
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
82
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
83 currDesktop = os.environ.get("XDG_CURRENT_DESKTOP", "")
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
84 if currDesktop:
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
85 return currDesktop
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
86
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
87 currDesktop = os.environ.get("XDG_SESSION_DESKTOP", "")
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
88 if currDesktop:
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
89 return currDesktop
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
90
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
91 currDesktop = os.environ.get("GDMSESSION", "")
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
92 if currDesktop:
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
93 return currDesktop
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
94
6914
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
95 currDesktop = os.environ.get("GNOME_DESKTOP_SESSION_ID", "")
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
96 if currDesktop:
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
97 return currDesktop
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
98
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
99 currDesktop = os.environ.get("KDE_FULL_SESSION", "")
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
100 if currDesktop:
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
101 return currDesktop
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
102
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
103 currDesktop = os.environ.get("DESKTOP_SESSION", "")
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
104 if currDesktop:
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
105 return currDesktop
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
106
6289
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
107 return ""
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
108
f481df37413c Extended the error report to send the desktop environment in use (Linux only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
109
6914
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
110 def isKdeDesktop():
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
111 """
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
112 Function to check, if the current session is a KDE desktop (Linux only).
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
113
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
114 @return flag indicating a KDE desktop
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
115 @rtype bool
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
116 """
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
117 if not isLinuxPlatform():
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
118 return False
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
119
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
120 isKDE = False
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
121
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
122 desktop = os.environ.get("XDG_CURRENT_DESKTOP", "").lower() or \
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
123 os.environ.get("XDG_SESSION_DESKTOP", "").lower() or \
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
124 os.environ.get("DESKTOP_SESSION", "").lower()
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
125 if desktop:
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
126 isKDE = "kde" in desktop or "plasma" in desktop
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
127 else:
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
128 isKDE = bool(os.environ.get("KDE_FULL_SESSION", ""))
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
129
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
130 return isKDE
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
131
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
132
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
133 def isGnomeDesktop():
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
134 """
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
135 Function to check, if the current session is a Gnome desktop (Linux only).
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
136
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
137 @return flag indicating a Gnome desktop
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
138 @rtype bool
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
139 """
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
140 if not isLinuxPlatform():
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
141 return False
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
142
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
143 isGnome = False
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
144
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
145 desktop = os.environ.get("XDG_CURRENT_DESKTOP", "").lower() or \
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
146 os.environ.get("XDG_SESSION_DESKTOP", "").lower() or \
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
147 os.environ.get("GDMSESSION", "").lower()
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
148 if desktop:
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
149 isGnome = "gnome" in desktop
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
150 else:
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
151 isGnome = bool(os.environ.get("GNOME_DESKTOP_SESSION_ID", ""))
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
152
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
153 return isGnome
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
154
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
155
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
156 def sessionType():
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
157 """
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
158 Function to determine the name of the running session (Linux only).
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
159
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
160 @return name of the desktop environment
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
161 @rtype str
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
162 """
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
163 if not isLinuxPlatform():
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
164 return ""
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
165
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
166 sessionType = os.environ.get("XDG_SESSION_TYPE").lower()
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
167 if "x11" in sessionType:
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
168 return "X11"
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
169 elif "wayland" in sessionType:
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
170 return "Wayland"
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
171
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
172 sessionType = os.environ.get("WAYLAND_DISPLAY", "").lower()
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
173 if "wayland" in sessionType:
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
174 return "Wayland"
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
175
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
176 return ""
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
177
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
178
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
179 def isWaylandSession():
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
180 """
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
181 Function to check, if the current session is a wayland session.
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
182
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
183 @return flag indicating a wayland session
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
184 @rtype bool
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
185 """
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
186 return sessionType() == "Wayland"
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
187
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6682
diff changeset
188
2087
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
189 def getConfigDir():
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
190 """
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
191 Module function to get the name of the directory storing the config data.
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
192
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
193 @return directory name of the config dir (string)
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
194 """
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
195 if configDir is not None and os.path.exists(configDir):
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
196 hp = configDir
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
197 else:
6303
ec9ebaf206fb Got rid of the Windows "DotNet"-Hack (i.e. using _ instead of . as first character of special directories).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6289
diff changeset
198 cdn = ".eric6"
2087
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
199 if isWindowsPlatform():
6303
ec9ebaf206fb Got rid of the Windows "DotNet"-Hack (i.e. using _ instead of . as first character of special directories).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6289
diff changeset
200 # migrate the old config directory (< v18.06)
ec9ebaf206fb Got rid of the Windows "DotNet"-Hack (i.e. using _ instead of . as first character of special directories).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6289
diff changeset
201 cdnOld = "_eric6"
ec9ebaf206fb Got rid of the Windows "DotNet"-Hack (i.e. using _ instead of . as first character of special directories).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6289
diff changeset
202 hpOld = os.path.join(os.path.expanduser("~"), cdnOld)
ec9ebaf206fb Got rid of the Windows "DotNet"-Hack (i.e. using _ instead of . as first character of special directories).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6289
diff changeset
203 if os.path.exists(hpOld):
ec9ebaf206fb Got rid of the Windows "DotNet"-Hack (i.e. using _ instead of . as first character of special directories).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6289
diff changeset
204 hpNew = os.path.join(os.path.expanduser("~"), cdn)
6474
72c063cc730b Globals.__init__: fixed an issue that caused startup issues on Windows if both _eric6 and .eric6 were existing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6366
diff changeset
205 if os.path.exists(hpNew):
72c063cc730b Globals.__init__: fixed an issue that caused startup issues on Windows if both _eric6 and .eric6 were existing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6366
diff changeset
206 # simply delete the old config directory
6530
25b9dcfd6fcc Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6474
diff changeset
207 shutil.rmtree(hpOld, True)
6474
72c063cc730b Globals.__init__: fixed an issue that caused startup issues on Windows if both _eric6 and .eric6 were existing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6366
diff changeset
208 else:
72c063cc730b Globals.__init__: fixed an issue that caused startup issues on Windows if both _eric6 and .eric6 were existing.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6366
diff changeset
209 os.rename(hpOld, hpNew)
6303
ec9ebaf206fb Got rid of the Windows "DotNet"-Hack (i.e. using _ instead of . as first character of special directories).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6289
diff changeset
210
5823
70dfe6a4aa03 Fixed an issue getting the home directory during uninstallation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
211 hp = os.path.join(os.path.expanduser("~"), cdn)
70dfe6a4aa03 Fixed an issue getting the home directory during uninstallation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
212 if not os.path.exists(hp):
70dfe6a4aa03 Fixed an issue getting the home directory during uninstallation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
213 os.mkdir(hp)
70dfe6a4aa03 Fixed an issue getting the home directory during uninstallation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
214 return hp
2087
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
215
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
216
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
217 def setConfigDir(d):
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
218 """
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
219 Module function to set the name of the directory storing the config data.
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
220
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
221 @param d name of an existing directory (string)
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
222 """
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
223 global configDir
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
224 configDir = os.path.expanduser(d)
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
225
795992a5c561 Made the sixth set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
226
2608
01118174a2f5 Changed code to be compatible with latest PyQt4 Windows installers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
227 def getPythonModulesDirectory():
01118174a2f5 Changed code to be compatible with latest PyQt4 Windows installers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
228 """
01118174a2f5 Changed code to be compatible with latest PyQt4 Windows installers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
229 Function to determine the path to Python's modules directory.
01118174a2f5 Changed code to be compatible with latest PyQt4 Windows installers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
230
01118174a2f5 Changed code to be compatible with latest PyQt4 Windows installers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
231 @return path to the Python modules directory (string)
01118174a2f5 Changed code to be compatible with latest PyQt4 Windows installers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
232 """
01118174a2f5 Changed code to be compatible with latest PyQt4 Windows installers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
233 import distutils.sysconfig
01118174a2f5 Changed code to be compatible with latest PyQt4 Windows installers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
234 return distutils.sysconfig.get_python_lib(True)
2614
9c49b4419ea7 Changed the logic for detecting and using the PyQt4 module directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2608
diff changeset
235
9c49b4419ea7 Changed the logic for detecting and using the PyQt4 module directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2608
diff changeset
236
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
237 def getPyQt5ModulesDirectory():
2614
9c49b4419ea7 Changed the logic for detecting and using the PyQt4 module directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2608
diff changeset
238 """
3807
91fc2089c401 Added some more PyQt4 compatibility code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3778
diff changeset
239 Function to determine the path to PyQt5's (or PyQt4's) modules directory.
2614
9c49b4419ea7 Changed the logic for detecting and using the PyQt4 module directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2608
diff changeset
240
3807
91fc2089c401 Added some more PyQt4 compatibility code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3778
diff changeset
241 @return path to the PyQt5/PyQt4 modules directory (string)
2614
9c49b4419ea7 Changed the logic for detecting and using the PyQt4 module directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2608
diff changeset
242 """
9c49b4419ea7 Changed the logic for detecting and using the PyQt4 module directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2608
diff changeset
243 import distutils.sysconfig
3807
91fc2089c401 Added some more PyQt4 compatibility code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3778
diff changeset
244 for pyqt in ["PyQt5", "PyQt4"]:
91fc2089c401 Added some more PyQt4 compatibility code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3778
diff changeset
245 pyqtPath = os.path.join(distutils.sysconfig.get_python_lib(True), pyqt)
91fc2089c401 Added some more PyQt4 compatibility code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3778
diff changeset
246 if os.path.exists(pyqtPath):
91fc2089c401 Added some more PyQt4 compatibility code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3778
diff changeset
247 return pyqtPath
91fc2089c401 Added some more PyQt4 compatibility code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3778
diff changeset
248
91fc2089c401 Added some more PyQt4 compatibility code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3778
diff changeset
249 return ""
2608
01118174a2f5 Changed code to be compatible with latest PyQt4 Windows installers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
250
01118174a2f5 Changed code to be compatible with latest PyQt4 Windows installers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
251
5696
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
252 def getPyQtToolsPath(version=5):
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
253 """
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
254 Module function to get the path of the PyQt tools.
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
255
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
256 @param version PyQt major version
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
257 @type int
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
258 @return path to the PyQt tools
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
259 @rtype str
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
260 """
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
261 import Preferences
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
262
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
263 path = ""
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
264
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
265 # step 1: check, if the user has configured a tools path
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
266 path = Preferences.getQt("PyQtToolsDir")
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
267
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
268 # step 2: determine from used Python interpreter (pyrcc is test object)
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
269 if not path:
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
270 program = "pyrcc{0}".format(version)
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
271 if isWindowsPlatform():
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
272 program += ".exe"
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
273 dirName = os.path.dirname(sys.executable)
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
274 if os.path.exists(os.path.join(dirName, program)):
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
275 path = dirName
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
276 elif os.path.exists(os.path.join(dirName, "Scripts", program)):
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
277 path = os.path.join(dirName, "Scripts")
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
278 else:
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
279 dirName = os.path.dirname(sys.executable)
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
280 if os.path.exists(os.path.join(dirName, program)):
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
281 path = dirName
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
282
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
283 return path
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
284
68af0e9c57ad Started implementing the capability to configure the path to the PyQt tools or determine it based on the current Python interpreter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5401
diff changeset
285
2615
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
286 def getQtBinariesPath():
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
287 """
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
288 Module function to get the path of the Qt binaries.
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
289
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
290 @return path of the Qt binaries (string)
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
291 """
5070
4e4651e88674 Added capability to set the path to the Qt tools manually (because they are not included in the PyQt5 wheels).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4828
diff changeset
292 import Preferences
4e4651e88674 Added capability to set the path to the Qt tools manually (because they are not included in the PyQt5 wheels).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4828
diff changeset
293
2615
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
294 path = ""
5070
4e4651e88674 Added capability to set the path to the Qt tools manually (because they are not included in the PyQt5 wheels).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4828
diff changeset
295
4e4651e88674 Added capability to set the path to the Qt tools manually (because they are not included in the PyQt5 wheels).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4828
diff changeset
296 # step 1: check, if the user has configured a tools path
4e4651e88674 Added capability to set the path to the Qt tools manually (because they are not included in the PyQt5 wheels).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4828
diff changeset
297 path = Preferences.getQt("QtToolsDir")
4e4651e88674 Added capability to set the path to the Qt tools manually (because they are not included in the PyQt5 wheels).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4828
diff changeset
298
4e4651e88674 Added capability to set the path to the Qt tools manually (because they are not included in the PyQt5 wheels).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4828
diff changeset
299 if not path and isWindowsPlatform():
4e4651e88674 Added capability to set the path to the Qt tools manually (because they are not included in the PyQt5 wheels).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4828
diff changeset
300 # step 2.1: check for PyQt5 Windows installer (designer is test object)
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
301 modDir = getPyQt5ModulesDirectory()
2615
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
302 if os.path.exists(os.path.join(modDir, "bin", "designer.exe")):
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
303 path = os.path.join(modDir, "bin")
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
304 elif os.path.exists(os.path.join(modDir, "designer.exe")):
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
305 path = modDir
5735
f606dbe20be6 Added code to auto-discover the presence of the new 'pyqt5-tools' wheel (Windows only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5696
diff changeset
306
f606dbe20be6 Added code to auto-discover the presence of the new 'pyqt5-tools' wheel (Windows only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5696
diff changeset
307 if not path:
f606dbe20be6 Added code to auto-discover the presence of the new 'pyqt5-tools' wheel (Windows only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5696
diff changeset
308 import distutils.sysconfig
6589
613426e62983 Globals, UserInterface: improved the detection of the Qt tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6530
diff changeset
309 # step 2.2.1: check for the pyqt5-tools wheel (new variant)
613426e62983 Globals, UserInterface: improved the detection of the Qt tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6530
diff changeset
310 # (Windows only)
5735
f606dbe20be6 Added code to auto-discover the presence of the new 'pyqt5-tools' wheel (Windows only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5696
diff changeset
311 pyqt5ToolsPath = os.path.join(
6589
613426e62983 Globals, UserInterface: improved the detection of the Qt tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6530
diff changeset
312 distutils.sysconfig.get_python_lib(True), "pyqt5_tools")
5735
f606dbe20be6 Added code to auto-discover the presence of the new 'pyqt5-tools' wheel (Windows only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5696
diff changeset
313 if os.path.exists(os.path.join(pyqt5ToolsPath, "designer.exe")):
f606dbe20be6 Added code to auto-discover the presence of the new 'pyqt5-tools' wheel (Windows only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5696
diff changeset
314 path = pyqt5ToolsPath
6589
613426e62983 Globals, UserInterface: improved the detection of the Qt tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6530
diff changeset
315 if not path:
613426e62983 Globals, UserInterface: improved the detection of the Qt tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6530
diff changeset
316 # step 2.2.2: check for the pyqt5-tools wheel (old variant)
613426e62983 Globals, UserInterface: improved the detection of the Qt tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6530
diff changeset
317 # (Windows only)
613426e62983 Globals, UserInterface: improved the detection of the Qt tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6530
diff changeset
318 pyqt5ToolsPath = os.path.join(
613426e62983 Globals, UserInterface: improved the detection of the Qt tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6530
diff changeset
319 distutils.sysconfig.get_python_lib(True), "pyqt5-tools")
613426e62983 Globals, UserInterface: improved the detection of the Qt tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6530
diff changeset
320 if os.path.exists(os.path.join(pyqt5ToolsPath,
613426e62983 Globals, UserInterface: improved the detection of the Qt tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6530
diff changeset
321 "designer.exe")):
613426e62983 Globals, UserInterface: improved the detection of the Qt tools.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6530
diff changeset
322 path = pyqt5ToolsPath
2615
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
323
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
324 if not path:
5735
f606dbe20be6 Added code to auto-discover the presence of the new 'pyqt5-tools' wheel (Windows only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5696
diff changeset
325 # step 3: get the path from Qt
f606dbe20be6 Added code to auto-discover the presence of the new 'pyqt5-tools' wheel (Windows only).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5696
diff changeset
326 # Note: no Qt tools are to be found there for PyQt 5.7.0
2615
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
327 path = QLibraryInfo.location(QLibraryInfo.BinariesPath)
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
328 if not os.path.exists(path):
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
329 path = ""
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
330
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
331 return QDir.toNativeSeparators(path)
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
332
bdc9b4659826 Added a method to determine the Qt binaries path to the Globals package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2614
diff changeset
333
4828
b313794f46a2 updated pep8 to 1.7.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4724
diff changeset
334 def translate(*args):
b313794f46a2 updated pep8 to 1.7.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4724
diff changeset
335 """
b313794f46a2 updated pep8 to 1.7.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4724
diff changeset
336 Module function to handle different PyQt 4/5 QCoreApplication.translate
b313794f46a2 updated pep8 to 1.7.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4724
diff changeset
337 parameter.
b313794f46a2 updated pep8 to 1.7.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4724
diff changeset
338
b313794f46a2 updated pep8 to 1.7.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4724
diff changeset
339 @param args tuple of arguments from QCoreApplication.translate (tuple)
b313794f46a2 updated pep8 to 1.7.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4724
diff changeset
340 @return translated string (string)
b313794f46a2 updated pep8 to 1.7.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4724
diff changeset
341 """
5848
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
342 if QT_VERSION_STR.startswith('4.'):
4828
b313794f46a2 updated pep8 to 1.7.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4724
diff changeset
343 args = list(args)
b313794f46a2 updated pep8 to 1.7.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4724
diff changeset
344 args.insert(3, QCoreApplication.CodecForTr)
b313794f46a2 updated pep8 to 1.7.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4724
diff changeset
345 return QCoreApplication.translate(*args)
b313794f46a2 updated pep8 to 1.7.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4724
diff changeset
346
b313794f46a2 updated pep8 to 1.7.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4724
diff changeset
347
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
348 ###############################################################################
5848
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
349 ## functions for version handling
4686
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
350 ###############################################################################
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
351
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
352
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
353 def versionToTuple(version):
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
354 """
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
355 Module function to convert a version string into a tuple.
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
356
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
357 Note: A version string consists of non-negative decimals separated by "."
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
358 optionally followed by a suffix. Suffix is everything after the last
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
359 decimal.
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
360
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
361 @param version version string
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
362 @type str
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
363 @return version tuple without the suffix
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
364 @rtype tuple of int
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
365 """
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
366 versionParts = []
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
367
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
368 # step 1: extract suffix
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
369 version = re.split(r"[^\d.]", version)[0]
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
370 for part in version.split("."):
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
371 versionParts.append(int(part))
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
372
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
373 return tuple(versionParts)
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
374
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
375
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
376 def qVersionTuple():
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
377 """
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
378 Module function to get the Qt version as a tuple.
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
379
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
380 @return Qt version as a tuple
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
381 @rtype tuple of int
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
382 """
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
383 return (
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
384 (QT_VERSION & 0xff0000) >> 16,
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
385 (QT_VERSION & 0xff00) >> 8,
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
386 QT_VERSION & 0xff,
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
387 )
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
388
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
389
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
390 ###############################################################################
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
391 ## functions for extended string handling
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
392 ###############################################################################
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
393
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5735
diff changeset
394
4686
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
395 def strGroup(txt, sep, groupLen=4):
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
396 """
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
397 Module function to group a string into sub-strings separated by a
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
398 separator.
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
399
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
400 @param txt text to be grouped
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
401 @type str
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
402 @param sep separator string
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
403 @type str
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
404 @param groupLen length of each group
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
405 @type int
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
406 @return result string
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
407 @rtype str
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
408 """
4724
682f009d086d Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4695
diff changeset
409 groups = []
4686
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
410
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
411 while len(txt) // groupLen != 0:
4724
682f009d086d Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4695
diff changeset
412 groups.insert(0, txt[-groupLen:])
4686
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
413 txt = txt[:-groupLen]
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
414 if len(txt) > 0:
4724
682f009d086d Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4695
diff changeset
415 groups.insert(0, txt)
682f009d086d Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4695
diff changeset
416 return sep.join(groups)
4686
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
417
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
418
5848
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
419 def strToQByteArray(txt):
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
420 """
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
421 Module function to convert a Python string into a QByteArray.
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
422
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
423 @param txt Python string to be converted
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
424 @type str, bytes, bytearray, unicode
5859
28282fa0df7b Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5848
diff changeset
425 @return converted QByteArray
28282fa0df7b Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5848
diff changeset
426 @rtype QByteArray
5848
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
427 """
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
428 if sys.version_info[0] == 2:
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
429 if isinstance(txt, unicode): # __IGNORE_WARNING__
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
430 txt = txt.encode("utf-8")
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
431 else:
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
432 if isinstance(txt, str):
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
433 txt = txt.encode("utf-8")
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
434
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
435 return QByteArray(txt)
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
436
56388f41b1e6 Fixed an issue sending input to the mercurial and subversion processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5823
diff changeset
437
6682
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
438 def dataString(size):
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
439 """
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
440 Module function to generate a formatted size string.
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
441
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
442 @param size size to be formatted
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
443 @type int
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
444 @return formatted data string
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
445 @rtype str
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
446 """
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
447 if size < 1024:
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
448 return QCoreApplication.translate(
7085
328f0f44aa95 Globals: changed format of the data size output and added branch for TiB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
449 "Globals", "{0:4.2f} Bytes").format(size)
6682
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
450 elif size < 1024 * 1024:
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
451 size /= 1024
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
452 return QCoreApplication.translate(
7085
328f0f44aa95 Globals: changed format of the data size output and added branch for TiB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
453 "Globals", "{0:4.2f} KiB").format(size)
6682
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
454 elif size < 1024 * 1024 * 1024:
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
455 size /= 1024 * 1024
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
456 return QCoreApplication.translate(
7085
328f0f44aa95 Globals: changed format of the data size output and added branch for TiB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
457 "Globals", "{0:4.2f} MiB").format(size)
328f0f44aa95 Globals: changed format of the data size output and added branch for TiB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
458 elif size < 1024 * 1024 * 1024 * 1024:
6682
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
459 size /= 1024 * 1024 * 1024
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
460 return QCoreApplication.translate(
7085
328f0f44aa95 Globals: changed format of the data size output and added branch for TiB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
461 "Globals", "{0:4.2f} GiB").format(size)
328f0f44aa95 Globals: changed format of the data size output and added branch for TiB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
462 else:
328f0f44aa95 Globals: changed format of the data size output and added branch for TiB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
463 size /= 1024 * 1024 * 1024 * 1024
328f0f44aa95 Globals: changed format of the data size output and added branch for TiB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
464 return QCoreApplication.translate(
328f0f44aa95 Globals: changed format of the data size output and added branch for TiB.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
465 "Globals", "{0:4.2f} TiB").format(size)
6682
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
466
4326e802ff56 Globals: added the dataString() function to format a size into a human readable string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
467
4686
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
468 ###############################################################################
4241
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
469 ## functions for converting QSetting return types to valid types
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
470 ###############################################################################
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
471
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
472
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
473 def toBool(value):
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
474 """
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
475 Module function to convert a value to bool.
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
476
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
477 @param value value to be converted
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
478 @return converted data
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
479 """
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
480 if value in ["true", "1", "True"]:
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
481 return True
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
482 elif value in ["false", "0", "False"]:
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
483 return False
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
484 else:
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
485 return bool(value)
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
486
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
487
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
488 def toList(value):
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
489 """
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
490 Module function to convert a value to a list.
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
491
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
492 @param value value to be converted
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
493 @return converted data
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
494 """
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
495 if value is None:
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
496 return []
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
497 elif not isinstance(value, list):
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
498 return [value]
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
499 else:
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
500 return value
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
501
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
502
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
503 def toByteArray(value):
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
504 """
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
505 Module function to convert a value to a byte array.
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
506
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
507 @param value value to be converted
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
508 @return converted data
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
509 """
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
510 if value is None:
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
511 return QByteArray()
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
512 else:
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
513 return value
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
514
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
515
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
516 def toDict(value):
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
517 """
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
518 Module function to convert a value to a dictionary.
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
519
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
520 @param value value to be converted
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
521 @return converted data
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
522 """
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
523 if value is None:
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
524 return {}
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
525 else:
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
526 return value
4566
a2e8f3c420ec Dealt with the M801 code style checker messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4343
diff changeset
527
6630
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
528
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
529 ###############################################################################
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
530 ## functions for web browser variant detection
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
531 ###############################################################################
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
532
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
533
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
534 def getWebBrowserSupport():
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
535 """
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
536 Module function to determine the supported web browser variant.
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
537
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
538 @return string indicating the supported web browser variant ("QtWebEngine",
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
539 "QtWebKit" or "None")
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
540 @rtype str
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
541 """
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
542 from eric6config import getConfig
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
543 scriptPath = os.path.join(getConfig("ericDir"), "Tools",
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
544 "webBrowserSupport.py")
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
545 proc = QProcess()
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
546 proc.start(sys.executable, [scriptPath, qVersion()])
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
547 if proc.waitForFinished(10000):
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
548 variant = str(proc.readAllStandardOutput(), "utf-8", 'replace').strip()
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
549 else:
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
550 variant = "None"
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6589
diff changeset
551 return variant
4566
a2e8f3c420ec Dealt with the M801 code style checker messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4343
diff changeset
552 #
a2e8f3c420ec Dealt with the M801 code style checker messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4343
diff changeset
553 # eflag: noqa = M801

eric ide

mercurial