|
1 #!/usr/bin/env python3 |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # Copyright (c) 2004 - 2014 Detlev Offenbach <detlev@die-offenbachs.de> |
|
5 # |
|
6 |
|
7 """ |
|
8 Eric5 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 try: # Only for Py2 |
|
17 import Utilities.compatibility_fixes # __IGNORE_WARNING__ |
|
18 except (ImportError): |
|
19 pass |
|
20 |
|
21 import sys |
|
22 |
|
23 for arg in sys.argv: |
|
24 if arg.startswith("--config="): |
|
25 import Globals |
|
26 configDir = arg.replace("--config=", "") |
|
27 Globals.setConfigDir(configDir) |
|
28 sys.argv.remove(arg) |
|
29 break |
|
30 |
|
31 from E5Gui.E5Application import E5Application |
|
32 |
|
33 from Tools.TRSingleApplication import TRSingleApplicationClient |
|
34 from Globals import AppInfo |
|
35 |
|
36 from Toolbox import Startup |
|
37 |
|
38 |
|
39 def createMainWidget(argv): |
|
40 """ |
|
41 Function to create the main widget. |
|
42 |
|
43 @param argv list of commandline parameters (list of strings) |
|
44 @return reference to the main widget (QWidget) |
|
45 """ |
|
46 from Tools.TRPreviewer import TRPreviewer |
|
47 |
|
48 if len(argv) > 1: |
|
49 files = argv[1:] |
|
50 else: |
|
51 files = [] |
|
52 |
|
53 previewer = TRPreviewer(files, None, 'TRPreviewer') |
|
54 return previewer |
|
55 |
|
56 |
|
57 def main(): |
|
58 """ |
|
59 Main entry point into the application. |
|
60 """ |
|
61 options = [ |
|
62 ("--config=configDir", |
|
63 "use the given directory as the one containing the config files"), |
|
64 ] |
|
65 appinfo = AppInfo.makeAppInfo(sys.argv, |
|
66 "Eric5 TR Previewer", |
|
67 "file", |
|
68 "TR file previewer", |
|
69 options) |
|
70 |
|
71 app = E5Application(sys.argv) |
|
72 client = TRSingleApplicationClient() |
|
73 res = client.connect() |
|
74 if res > 0: |
|
75 if len(sys.argv) > 1: |
|
76 client.processArgs(sys.argv[1:]) |
|
77 sys.exit(0) |
|
78 elif res < 0: |
|
79 print("eric5_trpreviewer: {0}".format(client.errstr())) |
|
80 sys.exit(res) |
|
81 else: |
|
82 res = Startup.simpleAppStartup(sys.argv, |
|
83 appinfo, |
|
84 createMainWidget, |
|
85 app=app) |
|
86 sys.exit(res) |
|
87 |
|
88 if __name__ == '__main__': |
|
89 main() |