|
1 #!/usr/bin/env python3 |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # Copyright (c) 2002 - 2016 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 web browser. It is based on QtWebEngine. |
|
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 import sip |
|
26 sip.setdestroyonexit(False) |
|
27 except AttributeError: |
|
28 pass |
|
29 |
|
30 import sys |
|
31 import os |
|
32 |
|
33 # TODO: adjust this when done |
|
34 MIN_QT_VERSION = "5.5.0" |
|
35 |
|
36 from PyQt5.QtCore import qVersion |
|
37 if qVersion() < MIN_QT_VERSION: |
|
38 print("You need at least Qt Version {0} to execute the web browser." |
|
39 .format(MIN_QT_VERSION)) |
|
40 sys.exit(100) |
|
41 |
|
42 for arg in sys.argv[:]: |
|
43 if arg.startswith("--config="): |
|
44 import Globals |
|
45 configDir = arg.replace("--config=", "") |
|
46 Globals.setConfigDir(configDir) |
|
47 sys.argv.remove(arg) |
|
48 elif arg.startswith("--settings="): |
|
49 from PyQt5.QtCore import QSettings |
|
50 settingsDir = os.path.expanduser(arg.replace("--settings=", "")) |
|
51 if not os.path.isdir(settingsDir): |
|
52 os.makedirs(settingsDir) |
|
53 QSettings.setPath(QSettings.IniFormat, QSettings.UserScope, |
|
54 settingsDir) |
|
55 sys.argv.remove(arg) |
|
56 |
|
57 # make ThirdParty package available as a packages repository |
|
58 sys.path.insert(2, os.path.join(os.path.dirname(__file__), |
|
59 "ThirdParty", "Pygments")) |
|
60 |
|
61 from PyQt5 import QtWebEngineWidgets # __IGNORE_WARNING__ |
|
62 |
|
63 import Globals |
|
64 from Globals import AppInfo |
|
65 |
|
66 from Toolbox import Startup |
|
67 |
|
68 |
|
69 def createMainWidget(argv): |
|
70 """ |
|
71 Function to create the main widget. |
|
72 |
|
73 @param argv list of commandline parameters (list of strings) |
|
74 @return reference to the main widget (QWidget) |
|
75 """ |
|
76 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
77 |
|
78 searchWord = None |
|
79 for arg in reversed(argv): |
|
80 if arg.startswith("--search="): |
|
81 searchWord = argv[1].split("=", 1)[1] |
|
82 argv.remove(arg) |
|
83 elif arg.startswith("--"): |
|
84 argv.remove(arg) |
|
85 |
|
86 try: |
|
87 home = argv[1] |
|
88 except IndexError: |
|
89 home = "" |
|
90 |
|
91 browser = WebBrowserWindow(home, '.', None, 'web_browser', |
|
92 searchWord=searchWord) |
|
93 return browser |
|
94 |
|
95 |
|
96 def main(): |
|
97 """ |
|
98 Main entry point into the application. |
|
99 """ |
|
100 options = [ |
|
101 ("--config=configDir", |
|
102 "use the given directory as the one containing the config files"), |
|
103 ("--search=word", "search for the given word"), |
|
104 ("--settings=settingsDir", |
|
105 "use the given directory to store the settings files"), |
|
106 ] |
|
107 appinfo = AppInfo.makeAppInfo(sys.argv, |
|
108 "eric6 Web Browser", |
|
109 "file", |
|
110 "web browser", |
|
111 options) |
|
112 |
|
113 if not Globals.checkBlacklistedVersions(): |
|
114 sys.exit(100) |
|
115 |
|
116 res = Startup.simpleAppStartup(sys.argv, |
|
117 appinfo, |
|
118 createMainWidget, |
|
119 installErrorHandler=True) |
|
120 sys.exit(res) |
|
121 |
|
122 if __name__ == '__main__': |
|
123 main() |