src/eric7/Tools/TRSingleApplication.py

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

eric ide

mercurial