eric6/eric6_webbrowser.py

changeset 6942
2602857055c5
parent 6702
793af5761910
child 6947
179eef72c548
child 6949
a5255f1ba3f0
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3
4 # Copyright (c) 2002 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
5 #
6
7 """
8 Eric6 Web Browser.
9
10 This is the main Python script that performs the necessary initialization
11 of the web browser and starts the Qt event loop. This is a standalone version
12 of the integrated helpviewer.
13 """
14
15 from __future__ import unicode_literals
16
17 import Toolbox.PyQt4ImportHook # __IGNORE_WARNING__
18
19 try: # Only for Py2
20 import Globals.compatibility_fixes # __IGNORE_WARNING__
21 except (ImportError):
22 pass
23
24 try:
25 try:
26 from PyQt5 import sip
27 except ImportError:
28 import sip
29 sip.setdestroyonexit(False)
30 except AttributeError:
31 pass
32
33 import sys
34 import os
35
36 try:
37 from PyQt5 import QtWebKit # __IGNORE_WARNING__
38 except ImportError:
39 if "--quiet" not in sys.argv:
40 from PyQt5.QtCore import qVersion, QTimer
41 from PyQt5.QtWidgets import QApplication
42 from E5Gui import E5MessageBox
43 app = QApplication([])
44 QTimer.singleShot(0, lambda: E5MessageBox.critical(
45 None,
46 "eric6 Web Browser (QtWebKit based)",
47 "QtWebKit is needed to run this variant of the eric6 Web Browser."
48 " However, it seems to be missing. You are using Qt {0}, which"
49 " doesn't include this anymore.".format(qVersion())))
50 app.exec_()
51 sys.exit(100)
52
53 for arg in sys.argv[:]:
54 if arg.startswith("--config="):
55 import Globals
56 configDir = arg.replace("--config=", "")
57 Globals.setConfigDir(configDir)
58 sys.argv.remove(arg)
59 elif arg.startswith("--settings="):
60 from PyQt5.QtCore import QSettings
61 settingsDir = os.path.expanduser(arg.replace("--settings=", ""))
62 if not os.path.isdir(settingsDir):
63 os.makedirs(settingsDir)
64 QSettings.setPath(QSettings.IniFormat, QSettings.UserScope,
65 settingsDir)
66 sys.argv.remove(arg)
67
68 # make ThirdParty package available as a packages repository
69 sys.path.insert(2, os.path.join(os.path.dirname(__file__),
70 "ThirdParty", "Pygments"))
71 sys.path.insert(2, os.path.join(os.path.dirname(__file__),
72 "ThirdParty", "EditorConfig"))
73
74 import Globals
75 from Globals import AppInfo
76
77 from E5Gui.E5Application import E5Application
78
79 from Toolbox import Startup
80
81 from Helpviewer.HelpSingleApplication import HelpSingleApplicationClient
82
83 app = None
84
85
86 def createMainWidget(argv):
87 """
88 Function to create the main widget.
89
90 @param argv list of command line parameters
91 @type list of str
92 @return reference to the main widget
93 @rtype QWidget
94 """
95 from Helpviewer.HelpWindow import HelpWindow
96
97 searchWord = None
98 qthelp = False
99 single = False
100 name = ""
101
102 for arg in reversed(argv):
103 if arg.startswith("--search="):
104 searchWord = argv[1].split("=", 1)[1]
105 argv.remove(arg)
106 elif arg.startswith("--name="):
107 name = arg.replace("--name=", "")
108 argv.remove(arg)
109 elif arg.startswith("--newtab="):
110 # only used for single application client
111 argv.remove(arg)
112 elif arg == "--qthelp":
113 qthelp = True
114 argv.remove(arg)
115 elif arg == "--quiet":
116 # only needed until we reach this point
117 argv.remove(arg)
118 elif arg == "--single":
119 single = True
120 argv.remove(arg)
121 elif arg.startswith("--"):
122 argv.remove(arg)
123
124 try:
125 home = argv[1]
126 except IndexError:
127 home = ""
128
129 helpWindow = HelpWindow(home, '.', None, 'help viewer',
130 searchWord=searchWord, qthelp=qthelp,
131 single=single, saname=name)
132 return helpWindow
133
134
135 def main():
136 """
137 Main entry point into the application.
138 """
139 global app
140
141 options = [
142 ("--config=configDir",
143 "use the given directory as the one containing the config files"),
144 ("--qthelp", "start the browser with support for QtHelp"),
145 ("--quiet", "don't show any startup error messages"),
146 ("--search=word", "search for the given word"),
147 ("--settings=settingsDir",
148 "use the given directory to store the settings files"),
149 ("--single", "start the browser as a single application"),
150 ]
151 appinfo = AppInfo.makeAppInfo(sys.argv,
152 "eric6 Web Browser",
153 "file",
154 "web browser",
155 options)
156
157 if not Globals.checkBlacklistedVersions():
158 sys.exit(100)
159
160 # set the library paths for plugins
161 Startup.setLibraryPaths()
162
163 app = E5Application(sys.argv)
164 client = HelpSingleApplicationClient()
165 res = client.connect()
166 if res > 0:
167 if len(sys.argv) > 1:
168 client.processArgs(sys.argv[1:])
169 sys.exit(0)
170 elif res < 0:
171 print("eric6_webbrowser: {0}".format(client.errstr()))
172 # __IGNORE_WARNING_M801__
173 sys.exit(res)
174
175 res = Startup.simpleAppStartup(sys.argv,
176 appinfo,
177 createMainWidget,
178 installErrorHandler=True,
179 app=app)
180 sys.exit(res)
181
182 if __name__ == '__main__':
183 main()

eric ide

mercurial