|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2002 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the project browser part of the eric4 UI. |
|
8 """ |
|
9 |
|
10 import os |
|
11 import sys |
|
12 |
|
13 from PyQt4.QtCore import * |
|
14 from PyQt4.QtGui import * |
|
15 |
|
16 from UI.Browser import Browser |
|
17 |
|
18 from E4Gui.E4TabWidget import E4TabWidget |
|
19 from E4Gui.E4Led import E4Led |
|
20 |
|
21 from ProjectSourcesBrowser import ProjectSourcesBrowser |
|
22 from ProjectFormsBrowser import ProjectFormsBrowser |
|
23 from ProjectTranslationsBrowser import ProjectTranslationsBrowser |
|
24 from ProjectResourcesBrowser import ProjectResourcesBrowser |
|
25 from ProjectInterfacesBrowser import ProjectInterfacesBrowser |
|
26 from ProjectOthersBrowser import ProjectOthersBrowser |
|
27 |
|
28 import UI.PixmapCache |
|
29 import Preferences |
|
30 |
|
31 from ProjectBrowserFlags import SourcesBrowserFlag, FormsBrowserFlag, \ |
|
32 ResourcesBrowserFlag, TranslationsBrowserFlag, InterfacesBrowserFlag, \ |
|
33 OthersBrowserFlag, AllBrowsersFlag |
|
34 |
|
35 class ProjectBrowser(E4TabWidget): |
|
36 """ |
|
37 Class implementing the project browser part of the eric4 UI. |
|
38 |
|
39 It generates a widget with up to seven tabs. The individual tabs contain |
|
40 the project sources browser, the project forms browser, |
|
41 the project resources browser, the project translations browser, |
|
42 the project interfaces (IDL) browser and a browser for stuff, |
|
43 that doesn't fit these categories. Optionally it contains an additional |
|
44 tab with the file system browser. |
|
45 """ |
|
46 |
|
47 def __init__(self, project, parent = None, embeddedBrowser = True): |
|
48 """ |
|
49 Constructor |
|
50 |
|
51 @param project reference to the project object |
|
52 @param parent parent widget (QWidget) |
|
53 @param embeddedBrowser flag indicating whether the file browser should |
|
54 be included. This flag is set to False by those layouts, that |
|
55 have the file browser in a separate window or embedded |
|
56 in the debeug browser instead |
|
57 """ |
|
58 E4TabWidget.__init__(self, parent) |
|
59 self.project = project |
|
60 |
|
61 self.setWindowIcon(UI.PixmapCache.getIcon("eric.png")) |
|
62 |
|
63 self.vcsStatusIndicator = E4Led(self) |
|
64 self.setCornerWidget(self.vcsStatusIndicator, Qt.TopLeftCorner) |
|
65 self.vcsStatusColorNames = { |
|
66 "A" : "VcsAdded", |
|
67 "M" : "VcsModified", |
|
68 "R" : "VcsReplaced", |
|
69 "U" : "VcsUpdate", |
|
70 "Z" : "VcsConflict", |
|
71 } |
|
72 self.vcsStatusText = { |
|
73 " " : self.trUtf8("up to date"), |
|
74 "A" : self.trUtf8("files added"), |
|
75 "M" : self.trUtf8("local modifications"), |
|
76 "R" : self.trUtf8("files replaced"), |
|
77 "U" : self.trUtf8("update required"), |
|
78 "Z" : self.trUtf8("conflict"), |
|
79 } |
|
80 self.__vcsStateChanged(" ") |
|
81 |
|
82 # step 1: create all the individual browsers |
|
83 # sources browser |
|
84 self.psBrowser = ProjectSourcesBrowser(self.project) |
|
85 # forms browser |
|
86 self.pfBrowser = ProjectFormsBrowser(self.project) |
|
87 # resources browser |
|
88 self.prBrowser = ProjectResourcesBrowser(self.project) |
|
89 # translations browser |
|
90 self.ptBrowser = ProjectTranslationsBrowser(self.project) |
|
91 # interfaces (IDL) browser |
|
92 self.piBrowser = ProjectInterfacesBrowser(self.project) |
|
93 # others browser |
|
94 self.poBrowser = ProjectOthersBrowser(self.project) |
|
95 |
|
96 # add the file browser, if it should be embedded here |
|
97 self.embeddedBrowser = embeddedBrowser |
|
98 if embeddedBrowser: |
|
99 self.fileBrowser = Browser() |
|
100 |
|
101 # step 2: connect all the browsers |
|
102 # connect the sources browser |
|
103 self.connect(self.project, SIGNAL('projectClosed'), |
|
104 self.psBrowser._projectClosed) |
|
105 self.connect(self.project, SIGNAL('projectOpened'), |
|
106 self.psBrowser._projectOpened) |
|
107 self.connect(self.project, SIGNAL('newProject'), |
|
108 self.psBrowser._newProject) |
|
109 self.connect(self.project, SIGNAL('reinitVCS'), |
|
110 self.psBrowser._initMenusAndVcs) |
|
111 |
|
112 # connect the forms browser |
|
113 self.connect(self.project, SIGNAL('projectClosed'), |
|
114 self.pfBrowser._projectClosed) |
|
115 self.connect(self.project, SIGNAL('projectOpened'), |
|
116 self.pfBrowser._projectOpened) |
|
117 self.connect(self.project, SIGNAL('newProject'), |
|
118 self.pfBrowser._newProject) |
|
119 self.connect(self.project, SIGNAL('reinitVCS'), |
|
120 self.pfBrowser._initMenusAndVcs) |
|
121 |
|
122 # connect the resources browser |
|
123 self.connect(self.project, SIGNAL('projectClosed'), |
|
124 self.prBrowser._projectClosed) |
|
125 self.connect(self.project, SIGNAL('projectOpened'), |
|
126 self.prBrowser._projectOpened) |
|
127 self.connect(self.project, SIGNAL('newProject'), |
|
128 self.prBrowser._newProject) |
|
129 self.connect(self.project, SIGNAL('reinitVCS'), |
|
130 self.prBrowser._initMenusAndVcs) |
|
131 |
|
132 # connect the translations browser |
|
133 self.connect(self.project, SIGNAL('projectClosed'), |
|
134 self.ptBrowser._projectClosed) |
|
135 self.connect(self.project, SIGNAL('projectOpened'), |
|
136 self.ptBrowser._projectOpened) |
|
137 self.connect(self.project, SIGNAL('newProject'), |
|
138 self.ptBrowser._newProject) |
|
139 self.connect(self.project, SIGNAL('reinitVCS'), |
|
140 self.ptBrowser._initMenusAndVcs) |
|
141 |
|
142 # connect the interfaces (IDL) browser |
|
143 self.connect(self.project, SIGNAL('projectClosed'), |
|
144 self.piBrowser._projectClosed) |
|
145 self.connect(self.project, SIGNAL('projectOpened'), |
|
146 self.piBrowser._projectOpened) |
|
147 self.connect(self.project, SIGNAL('newProject'), |
|
148 self.piBrowser._newProject) |
|
149 self.connect(self.project, SIGNAL('reinitVCS'), |
|
150 self.piBrowser._initMenusAndVcs) |
|
151 |
|
152 # connect the others browser |
|
153 self.connect(self.project, SIGNAL('projectClosed'), |
|
154 self.poBrowser._projectClosed) |
|
155 self.connect(self.project, SIGNAL('projectOpened'), |
|
156 self.poBrowser._projectOpened) |
|
157 self.connect(self.project, SIGNAL('newProject'), |
|
158 self.poBrowser._newProject) |
|
159 self.connect(self.project, SIGNAL('reinitVCS'), |
|
160 self.poBrowser._initMenusAndVcs) |
|
161 |
|
162 # add signal connection to ourself |
|
163 self.connect(self.project, SIGNAL('projectOpened'), |
|
164 self.__projectOpened) |
|
165 self.connect(self.project, SIGNAL('projectClosed'), |
|
166 self.__projectClosed) |
|
167 self.connect(self.project, SIGNAL('newProject'), |
|
168 self.__newProject) |
|
169 self.connect(self.project, SIGNAL('projectPropertiesChanged'), |
|
170 self.__projectPropertiesChanged) |
|
171 self.connect(self, SIGNAL("currentChanged(int)"), self.__currentChanged) |
|
172 self.connect(self.project.getModel(), SIGNAL("vcsStateChanged"), |
|
173 self.__vcsStateChanged) |
|
174 |
|
175 self.__currentBrowsersFlags = 0 |
|
176 self.__projectPropertiesChanged() |
|
177 if self.embeddedBrowser: |
|
178 self.setCurrentWidget(self.fileBrowser) |
|
179 else: |
|
180 self.setCurrentIndex(0) |
|
181 |
|
182 def __setBrowsersAvailable(self, browserFlags): |
|
183 """ |
|
184 Private method to add selected browsers to the project browser |
|
185 |
|
186 @param browserFlags flags indicating the browsers to add (integer) |
|
187 """ |
|
188 # step 1: remove all tabs |
|
189 while self.count() > 0: |
|
190 self.removeTab(0) |
|
191 |
|
192 # step 2: add browsers |
|
193 if browserFlags & SourcesBrowserFlag: |
|
194 index = self.addTab(self.psBrowser, |
|
195 UI.PixmapCache.getIcon("projectSources.png"), '') |
|
196 self.setTabToolTip(index, self.psBrowser.windowTitle()) |
|
197 |
|
198 if browserFlags & FormsBrowserFlag: |
|
199 index = self.addTab(self.pfBrowser, |
|
200 UI.PixmapCache.getIcon("projectForms.png"), '') |
|
201 self.setTabToolTip(index, self.pfBrowser.windowTitle()) |
|
202 |
|
203 if browserFlags & ResourcesBrowserFlag: |
|
204 index = self.addTab(self.prBrowser, |
|
205 UI.PixmapCache.getIcon("projectResources.png"), '') |
|
206 self.setTabToolTip(index, self.prBrowser.windowTitle()) |
|
207 |
|
208 if browserFlags & TranslationsBrowserFlag: |
|
209 index = self.addTab(self.ptBrowser, |
|
210 UI.PixmapCache.getIcon("projectTranslations.png"), '') |
|
211 self.setTabToolTip(index, self.ptBrowser.windowTitle()) |
|
212 |
|
213 if browserFlags & InterfacesBrowserFlag: |
|
214 index = self.addTab(self.piBrowser, |
|
215 UI.PixmapCache.getIcon("projectInterfaces.png"), '') |
|
216 self.setTabToolTip(index, self.piBrowser.windowTitle()) |
|
217 |
|
218 if browserFlags & OthersBrowserFlag: |
|
219 index = self.addTab(self.poBrowser, |
|
220 UI.PixmapCache.getIcon("projectOthers.png"), '') |
|
221 self.setTabToolTip(index, self.poBrowser.windowTitle()) |
|
222 |
|
223 if self.embeddedBrowser: |
|
224 index = self.addTab(self.fileBrowser, |
|
225 UI.PixmapCache.getIcon("browser.png"), '') |
|
226 self.setTabToolTip(index, self.fileBrowser.windowTitle()) |
|
227 |
|
228 QApplication.processEvents() |
|
229 |
|
230 def showEvent(self, evt): |
|
231 """ |
|
232 Protected method handleing the show event. |
|
233 |
|
234 @param evt show event to handle (QShowEvent) |
|
235 """ |
|
236 E4TabWidget.showEvent(self, evt) |
|
237 if self.embeddedBrowser: |
|
238 self.fileBrowser.layoutDisplay() |
|
239 |
|
240 def __currentChanged(self, index): |
|
241 """ |
|
242 Private slot to handle the currentChanged(int) signal. |
|
243 """ |
|
244 if index > -1: |
|
245 browser = self.widget(index) |
|
246 if browser is not None: |
|
247 browser.layoutDisplay() |
|
248 |
|
249 def __projectOpened(self): |
|
250 """ |
|
251 Private slot to handle the projectOpened signal. |
|
252 """ |
|
253 self.__projectPropertiesChanged() |
|
254 self.setCurrentIndex(0) |
|
255 self.__vcsStateChanged(" ") |
|
256 |
|
257 def __projectClosed(self): |
|
258 """ |
|
259 Private slot to handle the projectClosed signal. |
|
260 """ |
|
261 self.__projectPropertiesChanged() |
|
262 if self.embeddedBrowser: |
|
263 self.setCurrentWidget(self.fileBrowser) |
|
264 else: |
|
265 self.setCurrentIndex(0) |
|
266 self.__setSourcesIcon() |
|
267 self.__vcsStateChanged(" ") |
|
268 |
|
269 def __newProject(self): |
|
270 """ |
|
271 Private slot to handle the newProject signal. |
|
272 """ |
|
273 self.setCurrentIndex(0) |
|
274 self.__projectPropertiesChanged() |
|
275 |
|
276 def __projectPropertiesChanged(self): |
|
277 """ |
|
278 Private slot to handle the projectPropertiesChanged signal. |
|
279 """ |
|
280 if self.project.isOpen(): |
|
281 flags = Preferences.getProjectBrowserFlags(self.project.getProjectType()) |
|
282 else: |
|
283 flags = AllBrowsersFlag |
|
284 |
|
285 if flags != self.__currentBrowsersFlags: |
|
286 self.__currentBrowsersFlags = flags |
|
287 self.__setBrowsersAvailable(flags) |
|
288 |
|
289 if self.embeddedBrowser: |
|
290 endIndex = self.count() - 1 |
|
291 else: |
|
292 endIndex = self.count() |
|
293 for index in range(endIndex) : |
|
294 self.setTabEnabled(index, self.project.isOpen()) |
|
295 |
|
296 self.__setSourcesIcon() |
|
297 |
|
298 def __setSourcesIcon(self): |
|
299 """ |
|
300 Private method to set the right icon for the sources browser tab. |
|
301 """ |
|
302 if not self.project.isOpen(): |
|
303 icon = UI.PixmapCache.getIcon("projectSources.png") |
|
304 else: |
|
305 if self.project.pdata["PROGLANGUAGE"][0] in ["Python", "Python3"]: |
|
306 if self.project.pdata["MIXEDLANGUAGE"][0]: |
|
307 icon = UI.PixmapCache.getIcon("projectSourcesPyMixed.png") |
|
308 else: |
|
309 icon = UI.PixmapCache.getIcon("projectSourcesPy.png") |
|
310 elif self.project.pdata["PROGLANGUAGE"][0] == "Ruby": |
|
311 if self.project.pdata["MIXEDLANGUAGE"][0]: |
|
312 icon = UI.PixmapCache.getIcon("projectSourcesRbMixed.png") |
|
313 else: |
|
314 icon = UI.PixmapCache.getIcon("projectSourcesRb.png") |
|
315 else: |
|
316 icon = UI.PixmapCache.getIcon("projectSources.png") |
|
317 self.setTabIcon(self.indexOf(self.psBrowser), icon) |
|
318 |
|
319 def handleEditorChanged(self, fn): |
|
320 """ |
|
321 Public slot to handle the editorChanged signal. |
|
322 |
|
323 @param fn filename of the changed file (string) |
|
324 """ |
|
325 if Preferences.getProject("FollowEditor"): |
|
326 if self.project.isProjectSource(fn): |
|
327 self.psBrowser.selectFile(fn) |
|
328 elif self.project.isProjectForm(fn): |
|
329 self.pfBrowser.selectFile(fn) |
|
330 elif self.project.isProjectInterface(fn): |
|
331 self.piBrowser.selectFile(fn) |
|
332 |
|
333 def getProjectBrowsers(self): |
|
334 """ |
|
335 Public method to get references to the individual project browsers. |
|
336 |
|
337 @return list of references to project browsers |
|
338 """ |
|
339 return [self.psBrowser, self.pfBrowser, self.prBrowser, |
|
340 self.ptBrowser, self.piBrowser, self.poBrowser] |
|
341 |
|
342 def getProjectBrowser(self, name): |
|
343 """ |
|
344 Public method to get a reference to the named project browser. |
|
345 |
|
346 @param name name of the requested project browser (string). |
|
347 Valid names are "sources, forms, resources, translations, |
|
348 interfaces, others". |
|
349 @return reference to the requested browser or None |
|
350 """ |
|
351 if name == "sources": |
|
352 return self.psBrowser |
|
353 elif name == "forms": |
|
354 return self.pfBrowser |
|
355 elif name == "resources": |
|
356 return self.prBrowser |
|
357 elif name == "translations": |
|
358 return self.ptBrowser |
|
359 elif name == "interfaces": |
|
360 return self.piBrowser |
|
361 elif name == "others": |
|
362 return self.poBrowser |
|
363 else: |
|
364 return None |
|
365 |
|
366 def handlePreferencesChanged(self): |
|
367 """ |
|
368 Public slot used to handle the preferencesChanged signal. |
|
369 """ |
|
370 self.__projectPropertiesChanged() |
|
371 self.__vcsStateChanged(self.currentVcsStatus) |
|
372 |
|
373 def __vcsStateChanged(self, state): |
|
374 """ |
|
375 Private slot to handle a change in the vcs state. |
|
376 |
|
377 @param state new vcs state (string) |
|
378 """ |
|
379 self.currentVcsStatus = state |
|
380 if state == " " or state not in self.vcsStatusColorNames: |
|
381 self.vcsStatusIndicator.setColor(QColor(Qt.lightGray)) |
|
382 else: |
|
383 self.vcsStatusIndicator.setColor(\ |
|
384 Preferences.getProjectBrowserColour(self.vcsStatusColorNames[state])) |
|
385 self.vcsStatusIndicator.setToolTip(self.vcsStatusText[state]) |