src/eric7/eric7_tray.py

Wed, 25 Sep 2024 14:48:57 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 25 Sep 2024 14:48:57 +0200
branch
eric7
changeset 10926
9ef616cd220d
parent 10716
11cdcc824469
child 11090
f5f5f5803935
permissions
-rw-r--r--

Moved some functions from 'Globals' to 'EricUtilities'.

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
10439
21c28b0f9e41 Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10303
diff changeset
4 # Copyright (c) 2006 - 2024 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: 7923
diff changeset
8 eric Tray.
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 system-tray application. This acts as a quickstarter by providing a
7960
e8fc383322f7 Harmonized some user visible strings and changed the term 'eric6' to the more generic 'eric'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
12 context menu to start the eric IDE and the eric tools.
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
4102
74cd4222f872 Fixed an issue with the tray starter not forwarding the use of the '--pyqt4' command line option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
17 import sys
74cd4222f872 Fixed an issue with the tray starter not forwarding the use of the '--pyqt4' command line option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
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
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
21
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
22 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
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 Function to create an argument parser.
4102
74cd4222f872 Fixed an issue with the tray starter not forwarding the use of the '--pyqt4' command line option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
25
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
26 @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
27 @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
28 """
10716
11cdcc824469 Relocated the Version information into a top level '__version__.py' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10683
diff changeset
29 from eric7.__version__ import Version
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
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 # 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
32 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
33 description="Tray starter for the tools of the eric tool suite.",
10439
21c28b0f9e41 Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10303
diff changeset
34 epilog="Copyright (c) 2006 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>.",
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
35 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
36
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
37 # 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
38 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
39 "-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
40 "--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
41 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
42 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
43 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
44 )
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 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
46 "--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
47 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
48 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
49 )
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 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
51 "--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
52 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
53 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
54 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
55
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
56 # 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
57 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
58 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
59
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
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 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
62 if args.config:
10926
9ef616cd220d Moved some functions from 'Globals' to 'EricUtilities'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10716
diff changeset
63 from eric7 import EricUtilities
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
10926
9ef616cd220d Moved some functions from 'Globals' to 'EricUtilities'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10716
diff changeset
65 EricUtilities.setConfigDir(args.config)
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
66 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
67 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
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 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
70 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
71 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
72 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
73 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
74 )
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 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
76 SettingsDir = None
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
77 from eric7.Toolbox import Startup
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 896
diff changeset
79
10683
779cda568acb Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10439
diff changeset
80 def createMainWidget(_args):
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 """
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 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
83
10683
779cda568acb Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10439
diff changeset
84 @param _args namespace object containing the parsed command line parameters
779cda568acb Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10439
diff changeset
85 (unused)
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
86 @type argparse.Namespace
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 @return reference to the main widget
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 @rtype QWidget
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 """
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
90 from eric7.Tools.TrayStarter import TrayStarter
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
91
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
92 return TrayStarter(SettingsDir)
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 896
diff changeset
94
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 def main():
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 """
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 Main entry point into the application.
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 """
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: 10069
diff changeset
99 QGuiApplication.setDesktopFileName("eric7_tray")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
100
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
101 res = Startup.appStartup(
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 args, createMainWidget, quitOnLastWindowClosed=False, raiseIt=False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
103 )
15
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 sys.exit(res)
f6ccc31d6e72 Started to rename stuff for eric5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
106
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
107 if __name__ == "__main__":
97
c4086afea02b Finished cleaning up the code supported by py3flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 18
diff changeset
108 main()

eric ide

mercurial