eric6/Plugins/VcsPlugins/vcsMercurial/HisteditExtension/HgHisteditEditor.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7192
a22eee00b052
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3
4 # Copyright (c) 2016 - 2019 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 from __future__ import unicode_literals
15
16 import sys
17 import os
18
19 sys.path.insert(1, os.path.join(
20 os.path.dirname(__file__), "..", "..", "..", ".."))
21 # four times up is the eric6 package directory
22
23 import Toolbox.PyQt4ImportHook # __IGNORE_WARNING__
24
25 try: # Only for Py2
26 import Globals.compatibility_fixes # __IGNORE_WARNING__
27 except (ImportError):
28 pass
29
30 for arg in sys.argv[:]:
31 if arg.startswith("--config="):
32 import Globals
33 configDir = arg.replace("--config=", "")
34 Globals.setConfigDir(configDir)
35 sys.argv.remove(arg)
36 elif arg.startswith("--settings="):
37 from PyQt5.QtCore import QSettings
38 settingsDir = os.path.expanduser(arg.replace("--settings=", ""))
39 if not os.path.isdir(settingsDir):
40 os.makedirs(settingsDir)
41 QSettings.setPath(QSettings.IniFormat, QSettings.UserScope,
42 settingsDir)
43 sys.argv.remove(arg)
44
45 from Globals import AppInfo
46
47 from Toolbox import Startup
48
49
50 def createMainWidget(argv):
51 """
52 Function to create the main widget.
53
54 @param argv list of commandline parameters
55 @type list of str
56 @return reference to the main widget or None in case of an error
57 @rtype QWidget or None
58 """
59 if len(argv) > 1:
60 fileName = os.path.basename(argv[1])
61 if fileName.startswith("hg-histedit-"):
62 from HgHisteditPlanEditor import HgHisteditPlanEditor
63 return HgHisteditPlanEditor(argv[1])
64 elif fileName.startswith("hg-editor-"):
65 from HgHisteditCommitEditor import HgHisteditCommitEditor
66 return HgHisteditCommitEditor(argv[1])
67
68 return None
69
70
71 def main():
72 """
73 Main entry point into the application.
74 """
75 options = [
76 ("--config=configDir",
77 "use the given directory as the one containing the config files"),
78 ("--settings=settingsDir",
79 "use the given directory to store the settings files"),
80 ("", "name of file to edit")
81 ]
82 appinfo = AppInfo.makeAppInfo(sys.argv,
83 "Mercurial Histedit Editor",
84 "",
85 "Editor for the Mercurial histedit command",
86 options)
87 res = Startup.simpleAppStartup(sys.argv,
88 appinfo,
89 createMainWidget)
90 sys.exit(res)
91
92 if __name__ == '__main__':
93 main()

eric ide

mercurial