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