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