eric6/eric6.py

branch
without_py2_and_pyqt4
changeset 7192
a22eee00b052
parent 6949
a5255f1ba3f0
child 7198
684261ef2165
equal deleted inserted replaced
7191:960850ec284c 7192:a22eee00b052
26 if arg.split("=", 1)[0] in restartArgsList] 26 if arg.split("=", 1)[0] in restartArgsList]
27 27
28 sys.path.insert(1, os.path.dirname(__file__)) 28 sys.path.insert(1, os.path.dirname(__file__))
29 29
30 import Toolbox.PyQt4ImportHook # __IGNORE_WARNING__ 30 import Toolbox.PyQt4ImportHook # __IGNORE_WARNING__
31
32 try: # Only for Py2
33 import Globals.compatibility_fixes # __IGNORE_WARNING__
34 import StringIO as io # __IGNORE_EXCEPTION__
35 import locale
36 except ImportError:
37 import io # __IGNORE_WARNING__
38 basestring = str
39 31
40 try: 32 try:
41 try: 33 try:
42 from PyQt5 import sip # __IGNORE_EXCEPTION__ 34 from PyQt5 import sip # __IGNORE_EXCEPTION__
43 except ImportError: 35 except ImportError:
47 pass 39 pass
48 40
49 import traceback 41 import traceback
50 import time 42 import time
51 import logging 43 import logging
44 import io
52 45
53 try: 46 try:
54 from PyQt5.QtCore import qWarning, QLibraryInfo, QTimer, QCoreApplication 47 from PyQt5.QtCore import qWarning, QLibraryInfo, QTimer, QCoreApplication
55 except ImportError: 48 except ImportError:
56 try: # Py2 49 try:
57 import tkMessageBox as messagebox 50 from tkinter import messagebox
58 except ImportError: 51 except ImportError:
59 try: # Py3 52 sys.exit(100)
60 from tkinter import messagebox
61 except ImportError:
62 sys.exit(100)
63 messagebox.showerror( 53 messagebox.showerror(
64 "eric6 Error", 54 "eric6 Error",
65 "PyQt could not be imported. Please make sure" 55 "PyQt could not be imported. Please make sure"
66 " it is installed and accessible.") 56 " it is installed and accessible.")
67 sys.exit(100) 57 sys.exit(100)
192 versionInfo += "{0}\n{1}".format(separator, pluginVersionInfo) 182 versionInfo += "{0}\n{1}".format(separator, pluginVersionInfo)
193 distroInfo = Utilities.generateDistroInfo() 183 distroInfo = Utilities.generateDistroInfo()
194 if distroInfo: 184 if distroInfo:
195 versionInfo += "{0}\n{1}".format(separator, distroInfo) 185 versionInfo += "{0}\n{1}".format(separator, distroInfo)
196 186
197 if isinstance(excType, basestring): 187 if isinstance(excType, str):
198 tbinfo = tracebackobj 188 tbinfo = tracebackobj
199 else: 189 else:
200 tbinfofile = io.StringIO() 190 tbinfofile = io.StringIO()
201 traceback.print_tb(tracebackobj, None, tbinfofile) 191 traceback.print_tb(tracebackobj, None, tbinfofile)
202 tbinfofile.seek(0) 192 tbinfofile.seek(0)
203 tbinfo = tbinfofile.read() 193 tbinfo = tbinfofile.read()
204 if sys.version_info[0] == 2:
205 tbinfo = tbinfo.decode(locale.getpreferredencoding())
206 errmsg = '{0}: \n{1}'.format(str(excType), str(excValue)) 194 errmsg = '{0}: \n{1}'.format(str(excType), str(excValue))
207 sections = [separator, timeString, separator, errmsg, separator, tbinfo] 195 sections = [separator, timeString, separator, errmsg, separator, tbinfo]
208 msg = '\n'.join(sections) 196 msg = '\n'.join(sections)
209 try: 197 try:
210 f = open(logFile, "w", encoding="utf-8") 198 f = open(logFile, "w", encoding="utf-8")
213 f.close() 201 f.close()
214 except IOError: 202 except IOError:
215 pass 203 pass
216 204
217 if inMainLoop is None: 205 if inMainLoop is None:
218 if sys.version_info[0] == 2:
219 notice = notice.encode(sys.stdout.encoding, 'replace')
220 msg = msg.encode(sys.stdout.encoding, 'replace')
221 versionInfo = versionInfo.encode(sys.stdout.encoding, 'replace')
222 warning = notice + msg + versionInfo 206 warning = notice + msg + versionInfo
223 print(warning) # __IGNORE_WARNING_M801__ 207 print(warning) # __IGNORE_WARNING_M801__
224 else: 208 else:
225 warning = notice + msg + versionInfo 209 warning = notice + msg + versionInfo
226 # Escape &<> otherwise it's not visible in the error dialog 210 # Escape &<> otherwise it's not visible in the error dialog
227 warning = warning\ 211 warning = warning\
228 .replace("&", "&amp;")\ 212 .replace("&", "&amp;")\
229 .replace(">", "&gt;")\ 213 .replace(">", "&gt;")\
230 .replace("<", "&lt;") 214 .replace("<", "&lt;")
231 if sys.version_info[0] == 2:
232 warning = warning.encode('utf-8', 'replace')
233 qWarning(warning) 215 qWarning(warning)
234 216
235 217
236 def uiStartUp(): 218 def uiStartUp():
237 """ 219 """
333 pyqtDataDir = Globals.getPyQt5ModulesDirectory() 315 pyqtDataDir = Globals.getPyQt5ModulesDirectory()
334 if os.path.exists(os.path.join(pyqtDataDir, "bin")): 316 if os.path.exists(os.path.join(pyqtDataDir, "bin")):
335 path = os.path.join(pyqtDataDir, "bin") 317 path = os.path.join(pyqtDataDir, "bin")
336 else: 318 else:
337 path = pyqtDataDir 319 path = pyqtDataDir
338 if sys.version_info[0] == 2:
339 path = path.encode(sys.getfilesystemencoding())
340 os.environ["PATH"] = path + os.pathsep + os.environ["PATH"] 320 os.environ["PATH"] = path + os.pathsep + os.environ["PATH"]
341 321
342 pluginFile = None 322 pluginFile = None
343 noopen = False 323 noopen = False
344 nocrash = False 324 nocrash = False

eric ide

mercurial