Plugins/ViewManagerPlugins/Tabview/Tabview.py

changeset 500
c3abc7895a01
parent 486
e4711a55e482
child 501
5c615a85241a
equal deleted inserted replaced
499:622ab17a68d5 500:c3abc7895a01
41 giving the id of the source tab widget, the index in the source tab widget 41 giving the id of the source tab widget, the index in the source tab widget
42 and the new index position 42 and the new index position
43 @signal tabCopyRequested(int, int) emitted to signal a clone request giving 43 @signal tabCopyRequested(int, int) emitted to signal a clone request giving
44 the old and new index position 44 the old and new index position
45 """ 45 """
46 tabMoveRequested = pyqtSignal(int, int)
47 tabRelocateRequested = pyqtSignal(int, int, int)
48 tabCopyRequested = pyqtSignal(int, int, int)
49 tabCopyRequested = pyqtSignal(int, int)
50
46 def __init__(self, parent = None): 51 def __init__(self, parent = None):
47 """ 52 """
48 Constructor 53 Constructor
49 54
50 @param parent reference to the parent widget (QWidget) 55 @param parent reference to the parent widget (QWidget)
116 fromIndex = mimeData.data("source-index").toInt()[0] 121 fromIndex = mimeData.data("source-index").toInt()[0]
117 toIndex = self.tabAt(event.pos()) 122 toIndex = self.tabAt(event.pos())
118 if oldID != id(self): 123 if oldID != id(self):
119 parentID = mimeData.data("tabwidget-id").toLong()[0] 124 parentID = mimeData.data("tabwidget-id").toLong()[0]
120 if event.proposedAction() == Qt.MoveAction: 125 if event.proposedAction() == Qt.MoveAction:
121 self.emit(SIGNAL("tabRelocateRequested(long, int, int)"), 126 self.tabRelocateRequested.emit(parentID, fromIndex, toIndex)
122 parentID, fromIndex, toIndex)
123 event.acceptProposedAction() 127 event.acceptProposedAction()
124 elif event.proposedAction() == Qt.CopyAction: 128 elif event.proposedAction() == Qt.CopyAction:
125 self.emit(SIGNAL("tabCopyRequested(long, int, int)"), 129 self.tabCopyRequested.emit(parentID, fromIndex, toIndex)
126 parentID, fromIndex, toIndex)
127 event.acceptProposedAction() 130 event.acceptProposedAction()
128 else: 131 else:
129 if fromIndex != toIndex: 132 if fromIndex != toIndex:
130 if event.proposedAction() == Qt.MoveAction: 133 if event.proposedAction() == Qt.MoveAction:
131 self.emit(SIGNAL("tabMoveRequested(int, int)"), fromIndex, toIndex) 134 self.tabMoveRequested.emit(fromIndex, toIndex)
132 event.acceptProposedAction() 135 event.acceptProposedAction()
133 elif event.proposedAction() == Qt.CopyAction: 136 elif event.proposedAction() == Qt.CopyAction:
134 self.emit(SIGNAL("tabCopyRequested(int, int)"), fromIndex, toIndex) 137 self.tabCopyRequested.emit(fromIndex, toIndex)
135 event.acceptProposedAction() 138 event.acceptProposedAction()
136 E5WheelTabBar.dropEvent(self, event) 139 E5WheelTabBar.dropEvent(self, event)
137 140
138 class TabWidget(E5TabWidget): 141 class TabWidget(E5TabWidget):
139 """ 142 """
149 self.setAttribute(Qt.WA_DeleteOnClose, True) 152 self.setAttribute(Qt.WA_DeleteOnClose, True)
150 153
151 self.__tabBar = TabBar(self) 154 self.__tabBar = TabBar(self)
152 self.setTabBar(self.__tabBar) 155 self.setTabBar(self.__tabBar)
153 156
154 self.connect(self.__tabBar, SIGNAL("tabMoveRequested(int, int)"), 157 self.__tabBar.tabMoveRequested.connect(self.moveTab)
155 self.moveTab) 158 self.__tabBar.tabRelocateRequested.connect(self.relocateTab)
156 self.connect(self.__tabBar, SIGNAL("tabRelocateRequested(long, int, int)"), 159 self.__tabBar.tabCopyRequested.connect(self.copyTabOther)
157 self.relocateTab) 160 self.__tabBar.tabCopyRequested.connect(self.copyTab)
158 self.connect(self.__tabBar, SIGNAL("tabCopyRequested(long, int, int)"),
159 self.copyTabOther)
160 self.connect(self.__tabBar, SIGNAL("tabCopyRequested(int, int)"),
161 self.copyTab)
162 161
163 self.vm = vm 162 self.vm = vm
164 self.editors = [] 163 self.editors = []
165 164
166 self.indicator = E5Led(self) 165 self.indicator = E5Led(self)
171 self.rightCornerWidgetLayout.setMargin(0) 170 self.rightCornerWidgetLayout.setMargin(0)
172 self.rightCornerWidgetLayout.setSpacing(0) 171 self.rightCornerWidgetLayout.setSpacing(0)
173 172
174 self.__navigationMenu = QMenu(self) 173 self.__navigationMenu = QMenu(self)
175 self.__navigationMenu.aboutToShow.connect(self.__showNavigationMenu) 174 self.__navigationMenu.aboutToShow.connect(self.__showNavigationMenu)
176 self.connect(self.__navigationMenu, SIGNAL("triggered(QAction*)"), 175 self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered)
177 self.__navigationMenuTriggered)
178 176
179 self.navigationButton = QToolButton(self) 177 self.navigationButton = QToolButton(self)
180 self.navigationButton.setIcon(UI.PixmapCache.getIcon("1downarrow.png")) 178 self.navigationButton.setIcon(UI.PixmapCache.getIcon("1downarrow.png"))
181 self.navigationButton.setToolTip(self.trUtf8("Show a navigation menu")) 179 self.navigationButton.setToolTip(self.trUtf8("Show a navigation menu"))
182 self.navigationButton.setPopupMode(QToolButton.InstantPopup) 180 self.navigationButton.setPopupMode(QToolButton.InstantPopup)
191 self.closeButton.setToolTip(self.trUtf8("Close the current editor")) 189 self.closeButton.setToolTip(self.trUtf8("Close the current editor"))
192 self.closeButton.setEnabled(False) 190 self.closeButton.setEnabled(False)
193 self.closeButton.clicked[bool].connect(self.__closeButtonClicked) 191 self.closeButton.clicked[bool].connect(self.__closeButtonClicked)
194 self.rightCornerWidgetLayout.addWidget(self.closeButton) 192 self.rightCornerWidgetLayout.addWidget(self.closeButton)
195 else: 193 else:
196 self.connect(self, SIGNAL("tabCloseRequested(int)"), 194 self.tabCloseRequested.connect(self.__closeRequested)
197 self.__closeRequested)
198 self.closeButton = None 195 self.closeButton = None
199 196
200 self.setCornerWidget(self.rightCornerWidget, Qt.TopRightCorner) 197 self.setCornerWidget(self.rightCornerWidget, Qt.TopRightCorner)
201 198
202 self.__initMenu() 199 self.__initMenu()
323 self.setTabsClosable(True) 320 self.setTabsClosable(True)
324 self.navigationButton.setEnabled(True) 321 self.navigationButton.setEnabled(True)
325 322
326 if not editor in self.editors: 323 if not editor in self.editors:
327 self.editors.append(editor) 324 self.editors.append(editor)
328 self.connect(editor, SIGNAL('captionChanged'), 325 editor.captionChanged.connect(self.__captionChange)
329 self.__captionChange)
330 326
331 emptyIndex = self.indexOf(self.emptyLabel) 327 emptyIndex = self.indexOf(self.emptyLabel)
332 if emptyIndex > -1: 328 if emptyIndex > -1:
333 self.removeTab(emptyIndex) 329 self.removeTab(emptyIndex)
334 330
350 self.setTabsClosable(True) 346 self.setTabsClosable(True)
351 self.navigationButton.setEnabled(True) 347 self.navigationButton.setEnabled(True)
352 348
353 if not editor in self.editors: 349 if not editor in self.editors:
354 self.editors.append(editor) 350 self.editors.append(editor)
355 self.connect(editor, SIGNAL('captionChanged'), 351 editor.captionChanged.connect(self.__captionChange)
356 self.__captionChange)
357 352
358 emptyIndex = self.indexOf(self.emptyLabel) 353 emptyIndex = self.indexOf(self.emptyLabel)
359 if emptyIndex > -1: 354 if emptyIndex > -1:
360 self.removeTab(emptyIndex) 355 self.removeTab(emptyIndex)
361 356
397 index = self.indexOf(object) 392 index = self.indexOf(object)
398 if index > -1: 393 if index > -1:
399 self.removeTab(index) 394 self.removeTab(index)
400 395
401 if isinstance(object, QScintilla.Editor.Editor): 396 if isinstance(object, QScintilla.Editor.Editor):
402 self.disconnect(object, SIGNAL('captionChanged'), 397 object.captionChanged.disconnect(self.__captionChange)
403 self.__captionChange)
404 self.editors.remove(object) 398 self.editors.remove(object)
405 399
406 if not self.editors: 400 if not self.editors:
407 E5TabWidget.addTab(self, self.emptyLabel, 401 E5TabWidget.addTab(self, self.emptyLabel,
408 UI.PixmapCache.getIcon("empty.png"), "") 402 UI.PixmapCache.getIcon("empty.png"), "")
619 """ 613 """
620 Class implementing a tabbed viewmanager class embedded in a splitter. 614 Class implementing a tabbed viewmanager class embedded in a splitter.
621 615
622 @signal changeCaption(string) emitted if a change of the caption is necessary 616 @signal changeCaption(string) emitted if a change of the caption is necessary
623 @signal editorChanged(string) emitted when the current editor has changed 617 @signal editorChanged(string) emitted when the current editor has changed
618 @signal lastEditorClosed() emitted after the last editor window was closed
619 @signal editorOpened(string) emitted after an editor window was opened
620 @signal editorOpenedEd(editor) emitted after an editor window was opened
621 @signal editorClosed(string) emitted just before an editor window gets closed
622 @signal editorClosedEd(editor) emitted just before an editor window gets closed
623 @signal editorSaved(string) emitted after an editor window was saved
624 @signal checkActions(editor) emitted when some actions should be checked
625 for their status
626 @signal cursorChanged(editor) emitted after the cursor position of the active
627 window has changed
628 @signal breakpointToggled(editor) emitted when a breakpoint is toggled.
629 @signal bookmarkToggled(editor) emitted when a bookmark is toggled.
624 """ 630 """
631 changeCaption = pyqtSignal(str)
632 editorChanged = pyqtSignal(str)
633
634 lastEditorClosed = pyqtSignal()
625 editorOpened = pyqtSignal(str) 635 editorOpened = pyqtSignal(str)
626 lastEditorClosed = pyqtSignal() 636 editorOpenedEd = pyqtSignal(Editor)
637 editorClosed = pyqtSignal(str)
638 editorClosedEd = pyqtSignal(Editor)
639 editorSaved = pyqtSignal(str)
627 checkActions = pyqtSignal(Editor) 640 checkActions = pyqtSignal(Editor)
628 cursorChanged = pyqtSignal(Editor) 641 cursorChanged = pyqtSignal(Editor)
629 breakpointToggled = pyqtSignal(Editor) 642 breakpointToggled = pyqtSignal(Editor)
643 bookmarkToggled = pyqtSignal(Editor)
644 syntaxerrorToggled = pyqtSignal(Editor)
630 645
631 def __init__(self, parent): 646 def __init__(self, parent):
632 """ 647 """
633 Constructor 648 Constructor
634 649
643 tw = TabWidget(self) 658 tw = TabWidget(self)
644 self.addWidget(tw) 659 self.addWidget(tw)
645 self.tabWidgets.append(tw) 660 self.tabWidgets.append(tw)
646 self.currentTabWidget = tw 661 self.currentTabWidget = tw
647 self.currentTabWidget.showIndicator(True) 662 self.currentTabWidget.showIndicator(True)
648 self.connect(tw, SIGNAL('currentChanged(int)'), 663 tw.currentChanged.connect(self.__currentChanged)
649 self.__currentChanged)
650 tw.installEventFilter(self) 664 tw.installEventFilter(self)
651 tw.tabBar().installEventFilter(self) 665 tw.tabBar().installEventFilter(self)
652 self.setOrientation(Qt.Vertical) 666 self.setOrientation(Qt.Vertical)
653 self.__inRemoveView = False 667 self.__inRemoveView = False
654 668
724 break 738 break
725 739
726 aw = self.activeWindow() 740 aw = self.activeWindow()
727 fn = aw and aw.getFileName() or None 741 fn = aw and aw.getFileName() or None
728 if fn: 742 if fn:
729 self.emit(SIGNAL('changeCaption'), fn) 743 self.changeCaption.emit(fn)
730 self.emit(SIGNAL('editorChanged'), fn) 744 self.editorChanged.emit(fn)
731 else: 745 else:
732 self.emit(SIGNAL('changeCaption'), "") 746 self.changeCaption.emit("")
733 747
734 def _addView(self, win, fn = None, noName = ""): 748 def _addView(self, win, fn = None, noName = ""):
735 """ 749 """
736 Protected method to add a view (i.e. window) 750 Protected method to add a view (i.e. window)
737 751
759 self.currentTabWidget.setTabToolTip(index, fn) 773 self.currentTabWidget.setTabToolTip(index, fn)
760 self.currentTabWidget.setCurrentWidget(win) 774 self.currentTabWidget.setCurrentWidget(win)
761 win.show() 775 win.show()
762 win.setFocus() 776 win.setFocus()
763 if fn: 777 if fn:
764 self.emit(SIGNAL('changeCaption'), fn) 778 self.changeCaption.emit(fn)
765 self.emit(SIGNAL('editorChanged'), fn) 779 self.editorChanged.emit(fn)
766 else: 780 else:
767 self.emit(SIGNAL('changeCaption'), "") 781 self.changeCaption.emit("")
768 782
769 def insertView(self, win, tabWidget, index, fn = None, noName = ""): 783 def insertView(self, win, tabWidget, index, fn = None, noName = ""):
770 """ 784 """
771 Protected method to add a view (i.e. window) 785 Protected method to add a view (i.e. window)
772 786
795 tabWidget.setTabToolTip(nindex, fn) 809 tabWidget.setTabToolTip(nindex, fn)
796 tabWidget.setCurrentWidget(win) 810 tabWidget.setCurrentWidget(win)
797 win.show() 811 win.show()
798 win.setFocus() 812 win.setFocus()
799 if fn: 813 if fn:
800 self.emit(SIGNAL('changeCaption'), fn) 814 self.changeCaption.emit(fn)
801 self.emit(SIGNAL('editorChanged'), fn) 815 self.editorChanged.emit(fn)
802 else: 816 else:
803 self.emit(SIGNAL('changeCaption'), "") 817 self.changeCaption.emit("")
804 818
805 self._modificationStatusChanged(win.isModified(), win) 819 self._modificationStatusChanged(win.isModified(), win)
806 self._checkActions(win) 820 self._checkActions(win)
807 821
808 def _showView(self, win, fn = None): 822 def _showView(self, win, fn = None):
858 if len(tabName) > self.maxFileNameChars: 872 if len(tabName) > self.maxFileNameChars:
859 tabName = "...{0}".format(tabName[-self.maxFileNameChars:]) 873 tabName = "...{0}".format(tabName[-self.maxFileNameChars:])
860 index = self.currentTabWidget.indexOf(editor) 874 index = self.currentTabWidget.indexOf(editor)
861 self.currentTabWidget.setTabText(index, tabName) 875 self.currentTabWidget.setTabText(index, tabName)
862 self.currentTabWidget.setTabToolTip(index, newName) 876 self.currentTabWidget.setTabToolTip(index, newName)
863 self.emit(SIGNAL('changeCaption'), newName) 877 self.changeCaption.emit(newName)
864 878
865 def _modificationStatusChanged(self, m, editor): 879 def _modificationStatusChanged(self, m, editor):
866 """ 880 """
867 Protected slot to handle the modificationStatusChanged signal. 881 Protected slot to handle the modificationStatusChanged signal.
868 882
911 self.addWidget(tw) 925 self.addWidget(tw)
912 self.tabWidgets.append(tw) 926 self.tabWidgets.append(tw)
913 self.currentTabWidget.showIndicator(False) 927 self.currentTabWidget.showIndicator(False)
914 self.currentTabWidget = self.tabWidgets[-1] 928 self.currentTabWidget = self.tabWidgets[-1]
915 self.currentTabWidget.showIndicator(True) 929 self.currentTabWidget.showIndicator(True)
916 self.connect(tw, SIGNAL('currentChanged(int)'), 930 tw.currentChanged.connect(self.__currentChanged)
917 self.__currentChanged)
918 tw.installEventFilter(self) 931 tw.installEventFilter(self)
919 tw.tabBar().installEventFilter(self) 932 tw.tabBar().installEventFilter(self)
920 if self.orientation() == Qt.Horizontal: 933 if self.orientation() == Qt.Horizontal:
921 size = self.width() 934 size = self.width()
922 else: 935 else:
1017 1030
1018 self._checkActions(editor) 1031 self._checkActions(editor)
1019 editor.setFocus() 1032 editor.setFocus()
1020 fn = editor.getFileName() 1033 fn = editor.getFileName()
1021 if fn: 1034 if fn:
1022 self.emit(SIGNAL('changeCaption'), fn) 1035 self.changeCaption.emit(fn)
1023 if not self.__inRemoveView: 1036 if not self.__inRemoveView:
1024 self.emit(SIGNAL('editorChanged'), fn) 1037 self.editorChanged.emit(fn)
1025 else: 1038 else:
1026 self.emit(SIGNAL('changeCaption'), "") 1039 self.changeCaption.emit("")
1027 1040
1028 def eventFilter(self, watched, event): 1041 def eventFilter(self, watched, event):
1029 """ 1042 """
1030 Public method called to filter the event queue. 1043 Public method called to filter the event queue.
1031 1044
1057 if aw is not None: 1070 if aw is not None:
1058 self._checkActions(aw) 1071 self._checkActions(aw)
1059 aw.setFocus() 1072 aw.setFocus()
1060 fn = aw.getFileName() 1073 fn = aw.getFileName()
1061 if fn: 1074 if fn:
1062 self.emit(SIGNAL('changeCaption'), fn) 1075 self.changeCaption.emit(fn)
1063 if switched: 1076 if switched:
1064 self.emit(SIGNAL('editorChanged'), fn) 1077 self.editorChanged.emit(fn)
1065 else: 1078 else:
1066 self.emit(SIGNAL('changeCaption'), "") 1079 self.changeCaption.emit("")
1067 1080
1068 return False 1081 return False
1069 1082
1070 def preferencesChanged(self): 1083 def preferencesChanged(self):
1071 """ 1084 """

eric ide

mercurial