|
1 #!/usr/bin/env python3 |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # Copyright (c) 2004 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
5 # |
|
6 |
|
7 """ |
|
8 eric 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 sys.path.insert(1, os.path.dirname(__file__)) |
|
19 |
|
20 for arg in sys.argv[:]: |
|
21 if arg.startswith("--config="): |
|
22 import Globals |
|
23 configDir = arg.replace("--config=", "") |
|
24 Globals.setConfigDir(configDir) |
|
25 sys.argv.remove(arg) |
|
26 elif arg.startswith("--settings="): |
|
27 from PyQt5.QtCore import QSettings |
|
28 settingsDir = os.path.expanduser(arg.replace("--settings=", "")) |
|
29 if not os.path.isdir(settingsDir): |
|
30 os.makedirs(settingsDir) |
|
31 QSettings.setPath( |
|
32 QSettings.Format.IniFormat, QSettings.Scope.UserScope, settingsDir) |
|
33 sys.argv.remove(arg) |
|
34 |
|
35 from E5Gui.E5Application import E5Application |
|
36 |
|
37 from Tools.TRSingleApplication import TRSingleApplicationClient |
|
38 from Globals import AppInfo |
|
39 |
|
40 from Toolbox import Startup |
|
41 |
|
42 app = None |
|
43 |
|
44 |
|
45 def createMainWidget(argv): |
|
46 """ |
|
47 Function to create the main widget. |
|
48 |
|
49 @param argv list of commandline parameters (list of strings) |
|
50 @return reference to the main widget (QWidget) |
|
51 """ |
|
52 from Tools.TRPreviewer import TRPreviewer |
|
53 |
|
54 files = argv[1:] if len(argv) > 1 else [] |
|
55 previewer = TRPreviewer(files, None, 'TRPreviewer') |
|
56 |
|
57 return previewer |
|
58 |
|
59 |
|
60 def main(): |
|
61 """ |
|
62 Main entry point into the application. |
|
63 """ |
|
64 global app |
|
65 |
|
66 from PyQt5.QtGui import QGuiApplication |
|
67 QGuiApplication.setDesktopFileName("eric6_trpreviewer.desktop") |
|
68 |
|
69 options = [ |
|
70 ("--config=configDir", |
|
71 "use the given directory as the one containing the config files"), |
|
72 ("--settings=settingsDir", |
|
73 "use the given directory to store the settings files"), |
|
74 ] |
|
75 appinfo = AppInfo.makeAppInfo(sys.argv, |
|
76 "eric TR Previewer", |
|
77 "file", |
|
78 "TR file previewer", |
|
79 options) |
|
80 |
|
81 # set the library paths for plugins |
|
82 Startup.setLibraryPaths() |
|
83 |
|
84 app = E5Application(sys.argv) |
|
85 client = TRSingleApplicationClient() |
|
86 res = client.connect() |
|
87 if res > 0: |
|
88 if len(sys.argv) > 1: |
|
89 client.processArgs(sys.argv[1:]) |
|
90 sys.exit(0) |
|
91 elif res < 0: |
|
92 print("eric6_trpreviewer: {0}".format(client.errstr())) |
|
93 sys.exit(res) |
|
94 else: |
|
95 res = Startup.simpleAppStartup(sys.argv, |
|
96 appinfo, |
|
97 createMainWidget, |
|
98 app=app) |
|
99 sys.exit(res) |
|
100 |
|
101 if __name__ == '__main__': |
|
102 main() |
|
103 |
|
104 # |
|
105 # eflag: noqa = M801 |