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