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