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 |
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() |
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 """ |
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 |