|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2004 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the single application server and client. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 import os |
|
13 |
|
14 from PyQt5.QtCore import pyqtSignal |
|
15 |
|
16 from Toolbox.SingleApplication import SingleApplicationClient, \ |
|
17 SingleApplicationServer |
|
18 |
|
19 ########################################################################### |
|
20 ## define some module global stuff |
|
21 ########################################################################### |
|
22 |
|
23 SAFile = "eric6_trpreviewer" |
|
24 |
|
25 # define the protocol tokens |
|
26 SALoadForm = 'LoadForm' |
|
27 SALoadTranslation = 'LoadTranslation' |
|
28 |
|
29 |
|
30 class TRSingleApplicationServer(SingleApplicationServer): |
|
31 """ |
|
32 Class implementing the single application server embedded within the |
|
33 Translations Previewer. |
|
34 |
|
35 @signal loadForm(str) emitted to load a form file |
|
36 @signal loadTranslation(str, bool) emitted to load a translation file |
|
37 """ |
|
38 loadForm = pyqtSignal(str) |
|
39 loadTranslation = pyqtSignal(str, bool) |
|
40 |
|
41 def __init__(self, parent): |
|
42 """ |
|
43 Constructor |
|
44 |
|
45 @param parent parent widget (QWidget) |
|
46 """ |
|
47 SingleApplicationServer.__init__(self, SAFile) |
|
48 |
|
49 self.parent = parent |
|
50 |
|
51 def handleCommand(self, command, arguments): |
|
52 """ |
|
53 Public slot to handle the command sent by the client. |
|
54 |
|
55 @param command command sent by the client |
|
56 @type str |
|
57 @param arguments list of command arguments |
|
58 @type list of str |
|
59 """ |
|
60 if command == SALoadForm: |
|
61 self.__saLoadForm(arguments) |
|
62 |
|
63 elif command == SALoadTranslation: |
|
64 self.__saLoadTranslation(arguments) |
|
65 |
|
66 def __saLoadForm(self, fnames): |
|
67 """ |
|
68 Private method used to handle the "Load Form" command. |
|
69 |
|
70 @param fnames filenames of the forms to be loaded (list of strings) |
|
71 """ |
|
72 for fname in fnames: |
|
73 self.loadForm.emit(fname) |
|
74 |
|
75 def __saLoadTranslation(self, fnames): |
|
76 """ |
|
77 Private method used to handle the "Load Translation" command. |
|
78 |
|
79 @param fnames filenames of the translations to be loaded |
|
80 (list of strings) |
|
81 """ |
|
82 first = True |
|
83 for fname in fnames: |
|
84 self.loadTranslation.emit(fname, first) |
|
85 first = False |
|
86 |
|
87 |
|
88 class TRSingleApplicationClient(SingleApplicationClient): |
|
89 """ |
|
90 Class implementing the single application client of the Translations |
|
91 Previewer. |
|
92 """ |
|
93 def __init__(self): |
|
94 """ |
|
95 Constructor |
|
96 """ |
|
97 SingleApplicationClient.__init__(self, SAFile) |
|
98 |
|
99 def processArgs(self, args): |
|
100 """ |
|
101 Public method to process the command line args passed to the UI. |
|
102 |
|
103 @param args list of files to open |
|
104 """ |
|
105 # no args, return |
|
106 if args is None: |
|
107 return |
|
108 |
|
109 uiFiles = [] |
|
110 qmFiles = [] |
|
111 |
|
112 for arg in args: |
|
113 ext = os.path.splitext(arg)[1] |
|
114 ext = ext.lower() |
|
115 |
|
116 if ext == '.ui': |
|
117 uiFiles.append(arg) |
|
118 elif ext == '.qm': |
|
119 qmFiles.append(arg) |
|
120 |
|
121 self.sendCommand(SALoadForm, uiFiles) |
|
122 self.sendCommand(SALoadTranslation, qmFiles) |
|
123 |
|
124 self.disconnect() |