src/eric7/Plugins/ViewManagerPlugins/Listspace/Listspace.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
9 9
10 import os 10 import os
11 11
12 from PyQt6.QtCore import pyqtSignal, pyqtSlot, QEvent, Qt 12 from PyQt6.QtCore import pyqtSignal, pyqtSlot, QEvent, Qt
13 from PyQt6.QtWidgets import ( 13 from PyQt6.QtWidgets import (
14 QStackedWidget, QSplitter, QListWidget, QListWidgetItem, QSizePolicy, 14 QStackedWidget,
15 QMenu, QApplication 15 QSplitter,
16 QListWidget,
17 QListWidgetItem,
18 QSizePolicy,
19 QMenu,
20 QApplication,
16 ) 21 )
17 22
18 from EricWidgets.EricApplication import ericApp 23 from EricWidgets.EricApplication import ericApp
19 24
20 from ViewManager.ViewManager import ViewManager 25 from ViewManager.ViewManager import ViewManager
29 34
30 class StackedWidget(QStackedWidget): 35 class StackedWidget(QStackedWidget):
31 """ 36 """
32 Class implementing a custimized StackedWidget. 37 Class implementing a custimized StackedWidget.
33 """ 38 """
39
34 def __init__(self, parent): 40 def __init__(self, parent):
35 """ 41 """
36 Constructor 42 Constructor
37 43
38 @param parent parent widget 44 @param parent parent widget
39 @type QWidget 45 @type QWidget
40 """ 46 """
41 super().__init__(parent) 47 super().__init__(parent)
42 48
43 self.editors = [] 49 self.editors = []
44 50
45 def addWidget(self, assembly): 51 def addWidget(self, assembly):
46 """ 52 """
47 Public method to add a new widget. 53 Public method to add a new widget.
48 54
49 @param assembly editor assembly object to be added 55 @param assembly editor assembly object to be added
50 @type QScintilla.EditorAssembly.EditorAssembly 56 @type QScintilla.EditorAssembly.EditorAssembly
51 """ 57 """
52 editor = assembly.getEditor() 58 editor = assembly.getEditor()
53 super().addWidget(assembly) 59 super().addWidget(assembly)
54 if editor not in self.editors: 60 if editor not in self.editors:
55 self.editors.append(editor) 61 self.editors.append(editor)
56 62
57 def removeWidget(self, widget): 63 def removeWidget(self, widget):
58 """ 64 """
59 Public method to remove a widget. 65 Public method to remove a widget.
60 66
61 @param widget widget to be removed 67 @param widget widget to be removed
62 @type QWidget 68 @type QWidget
63 """ 69 """
64 if isinstance(widget, QScintilla.Editor.Editor): 70 if isinstance(widget, QScintilla.Editor.Editor):
65 self.editors.remove(widget) 71 self.editors.remove(widget)
66 widget = widget.parent() 72 widget = widget.parent()
67 super().removeWidget(widget) 73 super().removeWidget(widget)
68 74
69 def currentWidget(self): 75 def currentWidget(self):
70 """ 76 """
71 Public method to get a reference to the current editor. 77 Public method to get a reference to the current editor.
72 78
73 @return reference to the current editor 79 @return reference to the current editor
74 @rtype Editor 80 @rtype Editor
75 """ 81 """
76 widget = super().currentWidget() 82 widget = super().currentWidget()
77 if widget is not None: 83 if widget is not None:
78 widget = widget.getEditor() 84 widget = widget.getEditor()
79 return widget 85 return widget
80 86
81 def setCurrentWidget(self, widget): 87 def setCurrentWidget(self, widget):
82 """ 88 """
83 Public method to set the current widget. 89 Public method to set the current widget.
84 90
85 @param widget widget to be made current 91 @param widget widget to be made current
86 @type QWidget 92 @type QWidget
87 """ 93 """
88 if widget is not None: 94 if widget is not None:
89 if isinstance(widget, QScintilla.Editor.Editor): 95 if isinstance(widget, QScintilla.Editor.Editor):
90 self.editors.remove(widget) 96 self.editors.remove(widget)
91 self.editors.insert(0, widget) 97 self.editors.insert(0, widget)
92 widget = widget.parent() 98 widget = widget.parent()
93 super().setCurrentWidget(widget) 99 super().setCurrentWidget(widget)
94 100
95 def setCurrentIndex(self, index): 101 def setCurrentIndex(self, index):
96 """ 102 """
97 Public method to set the current widget by its index. 103 Public method to set the current widget by its index.
98 104
99 @param index index of widget to be made current 105 @param index index of widget to be made current
100 @type int 106 @type int
101 """ 107 """
102 widget = self.widget(index) 108 widget = self.widget(index)
103 if widget is not None: 109 if widget is not None:
104 self.setCurrentWidget(widget) 110 self.setCurrentWidget(widget)
105 111
106 def nextTab(self): 112 def nextTab(self):
107 """ 113 """
108 Public slot used to show the next tab. 114 Public slot used to show the next tab.
109 """ 115 """
110 ind = self.currentIndex() + 1 116 ind = self.currentIndex() + 1
111 if ind == self.count(): 117 if ind == self.count():
112 ind = 0 118 ind = 0
113 119
114 self.setCurrentIndex(ind) 120 self.setCurrentIndex(ind)
115 self.currentWidget().setFocus() 121 self.currentWidget().setFocus()
116 122
117 def prevTab(self): 123 def prevTab(self):
118 """ 124 """
119 Public slot used to show the previous tab. 125 Public slot used to show the previous tab.
120 """ 126 """
121 ind = self.currentIndex() - 1 127 ind = self.currentIndex() - 1
122 if ind == -1: 128 if ind == -1:
123 ind = self.count() - 1 129 ind = self.count() - 1
124 130
125 self.setCurrentIndex(ind) 131 self.setCurrentIndex(ind)
126 self.currentWidget().setFocus() 132 self.currentWidget().setFocus()
127 133
128 def hasEditor(self, editor): 134 def hasEditor(self, editor):
129 """ 135 """
130 Public method to check for an editor. 136 Public method to check for an editor.
131 137
132 @param editor editor object to check for 138 @param editor editor object to check for
133 @type Editor 139 @type Editor
134 @return flag indicating, whether the editor to be checked belongs 140 @return flag indicating, whether the editor to be checked belongs
135 to the list of editors managed by this stacked widget. 141 to the list of editors managed by this stacked widget.
136 @rtype bool 142 @rtype bool
137 """ 143 """
138 return editor in self.editors 144 return editor in self.editors
139 145
140 def firstEditor(self): 146 def firstEditor(self):
141 """ 147 """
142 Public method to retrieve the first editor in the list of managed 148 Public method to retrieve the first editor in the list of managed
143 editors. 149 editors.
144 150
145 @return first editor in list 151 @return first editor in list
146 @rtype QScintilla.Editor.Editor 152 @rtype QScintilla.Editor.Editor
147 """ 153 """
148 return len(self.editors) and self.editors[0] or None 154 return len(self.editors) and self.editors[0] or None
149 155
150 156
151 class Listspace(ViewManager): 157 class Listspace(ViewManager):
152 """ 158 """
153 Class implementing the listspace viewmanager class. 159 Class implementing the listspace viewmanager class.
154 160
155 @signal changeCaption(str) emitted if a change of the caption is necessary 161 @signal changeCaption(str) emitted if a change of the caption is necessary
156 @signal editorChanged(str) emitted when the current editor has changed 162 @signal editorChanged(str) emitted when the current editor has changed
157 @signal editorChangedEd(Editor) emitted when the current editor has changed 163 @signal editorChangedEd(Editor) emitted when the current editor has changed
158 @signal lastEditorClosed() emitted after the last editor window was closed 164 @signal lastEditorClosed() emitted after the last editor window was closed
159 @signal editorOpened(str) emitted after an editor window was opened 165 @signal editorOpened(str) emitted after an editor window was opened
185 @signal editorLineChanged(str,int) emitted to signal a change of an 191 @signal editorLineChanged(str,int) emitted to signal a change of an
186 editor's current line (line is given one based) 192 editor's current line (line is given one based)
187 @signal editorLineChangedEd(Editor,int) emitted to signal a change of an 193 @signal editorLineChangedEd(Editor,int) emitted to signal a change of an
188 editor's current line (line is given one based) 194 editor's current line (line is given one based)
189 """ 195 """
196
190 changeCaption = pyqtSignal(str) 197 changeCaption = pyqtSignal(str)
191 editorChanged = pyqtSignal(str) 198 editorChanged = pyqtSignal(str)
192 editorChangedEd = pyqtSignal(Editor) 199 editorChangedEd = pyqtSignal(Editor)
193 lastEditorClosed = pyqtSignal() 200 lastEditorClosed = pyqtSignal()
194 editorOpened = pyqtSignal(str) 201 editorOpened = pyqtSignal(str)
208 astViewerStateChanged = pyqtSignal(bool) 215 astViewerStateChanged = pyqtSignal(bool)
209 editorLanguageChanged = pyqtSignal(Editor) 216 editorLanguageChanged = pyqtSignal(Editor)
210 editorTextChanged = pyqtSignal(Editor) 217 editorTextChanged = pyqtSignal(Editor)
211 editorLineChanged = pyqtSignal(str, int) 218 editorLineChanged = pyqtSignal(str, int)
212 editorLineChangedEd = pyqtSignal(Editor, int) 219 editorLineChangedEd = pyqtSignal(Editor, int)
213 220
214 def __init__(self, parent): 221 def __init__(self, parent):
215 """ 222 """
216 Constructor 223 Constructor
217 224
218 @param parent parent widget 225 @param parent parent widget
219 @type QWidget 226 @type QWidget
220 """ 227 """
221 self.stacks = [] 228 self.stacks = []
222 229
223 self.__splitter = QSplitter(parent) 230 self.__splitter = QSplitter(parent)
224 ViewManager.__init__(self) 231 ViewManager.__init__(self)
225 self.__splitter.setChildrenCollapsible(False) 232 self.__splitter.setChildrenCollapsible(False)
226 233
227 self.viewlist = QListWidget(self) 234 self.viewlist = QListWidget(self)
228 policy = self.viewlist.sizePolicy() 235 policy = self.viewlist.sizePolicy()
229 policy.setHorizontalPolicy(QSizePolicy.Policy.Ignored) 236 policy.setHorizontalPolicy(QSizePolicy.Policy.Ignored)
230 self.viewlist.setSizePolicy(policy) 237 self.viewlist.setSizePolicy(policy)
231 self.__splitter.addWidget(self.viewlist) 238 self.__splitter.addWidget(self.viewlist)
232 self.viewlist.setContextMenuPolicy( 239 self.viewlist.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
233 Qt.ContextMenuPolicy.CustomContextMenu)
234 self.viewlist.currentRowChanged.connect(self.__showSelectedView) 240 self.viewlist.currentRowChanged.connect(self.__showSelectedView)
235 self.viewlist.customContextMenuRequested.connect(self.__showMenu) 241 self.viewlist.customContextMenuRequested.connect(self.__showMenu)
236 242
237 self.stackArea = QSplitter(self) 243 self.stackArea = QSplitter(self)
238 self.stackArea.setChildrenCollapsible(False) 244 self.stackArea.setChildrenCollapsible(False)
239 self.__splitter.addWidget(self.stackArea) 245 self.__splitter.addWidget(self.stackArea)
240 self.stackArea.setOrientation(Qt.Orientation.Vertical) 246 self.stackArea.setOrientation(Qt.Orientation.Vertical)
241 stack = StackedWidget(self.stackArea) 247 stack = StackedWidget(self.stackArea)
242 self.stackArea.addWidget(stack) 248 self.stackArea.addWidget(stack)
243 self.stacks.append(stack) 249 self.stacks.append(stack)
244 self.currentStack = stack 250 self.currentStack = stack
245 stack.currentChanged.connect(self.__currentChanged) 251 stack.currentChanged.connect(self.__currentChanged)
246 stack.installEventFilter(self) 252 stack.installEventFilter(self)
247 self.__splitter.setSizes( 253 self.__splitter.setSizes([int(self.width() * 0.2), int(self.width() * 0.8)])
248 [int(self.width() * 0.2), int(self.width() * 0.8)])
249 # 20% for viewlist, 80% for the editors 254 # 20% for viewlist, 80% for the editors
250 self.__inRemoveView = False 255 self.__inRemoveView = False
251 256
252 self.__initMenu() 257 self.__initMenu()
253 self.contextMenuEditor = None 258 self.contextMenuEditor = None
254 self.contextMenuIndex = -1 259 self.contextMenuIndex = -1
255 260
256 def __initMenu(self): 261 def __initMenu(self):
257 """ 262 """
258 Private method to initialize the viewlist context menu. 263 Private method to initialize the viewlist context menu.
259 """ 264 """
260 self.__startMenu = QMenu(self.tr("Start"), self) 265 self.__startMenu = QMenu(self.tr("Start"), self)
261 self.__startMenu.addAction( 266 self.__startMenu.addAction(
262 UI.PixmapCache.getIcon("runScript"), 267 UI.PixmapCache.getIcon("runScript"),
263 self.tr('Run Script...'), 268 self.tr("Run Script..."),
264 self.__contextMenuRunScript) 269 self.__contextMenuRunScript,
270 )
265 self.__startMenu.addAction( 271 self.__startMenu.addAction(
266 UI.PixmapCache.getIcon("debugScript"), 272 UI.PixmapCache.getIcon("debugScript"),
267 self.tr('Debug Script...'), 273 self.tr("Debug Script..."),
268 self.__contextMenuDebugScript) 274 self.__contextMenuDebugScript,
275 )
269 self.__startMenu.addAction( 276 self.__startMenu.addAction(
270 UI.PixmapCache.getIcon("profileScript"), 277 UI.PixmapCache.getIcon("profileScript"),
271 self.tr('Profile Script...'), 278 self.tr("Profile Script..."),
272 self.__contextMenuProfileScript) 279 self.__contextMenuProfileScript,
280 )
273 self.__startMenu.addAction( 281 self.__startMenu.addAction(
274 UI.PixmapCache.getIcon("coverageScript"), 282 UI.PixmapCache.getIcon("coverageScript"),
275 self.tr('Coverage run of Script...'), 283 self.tr("Coverage run of Script..."),
276 self.__contextMenuCoverageScript) 284 self.__contextMenuCoverageScript,
277 285 )
286
278 self.__menu = QMenu(self) 287 self.__menu = QMenu(self)
279 self.__menu.addAction( 288 self.__menu.addAction(
280 UI.PixmapCache.getIcon("tabClose"), 289 UI.PixmapCache.getIcon("tabClose"),
281 self.tr('Close'), self.__contextMenuClose) 290 self.tr("Close"),
291 self.__contextMenuClose,
292 )
282 self.closeOthersMenuAct = self.__menu.addAction( 293 self.closeOthersMenuAct = self.__menu.addAction(
283 UI.PixmapCache.getIcon("tabCloseOther"), 294 UI.PixmapCache.getIcon("tabCloseOther"),
284 self.tr("Close Others"), 295 self.tr("Close Others"),
285 self.__contextMenuCloseOthers) 296 self.__contextMenuCloseOthers,
286 self.__menu.addAction( 297 )
287 self.tr('Close All'), self.__contextMenuCloseAll) 298 self.__menu.addAction(self.tr("Close All"), self.__contextMenuCloseAll)
288 self.__menu.addSeparator() 299 self.__menu.addSeparator()
289 self.saveMenuAct = self.__menu.addAction( 300 self.saveMenuAct = self.__menu.addAction(
290 UI.PixmapCache.getIcon("fileSave"), 301 UI.PixmapCache.getIcon("fileSave"), self.tr("Save"), self.__contextMenuSave
291 self.tr('Save'), self.__contextMenuSave) 302 )
292 self.__menu.addAction( 303 self.__menu.addAction(
293 UI.PixmapCache.getIcon("fileSaveAs"), 304 UI.PixmapCache.getIcon("fileSaveAs"),
294 self.tr('Save As...'), self.__contextMenuSaveAs) 305 self.tr("Save As..."),
306 self.__contextMenuSaveAs,
307 )
295 self.__menu.addAction( 308 self.__menu.addAction(
296 UI.PixmapCache.getIcon("fileSaveAll"), 309 UI.PixmapCache.getIcon("fileSaveAll"),
297 self.tr('Save All'), self.__contextMenuSaveAll) 310 self.tr("Save All"),
311 self.__contextMenuSaveAll,
312 )
298 self.__menu.addSeparator() 313 self.__menu.addSeparator()
299 self.openRejectionsMenuAct = self.__menu.addAction( 314 self.openRejectionsMenuAct = self.__menu.addAction(
300 self.tr("Open 'rejection' file"), 315 self.tr("Open 'rejection' file"), self.__contextMenuOpenRejections
301 self.__contextMenuOpenRejections) 316 )
302 self.__menu.addSeparator() 317 self.__menu.addSeparator()
303 self.__startAct = self.__menu.addMenu(self.__startMenu) 318 self.__startAct = self.__menu.addMenu(self.__startMenu)
304 self.__menu.addSeparator() 319 self.__menu.addSeparator()
305 self.__menu.addAction( 320 self.__menu.addAction(
306 UI.PixmapCache.getIcon("printPreview"), 321 UI.PixmapCache.getIcon("printPreview"),
307 self.tr("Print Preview"), self.__contextMenuPrintPreviewFile) 322 self.tr("Print Preview"),
323 self.__contextMenuPrintPreviewFile,
324 )
308 self.__menu.addAction( 325 self.__menu.addAction(
309 UI.PixmapCache.getIcon("print"), 326 UI.PixmapCache.getIcon("print"),
310 self.tr('Print'), self.__contextMenuPrintFile) 327 self.tr("Print"),
328 self.__contextMenuPrintFile,
329 )
311 self.__menu.addSeparator() 330 self.__menu.addSeparator()
312 self.copyPathAct = self.__menu.addAction( 331 self.copyPathAct = self.__menu.addAction(
313 self.tr("Copy Path to Clipboard"), 332 self.tr("Copy Path to Clipboard"), self.__contextMenuCopyPathToClipboard
314 self.__contextMenuCopyPathToClipboard) 333 )
315 334
316 def __showMenu(self, point): 335 def __showMenu(self, point):
317 """ 336 """
318 Private slot to handle the customContextMenuRequested signal of 337 Private slot to handle the customContextMenuRequested signal of
319 the viewlist. 338 the viewlist.
320 339
321 @param point position to open the menu at 340 @param point position to open the menu at
322 @type QPoint 341 @type QPoint
323 """ 342 """
324 if self.editors: 343 if self.editors:
325 itm = self.viewlist.itemAt(point) 344 itm = self.viewlist.itemAt(point)
326 if itm is not None: 345 if itm is not None:
327 row = self.viewlist.row(itm) 346 row = self.viewlist.row(itm)
328 self.contextMenuEditor = self.editors[row] 347 self.contextMenuEditor = self.editors[row]
329 self.contextMenuIndex = row 348 self.contextMenuIndex = row
330 if self.contextMenuEditor: 349 if self.contextMenuEditor:
331 self.saveMenuAct.setEnabled( 350 self.saveMenuAct.setEnabled(self.contextMenuEditor.isModified())
332 self.contextMenuEditor.isModified())
333 fileName = self.contextMenuEditor.getFileName() 351 fileName = self.contextMenuEditor.getFileName()
334 self.copyPathAct.setEnabled(bool(fileName)) 352 self.copyPathAct.setEnabled(bool(fileName))
335 if fileName: 353 if fileName:
336 rej = "{0}.rej".format(fileName) 354 rej = "{0}.rej".format(fileName)
337 self.openRejectionsMenuAct.setEnabled( 355 self.openRejectionsMenuAct.setEnabled(os.path.exists(rej))
338 os.path.exists(rej)) 356
339
340 ext = os.path.splitext(fileName)[1] 357 ext = os.path.splitext(fileName)[1]
341 self.__startAct.setEnabled( 358 self.__startAct.setEnabled(
342 ext in Preferences.getDebugger( 359 ext in Preferences.getDebugger("Python3Extensions").split()
343 "Python3Extensions").split()
344 ) 360 )
345 else: 361 else:
346 self.openRejectionsMenuAct.setEnabled(False) 362 self.openRejectionsMenuAct.setEnabled(False)
347 self.__startAct.setEnabled(False) 363 self.__startAct.setEnabled(False)
348 364
349 self.closeOthersMenuAct.setEnabled( 365 self.closeOthersMenuAct.setEnabled(self.viewlist.count() > 1)
350 self.viewlist.count() > 1) 366
351
352 self.__menu.popup(self.viewlist.mapToGlobal(point)) 367 self.__menu.popup(self.viewlist.mapToGlobal(point))
353 368
354 def mainWidget(self): 369 def mainWidget(self):
355 """ 370 """
356 Public method to return a reference to the main Widget of a 371 Public method to return a reference to the main Widget of a
357 specific view manager subclass. 372 specific view manager subclass.
358 373
359 @return reference to the main widget 374 @return reference to the main widget
360 @rtype QWidget 375 @rtype QWidget
361 """ 376 """
362 return self.__splitter 377 return self.__splitter
363 378
364 def canCascade(self): 379 def canCascade(self):
365 """ 380 """
366 Public method to signal if cascading of managed windows is available. 381 Public method to signal if cascading of managed windows is available.
367 382
368 @return flag indicating cascading of windows is available 383 @return flag indicating cascading of windows is available
369 @rtype bool 384 @rtype bool
370 """ 385 """
371 return False 386 return False
372 387
373 def canTile(self): 388 def canTile(self):
374 """ 389 """
375 Public method to signal if tiling of managed windows is available. 390 Public method to signal if tiling of managed windows is available.
376 391
377 @return flag indicating tiling of windows is available 392 @return flag indicating tiling of windows is available
378 @rtype bool 393 @rtype bool
379 """ 394 """
380 return False 395 return False
381 396
382 def canSplit(self): 397 def canSplit(self):
383 """ 398 """
384 public method to signal if splitting of the view is available. 399 public method to signal if splitting of the view is available.
385 400
386 @return flag indicating splitting of the view is available 401 @return flag indicating splitting of the view is available
387 @rtype bool 402 @rtype bool
388 """ 403 """
389 return True 404 return True
390 405
391 def tile(self): 406 def tile(self):
392 """ 407 """
393 Public method to tile the managed windows. 408 Public method to tile the managed windows.
394 """ 409 """
395 pass 410 pass
396 411
397 def cascade(self): 412 def cascade(self):
398 """ 413 """
399 Public method to cascade the managed windows. 414 Public method to cascade the managed windows.
400 """ 415 """
401 pass 416 pass
402 417
403 def _removeAllViews(self): 418 def _removeAllViews(self):
404 """ 419 """
405 Protected method to remove all views (i.e. windows). 420 Protected method to remove all views (i.e. windows).
406 """ 421 """
407 self.viewlist.clear() 422 self.viewlist.clear()
409 for stack in self.stacks: 424 for stack in self.stacks:
410 if stack.hasEditor(win): 425 if stack.hasEditor(win):
411 stack.removeWidget(win) 426 stack.removeWidget(win)
412 break 427 break
413 win.closeIt() 428 win.closeIt()
414 429
415 def _removeView(self, win): 430 def _removeView(self, win):
416 """ 431 """
417 Protected method to remove a view (i.e. window). 432 Protected method to remove a view (i.e. window).
418 433
419 @param win editor window to be removed 434 @param win editor window to be removed
420 @type Editor 435 @type Editor
421 """ 436 """
422 self.__inRemoveView = True 437 self.__inRemoveView = True
423 ind = self.editors.index(win) 438 ind = self.editors.index(win)
437 ind = 1 452 ind = 1
438 else: 453 else:
439 return 454 return
440 stack.setCurrentWidget(stack.firstEditor()) 455 stack.setCurrentWidget(stack.firstEditor())
441 self._showView(self.editors[ind].parent()) 456 self._showView(self.editors[ind].parent())
442 457
443 aw = self.activeWindow() 458 aw = self.activeWindow()
444 fn = aw and aw.getFileName() or None 459 fn = aw and aw.getFileName() or None
445 if fn: 460 if fn:
446 self.changeCaption.emit(fn) 461 self.changeCaption.emit(fn)
447 self.editorChanged.emit(fn) 462 self.editorChanged.emit(fn)
448 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1) 463 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1)
449 else: 464 else:
450 self.changeCaption.emit("") 465 self.changeCaption.emit("")
451 self.editorChangedEd.emit(aw) 466 self.editorChangedEd.emit(aw)
452 467
453 def _addView(self, win, fn=None, noName="", addNext=False, indexes=None): 468 def _addView(self, win, fn=None, noName="", addNext=False, indexes=None):
454 """ 469 """
455 Protected method to add a view (i.e. window). 470 Protected method to add a view (i.e. window).
456 471
457 @param win editor assembly to be added 472 @param win editor assembly to be added
458 @type EditorAssembly 473 @type EditorAssembly
459 @param fn filename of this editor 474 @param fn filename of this editor
460 @type str 475 @type str
461 @param noName name to be used for an unnamed editor 476 @param noName name to be used for an unnamed editor
490 else: 505 else:
491 self.currentStack.addWidget(win) 506 self.currentStack.addWidget(win)
492 self.currentStack.setCurrentWidget(win) 507 self.currentStack.setCurrentWidget(win)
493 editor.captionChanged.connect(self.__captionChange) 508 editor.captionChanged.connect(self.__captionChange)
494 editor.cursorLineChanged.connect( 509 editor.cursorLineChanged.connect(
495 lambda lineno: self.__cursorLineChanged(lineno, editor)) 510 lambda lineno: self.__cursorLineChanged(lineno, editor)
496 511 )
512
497 index = self.editors.index(editor) 513 index = self.editors.index(editor)
498 self.viewlist.setCurrentRow(index) 514 self.viewlist.setCurrentRow(index)
499 editor.setFocus() 515 editor.setFocus()
500 if fn: 516 if fn:
501 self.changeCaption.emit(fn) 517 self.changeCaption.emit(fn)
502 self.editorChanged.emit(fn) 518 self.editorChanged.emit(fn)
503 self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1) 519 self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1)
504 else: 520 else:
505 self.changeCaption.emit("") 521 self.changeCaption.emit("")
506 self.editorChangedEd.emit(editor) 522 self.editorChangedEd.emit(editor)
507 523
508 def __captionChange(self, cap, editor): 524 def __captionChange(self, cap, editor):
509 """ 525 """
510 Private method to handle caption change signals from the editor. 526 Private method to handle caption change signals from the editor.
511 527
512 Updates the listwidget text to reflect the new caption information. 528 Updates the listwidget text to reflect the new caption information.
513 529
514 @param cap Caption for the editor 530 @param cap Caption for the editor
515 @type str 531 @type str
516 @param editor Editor to update the caption for 532 @param editor Editor to update the caption for
517 @type Editor 533 @type Editor
518 """ 534 """
519 fn = editor.getFileName() 535 fn = editor.getFileName()
520 if fn: 536 if fn:
521 self.setEditorName(editor, fn) 537 self.setEditorName(editor, fn)
522 538
523 def __cursorLineChanged(self, lineno, editor): 539 def __cursorLineChanged(self, lineno, editor):
524 """ 540 """
525 Private slot to handle a change of the current editor's cursor line. 541 Private slot to handle a change of the current editor's cursor line.
526 542
527 @param lineno line number of the editor's cursor (zero based) 543 @param lineno line number of the editor's cursor (zero based)
528 @type int 544 @type int
529 @param editor reference to the editor 545 @param editor reference to the editor
530 @type Editor 546 @type Editor
531 """ 547 """
532 if editor: 548 if editor:
533 fn = editor.getFileName() 549 fn = editor.getFileName()
534 if fn: 550 if fn:
535 self.editorLineChanged.emit(fn, lineno + 1) 551 self.editorLineChanged.emit(fn, lineno + 1)
536 self.editorLineChangedEd.emit(editor, lineno + 1) 552 self.editorLineChangedEd.emit(editor, lineno + 1)
537 553
538 def _showView(self, win, fn=None): 554 def _showView(self, win, fn=None):
539 """ 555 """
540 Protected method to show a view (i.e. window). 556 Protected method to show a view (i.e. window).
541 557
542 @param win editor assembly to be shown 558 @param win editor assembly to be shown
543 @type EditorAssembly 559 @type EditorAssembly
544 @param fn filename of this editor 560 @param fn filename of this editor
545 @type string 561 @type string
546 """ 562 """
559 self.editorChanged.emit(fn) 575 self.editorChanged.emit(fn)
560 self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1) 576 self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1)
561 else: 577 else:
562 self.changeCaption.emit("") 578 self.changeCaption.emit("")
563 self.editorChangedEd.emit(editor) 579 self.editorChangedEd.emit(editor)
564 580
565 def __showSelectedView(self, row): 581 def __showSelectedView(self, row):
566 """ 582 """
567 Private slot called to show a view selected in the list. 583 Private slot called to show a view selected in the list.
568 584
569 @param row row number of the item clicked on 585 @param row row number of the item clicked on
570 @type int 586 @type int
571 """ 587 """
572 if row != -1: 588 if row != -1:
573 self._showView(self.editors[row].parent()) 589 self._showView(self.editors[row].parent())
574 self._checkActions(self.editors[row]) 590 self._checkActions(self.editors[row])
575 591
576 def activeWindow(self): 592 def activeWindow(self):
577 """ 593 """
578 Public method to return the active (i.e. current) window. 594 Public method to return the active (i.e. current) window.
579 595
580 @return reference to the active editor 596 @return reference to the active editor
581 @rtype EditorAssembly 597 @rtype EditorAssembly
582 """ 598 """
583 return self.currentStack.currentWidget() 599 return self.currentStack.currentWidget()
584 600
585 def showWindowMenu(self, windowMenu): 601 def showWindowMenu(self, windowMenu):
586 """ 602 """
587 Public method to set up the viewmanager part of the Window menu. 603 Public method to set up the viewmanager part of the Window menu.
588 604
589 @param windowMenu reference to the window menu 605 @param windowMenu reference to the window menu
590 @type QMenu 606 @type QMenu
591 """ 607 """
592 pass 608 pass
593 609
594 def _initWindowActions(self): 610 def _initWindowActions(self):
595 """ 611 """
596 Protected method to define the user interface actions for window 612 Protected method to define the user interface actions for window
597 handling. 613 handling.
598 """ 614 """
599 pass 615 pass
600 616
601 def setEditorName(self, editor, newName): 617 def setEditorName(self, editor, newName):
602 """ 618 """
603 Public method to change the displayed name of the editor. 619 Public method to change the displayed name of the editor.
604 620
605 @param editor editor window to be changed 621 @param editor editor window to be changed
606 @type Editor 622 @type Editor
607 @param newName new name to be shown 623 @param newName new name to be shown
608 @type str 624 @type str
609 """ 625 """
617 if itm: 633 if itm:
618 itm.setText(txt) 634 itm.setText(txt)
619 itm.setToolTip(newName) 635 itm.setToolTip(newName)
620 self.viewlist.setCurrentRow(currentRow) 636 self.viewlist.setCurrentRow(currentRow)
621 self.changeCaption.emit(newName) 637 self.changeCaption.emit(newName)
622 638
623 def _modificationStatusChanged(self, m, editor): 639 def _modificationStatusChanged(self, m, editor):
624 """ 640 """
625 Protected slot to handle the modificationStatusChanged signal. 641 Protected slot to handle the modificationStatusChanged signal.
626 642
627 @param m flag indicating the modification status 643 @param m flag indicating the modification status
628 @type bool 644 @type bool
629 @param editor editor window changed 645 @param editor editor window changed
630 @type Editor 646 @type Editor
631 """ 647 """
643 item = self.viewlist.item(index) 659 item = self.viewlist.item(index)
644 if item: 660 if item:
645 item.setIcon(UI.PixmapCache.getCombinedIcon(keys)) 661 item.setIcon(UI.PixmapCache.getCombinedIcon(keys))
646 self.viewlist.setCurrentRow(currentRow) 662 self.viewlist.setCurrentRow(currentRow)
647 self._checkActions(editor) 663 self._checkActions(editor)
648 664
649 def _syntaxErrorToggled(self, editor): 665 def _syntaxErrorToggled(self, editor):
650 """ 666 """
651 Protected slot to handle the syntaxerrorToggled signal. 667 Protected slot to handle the syntaxerrorToggled signal.
652 668
653 @param editor editor that sent the signal 669 @param editor editor that sent the signal
654 @type Editor 670 @type Editor
655 """ 671 """
656 currentRow = self.viewlist.currentRow() 672 currentRow = self.viewlist.currentRow()
657 index = self.editors.index(editor) 673 index = self.editors.index(editor)
666 keys.append("empty") 682 keys.append("empty")
667 item = self.viewlist.item(index) 683 item = self.viewlist.item(index)
668 if item: 684 if item:
669 item.setIcon(UI.PixmapCache.getCombinedIcon(keys)) 685 item.setIcon(UI.PixmapCache.getCombinedIcon(keys))
670 self.viewlist.setCurrentRow(currentRow) 686 self.viewlist.setCurrentRow(currentRow)
671 687
672 ViewManager._syntaxErrorToggled(self, editor) 688 ViewManager._syntaxErrorToggled(self, editor)
673 689
674 def addSplit(self): 690 def addSplit(self):
675 """ 691 """
676 Public method used to split the current view. 692 Public method used to split the current view.
677 """ 693 """
678 stack = StackedWidget(self.stackArea) 694 stack = StackedWidget(self.stackArea)
682 self.currentStack = stack 698 self.currentStack = stack
683 stack.currentChanged.connect(self.__currentChanged) 699 stack.currentChanged.connect(self.__currentChanged)
684 stack.installEventFilter(self) 700 stack.installEventFilter(self)
685 size = ( 701 size = (
686 self.stackArea.width() 702 self.stackArea.width()
687 if self.stackArea.orientation() == Qt.Orientation.Horizontal else 703 if self.stackArea.orientation() == Qt.Orientation.Horizontal
688 self.stackArea.height() 704 else self.stackArea.height()
689 ) 705 )
690 self.stackArea.setSizes( 706 self.stackArea.setSizes([int(size / len(self.stacks))] * len(self.stacks))
691 [int(size / len(self.stacks))] * len(self.stacks))
692 self.splitRemoveAct.setEnabled(True) 707 self.splitRemoveAct.setEnabled(True)
693 self.nextSplitAct.setEnabled(True) 708 self.nextSplitAct.setEnabled(True)
694 self.prevSplitAct.setEnabled(True) 709 self.prevSplitAct.setEnabled(True)
695 710
696 @pyqtSlot() 711 @pyqtSlot()
697 def removeSplit(self, index=-1): 712 def removeSplit(self, index=-1):
698 """ 713 """
699 Public method used to remove the current split view or a split view 714 Public method used to remove the current split view or a split view
700 by index. 715 by index.
701 716
702 @param index index of the split to be removed (-1 means to 717 @param index index of the split to be removed (-1 means to
703 delete the current split) 718 delete the current split)
704 @type int 719 @type int
705 @return flag indicating successful deletion 720 @return flag indicating successful deletion
706 @rtype bool 721 @rtype bool
730 if len(self.stacks) == 1: 745 if len(self.stacks) == 1:
731 self.splitRemoveAct.setEnabled(False) 746 self.splitRemoveAct.setEnabled(False)
732 self.nextSplitAct.setEnabled(False) 747 self.nextSplitAct.setEnabled(False)
733 self.prevSplitAct.setEnabled(False) 748 self.prevSplitAct.setEnabled(False)
734 return True 749 return True
735 750
736 return False 751 return False
737 752
738 def splitCount(self): 753 def splitCount(self):
739 """ 754 """
740 Public method to get the number of splitted views. 755 Public method to get the number of splitted views.
741 756
742 @return number of splitted views 757 @return number of splitted views
743 @rtype int 758 @rtype int
744 """ 759 """
745 return len(self.stacks) 760 return len(self.stacks)
746 761
747 def setSplitCount(self, count): 762 def setSplitCount(self, count):
748 """ 763 """
749 Public method to set the number of split views. 764 Public method to set the number of split views.
750 765
751 @param count number of split views 766 @param count number of split views
752 @type int 767 @type int
753 """ 768 """
754 if count > self.splitCount(): 769 if count > self.splitCount():
755 while self.splitCount() < count: 770 while self.splitCount() < count:
756 self.addSplit() 771 self.addSplit()
757 elif count < self.splitCount(): 772 elif count < self.splitCount():
758 while self.splitCount() > count: 773 while self.splitCount() > count:
759 # use an arbitrarily large index to remove the last one 774 # use an arbitrarily large index to remove the last one
760 self.removeSplit(index=100) 775 self.removeSplit(index=100)
761 776
762 def getSplitOrientation(self): 777 def getSplitOrientation(self):
763 """ 778 """
764 Public method to get the orientation of the split view. 779 Public method to get the orientation of the split view.
765 780
766 @return orientation of the split 781 @return orientation of the split
767 @rtype Qt.Orientation.Horizontal or Qt.Orientation.Vertical 782 @rtype Qt.Orientation.Horizontal or Qt.Orientation.Vertical
768 """ 783 """
769 return self.stackArea.orientation() 784 return self.stackArea.orientation()
770 785
771 def setSplitOrientation(self, orientation): 786 def setSplitOrientation(self, orientation):
772 """ 787 """
773 Public method used to set the orientation of the split view. 788 Public method used to set the orientation of the split view.
774 789
775 @param orientation orientation of the split 790 @param orientation orientation of the split
776 @type Qt.Orientation.Horizontal or Qt.Orientation.Vertical 791 @type Qt.Orientation.Horizontal or Qt.Orientation.Vertical
777 """ 792 """
778 self.stackArea.setOrientation(orientation) 793 self.stackArea.setOrientation(orientation)
779 794
780 def nextSplit(self): 795 def nextSplit(self):
781 """ 796 """
782 Public slot used to move to the next split. 797 Public slot used to move to the next split.
783 """ 798 """
784 aw = self.activeWindow() 799 aw = self.activeWindow()
785 _hasFocus = aw and aw.hasFocus() 800 _hasFocus = aw and aw.hasFocus()
786 ind = self.stacks.index(self.currentStack) + 1 801 ind = self.stacks.index(self.currentStack) + 1
787 if ind == len(self.stacks): 802 if ind == len(self.stacks):
788 ind = 0 803 ind = 0
789 804
790 self.currentStack = self.stacks[ind] 805 self.currentStack = self.stacks[ind]
791 if _hasFocus: 806 if _hasFocus:
792 aw = self.activeWindow() 807 aw = self.activeWindow()
793 if aw: 808 if aw:
794 aw.setFocus() 809 aw.setFocus()
795 810
796 cw = self.currentStack.currentWidget() 811 cw = self.currentStack.currentWidget()
797 if cw: 812 if cw:
798 index = self.editors.index(cw) 813 index = self.editors.index(cw)
799 self.viewlist.setCurrentRow(index) 814 self.viewlist.setCurrentRow(index)
800 815
801 def prevSplit(self): 816 def prevSplit(self):
802 """ 817 """
803 Public slot used to move to the previous split. 818 Public slot used to move to the previous split.
804 """ 819 """
805 aw = self.activeWindow() 820 aw = self.activeWindow()
806 _hasFocus = aw and aw.hasFocus() 821 _hasFocus = aw and aw.hasFocus()
807 ind = self.stacks.index(self.currentStack) - 1 822 ind = self.stacks.index(self.currentStack) - 1
808 if ind == -1: 823 if ind == -1:
809 ind = len(self.stacks) - 1 824 ind = len(self.stacks) - 1
810 825
811 self.currentStack = self.stacks[ind] 826 self.currentStack = self.stacks[ind]
812 if _hasFocus: 827 if _hasFocus:
813 aw = self.activeWindow() 828 aw = self.activeWindow()
814 if aw: 829 if aw:
815 aw.setFocus() 830 aw.setFocus()
816 831
817 cw = self.currentStack.currentWidget() 832 cw = self.currentStack.currentWidget()
818 if cw: 833 if cw:
819 index = self.editors.index(cw) 834 index = self.editors.index(cw)
820 self.viewlist.setCurrentRow(index) 835 self.viewlist.setCurrentRow(index)
821 836
822 def __contextMenuClose(self): 837 def __contextMenuClose(self):
823 """ 838 """
824 Private method to close the selected editor. 839 Private method to close the selected editor.
825 """ 840 """
826 if self.contextMenuEditor: 841 if self.contextMenuEditor:
827 self.closeEditorWindow(self.contextMenuEditor) 842 self.closeEditorWindow(self.contextMenuEditor)
828 843
829 def __contextMenuCloseOthers(self): 844 def __contextMenuCloseOthers(self):
830 """ 845 """
831 Private method to close the other editors. 846 Private method to close the other editors.
832 """ 847 """
833 index = self.contextMenuIndex 848 index = self.contextMenuIndex
834 for i in ( 849 for i in list(range(self.viewlist.count() - 1, index, -1)) + list(
835 list(range(self.viewlist.count() - 1, index, -1)) + 850 range(index - 1, -1, -1)
836 list(range(index - 1, -1, -1))
837 ): 851 ):
838 editor = self.editors[i] 852 editor = self.editors[i]
839 self.closeEditorWindow(editor) 853 self.closeEditorWindow(editor)
840 854
841 def __contextMenuCloseAll(self): 855 def __contextMenuCloseAll(self):
842 """ 856 """
843 Private method to close all editors. 857 Private method to close all editors.
844 """ 858 """
845 savedEditors = self.editors[:] 859 savedEditors = self.editors[:]
846 for editor in savedEditors: 860 for editor in savedEditors:
847 self.closeEditorWindow(editor) 861 self.closeEditorWindow(editor)
848 862
849 def __contextMenuSave(self): 863 def __contextMenuSave(self):
850 """ 864 """
851 Private method to save the selected editor. 865 Private method to save the selected editor.
852 """ 866 """
853 if self.contextMenuEditor: 867 if self.contextMenuEditor:
854 self.saveEditorEd(self.contextMenuEditor) 868 self.saveEditorEd(self.contextMenuEditor)
855 869
856 def __contextMenuSaveAs(self): 870 def __contextMenuSaveAs(self):
857 """ 871 """
858 Private method to save the selected editor to a new file. 872 Private method to save the selected editor to a new file.
859 """ 873 """
860 if self.contextMenuEditor: 874 if self.contextMenuEditor:
861 self.saveAsEditorEd(self.contextMenuEditor) 875 self.saveAsEditorEd(self.contextMenuEditor)
862 876
863 def __contextMenuSaveAll(self): 877 def __contextMenuSaveAll(self):
864 """ 878 """
865 Private method to save all editors. 879 Private method to save all editors.
866 """ 880 """
867 self.saveEditorsList(self.editors) 881 self.saveEditorsList(self.editors)
868 882
869 def __contextMenuOpenRejections(self): 883 def __contextMenuOpenRejections(self):
870 """ 884 """
871 Private slot to open a rejections file associated with the selected 885 Private slot to open a rejections file associated with the selected
872 editor. 886 editor.
873 """ 887 """
875 fileName = self.contextMenuEditor.getFileName() 889 fileName = self.contextMenuEditor.getFileName()
876 if fileName: 890 if fileName:
877 rej = "{0}.rej".format(fileName) 891 rej = "{0}.rej".format(fileName)
878 if os.path.exists(rej): 892 if os.path.exists(rej):
879 self.openSourceFile(rej) 893 self.openSourceFile(rej)
880 894
881 def __contextMenuPrintFile(self): 895 def __contextMenuPrintFile(self):
882 """ 896 """
883 Private method to print the selected editor. 897 Private method to print the selected editor.
884 """ 898 """
885 if self.contextMenuEditor: 899 if self.contextMenuEditor:
886 self.printEditor(self.contextMenuEditor) 900 self.printEditor(self.contextMenuEditor)
887 901
888 def __contextMenuPrintPreviewFile(self): 902 def __contextMenuPrintPreviewFile(self):
889 """ 903 """
890 Private method to show a print preview of the selected editor. 904 Private method to show a print preview of the selected editor.
891 """ 905 """
892 if self.contextMenuEditor: 906 if self.contextMenuEditor:
893 self.printPreviewEditor(self.contextMenuEditor) 907 self.printPreviewEditor(self.contextMenuEditor)
894 908
895 def __contextMenuCopyPathToClipboard(self): 909 def __contextMenuCopyPathToClipboard(self):
896 """ 910 """
897 Private method to copy the file name of the selected editor to the 911 Private method to copy the file name of the selected editor to the
898 clipboard. 912 clipboard.
899 """ 913 """
900 if self.contextMenuEditor: 914 if self.contextMenuEditor:
901 fn = self.contextMenuEditor.getFileName() 915 fn = self.contextMenuEditor.getFileName()
902 if fn: 916 if fn:
903 cb = QApplication.clipboard() 917 cb = QApplication.clipboard()
904 cb.setText(fn) 918 cb.setText(fn)
905 919
906 def __contextMenuRunScript(self): 920 def __contextMenuRunScript(self):
907 """ 921 """
908 Private method to run the editor script. 922 Private method to run the editor script.
909 """ 923 """
910 if self.contextMenuEditor: 924 if self.contextMenuEditor:
911 fn = self.contextMenuEditor.getFileName() 925 fn = self.contextMenuEditor.getFileName()
912 if fn: 926 if fn:
913 ericApp().getObject("DebugUI").doRun(False, script=fn) 927 ericApp().getObject("DebugUI").doRun(False, script=fn)
914 928
915 def __contextMenuDebugScript(self): 929 def __contextMenuDebugScript(self):
916 """ 930 """
917 Private method to debug the editor script. 931 Private method to debug the editor script.
918 """ 932 """
919 if self.contextMenuEditor: 933 if self.contextMenuEditor:
920 fn = self.contextMenuEditor.getFileName() 934 fn = self.contextMenuEditor.getFileName()
921 if fn: 935 if fn:
922 ericApp().getObject("DebugUI").doDebug(False, script=fn) 936 ericApp().getObject("DebugUI").doDebug(False, script=fn)
923 937
924 def __contextMenuProfileScript(self): 938 def __contextMenuProfileScript(self):
925 """ 939 """
926 Private method to profile the editor script. 940 Private method to profile the editor script.
927 """ 941 """
928 if self.contextMenuEditor: 942 if self.contextMenuEditor:
929 fn = self.contextMenuEditor.getFileName() 943 fn = self.contextMenuEditor.getFileName()
930 if fn: 944 if fn:
931 ericApp().getObject("DebugUI").doProfile(False, script=fn) 945 ericApp().getObject("DebugUI").doProfile(False, script=fn)
932 946
933 def __contextMenuCoverageScript(self): 947 def __contextMenuCoverageScript(self):
934 """ 948 """
935 Private method to run a coverage test of the editor script. 949 Private method to run a coverage test of the editor script.
936 """ 950 """
937 if self.contextMenuEditor: 951 if self.contextMenuEditor:
938 fn = self.contextMenuEditor.getFileName() 952 fn = self.contextMenuEditor.getFileName()
939 if fn: 953 if fn:
940 ericApp().getObject("DebugUI").doCoverage(False, script=fn) 954 ericApp().getObject("DebugUI").doCoverage(False, script=fn)
941 955
942 def __currentChanged(self, index): 956 def __currentChanged(self, index):
943 """ 957 """
944 Private slot to handle the currentChanged signal. 958 Private slot to handle the currentChanged signal.
945 959
946 @param index index of the current editor 960 @param index index of the current editor
947 @type int 961 @type int
948 """ 962 """
949 if index == -1 or not self.editors: 963 if index == -1 or not self.editors:
950 return 964 return
951 965
952 editor = self.activeWindow() 966 editor = self.activeWindow()
953 if editor is None: 967 if editor is None:
954 return 968 return
955 969
956 self._checkActions(editor) 970 self._checkActions(editor)
957 editor.setFocus() 971 editor.setFocus()
958 fn = editor.getFileName() 972 fn = editor.getFileName()
959 if fn: 973 if fn:
960 self.changeCaption.emit(fn) 974 self.changeCaption.emit(fn)
961 if not self.__inRemoveView: 975 if not self.__inRemoveView:
962 self.editorChanged.emit(fn) 976 self.editorChanged.emit(fn)
963 self.editorLineChanged.emit( 977 self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1)
964 fn, editor.getCursorPosition()[0] + 1)
965 else: 978 else:
966 self.changeCaption.emit("") 979 self.changeCaption.emit("")
967 self.editorChangedEd.emit(editor) 980 self.editorChangedEd.emit(editor)
968 981
969 cindex = self.editors.index(editor) 982 cindex = self.editors.index(editor)
970 self.viewlist.setCurrentRow(cindex) 983 self.viewlist.setCurrentRow(cindex)
971 984
972 def eventFilter(self, watched, event): 985 def eventFilter(self, watched, event):
973 """ 986 """
974 Public method called to filter the event queue. 987 Public method called to filter the event queue.
975 988
976 @param watched the QObject being watched 989 @param watched the QObject being watched
977 @type QObject 990 @type QObject
978 @param event the event that occurred 991 @param event the event that occurred
979 @type QEvent 992 @type QEvent
980 @return flag indicating, if we handled the event 993 @return flag indicating, if we handled the event
981 @rtype bool 994 @rtype bool
982 """ 995 """
983 if ( 996 if (
984 event.type() == QEvent.Type.MouseButtonPress and 997 event.type() == QEvent.Type.MouseButtonPress
985 event.button() != Qt.MouseButton.RightButton 998 and event.button() != Qt.MouseButton.RightButton
986 ): 999 ):
987 switched = True 1000 switched = True
988 if isinstance(watched, QStackedWidget): 1001 if isinstance(watched, QStackedWidget):
989 switched = watched is not self.currentStack 1002 switched = watched is not self.currentStack
990 self.currentStack = watched 1003 self.currentStack = watched
996 break 1009 break
997 currentWidget = self.currentStack.currentWidget() 1010 currentWidget = self.currentStack.currentWidget()
998 if currentWidget: 1011 if currentWidget:
999 index = self.editors.index(currentWidget) 1012 index = self.editors.index(currentWidget)
1000 self.viewlist.setCurrentRow(index) 1013 self.viewlist.setCurrentRow(index)
1001 1014
1002 aw = self.activeWindow() 1015 aw = self.activeWindow()
1003 if aw is not None: 1016 if aw is not None:
1004 self._checkActions(aw) 1017 self._checkActions(aw)
1005 aw.setFocus() 1018 aw.setFocus()
1006 fn = aw.getFileName() 1019 fn = aw.getFileName()
1007 if fn: 1020 if fn:
1008 self.changeCaption.emit(fn) 1021 self.changeCaption.emit(fn)
1009 if switched: 1022 if switched:
1010 self.editorChanged.emit(fn) 1023 self.editorChanged.emit(fn)
1011 self.editorLineChanged.emit( 1024 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1)
1012 fn, aw.getCursorPosition()[0] + 1)
1013 else: 1025 else:
1014 self.changeCaption.emit("") 1026 self.changeCaption.emit("")
1015 self.editorChangedEd.emit(aw) 1027 self.editorChangedEd.emit(aw)
1016 1028
1017 return False 1029 return False
1018 1030
1019 def getOpenEditorsForSession(self): 1031 def getOpenEditorsForSession(self):
1020 """ 1032 """
1021 Public method to get a lists of all open editors. 1033 Public method to get a lists of all open editors.
1022 1034
1023 The returned list contains one list per split view. If the view manager 1035 The returned list contains one list per split view. If the view manager
1024 cannot split the view, only one list of editors is returned. 1036 cannot split the view, only one list of editors is returned.
1025 1037
1026 @return list of list of editor references 1038 @return list of list of editor references
1027 @rtype list of list of Editor 1039 @rtype list of list of Editor
1028 """ 1040 """
1029 editorLists = [] 1041 editorLists = []
1030 for stack in self.stacks: 1042 for stack in self.stacks:

eric ide

mercurial