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