src/eric7/eric7_browser.py

Sat, 11 Nov 2023 12:44:51 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 11 Nov 2023 12:44:51 +0100
branch
eric7
changeset 10303
ee1aadab1215
parent 10238
9ea4634a697e
child 10308
d19766190e17
permissions
-rw-r--r--

Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.

15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 #!/usr/bin/env python3
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3
9653
e67609152c5e Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9500
diff changeset
4 # Copyright (c) 2002 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5 #
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 """
7960
e8fc383322f7 Harmonized some user visible strings and changed the term 'eric6' to the more generic 'eric'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
8 eric Web Browser.
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 This is the main Python script that performs the necessary initialization
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 of the web browser and starts the Qt event loop. This is a standalone version
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
12 of the integrated web browser. It is based on QtWebEngine.
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 """
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
15 import argparse
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
16 import os
6949
a5255f1ba3f0 setup.py: continued implementing support for setup.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
17 import sys
a5255f1ba3f0 setup.py: continued implementing support for setup.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
18
9482
a2bc06a54d9d Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
19 from PyQt6.QtGui import QGuiApplication
a2bc06a54d9d Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
20
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
21 from eric7 import Globals
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
22
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
23
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
24 def createArgparseNamespace():
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
25 """
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
26 Function to create an argument parser.
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
27
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
28 @return created argument parser object
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
29 @rtype argparse.ArgumentParser
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
30 """
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
31 from eric7.UI.Info import Version
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
32
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
33 # 1. create the argument parser
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
34 parser = argparse.ArgumentParser(
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
35 description="Web Browser application of the eric tool suite.",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
36 epilog="Copyright (c) 2002 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>.",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
37 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
38
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
39 # 2. add the arguments
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
40 parser.add_argument(
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
41 "-V",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
42 "--version",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
43 action="version",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
44 version="%(prog)s {0}".format(Version),
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
45 help="show version information and exit",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
46 )
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
47 parser.add_argument(
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
48 "--config",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
49 metavar="config_dir",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
50 help="use the given directory as the one containing the config files",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
51 )
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
52 parser.add_argument(
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
53 "--settings",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
54 metavar="settings_dir",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
55 help="use the given directory to store the settings files",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
56 )
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
57 parser.add_argument(
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
58 "--name",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
59 metavar="browser name",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
60 default="",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
61 help="name to be used for the browser instance",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
62 )
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
63 parser.add_argument(
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
64 "--new-tab",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
65 metavar="URL",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
66 action="append",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
67 help="open a new tab for the given URL",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
68 )
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
69 parser.add_argument(
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
70 "--private",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
71 action="store_true",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
72 help="start the browser in private browsing mode",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
73 )
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
74 parser.add_argument(
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
75 "--qthelp",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
76 action="store_true",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
77 help="start the browser with support for QtHelp",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
78 )
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
79 parser.add_argument(
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
80 "--quiet",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
81 action="store_true",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
82 help="don't show any startup error messages",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
83 )
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
84 parser.add_argument(
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
85 "--search",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
86 metavar="searchword",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
87 help="search for the given word",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
88 )
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
89 parser.add_argument(
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
90 "--shutdown",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
91 action="store_true",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
92 help="shut down the browser instance",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
93 )
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
94 parser.add_argument(
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
95 "--single",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
96 action="store_true",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
97 help="start the browser as a single application",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
98 )
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
99 parser.add_argument(
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
100 "home",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
101 nargs="?",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
102 default="",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
103 metavar="file | URL",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
104 help="open a file or URL",
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
105 )
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
106
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
107 # 3. create the Namespace object by parsing the command line
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
108 args = parser.parse_args()
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
109 return args
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
110
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
111
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
112 args = createArgparseNamespace()
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
113 if args.config:
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
114 Globals.setConfigDir(args.config)
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
115 if args.settings:
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
116 from PyQt6.QtCore import QSettings
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
117
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
118 SettingsDir = os.path.expanduser(args.settings)
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
119 if not os.path.isdir(SettingsDir):
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
120 os.makedirs(SettingsDir)
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
121 QSettings.setPath(
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
122 QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
123 )
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
124 else:
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
125 SettingsDir = None
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
126
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
127 app = None
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
4840
69ee7965ba27 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4831
diff changeset
129 try:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
130 from PyQt6 import QtWebEngineWidgets # __IGNORE_WARNING__
9500
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
131 from PyQt6.QtWebEngineCore import QWebEngineUrlScheme
4840
69ee7965ba27 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4831
diff changeset
132 except ImportError:
6628
c3f0f6bffd21 eric6_browser: added a '--quiet' option to suppress startup error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6625
diff changeset
133 if "--quiet" not in sys.argv:
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8314
diff changeset
134 from PyQt6.QtCore import QTimer
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8314
diff changeset
135 from PyQt6.QtWidgets import QApplication
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
136
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
137 from eric7.EricWidgets import EricMessageBox # __IGNORE_WARNING__
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
138
6628
c3f0f6bffd21 eric6_browser: added a '--quiet' option to suppress startup error messages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6625
diff changeset
139 app = QApplication([])
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
140 QTimer.singleShot(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
141 0,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
142 lambda: EricMessageBox.critical(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
143 None,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
144 "eric Web Browser",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
145 "QtWebEngineWidgets is not installed but needed to execute the"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
146 " web browser.",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
147 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
148 )
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7380
diff changeset
149 app.exec()
4840
69ee7965ba27 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4831
diff changeset
150 sys.exit(100)
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
151
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
152 from eric7.EricWidgets.EricApplication import EricApplication
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
153 from eric7.Toolbox import Startup
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
154 from eric7.WebBrowser.WebBrowserSingleApplication import (
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
155 WebBrowserSingleApplicationClient,
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
156 )
6623
c0882a599e18 WebBrowser: added single application mode.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6365
diff changeset
157
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 896
diff changeset
158
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
159 def createMainWidget(args):
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 """
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 Function to create the main widget.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
162
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
163 @param args namespace object containing the parsed command line parameters
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
164 @type argparse.Namespace
6630
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6628
diff changeset
165 @return reference to the main widget
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6628
diff changeset
166 @rtype QWidget
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 """
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
168 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
169
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
170 browser = WebBrowserWindow(
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
171 args.home,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
172 ".",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
173 None,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
174 "web_browser",
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
175 searchWord=args.search,
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
176 private=args.private,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
177 settingsDir=SettingsDir,
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
178 qthelp=args.qthelp,
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
179 single=args.single,
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
180 saname=args.name,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
181 )
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
182 return browser
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 896
diff changeset
184
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 def main():
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 """
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 Main entry point into the application.
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 """
6702
793af5761910 Changed some code to (hopefully) get rid of a crash with upcoming PyQt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
189 global app
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
190
10238
9ea4634a697e Corrected the filename for 'QGuiApplication.setDesktopFileName()' to not include the '.desktop' extension anymore (as directed by Qt).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
191 QGuiApplication.setDesktopFileName("eric7_browser")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
192
6623
c0882a599e18 WebBrowser: added single application mode.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6365
diff changeset
193 # set the library paths for plugins
c0882a599e18 WebBrowser: added single application mode.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6365
diff changeset
194 Startup.setLibraryPaths()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
195
7945
76daafe10009 Removed code dealing with Qt versions less than the required one and removed use of QDesktopWidget or QApplication.desktop().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
196 scheme = QWebEngineUrlScheme(b"eric")
76daafe10009 Removed code dealing with Qt versions less than the required one and removed use of QDesktopWidget or QApplication.desktop().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
197 scheme.setSyntax(QWebEngineUrlScheme.Syntax.Path)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
198 scheme.setFlags(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
199 QWebEngineUrlScheme.Flag.SecureScheme
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
200 | QWebEngineUrlScheme.Flag.ContentSecurityPolicyIgnored
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
201 )
7945
76daafe10009 Removed code dealing with Qt versions less than the required one and removed use of QDesktopWidget or QApplication.desktop().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
202 QWebEngineUrlScheme.registerScheme(scheme)
76daafe10009 Removed code dealing with Qt versions less than the required one and removed use of QDesktopWidget or QApplication.desktop().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
203 if "--qthelp" in sys.argv:
7316
abe6dd39e4ee eric6_browser: moved the scheme registration to the main file to fulfill a Qt requirement.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7257
diff changeset
204 scheme = QWebEngineUrlScheme(b"qthelp")
abe6dd39e4ee eric6_browser: moved the scheme registration to the main file to fulfill a Qt requirement.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7257
diff changeset
205 scheme.setSyntax(QWebEngineUrlScheme.Syntax.Path)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7960
diff changeset
206 scheme.setFlags(QWebEngineUrlScheme.Flag.SecureScheme)
7316
abe6dd39e4ee eric6_browser: moved the scheme registration to the main file to fulfill a Qt requirement.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7257
diff changeset
207 QWebEngineUrlScheme.registerScheme(scheme)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
208
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
209 app = EricApplication(args)
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
210 if not args.private:
6623
c0882a599e18 WebBrowser: added single application mode.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6365
diff changeset
211 client = WebBrowserSingleApplicationClient()
c0882a599e18 WebBrowser: added single application mode.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6365
diff changeset
212 res = client.connect()
c0882a599e18 WebBrowser: added single application mode.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6365
diff changeset
213 if res > 0:
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
214 client.processArgs(args)
6623
c0882a599e18 WebBrowser: added single application mode.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6365
diff changeset
215 sys.exit(0)
c0882a599e18 WebBrowser: added single application mode.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6365
diff changeset
216 elif res < 0:
8314
e3642a6a1e71 Finished renaming eric6 to eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
217 print("eric7_browser: {0}".format(client.errstr()))
6625
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6623
diff changeset
218 # __IGNORE_WARNING_M801__
6623
c0882a599e18 WebBrowser: added single application mode.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6365
diff changeset
219 sys.exit(res)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
220
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10238
diff changeset
221 res = Startup.appStartup(args, createMainWidget, installErrorHandler=True, app=app)
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 sys.exit(res)
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
224
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
225 if __name__ == "__main__":
97
c4086afea02b Finished cleaning up the code supported by py3flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
226 main()

eric ide

mercurial