8 """ |
8 """ |
9 |
9 |
10 import contextlib |
10 import contextlib |
11 |
11 |
12 from PyQt6.QtCore import Qt, pyqtSignal |
12 from PyQt6.QtCore import Qt, pyqtSignal |
13 from PyQt6.QtGui import QColor |
13 from PyQt6.QtGui import QColor, QIcon |
14 from PyQt6.QtWidgets import QApplication |
|
15 |
14 |
16 from eric7 import Preferences |
15 from eric7 import Preferences |
17 from eric7.EricGui import EricPixmapCache |
16 from eric7.EricGui import EricPixmapCache |
18 from eric7.EricWidgets import EricMessageBox |
17 from eric7.EricWidgets import EricMessageBox |
19 from eric7.EricWidgets.EricLed import EricClickableLed |
18 from eric7.EricWidgets.EricLed import EricClickableLed |
20 from eric7.EricWidgets.EricTabWidget import EricTabWidget |
19 from eric7.EricWidgets.EricTabWidget import EricTabWidget |
21 |
20 |
22 from .ProjectBrowserFlags import ( |
|
23 AllBrowsersFlag, |
|
24 FormsBrowserFlag, |
|
25 InterfacesBrowserFlag, |
|
26 OthersBrowserFlag, |
|
27 ProtocolsBrowserFlag, |
|
28 ResourcesBrowserFlag, |
|
29 SourcesBrowserFlag, |
|
30 TranslationsBrowserFlag, |
|
31 ) |
|
32 from .ProjectBrowserRepositoryItem import ProjectBrowserRepositoryItem |
21 from .ProjectBrowserRepositoryItem import ProjectBrowserRepositoryItem |
33 from .ProjectFormsBrowser import ProjectFormsBrowser |
22 from .ProjectFormsBrowser import ProjectFormsBrowser |
34 from .ProjectInterfacesBrowser import ProjectInterfacesBrowser |
23 from .ProjectInterfacesBrowser import ProjectInterfacesBrowser |
35 from .ProjectOthersBrowser import ProjectOthersBrowser |
24 from .ProjectOthersBrowser import ProjectOthersBrowser |
36 from .ProjectProtocolsBrowser import ProjectProtocolsBrowser |
25 from .ProjectProtocolsBrowser import ProjectProtocolsBrowser |
160 self.project.newProject.connect(self.__newProject) |
149 self.project.newProject.connect(self.__newProject) |
161 self.project.projectPropertiesChanged.connect(self.__projectPropertiesChanged) |
150 self.project.projectPropertiesChanged.connect(self.__projectPropertiesChanged) |
162 self.currentChanged.connect(self.__currentChanged) |
151 self.currentChanged.connect(self.__currentChanged) |
163 self.project.getModel().vcsStateChanged.connect(self.__vcsStateChanged) |
152 self.project.getModel().vcsStateChanged.connect(self.__vcsStateChanged) |
164 |
153 |
165 self.__currentBrowsersFlags = 0 |
154 self.__currentBrowsersList = [] |
166 self.__projectPropertiesChanged() |
155 self.__projectPropertiesChanged() |
167 self.setCurrentIndex(0) |
156 self.setCurrentIndex(0) |
168 |
157 |
169 def addTypedProjectBrowser(self, browserType, projectBrowserItem): |
158 def addTypedProjectBrowser(self, browserType, projectBrowserItem): |
170 """ |
159 """ |
240 @return list of project browser types |
229 @return list of project browser types |
241 @rtype list of str |
230 @rtype list of str |
242 """ |
231 """ |
243 return list(self.__browserRepository.keys()) |
232 return list(self.__browserRepository.keys()) |
244 |
233 |
245 def __setBrowsersAvailable(self, browserFlags): |
234 def getProjectBrowserUserStrings(self): |
|
235 """ |
|
236 Public method to get a dictionary of defined project browser user strings. |
|
237 |
|
238 @return dictionary of defined project browser user strings |
|
239 @rtype dict |
|
240 """ |
|
241 return { |
|
242 key: item.projectBrowserUserString |
|
243 for key, item in self.__browserRepository.items() |
|
244 } |
|
245 |
|
246 def getProjectBrowserIcon(self, browserType): |
|
247 try: |
|
248 return self.__browserRepository[browserType].getIcon() |
|
249 except KeyError: |
|
250 return QIcon() |
|
251 |
|
252 def __setBrowsersAvailable(self, browsersList): |
246 """ |
253 """ |
247 Private method to add selected browsers to the project browser. |
254 Private method to add selected browsers to the project browser. |
248 |
255 |
249 @param browserFlags flags indicating the browsers to add (integer) |
256 @param browsersList list of project browsers to be shown |
|
257 @type list of str |
250 """ |
258 """ |
251 # step 1: remove all tabs |
259 # step 1: remove all tabs |
252 while self.count() > 0: |
260 while self.count() > 0: |
253 self.removeTab(0) |
261 self.removeTab(0) |
254 |
262 |
255 # step 2: add browsers |
263 # step 2: add browsers |
256 # TODO: change the logic after browser flags have been eliminated |
264 for browser in sorted( |
257 if browserFlags & SourcesBrowserFlag: |
265 browsersList, |
|
266 key=lambda x: self.__browserRepository[x].priority, |
|
267 reverse=True, |
|
268 ): |
258 index = self.addTab( |
269 index = self.addTab( |
259 self.__browserRepository["sources"].projectBrowser, |
270 self.__browserRepository[browser].projectBrowser, |
260 self.__browserRepository["sources"].getIcon(), |
271 self.__browserRepository[browser].getIcon(), |
261 "", |
272 "", |
262 ) |
273 ) |
263 self.setTabToolTip( |
274 self.setTabToolTip( |
264 index, |
275 index, |
265 self.__browserRepository["sources"].projectBrowser.windowTitle(), |
276 self.__browserRepository[browser].projectBrowser.windowTitle(), |
266 ) |
277 ) |
267 |
|
268 if browserFlags & FormsBrowserFlag: |
|
269 index = self.addTab( |
|
270 self.__browserRepository["forms"].projectBrowser, |
|
271 self.__browserRepository["forms"].getIcon(), |
|
272 "", |
|
273 ) |
|
274 self.setTabToolTip( |
|
275 index, |
|
276 self.__browserRepository["forms"].projectBrowser.windowTitle(), |
|
277 ) |
|
278 |
|
279 if browserFlags & ResourcesBrowserFlag: |
|
280 index = self.addTab( |
|
281 self.__browserRepository["resources"].projectBrowser, |
|
282 self.__browserRepository["resources"].getIcon(), |
|
283 "", |
|
284 ) |
|
285 self.setTabToolTip( |
|
286 index, |
|
287 self.__browserRepository["resources"].projectBrowser.windowTitle(), |
|
288 ) |
|
289 |
|
290 if browserFlags & TranslationsBrowserFlag: |
|
291 index = self.addTab( |
|
292 self.__browserRepository["translations"].projectBrowser, |
|
293 self.__browserRepository["translations"].getIcon(), |
|
294 "", |
|
295 ) |
|
296 self.setTabToolTip( |
|
297 index, |
|
298 self.__browserRepository["translations"].projectBrowser.windowTitle(), |
|
299 ) |
|
300 |
|
301 if browserFlags & InterfacesBrowserFlag: |
|
302 index = self.addTab( |
|
303 self.__browserRepository["interfaces"].projectBrowser, |
|
304 self.__browserRepository["interfaces"].getIcon(), |
|
305 "", |
|
306 ) |
|
307 self.setTabToolTip( |
|
308 index, |
|
309 self.__browserRepository["interfaces"].projectBrowser.windowTitle(), |
|
310 ) |
|
311 |
|
312 if browserFlags & ProtocolsBrowserFlag: |
|
313 index = self.addTab( |
|
314 self.__browserRepository["protocols"].projectBrowser, |
|
315 self.__browserRepository["protocols"].getIcon(), |
|
316 "", |
|
317 ) |
|
318 self.setTabToolTip( |
|
319 index, |
|
320 self.__browserRepository["protocols"].projectBrowser.windowTitle(), |
|
321 ) |
|
322 |
|
323 if browserFlags & OthersBrowserFlag: |
|
324 index = self.addTab( |
|
325 self.__browserRepository["others"].projectBrowser, |
|
326 self.__browserRepository["others"].getIcon(), |
|
327 "", |
|
328 ) |
|
329 self.setTabToolTip( |
|
330 index, |
|
331 self.__browserRepository["others"].projectBrowser.windowTitle(), |
|
332 ) |
|
333 |
|
334 QApplication.processEvents() |
|
335 |
278 |
336 def __currentChanged(self, index): |
279 def __currentChanged(self, index): |
337 """ |
280 """ |
338 Private slot to handle the currentChanged(int) signal. |
281 Private slot to handle the currentChanged(int) signal. |
339 |
282 |
370 |
313 |
371 def __projectPropertiesChanged(self): |
314 def __projectPropertiesChanged(self): |
372 """ |
315 """ |
373 Private slot to handle the projectPropertiesChanged signal. |
316 Private slot to handle the projectPropertiesChanged signal. |
374 """ |
317 """ |
375 flags = ( |
318 browsersList = ( |
376 Preferences.getProjectBrowserFlags(self.project.getProjectType()) |
319 Preferences.getProjectBrowsers(self.project.getProjectType()) |
377 if self.project.isOpen() |
320 if self.project.isOpen() |
378 else AllBrowsersFlag |
321 else list(self.__browserRepository.keys()) |
379 ) |
322 ) |
380 |
323 |
381 if flags != self.__currentBrowsersFlags: |
324 if browsersList != self.__currentBrowsersList: |
382 self.__currentBrowsersFlags = flags |
325 self.__currentBrowsersList = browsersList[:] |
383 self.__setBrowsersAvailable(flags) |
326 self.__setBrowsersAvailable(browsersList) |
384 |
327 |
385 endIndex = self.count() |
328 endIndex = self.count() |
386 for index in range(endIndex): |
329 for index in range(endIndex): |
387 self.setTabEnabled(index, self.project.isOpen()) |
330 self.setTabEnabled(index, self.project.isOpen()) |
388 |
331 |
389 self.__setSourcesIcon() |
332 self.__setSourcesIcon() |
390 |
333 |
391 # TODO: move the logic to determine the icon to the sources browser. |
|
392 def __setSourcesIcon(self): |
334 def __setSourcesIcon(self): |
393 """ |
335 """ |
394 Private method to set the right icon for the sources browser tab. |
336 Private method to set the right icon for the sources browser tab. |
395 """ |
337 """ |
396 if not self.project.isOpen(): |
338 self.setTabIcon( |
397 icon = EricPixmapCache.getIcon("projectSources") |
339 self.indexOf(self.getProjectBrowser("sources")), |
398 else: |
340 self.getProjectBrowserIcon("sources"), |
399 if self.project.getProjectLanguage() == "Python3": |
341 ) |
400 if self.project.isMixedLanguageProject(): |
|
401 icon = EricPixmapCache.getIcon("projectSourcesPyMixed") |
|
402 else: |
|
403 icon = EricPixmapCache.getIcon("projectSourcesPy") |
|
404 elif self.project.getProjectLanguage() == "MicroPython": |
|
405 icon = EricPixmapCache.getIcon("micropython") |
|
406 elif self.project.getProjectLanguage() == "Ruby": |
|
407 if self.project.isMixedLanguageProject(): |
|
408 icon = EricPixmapCache.getIcon("projectSourcesRbMixed") |
|
409 else: |
|
410 icon = EricPixmapCache.getIcon("projectSourcesRb") |
|
411 elif self.project.getProjectLanguage() == "JavaScript": |
|
412 icon = EricPixmapCache.getIcon("projectSourcesJavaScript") |
|
413 else: |
|
414 icon = EricPixmapCache.getIcon("projectSources") |
|
415 self.setTabIcon(self.indexOf(self.getProjectBrowser("sources")), icon) |
|
416 |
342 |
417 def handleEditorChanged(self, fn): |
343 def handleEditorChanged(self, fn): |
418 """ |
344 """ |
419 Public slot to handle the editorChanged signal. |
345 Public slot to handle the editorChanged signal. |
420 |
346 |