src/eric7/eric7_sqlbrowser.py

branch
eric7
changeset 10303
ee1aadab1215
parent 10238
9ea4634a697e
child 10439
21c28b0f9e41
equal deleted inserted replaced
10302:8cb0dabf852f 10303:ee1aadab1215
9 9
10 This is the main Python script that performs the necessary initialization 10 This is the main Python script that performs the necessary initialization
11 of the SQL browser and starts the Qt event loop. 11 of the SQL browser and starts the Qt event loop.
12 """ 12 """
13 13
14 import argparse
14 import os 15 import os
15 import sys 16 import sys
16 17
17 from PyQt6.QtGui import QGuiApplication 18 from PyQt6.QtGui import QGuiApplication
18 19
19 for arg in sys.argv[:]:
20 if arg.startswith("--config="):
21 from eric7 import Globals
22 20
23 configDir = arg.replace("--config=", "") 21 def createArgparseNamespace():
24 Globals.setConfigDir(configDir) 22 """
25 sys.argv.remove(arg) 23 Function to create an argument parser.
26 elif arg.startswith("--settings="):
27 from PyQt6.QtCore import QSettings
28 24
29 settingsDir = os.path.expanduser(arg.replace("--settings=", "")) 25 @return created argument parser object
30 if not os.path.isdir(settingsDir): 26 @rtype argparse.ArgumentParser
31 os.makedirs(settingsDir) 27 """
32 QSettings.setPath( 28 from eric7.UI.Info import Version
33 QSettings.Format.IniFormat, QSettings.Scope.UserScope, settingsDir
34 )
35 sys.argv.remove(arg)
36 29
37 from eric7.Globals import AppInfo 30 # 1. create the argument parser
31 parser = argparse.ArgumentParser(
32 description="Graphical tool of the eric tool suite to inspect SQL databases.",
33 epilog="Copyright (c) 2009 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>.",
34 )
35
36 # 2. add the arguments
37 parser.add_argument(
38 "-V",
39 "--version",
40 action="version",
41 version="%(prog)s {0}".format(Version),
42 help="show version information and exit",
43 )
44 parser.add_argument(
45 "--config",
46 metavar="config_dir",
47 help="use the given directory as the one containing the config files",
48 )
49 parser.add_argument(
50 "--settings",
51 metavar="settings_dir",
52 help="use the given directory to store the settings files",
53 )
54 parser.add_argument(
55 "connection",
56 nargs="*",
57 default=[],
58 help="database connection string",
59 )
60
61 # 3. create the Namespace object by parsing the command line
62 args = parser.parse_args()
63 return args
64
65
66 args = createArgparseNamespace()
67 if args.config:
68 from eric7 import Globals
69
70 Globals.setConfigDir(args.config)
71 if args.settings:
72 from PyQt6.QtCore import QSettings
73
74 SettingsDir = os.path.expanduser(args.settings)
75 if not os.path.isdir(SettingsDir):
76 os.makedirs(SettingsDir)
77 QSettings.setPath(
78 QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir
79 )
80
38 from eric7.Toolbox import Startup 81 from eric7.Toolbox import Startup
39 82
40 83
41 def createMainWidget(argv): 84 def createMainWidget(args):
42 """ 85 """
43 Function to create the main widget. 86 Function to create the main widget.
44 87
45 @param argv list of commandline parameters (list of strings) 88 @param args namespace object containing the parsed command line parameters
46 @return reference to the main widget (QWidget) 89 @type argparse.Namespace
90 @return reference to the main widget
91 @rtype QWidget
47 """ 92 """
48 from eric7.SqlBrowser.SqlBrowser import SqlBrowser 93 from eric7.SqlBrowser.SqlBrowser import SqlBrowser
49 94
50 connections = argv[1:] if len(argv) > 1 else [] 95 browser = SqlBrowser(args.connection)
51 browser = SqlBrowser(connections)
52 96
53 return browser 97 return browser
54 98
55 99
56 def main(): 100 def main():
57 """ 101 """
58 Main entry point into the application. 102 Main entry point into the application.
59 """ 103 """
60 QGuiApplication.setDesktopFileName("eric7_sqlbrowser") 104 QGuiApplication.setDesktopFileName("eric7_sqlbrowser")
61 105
62 options = [ 106 res = Startup.appStartup(args, createMainWidget)
63 (
64 "--config=configDir",
65 "use the given directory as the one containing the config files",
66 ),
67 (
68 "--settings=settingsDir",
69 "use the given directory to store the settings files",
70 ),
71 ]
72 appinfo = AppInfo.makeAppInfo(
73 sys.argv, "eric SQL Browser", "connection", "SQL browser", options
74 )
75 res = Startup.simpleAppStartup(sys.argv, appinfo, createMainWidget)
76 sys.exit(res) 107 sys.exit(res)
77 108
78 109
79 if __name__ == "__main__": 110 if __name__ == "__main__":
80 main() 111 main()

eric ide

mercurial