|
1 #!/usr/bin/env python3 |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # Copyright (c) 2016 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
5 # |
|
6 |
|
7 """ |
|
8 Module implementing the main script for histedit. |
|
9 |
|
10 Depending on the file name given by the Mercurial histedit command one |
|
11 of two possible dialogs will be shown. |
|
12 """ |
|
13 |
|
14 import sys |
|
15 import os |
|
16 |
|
17 sys.path.insert(1, os.path.join( |
|
18 os.path.dirname(__file__), "..", "..", "..", "..")) |
|
19 # four times up is the eric7 package directory |
|
20 |
|
21 for arg in sys.argv[:]: |
|
22 if arg.startswith("--config="): |
|
23 import Globals |
|
24 configDir = arg.replace("--config=", "") |
|
25 Globals.setConfigDir(configDir) |
|
26 sys.argv.remove(arg) |
|
27 elif arg.startswith("--settings="): |
|
28 from PyQt6.QtCore import QSettings |
|
29 settingsDir = os.path.expanduser(arg.replace("--settings=", "")) |
|
30 if not os.path.isdir(settingsDir): |
|
31 os.makedirs(settingsDir) |
|
32 QSettings.setPath( |
|
33 QSettings.Format.IniFormat, QSettings.Scope.UserScope, settingsDir) |
|
34 sys.argv.remove(arg) |
|
35 |
|
36 from Globals import AppInfo |
|
37 |
|
38 from Toolbox import Startup |
|
39 |
|
40 |
|
41 def createMainWidget(argv): |
|
42 """ |
|
43 Function to create the main widget. |
|
44 |
|
45 @param argv list of commandline parameters |
|
46 @type list of str |
|
47 @return reference to the main widget or None in case of an error |
|
48 @rtype QWidget or None |
|
49 """ |
|
50 if len(argv) > 1: |
|
51 fileName = os.path.basename(argv[1]) |
|
52 if fileName.startswith("hg-histedit-"): |
|
53 from HgHisteditPlanEditor import HgHisteditPlanEditor |
|
54 return HgHisteditPlanEditor(argv[1]) |
|
55 elif fileName.startswith("hg-editor-"): |
|
56 from HgHisteditCommitEditor import HgHisteditCommitEditor |
|
57 return HgHisteditCommitEditor(argv[1]) |
|
58 |
|
59 return None |
|
60 |
|
61 |
|
62 def main(): |
|
63 """ |
|
64 Main entry point into the application. |
|
65 """ |
|
66 options = [ |
|
67 ("--config=configDir", |
|
68 "use the given directory as the one containing the config files"), |
|
69 ("--settings=settingsDir", |
|
70 "use the given directory to store the settings files"), |
|
71 ("", "name of file to edit") |
|
72 ] |
|
73 appinfo = AppInfo.makeAppInfo(sys.argv, |
|
74 "Mercurial Histedit Editor", |
|
75 "", |
|
76 "Editor for the Mercurial histedit command", |
|
77 options) |
|
78 res = Startup.simpleAppStartup(sys.argv, |
|
79 appinfo, |
|
80 createMainWidget) |
|
81 sys.exit(res) |
|
82 |
|
83 if __name__ == '__main__': |
|
84 main() |