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