|
1 #!/usr/bin/env python3 |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # Copyright (c) 2004 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
5 # |
|
6 |
|
7 """ |
|
8 Eric6 TR Previewer. |
|
9 |
|
10 This is the main Python script that performs the necessary initialization |
|
11 of the tr previewer and starts the Qt event loop. This is a standalone version |
|
12 of the integrated tr previewer. |
|
13 """ |
|
14 |
|
15 from __future__ import unicode_literals |
|
16 |
|
17 import Toolbox.PyQt4ImportHook # __IGNORE_WARNING__ |
|
18 |
|
19 try: # Only for Py2 |
|
20 import Globals.compatibility_fixes # __IGNORE_WARNING__ |
|
21 except (ImportError): |
|
22 pass |
|
23 |
|
24 import sys |
|
25 import os |
|
26 |
|
27 for arg in sys.argv[:]: |
|
28 if arg.startswith("--config="): |
|
29 import Globals |
|
30 configDir = arg.replace("--config=", "") |
|
31 Globals.setConfigDir(configDir) |
|
32 sys.argv.remove(arg) |
|
33 elif arg.startswith("--settings="): |
|
34 from PyQt5.QtCore import QSettings |
|
35 settingsDir = os.path.expanduser(arg.replace("--settings=", "")) |
|
36 if not os.path.isdir(settingsDir): |
|
37 os.makedirs(settingsDir) |
|
38 QSettings.setPath(QSettings.IniFormat, QSettings.UserScope, |
|
39 settingsDir) |
|
40 sys.argv.remove(arg) |
|
41 |
|
42 from E5Gui.E5Application import E5Application |
|
43 |
|
44 from Tools.TRSingleApplication import TRSingleApplicationClient |
|
45 from Globals import AppInfo |
|
46 |
|
47 from Toolbox import Startup |
|
48 |
|
49 app = None |
|
50 |
|
51 |
|
52 def createMainWidget(argv): |
|
53 """ |
|
54 Function to create the main widget. |
|
55 |
|
56 @param argv list of commandline parameters (list of strings) |
|
57 @return reference to the main widget (QWidget) |
|
58 """ |
|
59 from Tools.TRPreviewer import TRPreviewer |
|
60 |
|
61 if len(argv) > 1: |
|
62 files = argv[1:] |
|
63 else: |
|
64 files = [] |
|
65 |
|
66 previewer = TRPreviewer(files, None, 'TRPreviewer') |
|
67 return previewer |
|
68 |
|
69 |
|
70 def main(): |
|
71 """ |
|
72 Main entry point into the application. |
|
73 """ |
|
74 global app |
|
75 |
|
76 options = [ |
|
77 ("--config=configDir", |
|
78 "use the given directory as the one containing the config files"), |
|
79 ("--settings=settingsDir", |
|
80 "use the given directory to store the settings files"), |
|
81 ] |
|
82 appinfo = AppInfo.makeAppInfo(sys.argv, |
|
83 "Eric6 TR Previewer", |
|
84 "file", |
|
85 "TR file previewer", |
|
86 options) |
|
87 |
|
88 # set the library paths for plugins |
|
89 Startup.setLibraryPaths() |
|
90 |
|
91 app = E5Application(sys.argv) |
|
92 client = TRSingleApplicationClient() |
|
93 res = client.connect() |
|
94 if res > 0: |
|
95 if len(sys.argv) > 1: |
|
96 client.processArgs(sys.argv[1:]) |
|
97 sys.exit(0) |
|
98 elif res < 0: |
|
99 print("eric6_trpreviewer: {0}".format(client.errstr())) |
|
100 sys.exit(res) |
|
101 else: |
|
102 res = Startup.simpleAppStartup(sys.argv, |
|
103 appinfo, |
|
104 createMainWidget, |
|
105 app=app) |
|
106 sys.exit(res) |
|
107 |
|
108 if __name__ == '__main__': |
|
109 main() |
|
110 |
|
111 # |
|
112 # eflag: noqa = M801 |