src/eric7/eric7_browser.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
21 SettingsDir = None 21 SettingsDir = None
22 22
23 for arg in sys.argv[:]: 23 for arg in sys.argv[:]:
24 if arg.startswith("--config="): 24 if arg.startswith("--config="):
25 import Globals 25 import Globals
26
26 configDir = arg.replace("--config=", "") 27 configDir = arg.replace("--config=", "")
27 Globals.setConfigDir(configDir) 28 Globals.setConfigDir(configDir)
28 sys.argv.remove(arg) 29 sys.argv.remove(arg)
29 elif arg.startswith("--settings="): 30 elif arg.startswith("--settings="):
30 from PyQt6.QtCore import QSettings 31 from PyQt6.QtCore import QSettings
32
31 SettingsDir = os.path.expanduser(arg.replace("--settings=", "")) 33 SettingsDir = os.path.expanduser(arg.replace("--settings=", ""))
32 if not os.path.isdir(SettingsDir): 34 if not os.path.isdir(SettingsDir):
33 os.makedirs(SettingsDir) 35 os.makedirs(SettingsDir)
34 QSettings.setPath( 36 QSettings.setPath(
35 QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir) 37 QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir
38 )
36 sys.argv.remove(arg) 39 sys.argv.remove(arg)
37 40
38 try: 41 try:
39 from PyQt6 import QtWebEngineWidgets # __IGNORE_WARNING__ 42 from PyQt6 import QtWebEngineWidgets # __IGNORE_WARNING__
40 except ImportError: 43 except ImportError:
41 if "--quiet" not in sys.argv: 44 if "--quiet" not in sys.argv:
42 from PyQt6.QtCore import QTimer 45 from PyQt6.QtCore import QTimer
43 from PyQt6.QtWidgets import QApplication 46 from PyQt6.QtWidgets import QApplication
44 from EricWidgets import EricMessageBox # __IGNORE_WARNING__ 47 from EricWidgets import EricMessageBox # __IGNORE_WARNING__
48
45 app = QApplication([]) 49 app = QApplication([])
46 QTimer.singleShot(0, lambda: EricMessageBox.critical( 50 QTimer.singleShot(
47 None, 51 0,
48 "eric Web Browser", 52 lambda: EricMessageBox.critical(
49 "QtWebEngineWidgets is not installed but needed to execute the" 53 None,
50 " web browser.")) 54 "eric Web Browser",
55 "QtWebEngineWidgets is not installed but needed to execute the"
56 " web browser.",
57 ),
58 )
51 app.exec() 59 app.exec()
52 sys.exit(100) 60 sys.exit(100)
53 61
54 from PyQt6.QtWebEngineCore import QWebEngineUrlScheme 62 from PyQt6.QtWebEngineCore import QWebEngineUrlScheme
55 63
58 66
59 from EricWidgets.EricApplication import EricApplication 67 from EricWidgets.EricApplication import EricApplication
60 68
61 from Toolbox import Startup 69 from Toolbox import Startup
62 70
63 from WebBrowser.WebBrowserSingleApplication import ( 71 from WebBrowser.WebBrowserSingleApplication import WebBrowserSingleApplicationClient
64 WebBrowserSingleApplicationClient
65 )
66 72
67 73
68 def createMainWidget(argv): 74 def createMainWidget(argv):
69 """ 75 """
70 Function to create the main widget. 76 Function to create the main widget.
71 77
72 @param argv list of command line parameters 78 @param argv list of command line parameters
73 @type list of str 79 @type list of str
74 @return reference to the main widget 80 @return reference to the main widget
75 @rtype QWidget 81 @rtype QWidget
76 """ 82 """
77 from WebBrowser.WebBrowserWindow import WebBrowserWindow 83 from WebBrowser.WebBrowserWindow import WebBrowserWindow
78 84
79 searchWord = None 85 searchWord = None
80 private = False 86 private = False
81 qthelp = False 87 qthelp = False
82 single = False 88 single = False
83 name = "" 89 name = ""
84 90
85 for arg in reversed(argv): 91 for arg in reversed(argv):
86 if arg.startswith("--search="): 92 if arg.startswith("--search="):
87 searchWord = argv[1].split("=", 1)[1] 93 searchWord = argv[1].split("=", 1)[1]
88 argv.remove(arg) 94 argv.remove(arg)
89 elif arg.startswith("--name="): 95 elif arg.startswith("--name="):
96 qthelp = True 102 qthelp = True
97 argv.remove(arg) 103 argv.remove(arg)
98 elif arg == "--single": 104 elif arg == "--single":
99 single = True 105 single = True
100 argv.remove(arg) 106 argv.remove(arg)
101 elif ( 107 elif arg.startswith(("--newtab=", "--")) or arg == "--quiet":
102 arg.startswith(("--newtab=", "--")) or
103 arg == "--quiet"
104 ):
105 # only needed until we reach this point 108 # only needed until we reach this point
106 argv.remove(arg) 109 argv.remove(arg)
107 110
108 try: 111 try:
109 home = argv[1] 112 home = argv[1]
110 except IndexError: 113 except IndexError:
111 home = "" 114 home = ""
112 115
113 browser = WebBrowserWindow(home, '.', None, 'web_browser', 116 browser = WebBrowserWindow(
114 searchWord=searchWord, private=private, 117 home,
115 settingsDir=SettingsDir, qthelp=qthelp, 118 ".",
116 single=single, saname=name) 119 None,
120 "web_browser",
121 searchWord=searchWord,
122 private=private,
123 settingsDir=SettingsDir,
124 qthelp=qthelp,
125 single=single,
126 saname=name,
127 )
117 return browser 128 return browser
118 129
119 130
120 def main(): 131 def main():
121 """ 132 """
122 Main entry point into the application. 133 Main entry point into the application.
123 """ 134 """
124 global app 135 global app
125 136
126 from PyQt6.QtGui import QGuiApplication 137 from PyQt6.QtGui import QGuiApplication
138
127 QGuiApplication.setDesktopFileName("eric7_browser.desktop") 139 QGuiApplication.setDesktopFileName("eric7_browser.desktop")
128 140
129 options = [ 141 options = [
130 ("--config=configDir", 142 (
131 "use the given directory as the one containing the config files"), 143 "--config=configDir",
144 "use the given directory as the one containing the config files",
145 ),
132 ("--private", "start the browser in private browsing mode"), 146 ("--private", "start the browser in private browsing mode"),
133 ("--qthelp", "start the browser with support for QtHelp"), 147 ("--qthelp", "start the browser with support for QtHelp"),
134 ("--quiet", "don't show any startup error messages"), 148 ("--quiet", "don't show any startup error messages"),
135 ("--search=word", "search for the given word"), 149 ("--search=word", "search for the given word"),
136 ("--settings=settingsDir", 150 (
137 "use the given directory to store the settings files"), 151 "--settings=settingsDir",
152 "use the given directory to store the settings files",
153 ),
138 ("--single", "start the browser as a single application"), 154 ("--single", "start the browser as a single application"),
139 ] 155 ]
140 appinfo = AppInfo.makeAppInfo(sys.argv, 156 appinfo = AppInfo.makeAppInfo(
141 "eric Web Browser", 157 sys.argv, "eric Web Browser", "file", "web browser", options
142 "file", 158 )
143 "web browser", 159
144 options)
145
146 # set the library paths for plugins 160 # set the library paths for plugins
147 Startup.setLibraryPaths() 161 Startup.setLibraryPaths()
148 162
149 scheme = QWebEngineUrlScheme(b"eric") 163 scheme = QWebEngineUrlScheme(b"eric")
150 scheme.setSyntax(QWebEngineUrlScheme.Syntax.Path) 164 scheme.setSyntax(QWebEngineUrlScheme.Syntax.Path)
151 scheme.setFlags(QWebEngineUrlScheme.Flag.SecureScheme | 165 scheme.setFlags(
152 QWebEngineUrlScheme.Flag.ContentSecurityPolicyIgnored) 166 QWebEngineUrlScheme.Flag.SecureScheme
167 | QWebEngineUrlScheme.Flag.ContentSecurityPolicyIgnored
168 )
153 QWebEngineUrlScheme.registerScheme(scheme) 169 QWebEngineUrlScheme.registerScheme(scheme)
154 if "--qthelp" in sys.argv: 170 if "--qthelp" in sys.argv:
155 scheme = QWebEngineUrlScheme(b"qthelp") 171 scheme = QWebEngineUrlScheme(b"qthelp")
156 scheme.setSyntax(QWebEngineUrlScheme.Syntax.Path) 172 scheme.setSyntax(QWebEngineUrlScheme.Syntax.Path)
157 scheme.setFlags(QWebEngineUrlScheme.Flag.SecureScheme) 173 scheme.setFlags(QWebEngineUrlScheme.Flag.SecureScheme)
158 QWebEngineUrlScheme.registerScheme(scheme) 174 QWebEngineUrlScheme.registerScheme(scheme)
159 175
160 app = EricApplication(sys.argv) 176 app = EricApplication(sys.argv)
161 if "--private" not in sys.argv: 177 if "--private" not in sys.argv:
162 client = WebBrowserSingleApplicationClient() 178 client = WebBrowserSingleApplicationClient()
163 res = client.connect() 179 res = client.connect()
164 if res > 0: 180 if res > 0:
167 sys.exit(0) 183 sys.exit(0)
168 elif res < 0: 184 elif res < 0:
169 print("eric7_browser: {0}".format(client.errstr())) 185 print("eric7_browser: {0}".format(client.errstr()))
170 # __IGNORE_WARNING_M801__ 186 # __IGNORE_WARNING_M801__
171 sys.exit(res) 187 sys.exit(res)
172 188
173 res = Startup.simpleAppStartup(sys.argv, 189 res = Startup.simpleAppStartup(
174 appinfo, 190 sys.argv, appinfo, createMainWidget, installErrorHandler=True, app=app
175 createMainWidget, 191 )
176 installErrorHandler=True,
177 app=app)
178 sys.exit(res) 192 sys.exit(res)
179 193
180 if __name__ == '__main__': 194
195 if __name__ == "__main__":
181 main() 196 main()

eric ide

mercurial