Plugins/ViewManagerPlugins/Tabview/Tabview.py

branch
Py2 comp.
changeset 2791
a9577f248f04
parent 2525
8b507a9a2d40
parent 2770
fd5ee85f0450
child 2847
1843ef6e2656
equal deleted inserted replaced
2790:6686a3326df8 2791:a9577f248f04
341 self.navigationButton.setEnabled(True) 341 self.navigationButton.setEnabled(True)
342 342
343 if not editor in self.editors: 343 if not editor in self.editors:
344 self.editors.append(editor) 344 self.editors.append(editor)
345 editor.captionChanged.connect(self.__captionChange) 345 editor.captionChanged.connect(self.__captionChange)
346 editor.cursorLineChanged.connect(self.__cursorLineChanged)
346 347
347 emptyIndex = self.indexOf(self.emptyLabel) 348 emptyIndex = self.indexOf(self.emptyLabel)
348 if emptyIndex > -1: 349 if emptyIndex > -1:
349 self.removeTab(emptyIndex) 350 self.removeTab(emptyIndex)
350 351
369 self.navigationButton.setEnabled(True) 370 self.navigationButton.setEnabled(True)
370 371
371 if not editor in self.editors: 372 if not editor in self.editors:
372 self.editors.append(editor) 373 self.editors.append(editor)
373 editor.captionChanged.connect(self.__captionChange) 374 editor.captionChanged.connect(self.__captionChange)
374 375 editor.cursorLineChanged.connect(self.__cursorLineChanged)
375 emptyIndex = self.indexOf(self.emptyLabel) 376 emptyIndex = self.indexOf(self.emptyLabel)
376 if emptyIndex > -1: 377 if emptyIndex > -1:
377 self.removeTab(emptyIndex) 378 self.removeTab(emptyIndex)
378 379
379 return newIndex 380 return newIndex
380 381
381 def __captionChange(self, cap, editor): 382 def __captionChange(self, cap, editor):
382 """ 383 """
383 Private method to handle Caption change signals from the editor. 384 Private slot to handle Caption change signals from the editor.
384 385
385 Updates the tab text and tooltip text to reflect the new caption information. 386 Updates the tab text and tooltip text to reflect the new caption information.
386 387
387 @param cap Caption for the editor 388 @param cap Caption for the editor
388 @param editor Editor to update the caption for 389 @param editor Editor to update the caption for
404 index = self.indexOf(assembly) 405 index = self.indexOf(assembly)
405 if index > -1: 406 if index > -1:
406 self.setTabText(index, txt) 407 self.setTabText(index, txt)
407 self.setTabToolTip(index, fn) 408 self.setTabToolTip(index, fn)
408 409
410 def __cursorLineChanged(self, lineno):
411 """
412 Private slot to handle a change of the current editor's cursor line.
413
414 @param lineno line number of the current editor's cursor (zero based)
415 """
416 editor = self.sender()
417 if editor:
418 fn = editor.getFileName()
419 if fn:
420 self.vm.editorLineChanged.emit(fn, lineno + 1)
421
409 def removeWidget(self, object): 422 def removeWidget(self, object):
410 """ 423 """
411 Public method to remove a widget. 424 Public method to remove a widget.
412 425
413 @param object object to be removed (QWidget) 426 @param object object to be removed (QWidget)
414 """ 427 """
415 if isinstance(object, QScintilla.Editor.Editor): 428 if isinstance(object, QScintilla.Editor.Editor):
429 object.cursorLineChanged.disconnect(self.__cursorLineChanged)
416 object.captionChanged.disconnect(self.__captionChange) 430 object.captionChanged.disconnect(self.__captionChange)
417 self.editors.remove(object) 431 self.editors.remove(object)
418 index = self.indexOf(object.parent()) 432 index = self.indexOf(object.parent())
419 else: 433 else:
420 index = self.indexOf(object) 434 index = self.indexOf(object)
680 @signal syntaxerrorToggled(Editor) emitted when a syntax error is toggled. 694 @signal syntaxerrorToggled(Editor) emitted when a syntax error is toggled.
681 @signal previewStateChanged(bool) emitted to signal a change in the preview state 695 @signal previewStateChanged(bool) emitted to signal a change in the preview state
682 @signal editorLanguageChanged(Editor) emitted to signal a change of an 696 @signal editorLanguageChanged(Editor) emitted to signal a change of an
683 editors language 697 editors language
684 @signal editorTextChanged(Editor) emitted to signal a change of an editor's text 698 @signal editorTextChanged(Editor) emitted to signal a change of an editor's text
699 @signal editorLineChanged(str,int) emitted to signal a change of an editor's
700 current line (line is given one based)
685 """ 701 """
686 changeCaption = pyqtSignal(str) 702 changeCaption = pyqtSignal(str)
687 editorChanged = pyqtSignal(str) 703 editorChanged = pyqtSignal(str)
688 editorChangedEd = pyqtSignal(Editor) 704 editorChangedEd = pyqtSignal(Editor)
689 lastEditorClosed = pyqtSignal() 705 lastEditorClosed = pyqtSignal()
698 bookmarkToggled = pyqtSignal(Editor) 714 bookmarkToggled = pyqtSignal(Editor)
699 syntaxerrorToggled = pyqtSignal(Editor) 715 syntaxerrorToggled = pyqtSignal(Editor)
700 previewStateChanged = pyqtSignal(bool) 716 previewStateChanged = pyqtSignal(bool)
701 editorLanguageChanged = pyqtSignal(Editor) 717 editorLanguageChanged = pyqtSignal(Editor)
702 editorTextChanged = pyqtSignal(Editor) 718 editorTextChanged = pyqtSignal(Editor)
719 editorLineChanged = pyqtSignal(str, int)
703 720
704 def __init__(self, parent): 721 def __init__(self, parent):
705 """ 722 """
706 Constructor 723 Constructor
707 724
798 aw = self.activeWindow() 815 aw = self.activeWindow()
799 fn = aw and aw.getFileName() or None 816 fn = aw and aw.getFileName() or None
800 if fn: 817 if fn:
801 self.changeCaption.emit(fn) 818 self.changeCaption.emit(fn)
802 self.editorChanged.emit(fn) 819 self.editorChanged.emit(fn)
820 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1)
803 else: 821 else:
804 self.changeCaption.emit("") 822 self.changeCaption.emit("")
805 self.editorChangedEd.emit(aw) 823 self.editorChangedEd.emit(aw)
806 824
807 def _addView(self, win, fn=None, noName=""): 825 def _addView(self, win, fn=None, noName=""):
835 win.show() 853 win.show()
836 editor.setFocus() 854 editor.setFocus()
837 if fn: 855 if fn:
838 self.changeCaption.emit(fn) 856 self.changeCaption.emit(fn)
839 self.editorChanged.emit(fn) 857 self.editorChanged.emit(fn)
858 self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1)
840 else: 859 else:
841 self.changeCaption.emit("") 860 self.changeCaption.emit("")
842 self.editorChangedEd.emit(editor) 861 self.editorChangedEd.emit(editor)
843 862
844 def insertView(self, win, tabWidget, index, fn=None, noName=""): 863 def insertView(self, win, tabWidget, index, fn=None, noName=""):
873 win.show() 892 win.show()
874 editor.setFocus() 893 editor.setFocus()
875 if fn: 894 if fn:
876 self.changeCaption.emit(fn) 895 self.changeCaption.emit(fn)
877 self.editorChanged.emit(fn) 896 self.editorChanged.emit(fn)
897 self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1)
878 else: 898 else:
879 self.changeCaption.emit("") 899 self.changeCaption.emit("")
880 self.editorChangedEd.emit(editor) 900 self.editorChangedEd.emit(editor)
881 901
882 self._modificationStatusChanged(editor.isModified(), editor) 902 self._modificationStatusChanged(editor.isModified(), editor)
1104 fn = editor.getFileName() 1124 fn = editor.getFileName()
1105 if fn: 1125 if fn:
1106 self.changeCaption.emit(fn) 1126 self.changeCaption.emit(fn)
1107 if not self.__inRemoveView: 1127 if not self.__inRemoveView:
1108 self.editorChanged.emit(fn) 1128 self.editorChanged.emit(fn)
1129 self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1)
1109 else: 1130 else:
1110 self.changeCaption.emit("") 1131 self.changeCaption.emit("")
1111 self.editorChangedEd.emit(editor) 1132 self.editorChangedEd.emit(editor)
1112 1133
1113 def eventFilter(self, watched, event): 1134 def eventFilter(self, watched, event):
1145 fn = aw.getFileName() 1166 fn = aw.getFileName()
1146 if fn: 1167 if fn:
1147 self.changeCaption.emit(fn) 1168 self.changeCaption.emit(fn)
1148 if switched: 1169 if switched:
1149 self.editorChanged.emit(fn) 1170 self.editorChanged.emit(fn)
1171 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1)
1150 else: 1172 else:
1151 self.changeCaption.emit("") 1173 self.changeCaption.emit("")
1152 self.editorChangedEd.emit(aw) 1174 self.editorChangedEd.emit(aw)
1153 1175
1154 return False 1176 return False
1178 txt = self.trUtf8("{0} (ro)").format(txt) 1200 txt = self.trUtf8("{0} (ro)").format(txt)
1179 tabWidget.setTabText(index, txt) 1201 tabWidget.setTabText(index, txt)
1180 1202
1181 def getTabWidgetById(self, id_): 1203 def getTabWidgetById(self, id_):
1182 """ 1204 """
1183 Public method to get a reference to a tab widget knowing it's ID. 1205 Public method to get a reference to a tab widget knowing its ID.
1184 1206
1185 @param id_ id of the tab widget (long) 1207 @param id_ id of the tab widget (long)
1186 @return reference to the tab widget (TabWidget) 1208 @return reference to the tab widget (TabWidget)
1187 """ 1209 """
1188 for tw in self.tabWidgets: 1210 for tw in self.tabWidgets:

eric ide

mercurial