|
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 E5Gui.E5Application import e5App |
|
15 |
|
16 from Toolbox.SingleApplication import SingleApplicationClient, \ |
|
17 SingleApplicationServer |
|
18 |
|
19 import Utilities |
|
20 |
|
21 ########################################################################### |
|
22 ## define some module global stuff |
|
23 ########################################################################### |
|
24 |
|
25 SAFile = "eric6" |
|
26 |
|
27 # define the protocol tokens |
|
28 SAOpenFile = 'OpenFile' |
|
29 SAOpenProject = 'OpenProject' |
|
30 SAOpenMultiProject = 'OpenMultiProject' |
|
31 SAArguments = 'Arguments' |
|
32 |
|
33 |
|
34 class E5SingleApplicationServer(SingleApplicationServer): |
|
35 """ |
|
36 Class implementing the single application server embedded within the IDE. |
|
37 """ |
|
38 def __init__(self): |
|
39 """ |
|
40 Constructor |
|
41 """ |
|
42 SingleApplicationServer.__init__(self, SAFile) |
|
43 |
|
44 def handleCommand(self, command, arguments): |
|
45 """ |
|
46 Public slot to handle the command sent by the client. |
|
47 |
|
48 @param command command sent by the client |
|
49 @type str |
|
50 @param arguments list of command arguments |
|
51 @type list of str |
|
52 """ |
|
53 if command == SAOpenFile: |
|
54 self.__saOpenFile(arguments[0]) |
|
55 return |
|
56 |
|
57 if command == SAOpenProject: |
|
58 self.__saOpenProject(arguments[0]) |
|
59 return |
|
60 |
|
61 if command == SAOpenMultiProject: |
|
62 self.__saOpenMultiProject(arguments[0]) |
|
63 return |
|
64 |
|
65 if command == SAArguments: |
|
66 self.__saArguments(arguments[0]) |
|
67 return |
|
68 |
|
69 def __saOpenFile(self, fname): |
|
70 """ |
|
71 Private method used to handle the "Open File" command. |
|
72 |
|
73 @param fname filename to be opened (string) |
|
74 """ |
|
75 e5App().getObject("ViewManager").openSourceFile(fname) |
|
76 |
|
77 def __saOpenProject(self, pfname): |
|
78 """ |
|
79 Private method used to handle the "Open Project" command. |
|
80 |
|
81 @param pfname filename of the project to be opened (string) |
|
82 """ |
|
83 e5App().getObject("Project").openProject(pfname) |
|
84 |
|
85 def __saOpenMultiProject(self, pfname): |
|
86 """ |
|
87 Private method used to handle the "Open Multi-Project" command. |
|
88 |
|
89 @param pfname filename of the multi project to be opened (string) |
|
90 """ |
|
91 e5App().getObject("MultiProject").openMultiProject(pfname) |
|
92 |
|
93 def __saArguments(self, argsStr): |
|
94 """ |
|
95 Private method used to handle the "Arguments" command. |
|
96 |
|
97 @param argsStr space delimited list of command args(string) |
|
98 """ |
|
99 e5App().getObject("DebugUI").setArgvHistory(argsStr) |
|
100 |
|
101 |
|
102 class E5SingleApplicationClient(SingleApplicationClient): |
|
103 """ |
|
104 Class implementing the single application client of the IDE. |
|
105 """ |
|
106 def __init__(self): |
|
107 """ |
|
108 Constructor |
|
109 """ |
|
110 SingleApplicationClient.__init__(self, SAFile) |
|
111 |
|
112 def processArgs(self, args): |
|
113 """ |
|
114 Public method to process the command line args passed to the UI. |
|
115 |
|
116 @param args list of files to open |
|
117 """ |
|
118 # no args, return |
|
119 if args is None: |
|
120 return |
|
121 |
|
122 # holds space delimited list of command args, if any |
|
123 argsStr = None |
|
124 # flag indicating '--' options was found |
|
125 ddseen = False |
|
126 |
|
127 if Utilities.isWindowsPlatform(): |
|
128 argChars = ['-', '/'] |
|
129 else: |
|
130 argChars = ['-'] |
|
131 |
|
132 for arg in args: |
|
133 if arg == '--' and not ddseen: |
|
134 ddseen = True |
|
135 continue |
|
136 |
|
137 if arg[0] in argChars or ddseen: |
|
138 if argsStr is None: |
|
139 argsStr = arg |
|
140 else: |
|
141 argsStr = "{0} {1}".format(argsStr, arg) |
|
142 continue |
|
143 |
|
144 ext = os.path.splitext(arg)[1] |
|
145 ext = os.path.normcase(ext) |
|
146 |
|
147 if ext in ['.e4p']: |
|
148 self.__openProject(arg) |
|
149 elif ext in ['.e4m', '.e5m']: |
|
150 self.__openMultiProject(arg) |
|
151 else: |
|
152 self.__openFile(arg) |
|
153 |
|
154 # send any args we had |
|
155 if argsStr is not None: |
|
156 self.__sendArguments(argsStr) |
|
157 |
|
158 self.disconnect() |
|
159 |
|
160 def __openFile(self, fname): |
|
161 """ |
|
162 Private method to open a file in the application server. |
|
163 |
|
164 @param fname name of file to be opened (string) |
|
165 """ |
|
166 self.sendCommand(SAOpenFile, [Utilities.normabspath(fname)]) |
|
167 |
|
168 def __openProject(self, pfname): |
|
169 """ |
|
170 Private method to open a project in the application server. |
|
171 |
|
172 @param pfname name of the projectfile to be opened (string) |
|
173 """ |
|
174 self.sendCommand(SAOpenProject, [Utilities.normabspath(pfname)]) |
|
175 |
|
176 def __openMultiProject(self, pfname): |
|
177 """ |
|
178 Private method to open a project in the application server. |
|
179 |
|
180 @param pfname name of the projectfile to be opened (string) |
|
181 """ |
|
182 self.sendCommand(SAOpenMultiProject, [Utilities.normabspath(pfname)]) |
|
183 |
|
184 def __sendArguments(self, argsStr): |
|
185 """ |
|
186 Private method to set the command arguments in the application server. |
|
187 |
|
188 @param argsStr space delimited list of command args (string) |
|
189 """ |
|
190 self.sendCommand(SAArguments, [argsStr]) |