eric6_browser.py

branch
maintenance
changeset 6646
51eefa621de4
parent 6645
ad476851d7e0
child 6702
793af5761910
equal deleted inserted replaced
6603:77189681b787 6646:51eefa621de4
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 # Copyright (c) 2002 - 2018 Detlev Offenbach <detlev@die-offenbachs.de> 4 # Copyright (c) 2002 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
5 # 5 #
6 6
7 """ 7 """
8 Eric6 Web Browser. 8 Eric6 Web Browser.
9 9
35 35
36 from Globals import qVersionTuple 36 from Globals import qVersionTuple
37 37
38 38
39 if qVersionTuple() < (5, 6, 0): 39 if qVersionTuple() < (5, 6, 0):
40 from PyQt5.QtCore import QTimer 40 if "--quiet" not in sys.argv:
41 from PyQt5.QtWidgets import QApplication 41 from PyQt5.QtCore import QTimer
42 from E5Gui import E5MessageBox 42 from PyQt5.QtWidgets import QApplication
43 app = QApplication([]) 43 from E5Gui import E5MessageBox
44 QTimer.singleShot(0, lambda: E5MessageBox.critical( 44 app = QApplication([])
45 None, 45 QTimer.singleShot(0, lambda: E5MessageBox.critical(
46 "eric6 Web Browser", 46 None,
47 "You need at least Qt Version 5.6.0 to execute the web browser.") 47 "eric6 Web Browser",
48 ) 48 "You need at least Qt Version 5.6.0 to execute the web browser.")
49 app.exec_() 49 )
50 app.exec_()
50 sys.exit(100) 51 sys.exit(100)
51 52
52 SettingsDir = None 53 SettingsDir = None
53 54
54 for arg in sys.argv[:]: 55 for arg in sys.argv[:]:
73 "ThirdParty", "EditorConfig")) 74 "ThirdParty", "EditorConfig"))
74 75
75 try: 76 try:
76 from PyQt5 import QtWebEngineWidgets # __IGNORE_WARNING__ 77 from PyQt5 import QtWebEngineWidgets # __IGNORE_WARNING__
77 except ImportError: 78 except ImportError:
78 from PyQt5.QtCore import QTimer 79 if "--quiet" not in sys.argv:
79 from PyQt5.QtWidgets import QApplication 80 from PyQt5.QtCore import QTimer
80 from E5Gui import E5MessageBox # __IGNORE_WARNING__ 81 from PyQt5.QtWidgets import QApplication
81 app = QApplication([]) 82 from E5Gui import E5MessageBox # __IGNORE_WARNING__
82 QTimer.singleShot(0, lambda: E5MessageBox.critical( 83 app = QApplication([])
83 None, 84 QTimer.singleShot(0, lambda: E5MessageBox.critical(
84 "eric6 Web Browser", 85 None,
85 "QtWebEngineWidgets is not installed but needed to execute the" 86 "eric6 Web Browser",
86 " web browser.")) 87 "QtWebEngineWidgets is not installed but needed to execute the"
87 app.exec_() 88 " web browser."))
89 app.exec_()
88 sys.exit(100) 90 sys.exit(100)
89 91
90 import Globals 92 import Globals
91 from Globals import AppInfo 93 from Globals import AppInfo
92 94
95 from E5Gui.E5Application import E5Application
96
93 from Toolbox import Startup 97 from Toolbox import Startup
94 98
99 from WebBrowser.WebBrowserSingleApplication import \
100 WebBrowserSingleApplicationClient
101
95 102
96 def createMainWidget(argv): 103 def createMainWidget(argv):
97 """ 104 """
98 Function to create the main widget. 105 Function to create the main widget.
99 106
100 @param argv list of commandline parameters (list of strings) 107 @param argv list of command line parameters
101 @return reference to the main widget (QWidget) 108 @type list of str
109 @return reference to the main widget
110 @rtype QWidget
102 """ 111 """
103 from WebBrowser.WebBrowserWindow import WebBrowserWindow 112 from WebBrowser.WebBrowserWindow import WebBrowserWindow
104 113
105 searchWord = None 114 searchWord = None
106 private = False 115 private = False
107 qthelp = False 116 qthelp = False
117 single = False
118 name = ""
108 119
109 for arg in reversed(argv): 120 for arg in reversed(argv):
110 if arg.startswith("--search="): 121 if arg.startswith("--search="):
111 searchWord = argv[1].split("=", 1)[1] 122 searchWord = argv[1].split("=", 1)[1]
112 argv.remove(arg) 123 argv.remove(arg)
124 elif arg.startswith("--name="):
125 name = arg.replace("--name=", "")
126 argv.remove(arg)
127 elif arg.startswith("--newtab="):
128 # only used for single application client
129 argv.remove(arg)
113 elif arg == "--private": 130 elif arg == "--private":
114 private = True 131 private = True
115 argv.remove(arg) 132 argv.remove(arg)
116 elif arg == "--qthelp": 133 elif arg == "--qthelp":
117 qthelp = True 134 qthelp = True
135 argv.remove(arg)
136 elif arg == "--quiet":
137 # only needed until we reach this point
138 argv.remove(arg)
139 elif arg == "--single":
140 single = True
118 argv.remove(arg) 141 argv.remove(arg)
119 elif arg.startswith("--"): 142 elif arg.startswith("--"):
120 argv.remove(arg) 143 argv.remove(arg)
121 144
122 try: 145 try:
124 except IndexError: 147 except IndexError:
125 home = "" 148 home = ""
126 149
127 browser = WebBrowserWindow(home, '.', None, 'web_browser', 150 browser = WebBrowserWindow(home, '.', None, 'web_browser',
128 searchWord=searchWord, private=private, 151 searchWord=searchWord, private=private,
129 settingsDir=SettingsDir, qthelp=qthelp) 152 settingsDir=SettingsDir, qthelp=qthelp,
153 single=single, saname=name)
130 return browser 154 return browser
131 155
132 156
133 def main(): 157 def main():
134 """ 158 """
137 options = [ 161 options = [
138 ("--config=configDir", 162 ("--config=configDir",
139 "use the given directory as the one containing the config files"), 163 "use the given directory as the one containing the config files"),
140 ("--private", "start the browser in private browsing mode"), 164 ("--private", "start the browser in private browsing mode"),
141 ("--qthelp", "start the browser with support for QtHelp"), 165 ("--qthelp", "start the browser with support for QtHelp"),
166 ("--quiet", "don't show any startup error messages"),
142 ("--search=word", "search for the given word"), 167 ("--search=word", "search for the given word"),
143 ("--settings=settingsDir", 168 ("--settings=settingsDir",
144 "use the given directory to store the settings files"), 169 "use the given directory to store the settings files"),
170 ("--single", "start the browser as a single application"),
145 ] 171 ]
146 appinfo = AppInfo.makeAppInfo(sys.argv, 172 appinfo = AppInfo.makeAppInfo(sys.argv,
147 "eric6 Web Browser", 173 "eric6 Web Browser",
148 "file", 174 "file",
149 "web browser", 175 "web browser",
150 options) 176 options)
151 177
152 if not Globals.checkBlacklistedVersions(): 178 if not Globals.checkBlacklistedVersions():
153 sys.exit(100) 179 sys.exit(100)
154 180
181 # set the library paths for plugins
182 Startup.setLibraryPaths()
183
184 app = E5Application(sys.argv)
185 if "--private" not in sys.argv:
186 client = WebBrowserSingleApplicationClient()
187 res = client.connect()
188 if res > 0:
189 if len(sys.argv) > 1:
190 client.processArgs(sys.argv[1:])
191 sys.exit(0)
192 elif res < 0:
193 print("eric6_browser: {0}".format(client.errstr()))
194 # __IGNORE_WARNING_M801__
195 sys.exit(res)
196
155 res = Startup.simpleAppStartup(sys.argv, 197 res = Startup.simpleAppStartup(sys.argv,
156 appinfo, 198 appinfo,
157 createMainWidget, 199 createMainWidget,
158 installErrorHandler=True) 200 installErrorHandler=True,
201 app=app)
159 sys.exit(res) 202 sys.exit(res)
160 203
161 if __name__ == '__main__': 204 if __name__ == '__main__':
162 main() 205 main()

eric ide

mercurial