E5Gui/E5SingleApplication.py

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

eric ide

mercurial