60 """ |
60 """ |
61 Constructor |
61 Constructor |
62 |
62 |
63 @param project reference to the project object (Project.Project) |
63 @param project reference to the project object (Project.Project) |
64 @param parent parent widget (usually the ui object) (QWidget) |
64 @param parent parent widget (usually the ui object) (QWidget) |
65 @param filename optional filename of a multi project file to open (string) |
65 @param filename optional filename of a multi project file to open |
|
66 (string) |
66 """ |
67 """ |
67 super(MultiProject, self).__init__(parent) |
68 super(MultiProject, self).__init__(parent) |
68 |
69 |
69 self.ui = parent |
70 self.ui = parent |
70 self.projectObject = project |
71 self.projectObject = project |
86 self.pfile = "" # name of the multi project file |
87 self.pfile = "" # name of the multi project file |
87 self.ppath = "" # name of the multi project directory |
88 self.ppath = "" # name of the multi project directory |
88 self.description = "" # description of the multi project |
89 self.description = "" # description of the multi project |
89 self.name = "" |
90 self.name = "" |
90 self.opened = False |
91 self.opened = False |
91 self.projects = [] # list of project info; each info entry is a dictionary |
92 self.projects = [] # list of project info; each info entry is |
|
93 # a dictionary |
92 # 'name' : Name of the project |
94 # 'name' : Name of the project |
93 # 'file' : project filename |
95 # 'file' : project filename |
94 # 'master' : flag indicating the master project |
96 # 'master' : flag indicating the master |
|
97 # project |
95 # 'description' : description of the project |
98 # 'description' : description of the project |
96 |
99 |
97 def __loadRecent(self): |
100 def __loadRecent(self): |
98 """ |
101 """ |
99 Private method to load the recently opened multi project filenames. |
102 Private method to load the recently opened multi project filenames. |
108 |
111 |
109 def __saveRecent(self): |
112 def __saveRecent(self): |
110 """ |
113 """ |
111 Private method to save the list of recently opened filenames. |
114 Private method to save the list of recently opened filenames. |
112 """ |
115 """ |
113 Preferences.Prefs.rsettings.setValue(recentNameMultiProject, self.recent) |
116 Preferences.Prefs.rsettings.setValue( |
|
117 recentNameMultiProject, self.recent) |
114 Preferences.Prefs.rsettings.sync() |
118 Preferences.Prefs.rsettings.sync() |
115 |
119 |
116 def getMostRecent(self): |
120 def getMostRecent(self): |
117 """ |
121 """ |
118 Public method to get the most recently opened multiproject. |
122 Public method to get the most recently opened multiproject. |
203 return False |
207 return False |
204 else: |
208 else: |
205 QApplication.restoreOverrideCursor() |
209 QApplication.restoreOverrideCursor() |
206 E5MessageBox.critical(self.ui, |
210 E5MessageBox.critical(self.ui, |
207 self.trUtf8("Read multiproject file"), |
211 self.trUtf8("Read multiproject file"), |
208 self.trUtf8("<p>The multiproject file <b>{0}</b> could not be read.</p>")\ |
212 self.trUtf8( |
209 .format(fn)) |
213 "<p>The multiproject file <b>{0}</b> could not be" |
|
214 " read.</p>").format(fn)) |
210 return False |
215 return False |
211 |
216 |
212 self.pfile = os.path.abspath(fn) |
217 self.pfile = os.path.abspath(fn) |
213 self.ppath = os.path.abspath(os.path.dirname(fn)) |
218 self.ppath = os.path.abspath(os.path.dirname(fn)) |
214 |
219 |
225 def __writeMultiProject(self, fn=None): |
230 def __writeMultiProject(self, fn=None): |
226 """ |
231 """ |
227 Private method to save the multi project infos to a multi project file. |
232 Private method to save the multi project infos to a multi project file. |
228 |
233 |
229 @param fn optional filename of the multi project file to be written. |
234 @param fn optional filename of the multi project file to be written. |
230 If fn is None, the filename stored in the multi project object |
235 If fn is None, the filename stored in the multi project object |
231 is used. This is the 'save' action. If fn is given, this filename |
236 is used. This is the 'save' action. If fn is given, this filename |
232 is used instead of the one in the multi project object. This is the |
237 is used instead of the one in the multi project object. This is the |
233 'save as' action. |
238 'save as' action. |
234 @return flag indicating success |
239 @return flag indicating success |
235 """ |
240 """ |
236 if fn is None: |
241 if fn is None: |
237 fn = self.pfile |
242 fn = self.pfile |
238 |
243 |
239 f = QFile(fn) |
244 f = QFile(fn) |
240 if f.open(QIODevice.WriteOnly): |
245 if f.open(QIODevice.WriteOnly): |
241 from E5XML.MultiProjectWriter import MultiProjectWriter |
246 from E5XML.MultiProjectWriter import MultiProjectWriter |
242 MultiProjectWriter(f, self, os.path.splitext(os.path.basename(fn))[0])\ |
247 MultiProjectWriter( |
|
248 f, self, os.path.splitext(os.path.basename(fn))[0])\ |
243 .writeXML() |
249 .writeXML() |
244 res = True |
250 res = True |
245 else: |
251 else: |
246 E5MessageBox.critical(self.ui, |
252 E5MessageBox.critical(self.ui, |
247 self.trUtf8("Save multiproject file"), |
253 self.trUtf8("Save multiproject file"), |
349 |
355 |
350 def removeProject(self, fn): |
356 def removeProject(self, fn): |
351 """ |
357 """ |
352 Public slot to remove a project from the multi project. |
358 Public slot to remove a project from the multi project. |
353 |
359 |
354 @param fn filename of the project to be removed from the multi project (string) |
360 @param fn filename of the project to be removed from the multi |
|
361 project (string) |
355 """ |
362 """ |
356 for project in self.projects: |
363 for project in self.projects: |
357 if project['file'] == fn: |
364 if project['file'] == fn: |
358 self.projects.remove(project) |
365 self.projects.remove(project) |
359 self.projectRemoved.emit(project) |
366 self.projectRemoved.emit(project) |
396 |
403 |
397 def openMultiProject(self, fn=None, openMaster=True): |
404 def openMultiProject(self, fn=None, openMaster=True): |
398 """ |
405 """ |
399 Public slot to open a multi project. |
406 Public slot to open a multi project. |
400 |
407 |
401 @param fn optional filename of the multi project file to be read (string) |
408 @param fn optional filename of the multi project file to be |
|
409 read (string) |
402 @param openMaster flag indicating, that the master project |
410 @param openMaster flag indicating, that the master project |
403 should be opened depending on the configuration (boolean) |
411 should be opened depending on the configuration (boolean) |
404 """ |
412 """ |
405 if not self.checkDirty(): |
413 if not self.checkDirty(): |
406 return |
414 return |
407 |
415 |
408 if fn is None: |
416 if fn is None: |
409 fn = E5FileDialog.getOpenFileName( |
417 fn = E5FileDialog.getOpenFileName( |
410 self.parent(), |
418 self.parent(), |
411 self.trUtf8("Open multiproject"), |
419 self.trUtf8("Open multiproject"), |
412 Preferences.getMultiProject("Workspace") or Utilities.getHomeDir(), |
420 Preferences.getMultiProject("Workspace") or \ |
|
421 Utilities.getHomeDir(), |
413 self.trUtf8("Multiproject Files (*.e4m)")) |
422 self.trUtf8("Multiproject Files (*.e4m)")) |
414 |
423 |
415 if fn == "": |
424 if fn == "": |
416 fn = None |
425 fn = None |
417 |
426 |
431 self.addProjectAct.setEnabled(True) |
440 self.addProjectAct.setEnabled(True) |
432 self.propsAct.setEnabled(True) |
441 self.propsAct.setEnabled(True) |
433 |
442 |
434 self.multiProjectOpened.emit() |
443 self.multiProjectOpened.emit() |
435 |
444 |
436 if openMaster and Preferences.getMultiProject("OpenMasterAutomatically"): |
445 if openMaster and Preferences.getMultiProject( |
|
446 "OpenMasterAutomatically"): |
437 self.__openMasterProject(False) |
447 self.__openMasterProject(False) |
438 else: |
448 else: |
439 QApplication.restoreOverrideCursor() |
449 QApplication.restoreOverrideCursor() |
440 |
450 |
441 def saveMultiProject(self): |
451 def saveMultiProject(self): |
583 self.actions.append(act) |
593 self.actions.append(act) |
584 |
594 |
585 self.closeAct = E5Action(self.trUtf8('Close multiproject'), |
595 self.closeAct = E5Action(self.trUtf8('Close multiproject'), |
586 UI.PixmapCache.getIcon("multiProjectClose.png"), |
596 UI.PixmapCache.getIcon("multiProjectClose.png"), |
587 self.trUtf8('&Close'), 0, 0, self, 'multi_project_close') |
597 self.trUtf8('&Close'), 0, 0, self, 'multi_project_close') |
588 self.closeAct.setStatusTip(self.trUtf8('Close the current multiproject')) |
598 self.closeAct.setStatusTip(self.trUtf8( |
|
599 'Close the current multiproject')) |
589 self.closeAct.setWhatsThis(self.trUtf8( |
600 self.closeAct.setWhatsThis(self.trUtf8( |
590 """<b>Close</b>""" |
601 """<b>Close</b>""" |
591 """<p>This closes the current multiproject.</p>""" |
602 """<p>This closes the current multiproject.</p>""" |
592 )) |
603 )) |
593 self.closeAct.triggered[()].connect(self.closeMultiProject) |
604 self.closeAct.triggered[()].connect(self.closeMultiProject) |
604 self.saveAct.triggered[()].connect(self.saveMultiProject) |
615 self.saveAct.triggered[()].connect(self.saveMultiProject) |
605 self.actions.append(self.saveAct) |
616 self.actions.append(self.saveAct) |
606 |
617 |
607 self.saveasAct = E5Action(self.trUtf8('Save multiproject as'), |
618 self.saveasAct = E5Action(self.trUtf8('Save multiproject as'), |
608 UI.PixmapCache.getIcon("multiProjectSaveAs.png"), |
619 UI.PixmapCache.getIcon("multiProjectSaveAs.png"), |
609 self.trUtf8('Save &as...'), 0, 0, self, 'multi_project_save_as') |
620 self.trUtf8('Save &as...'), 0, 0, self, |
|
621 'multi_project_save_as') |
610 self.saveasAct.setStatusTip(self.trUtf8( |
622 self.saveasAct.setStatusTip(self.trUtf8( |
611 'Save the current multiproject to a new file')) |
623 'Save the current multiproject to a new file')) |
612 self.saveasAct.setWhatsThis(self.trUtf8( |
624 self.saveasAct.setWhatsThis(self.trUtf8( |
613 """<b>Save as</b>""" |
625 """<b>Save as</b>""" |
614 """<p>This saves the current multiproject to a new file.</p>""" |
626 """<p>This saves the current multiproject to a new file.</p>""" |
615 )) |
627 )) |
616 self.saveasAct.triggered[()].connect(self.saveMultiProjectAs) |
628 self.saveasAct.triggered[()].connect(self.saveMultiProjectAs) |
617 self.actions.append(self.saveasAct) |
629 self.actions.append(self.saveasAct) |
618 |
630 |
619 self.addProjectAct = E5Action(self.trUtf8('Add project to multiproject'), |
631 self.addProjectAct = E5Action( |
620 UI.PixmapCache.getIcon("fileProject.png"), |
632 self.trUtf8('Add project to multiproject'), |
621 self.trUtf8('Add &project...'), 0, 0, |
633 UI.PixmapCache.getIcon("fileProject.png"), |
622 self, 'multi_project_add_project') |
634 self.trUtf8('Add &project...'), 0, 0, |
|
635 self, 'multi_project_add_project') |
623 self.addProjectAct.setStatusTip(self.trUtf8( |
636 self.addProjectAct.setStatusTip(self.trUtf8( |
624 'Add a project to the current multiproject')) |
637 'Add a project to the current multiproject')) |
625 self.addProjectAct.setWhatsThis(self.trUtf8( |
638 self.addProjectAct.setWhatsThis(self.trUtf8( |
626 """<b>Add project...</b>""" |
639 """<b>Add project...</b>""" |
627 """<p>This opens a dialog for adding a project""" |
640 """<p>This opens a dialog for adding a project""" |
630 self.addProjectAct.triggered[()].connect(self.addProject) |
643 self.addProjectAct.triggered[()].connect(self.addProject) |
631 self.actions.append(self.addProjectAct) |
644 self.actions.append(self.addProjectAct) |
632 |
645 |
633 self.propsAct = E5Action(self.trUtf8('Multiproject properties'), |
646 self.propsAct = E5Action(self.trUtf8('Multiproject properties'), |
634 UI.PixmapCache.getIcon("multiProjectProps.png"), |
647 UI.PixmapCache.getIcon("multiProjectProps.png"), |
635 self.trUtf8('&Properties...'), 0, 0, self, 'multi_project_properties') |
648 self.trUtf8('&Properties...'), 0, 0, self, |
636 self.propsAct.setStatusTip(self.trUtf8('Show the multiproject properties')) |
649 'multi_project_properties') |
|
650 self.propsAct.setStatusTip(self.trUtf8( |
|
651 'Show the multiproject properties')) |
637 self.propsAct.setWhatsThis(self.trUtf8( |
652 self.propsAct.setWhatsThis(self.trUtf8( |
638 """<b>Properties...</b>""" |
653 """<b>Properties...</b>""" |
639 """<p>This shows a dialog to edit the multiproject properties.</p>""" |
654 """<p>This shows a dialog to edit the multiproject""" |
|
655 """ properties.</p>""" |
640 )) |
656 )) |
641 self.propsAct.triggered[()].connect(self.__showProperties) |
657 self.propsAct.triggered[()].connect(self.__showProperties) |
642 self.actions.append(self.propsAct) |
658 self.actions.append(self.propsAct) |
643 |
659 |
644 self.closeAct.setEnabled(False) |
660 self.closeAct.setEnabled(False) |
652 Public slot to initialize the multi project menu. |
668 Public slot to initialize the multi project menu. |
653 |
669 |
654 @return the menu generated (QMenu) |
670 @return the menu generated (QMenu) |
655 """ |
671 """ |
656 menu = QMenu(self.trUtf8('&Multiproject'), self.parent()) |
672 menu = QMenu(self.trUtf8('&Multiproject'), self.parent()) |
657 self.recentMenu = QMenu(self.trUtf8('Open &Recent Multiprojects'), menu) |
673 self.recentMenu = QMenu(self.trUtf8('Open &Recent Multiprojects'), |
|
674 menu) |
658 |
675 |
659 self.__menus = { |
676 self.__menus = { |
660 "Main": menu, |
677 "Main": menu, |
661 "Recent": self.recentMenu, |
678 "Recent": self.recentMenu, |
662 } |
679 } |
685 |
702 |
686 def initToolbar(self, toolbarManager): |
703 def initToolbar(self, toolbarManager): |
687 """ |
704 """ |
688 Public slot to initialize the multi project toolbar. |
705 Public slot to initialize the multi project toolbar. |
689 |
706 |
690 @param toolbarManager reference to a toolbar manager object (E5ToolBarManager) |
707 @param toolbarManager reference to a toolbar manager object |
|
708 (E5ToolBarManager) |
691 @return the toolbar generated (QToolBar) |
709 @return the toolbar generated (QToolBar) |
692 """ |
710 """ |
693 tb = QToolBar(self.trUtf8("Multiproject"), self.ui) |
711 tb = QToolBar(self.trUtf8("Multiproject"), self.ui) |
694 tb.setIconSize(UI.Config.ToolBarIconSize) |
712 tb.setIconSize(UI.Config.ToolBarIconSize) |
695 tb.setObjectName("MultiProjectToolbar") |
713 tb.setObjectName("MultiProjectToolbar") |
715 |
733 |
716 self.showMenu.emit("Main", self.__menus["Main"]) |
734 self.showMenu.emit("Main", self.__menus["Main"]) |
717 |
735 |
718 def __syncRecent(self): |
736 def __syncRecent(self): |
719 """ |
737 """ |
720 Private method to synchronize the list of recently opened multi projects |
738 Private method to synchronize the list of recently opened multi |
721 with the central store. |
739 projects with the central store. |
722 """ |
740 """ |
723 for recent in self.recent[:]: |
741 for recent in self.recent[:]: |
724 if Utilities.samepath(self.pfile, recent): |
742 if Utilities.samepath(self.pfile, recent): |
725 self.recent.remove(recent) |
743 self.recent.remove(recent) |
726 self.recent.insert(0, self.pfile) |
744 self.recent.insert(0, self.pfile) |