50 giving the string encoded id of the source tab widget, the index in the |
63 giving the string encoded id of the source tab widget, the index in the |
51 source tab widget and the new index position |
64 source tab widget and the new index position |
52 @signal tabCopyRequested(int, int) emitted to signal a clone request giving |
65 @signal tabCopyRequested(int, int) emitted to signal a clone request giving |
53 the old and new index position |
66 the old and new index position |
54 """ |
67 """ |
|
68 |
55 tabMoveRequested = pyqtSignal(int, int) |
69 tabMoveRequested = pyqtSignal(int, int) |
56 tabRelocateRequested = pyqtSignal(str, int, int) |
70 tabRelocateRequested = pyqtSignal(str, int, int) |
57 tabCopyRequested = pyqtSignal((str, int, int), (int, int)) |
71 tabCopyRequested = pyqtSignal((str, int, int), (int, int)) |
58 |
72 |
59 def __init__(self, parent=None): |
73 def __init__(self, parent=None): |
60 """ |
74 """ |
61 Constructor |
75 Constructor |
62 |
76 |
63 @param parent reference to the parent widget |
77 @param parent reference to the parent widget |
64 @type QWidget |
78 @type QWidget |
65 """ |
79 """ |
66 super().__init__(parent) |
80 super().__init__(parent) |
67 self.setAcceptDrops(True) |
81 self.setAcceptDrops(True) |
68 |
82 |
69 self.__dragStartPos = QPoint() |
83 self.__dragStartPos = QPoint() |
70 |
84 |
71 def mousePressEvent(self, event): |
85 def mousePressEvent(self, event): |
72 """ |
86 """ |
73 Protected method to handle mouse press events. |
87 Protected method to handle mouse press events. |
74 |
88 |
75 @param event reference to the mouse press event |
89 @param event reference to the mouse press event |
76 @type QMouseEvent |
90 @type QMouseEvent |
77 """ |
91 """ |
78 if event.button() == Qt.MouseButton.LeftButton: |
92 if event.button() == Qt.MouseButton.LeftButton: |
79 self.__dragStartPos = QPoint(event.position().toPoint()) |
93 self.__dragStartPos = QPoint(event.position().toPoint()) |
80 super().mousePressEvent(event) |
94 super().mousePressEvent(event) |
81 |
95 |
82 def mouseMoveEvent(self, event): |
96 def mouseMoveEvent(self, event): |
83 """ |
97 """ |
84 Protected method to handle mouse move events. |
98 Protected method to handle mouse move events. |
85 |
99 |
86 @param event reference to the mouse move event |
100 @param event reference to the mouse move event |
87 @type QMouseEvent |
101 @type QMouseEvent |
88 """ |
102 """ |
89 if ( |
103 if ( |
90 event.buttons() == Qt.MouseButton.LeftButton and |
104 event.buttons() == Qt.MouseButton.LeftButton |
91 (event.position().toPoint() - self.__dragStartPos) |
105 and (event.position().toPoint() - self.__dragStartPos).manhattanLength() |
92 .manhattanLength() > QApplication.startDragDistance() |
106 > QApplication.startDragDistance() |
93 ): |
107 ): |
94 drag = QDrag(self) |
108 drag = QDrag(self) |
95 mimeData = QMimeData() |
109 mimeData = QMimeData() |
96 index = self.tabAt(event.position().toPoint()) |
110 index = self.tabAt(event.position().toPoint()) |
97 mimeData.setText(self.tabText(index)) |
111 mimeData.setText(self.tabText(index)) |
98 mimeData.setData("action", b"tab-reordering") |
112 mimeData.setData("action", b"tab-reordering") |
99 mimeData.setData("tabbar-id", str(id(self)).encode("utf-8")) |
113 mimeData.setData("tabbar-id", str(id(self)).encode("utf-8")) |
100 mimeData.setData( |
114 mimeData.setData( |
101 "source-index", |
115 "source-index", QByteArray.number(self.tabAt(self.__dragStartPos)) |
102 QByteArray.number(self.tabAt(self.__dragStartPos))) |
116 ) |
103 mimeData.setData( |
117 mimeData.setData( |
104 "tabwidget-id", |
118 "tabwidget-id", str(id(self.parentWidget())).encode("utf-8") |
105 str(id(self.parentWidget())).encode("utf-8")) |
119 ) |
106 drag.setMimeData(mimeData) |
120 drag.setMimeData(mimeData) |
107 if event.modifiers() == Qt.KeyboardModifier.ShiftModifier: |
121 if event.modifiers() == Qt.KeyboardModifier.ShiftModifier: |
108 drag.exec(Qt.DropAction.CopyAction) |
122 drag.exec(Qt.DropAction.CopyAction) |
109 elif event.modifiers() == Qt.KeyboardModifier.NoModifier: |
123 elif event.modifiers() == Qt.KeyboardModifier.NoModifier: |
110 drag.exec(Qt.DropAction.MoveAction) |
124 drag.exec(Qt.DropAction.MoveAction) |
111 super().mouseMoveEvent(event) |
125 super().mouseMoveEvent(event) |
112 |
126 |
113 def dragEnterEvent(self, event): |
127 def dragEnterEvent(self, event): |
114 """ |
128 """ |
115 Protected method to handle drag enter events. |
129 Protected method to handle drag enter events. |
116 |
130 |
117 @param event reference to the drag enter event |
131 @param event reference to the drag enter event |
118 @type QDragEnterEvent |
132 @type QDragEnterEvent |
119 """ |
133 """ |
120 mimeData = event.mimeData() |
134 mimeData = event.mimeData() |
121 formats = mimeData.formats() |
135 formats = mimeData.formats() |
122 if ( |
136 if ( |
123 "action" in formats and |
137 "action" in formats |
124 mimeData.data("action") == b"tab-reordering" and |
138 and mimeData.data("action") == b"tab-reordering" |
125 "tabbar-id" in formats and |
139 and "tabbar-id" in formats |
126 "source-index" in formats and |
140 and "source-index" in formats |
127 "tabwidget-id" in formats |
141 and "tabwidget-id" in formats |
128 ): |
142 ): |
129 event.acceptProposedAction() |
143 event.acceptProposedAction() |
130 super().dragEnterEvent(event) |
144 super().dragEnterEvent(event) |
131 |
145 |
132 def dropEvent(self, event): |
146 def dropEvent(self, event): |
133 """ |
147 """ |
134 Protected method to handle drop events. |
148 Protected method to handle drop events. |
135 |
149 |
136 @param event reference to the drop event |
150 @param event reference to the drop event |
137 @type QDropEvent |
151 @type QDropEvent |
138 """ |
152 """ |
139 mimeData = event.mimeData() |
153 mimeData = event.mimeData() |
140 oldID = int(mimeData.data("tabbar-id")) |
154 oldID = int(mimeData.data("tabbar-id")) |
141 fromIndex = int(mimeData.data("source-index")) |
155 fromIndex = int(mimeData.data("source-index")) |
142 toIndex = self.tabAt(event.position().toPoint()) |
156 toIndex = self.tabAt(event.position().toPoint()) |
143 if oldID != id(self): |
157 if oldID != id(self): |
144 parentID = int(mimeData.data("tabwidget-id")) |
158 parentID = int(mimeData.data("tabwidget-id")) |
145 if event.proposedAction() == Qt.DropAction.MoveAction: |
159 if event.proposedAction() == Qt.DropAction.MoveAction: |
146 self.tabRelocateRequested.emit( |
160 self.tabRelocateRequested.emit(str(parentID), fromIndex, toIndex) |
147 str(parentID), fromIndex, toIndex) |
|
148 event.acceptProposedAction() |
161 event.acceptProposedAction() |
149 elif event.proposedAction() == Qt.DropAction.CopyAction: |
162 elif event.proposedAction() == Qt.DropAction.CopyAction: |
150 self.tabCopyRequested[str, int, int].emit( |
163 self.tabCopyRequested[str, int, int].emit( |
151 str(parentID), fromIndex, toIndex) |
164 str(parentID), fromIndex, toIndex |
|
165 ) |
152 event.acceptProposedAction() |
166 event.acceptProposedAction() |
153 else: |
167 else: |
154 if fromIndex != toIndex: |
168 if fromIndex != toIndex: |
155 if event.proposedAction() == Qt.DropAction.MoveAction: |
169 if event.proposedAction() == Qt.DropAction.MoveAction: |
156 self.tabMoveRequested.emit(fromIndex, toIndex) |
170 self.tabMoveRequested.emit(fromIndex, toIndex) |
163 |
177 |
164 class TabWidget(EricTabWidget): |
178 class TabWidget(EricTabWidget): |
165 """ |
179 """ |
166 Class implementing a custimized tab widget. |
180 Class implementing a custimized tab widget. |
167 """ |
181 """ |
|
182 |
168 def __init__(self, vm): |
183 def __init__(self, vm): |
169 """ |
184 """ |
170 Constructor |
185 Constructor |
171 |
186 |
172 @param vm view manager widget |
187 @param vm view manager widget |
173 @type Tabview |
188 @type Tabview |
174 """ |
189 """ |
175 super().__init__() |
190 super().__init__() |
176 |
191 |
177 self.__tabBar = TabBar(self) |
192 self.__tabBar = TabBar(self) |
178 self.setTabBar(self.__tabBar) |
193 self.setTabBar(self.__tabBar) |
179 iconSize = self.__tabBar.iconSize() |
194 iconSize = self.__tabBar.iconSize() |
180 self.__tabBar.setIconSize( |
195 self.__tabBar.setIconSize(QSize(2 * iconSize.width(), iconSize.height())) |
181 QSize(2 * iconSize.width(), iconSize.height())) |
196 |
182 |
|
183 self.setUsesScrollButtons(True) |
197 self.setUsesScrollButtons(True) |
184 self.setElideMode(Qt.TextElideMode.ElideNone) |
198 self.setElideMode(Qt.TextElideMode.ElideNone) |
185 if isMacPlatform(): |
199 if isMacPlatform(): |
186 self.setDocumentMode(True) |
200 self.setDocumentMode(True) |
187 |
201 |
188 self.__tabBar.tabMoveRequested.connect(self.moveTab) |
202 self.__tabBar.tabMoveRequested.connect(self.moveTab) |
189 self.__tabBar.tabRelocateRequested.connect(self.__relocateTab) |
203 self.__tabBar.tabRelocateRequested.connect(self.__relocateTab) |
190 self.__tabBar.tabCopyRequested[str, int, int].connect( |
204 self.__tabBar.tabCopyRequested[str, int, int].connect(self.__copyTabOther) |
191 self.__copyTabOther) |
|
192 self.__tabBar.tabCopyRequested[int, int].connect(self.__copyTab) |
205 self.__tabBar.tabCopyRequested[int, int].connect(self.__copyTab) |
193 |
206 |
194 self.vm = vm |
207 self.vm = vm |
195 self.editors = [] |
208 self.editors = [] |
196 |
209 |
197 self.indicator = EricLed(self) |
210 self.indicator = EricLed(self) |
198 self.setCornerWidget(self.indicator, Qt.Corner.TopLeftCorner) |
211 self.setCornerWidget(self.indicator, Qt.Corner.TopLeftCorner) |
199 |
212 |
200 self.rightCornerWidget = QWidget(self) |
213 self.rightCornerWidget = QWidget(self) |
201 self.rightCornerWidgetLayout = QHBoxLayout(self.rightCornerWidget) |
214 self.rightCornerWidgetLayout = QHBoxLayout(self.rightCornerWidget) |
202 self.rightCornerWidgetLayout.setContentsMargins(0, 0, 0, 0) |
215 self.rightCornerWidgetLayout.setContentsMargins(0, 0, 0, 0) |
203 self.rightCornerWidgetLayout.setSpacing(0) |
216 self.rightCornerWidgetLayout.setSpacing(0) |
204 |
217 |
205 self.__navigationMenu = QMenu(self) |
218 self.__navigationMenu = QMenu(self) |
206 self.__navigationMenu.aboutToShow.connect(self.__showNavigationMenu) |
219 self.__navigationMenu.aboutToShow.connect(self.__showNavigationMenu) |
207 self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered) |
220 self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered) |
208 |
221 |
209 self.navigationButton = QToolButton(self) |
222 self.navigationButton = QToolButton(self) |
210 self.navigationButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) |
223 self.navigationButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) |
211 self.navigationButton.setToolTip(self.tr("Show a navigation menu")) |
224 self.navigationButton.setToolTip(self.tr("Show a navigation menu")) |
212 self.navigationButton.setPopupMode( |
225 self.navigationButton.setPopupMode(QToolButton.ToolButtonPopupMode.InstantPopup) |
213 QToolButton.ToolButtonPopupMode.InstantPopup) |
|
214 self.navigationButton.setMenu(self.__navigationMenu) |
226 self.navigationButton.setMenu(self.__navigationMenu) |
215 self.navigationButton.setEnabled(False) |
227 self.navigationButton.setEnabled(False) |
216 self.rightCornerWidgetLayout.addWidget(self.navigationButton) |
228 self.rightCornerWidgetLayout.addWidget(self.navigationButton) |
217 |
229 |
218 self.tabCloseRequested.connect(self.__closeRequested) |
230 self.tabCloseRequested.connect(self.__closeRequested) |
219 |
231 |
220 self.setCornerWidget(self.rightCornerWidget, Qt.Corner.TopRightCorner) |
232 self.setCornerWidget(self.rightCornerWidget, Qt.Corner.TopRightCorner) |
221 |
233 |
222 self.__initMenu() |
234 self.__initMenu() |
223 self.contextMenuEditor = None |
235 self.contextMenuEditor = None |
224 self.contextMenuIndex = -1 |
236 self.contextMenuIndex = -1 |
225 |
237 |
226 self.setTabContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) |
238 self.setTabContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) |
227 self.customTabContextMenuRequested.connect(self.__showContextMenu) |
239 self.customTabContextMenuRequested.connect(self.__showContextMenu) |
228 |
240 |
229 ericPic = QPixmap( |
241 ericPic = QPixmap(os.path.join(getConfig("ericPixDir"), "eric_small.png")) |
230 os.path.join(getConfig('ericPixDir'), 'eric_small.png')) |
|
231 self.emptyLabel = QLabel() |
242 self.emptyLabel = QLabel() |
232 self.emptyLabel.setPixmap(ericPic) |
243 self.emptyLabel.setPixmap(ericPic) |
233 self.emptyLabel.setAlignment( |
244 self.emptyLabel.setAlignment( |
234 Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignHCenter) |
245 Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignHCenter |
235 super().addTab( |
246 ) |
236 self.emptyLabel, |
247 super().addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty"), "") |
237 UI.PixmapCache.getIcon("empty"), "") |
248 |
238 |
|
239 def __initMenu(self): |
249 def __initMenu(self): |
240 """ |
250 """ |
241 Private method to initialize the tab context menu. |
251 Private method to initialize the tab context menu. |
242 """ |
252 """ |
243 self.__startMenu = QMenu(self.tr("Start"), self) |
253 self.__startMenu = QMenu(self.tr("Start"), self) |
244 self.__startMenu.addAction( |
254 self.__startMenu.addAction( |
245 UI.PixmapCache.getIcon("runScript"), |
255 UI.PixmapCache.getIcon("runScript"), |
246 self.tr('Run Script...'), |
256 self.tr("Run Script..."), |
247 self.__contextMenuRunScript) |
257 self.__contextMenuRunScript, |
|
258 ) |
248 self.__startMenu.addAction( |
259 self.__startMenu.addAction( |
249 UI.PixmapCache.getIcon("debugScript"), |
260 UI.PixmapCache.getIcon("debugScript"), |
250 self.tr('Debug Script...'), |
261 self.tr("Debug Script..."), |
251 self.__contextMenuDebugScript) |
262 self.__contextMenuDebugScript, |
|
263 ) |
252 self.__startMenu.addAction( |
264 self.__startMenu.addAction( |
253 UI.PixmapCache.getIcon("profileScript"), |
265 UI.PixmapCache.getIcon("profileScript"), |
254 self.tr('Profile Script...'), |
266 self.tr("Profile Script..."), |
255 self.__contextMenuProfileScript) |
267 self.__contextMenuProfileScript, |
|
268 ) |
256 self.__startMenu.addAction( |
269 self.__startMenu.addAction( |
257 UI.PixmapCache.getIcon("coverageScript"), |
270 UI.PixmapCache.getIcon("coverageScript"), |
258 self.tr('Coverage run of Script...'), |
271 self.tr("Coverage run of Script..."), |
259 self.__contextMenuCoverageScript) |
272 self.__contextMenuCoverageScript, |
260 |
273 ) |
|
274 |
261 self.__menu = QMenu(self) |
275 self.__menu = QMenu(self) |
262 self.leftMenuAct = self.__menu.addAction( |
276 self.leftMenuAct = self.__menu.addAction( |
263 UI.PixmapCache.getIcon("1leftarrow"), |
277 UI.PixmapCache.getIcon("1leftarrow"), |
264 self.tr('Move Left'), self.__contextMenuMoveLeft) |
278 self.tr("Move Left"), |
|
279 self.__contextMenuMoveLeft, |
|
280 ) |
265 self.rightMenuAct = self.__menu.addAction( |
281 self.rightMenuAct = self.__menu.addAction( |
266 UI.PixmapCache.getIcon("1rightarrow"), |
282 UI.PixmapCache.getIcon("1rightarrow"), |
267 self.tr('Move Right'), self.__contextMenuMoveRight) |
283 self.tr("Move Right"), |
|
284 self.__contextMenuMoveRight, |
|
285 ) |
268 self.firstMenuAct = self.__menu.addAction( |
286 self.firstMenuAct = self.__menu.addAction( |
269 UI.PixmapCache.getIcon("2leftarrow"), |
287 UI.PixmapCache.getIcon("2leftarrow"), |
270 self.tr('Move First'), self.__contextMenuMoveFirst) |
288 self.tr("Move First"), |
|
289 self.__contextMenuMoveFirst, |
|
290 ) |
271 self.lastMenuAct = self.__menu.addAction( |
291 self.lastMenuAct = self.__menu.addAction( |
272 UI.PixmapCache.getIcon("2rightarrow"), |
292 UI.PixmapCache.getIcon("2rightarrow"), |
273 self.tr('Move Last'), self.__contextMenuMoveLast) |
293 self.tr("Move Last"), |
|
294 self.__contextMenuMoveLast, |
|
295 ) |
274 self.__menu.addSeparator() |
296 self.__menu.addSeparator() |
275 self.__menu.addAction( |
297 self.__menu.addAction( |
276 UI.PixmapCache.getIcon("tabClose"), |
298 UI.PixmapCache.getIcon("tabClose"), |
277 self.tr('Close'), self.__contextMenuClose) |
299 self.tr("Close"), |
|
300 self.__contextMenuClose, |
|
301 ) |
278 self.closeOthersMenuAct = self.__menu.addAction( |
302 self.closeOthersMenuAct = self.__menu.addAction( |
279 UI.PixmapCache.getIcon("tabCloseOther"), |
303 UI.PixmapCache.getIcon("tabCloseOther"), |
280 self.tr("Close Others"), self.__contextMenuCloseOthers) |
304 self.tr("Close Others"), |
281 self.__menu.addAction( |
305 self.__contextMenuCloseOthers, |
282 self.tr('Close All'), self.__contextMenuCloseAll) |
306 ) |
|
307 self.__menu.addAction(self.tr("Close All"), self.__contextMenuCloseAll) |
283 self.__menu.addSeparator() |
308 self.__menu.addSeparator() |
284 self.saveMenuAct = self.__menu.addAction( |
309 self.saveMenuAct = self.__menu.addAction( |
285 UI.PixmapCache.getIcon("fileSave"), |
310 UI.PixmapCache.getIcon("fileSave"), self.tr("Save"), self.__contextMenuSave |
286 self.tr('Save'), self.__contextMenuSave) |
311 ) |
287 self.__menu.addAction( |
312 self.__menu.addAction( |
288 UI.PixmapCache.getIcon("fileSaveAs"), |
313 UI.PixmapCache.getIcon("fileSaveAs"), |
289 self.tr('Save As...'), self.__contextMenuSaveAs) |
314 self.tr("Save As..."), |
|
315 self.__contextMenuSaveAs, |
|
316 ) |
290 self.__menu.addAction( |
317 self.__menu.addAction( |
291 UI.PixmapCache.getIcon("fileSaveAll"), |
318 UI.PixmapCache.getIcon("fileSaveAll"), |
292 self.tr('Save All'), self.__contextMenuSaveAll) |
319 self.tr("Save All"), |
|
320 self.__contextMenuSaveAll, |
|
321 ) |
293 self.__menu.addSeparator() |
322 self.__menu.addSeparator() |
294 self.openRejectionsMenuAct = self.__menu.addAction( |
323 self.openRejectionsMenuAct = self.__menu.addAction( |
295 self.tr("Open 'rejection' file"), |
324 self.tr("Open 'rejection' file"), self.__contextMenuOpenRejections |
296 self.__contextMenuOpenRejections) |
325 ) |
297 self.__menu.addSeparator() |
326 self.__menu.addSeparator() |
298 self.__startAct = self.__menu.addMenu(self.__startMenu) |
327 self.__startAct = self.__menu.addMenu(self.__startMenu) |
299 self.__menu.addSeparator() |
328 self.__menu.addSeparator() |
300 self.__menu.addAction( |
329 self.__menu.addAction( |
301 UI.PixmapCache.getIcon("printPreview"), |
330 UI.PixmapCache.getIcon("printPreview"), |
302 self.tr("Print Preview"), self.__contextMenuPrintPreviewFile) |
331 self.tr("Print Preview"), |
|
332 self.__contextMenuPrintPreviewFile, |
|
333 ) |
303 self.__menu.addAction( |
334 self.__menu.addAction( |
304 UI.PixmapCache.getIcon("print"), |
335 UI.PixmapCache.getIcon("print"), |
305 self.tr('Print'), self.__contextMenuPrintFile) |
336 self.tr("Print"), |
|
337 self.__contextMenuPrintFile, |
|
338 ) |
306 self.__menu.addSeparator() |
339 self.__menu.addSeparator() |
307 self.copyPathAct = self.__menu.addAction( |
340 self.copyPathAct = self.__menu.addAction( |
308 self.tr("Copy Path to Clipboard"), |
341 self.tr("Copy Path to Clipboard"), self.__contextMenuCopyPathToClipboard |
309 self.__contextMenuCopyPathToClipboard) |
342 ) |
310 |
343 |
311 def __showContextMenu(self, coord, index): |
344 def __showContextMenu(self, coord, index): |
312 """ |
345 """ |
313 Private slot to show the tab context menu. |
346 Private slot to show the tab context menu. |
314 |
347 |
315 @param coord the position of the mouse pointer |
348 @param coord the position of the mouse pointer |
316 @type QPoint |
349 @type QPoint |
317 @param index index of the tab the menu is requested for |
350 @param index index of the tab the menu is requested for |
318 @type int |
351 @type int |
319 """ |
352 """ |
320 if self.editors: |
353 if self.editors: |
321 widget = self.widget(index) |
354 widget = self.widget(index) |
322 if widget is not None: |
355 if widget is not None: |
323 self.contextMenuEditor = widget.getEditor() |
356 self.contextMenuEditor = widget.getEditor() |
324 if self.contextMenuEditor: |
357 if self.contextMenuEditor: |
325 self.saveMenuAct.setEnabled( |
358 self.saveMenuAct.setEnabled(self.contextMenuEditor.isModified()) |
326 self.contextMenuEditor.isModified()) |
|
327 fileName = self.contextMenuEditor.getFileName() |
359 fileName = self.contextMenuEditor.getFileName() |
328 self.copyPathAct.setEnabled(bool(fileName)) |
360 self.copyPathAct.setEnabled(bool(fileName)) |
329 if fileName: |
361 if fileName: |
330 rej = "{0}.rej".format(fileName) |
362 rej = "{0}.rej".format(fileName) |
331 self.openRejectionsMenuAct.setEnabled( |
363 self.openRejectionsMenuAct.setEnabled(os.path.exists(rej)) |
332 os.path.exists(rej)) |
364 |
333 |
|
334 ext = os.path.splitext(fileName)[1] |
365 ext = os.path.splitext(fileName)[1] |
335 self.__startAct.setEnabled( |
366 self.__startAct.setEnabled( |
336 ext in Preferences.getDebugger( |
367 ext in Preferences.getDebugger("Python3Extensions").split() |
337 "Python3Extensions").split() |
|
338 ) |
368 ) |
339 else: |
369 else: |
340 self.openRejectionsMenuAct.setEnabled(False) |
370 self.openRejectionsMenuAct.setEnabled(False) |
341 self.__startAct.setEnabled(False) |
371 self.__startAct.setEnabled(False) |
342 |
372 |
343 self.contextMenuIndex = index |
373 self.contextMenuIndex = index |
344 self.leftMenuAct.setEnabled(index > 0) |
374 self.leftMenuAct.setEnabled(index > 0) |
345 self.rightMenuAct.setEnabled(index < self.count() - 1) |
375 self.rightMenuAct.setEnabled(index < self.count() - 1) |
346 self.firstMenuAct.setEnabled(index > 0) |
376 self.firstMenuAct.setEnabled(index > 0) |
347 self.lastMenuAct.setEnabled(index < self.count() - 1) |
377 self.lastMenuAct.setEnabled(index < self.count() - 1) |
348 |
378 |
349 self.closeOthersMenuAct.setEnabled(self.count() > 1) |
379 self.closeOthersMenuAct.setEnabled(self.count() > 1) |
350 |
380 |
351 coord = self.mapToGlobal(coord) |
381 coord = self.mapToGlobal(coord) |
352 self.__menu.popup(coord) |
382 self.__menu.popup(coord) |
353 |
383 |
354 def __showNavigationMenu(self): |
384 def __showNavigationMenu(self): |
355 """ |
385 """ |
356 Private slot to show the navigation button menu. |
386 Private slot to show the navigation button menu. |
357 """ |
387 """ |
358 self.__navigationMenu.clear() |
388 self.__navigationMenu.clear() |
359 for index in range(self.count()): |
389 for index in range(self.count()): |
360 act = self.__navigationMenu.addAction(self.tabIcon(index), |
390 act = self.__navigationMenu.addAction( |
361 self.tabText(index)) |
391 self.tabIcon(index), self.tabText(index) |
|
392 ) |
362 act.setData(index) |
393 act.setData(index) |
363 |
394 |
364 def __navigationMenuTriggered(self, act): |
395 def __navigationMenuTriggered(self, act): |
365 """ |
396 """ |
366 Private slot called to handle the navigation button menu selection. |
397 Private slot called to handle the navigation button menu selection. |
367 |
398 |
368 @param act reference to the selected action |
399 @param act reference to the selected action |
369 @type QAction |
400 @type QAction |
370 """ |
401 """ |
371 index = act.data() |
402 index = act.data() |
372 if index is not None: |
403 if index is not None: |
373 self.setCurrentIndex(index) |
404 self.setCurrentIndex(index) |
374 |
405 |
375 def showIndicator(self, on): |
406 def showIndicator(self, on): |
376 """ |
407 """ |
377 Public slot to set the indicator on or off. |
408 Public slot to set the indicator on or off. |
378 |
409 |
379 @param on flag indicating the state of the indicator |
410 @param on flag indicating the state of the indicator |
380 @type bool |
411 @type bool |
381 """ |
412 """ |
382 if on: |
413 if on: |
383 self.indicator.setColor(QColor("green")) |
414 self.indicator.setColor(QColor("green")) |
384 else: |
415 else: |
385 self.indicator.setColor(QColor("red")) |
416 self.indicator.setColor(QColor("red")) |
386 |
417 |
387 def addTab(self, assembly, title): |
418 def addTab(self, assembly, title): |
388 """ |
419 """ |
389 Public method to add a new tab. |
420 Public method to add a new tab. |
390 |
421 |
391 @param assembly editor assembly object to be added |
422 @param assembly editor assembly object to be added |
392 @type QScintilla.EditorAssembly.EditorAssembly |
423 @type QScintilla.EditorAssembly.EditorAssembly |
393 @param title title for the new tab |
424 @param title title for the new tab |
394 @type str |
425 @type str |
395 """ |
426 """ |
396 editor = assembly.getEditor() |
427 editor = assembly.getEditor() |
397 super().addTab( |
428 super().addTab(assembly, UI.PixmapCache.getIcon("empty"), title) |
398 assembly, UI.PixmapCache.getIcon("empty"), title) |
|
399 self.setTabsClosable(True) |
429 self.setTabsClosable(True) |
400 self.navigationButton.setEnabled(True) |
430 self.navigationButton.setEnabled(True) |
401 |
431 |
402 if editor not in self.editors: |
432 if editor not in self.editors: |
403 self.editors.append(editor) |
433 self.editors.append(editor) |
404 editor.captionChanged.connect(self.__captionChange) |
434 editor.captionChanged.connect(self.__captionChange) |
405 editor.cursorLineChanged.connect( |
435 editor.cursorLineChanged.connect( |
406 lambda lineno: self.__cursorLineChanged(lineno, editor)) |
436 lambda lineno: self.__cursorLineChanged(lineno, editor) |
407 |
437 ) |
|
438 |
408 emptyIndex = self.indexOf(self.emptyLabel) |
439 emptyIndex = self.indexOf(self.emptyLabel) |
409 if emptyIndex > -1: |
440 if emptyIndex > -1: |
410 self.removeTab(emptyIndex) |
441 self.removeTab(emptyIndex) |
411 |
442 |
412 def insertWidget(self, index, assembly, title): |
443 def insertWidget(self, index, assembly, title): |
413 """ |
444 """ |
414 Public method to insert a new tab. |
445 Public method to insert a new tab. |
415 |
446 |
416 @param index index position for the new tab |
447 @param index index position for the new tab |
417 @type int |
448 @type int |
418 @param assembly editor assembly object to be added |
449 @param assembly editor assembly object to be added |
419 @type QScintilla.EditorAssembly.EditorAssembly |
450 @type QScintilla.EditorAssembly.EditorAssembly |
420 @param title title for the new tab |
451 @param title title for the new tab |
557 """ |
586 """ |
558 tw = self.vm.getTabWidgetById(int(sourceId)) |
587 tw = self.vm.getTabWidgetById(int(sourceId)) |
559 if tw is not None: |
588 if tw is not None: |
560 editor = tw.widget(sourceIndex).getEditor() |
589 editor = tw.widget(sourceIndex).getEditor() |
561 newEditor, assembly = self.vm.cloneEditor( |
590 newEditor, assembly = self.vm.cloneEditor( |
562 editor, editor.getFileType(), editor.getFileName()) |
591 editor, editor.getFileType(), editor.getFileName() |
563 self.vm.insertView(assembly, self, targetIndex, |
592 ) |
564 editor.getFileName(), editor.getNoName()) |
593 self.vm.insertView( |
565 |
594 assembly, self, targetIndex, editor.getFileName(), editor.getNoName() |
|
595 ) |
|
596 |
566 def __copyTab(self, sourceIndex, targetIndex): |
597 def __copyTab(self, sourceIndex, targetIndex): |
567 """ |
598 """ |
568 Private method to copy an editor. |
599 Private method to copy an editor. |
569 |
600 |
570 @param sourceIndex index of the tab |
601 @param sourceIndex index of the tab |
571 @type int |
602 @type int |
572 @param targetIndex index position to place it to |
603 @param targetIndex index position to place it to |
573 @type int |
604 @type int |
574 """ |
605 """ |
575 editor = self.widget(sourceIndex).getEditor() |
606 editor = self.widget(sourceIndex).getEditor() |
576 newEditor, assembly = self.vm.cloneEditor( |
607 newEditor, assembly = self.vm.cloneEditor( |
577 editor, editor.getFileType(), editor.getFileName()) |
608 editor, editor.getFileType(), editor.getFileName() |
578 self.vm.insertView(assembly, self, targetIndex, |
609 ) |
579 editor.getFileName(), editor.getNoName()) |
610 self.vm.insertView( |
580 |
611 assembly, self, targetIndex, editor.getFileName(), editor.getNoName() |
|
612 ) |
|
613 |
581 def currentWidget(self): |
614 def currentWidget(self): |
582 """ |
615 """ |
583 Public method to return a reference to the current page. |
616 Public method to return a reference to the current page. |
584 |
617 |
585 @return reference to the current page |
618 @return reference to the current page |
586 @rtype Editor |
619 @rtype Editor |
587 """ |
620 """ |
588 if not self.editors: |
621 if not self.editors: |
589 return None |
622 return None |
590 else: |
623 else: |
591 return super().currentWidget() |
624 return super().currentWidget() |
592 |
625 |
593 def setCurrentWidget(self, assembly): |
626 def setCurrentWidget(self, assembly): |
594 """ |
627 """ |
595 Public method to set the current tab by the given editor assembly. |
628 Public method to set the current tab by the given editor assembly. |
596 |
629 |
597 @param assembly editor assembly to determine current tab from |
630 @param assembly editor assembly to determine current tab from |
598 @type EditorAssembly.EditorAssembly |
631 @type EditorAssembly.EditorAssembly |
599 """ |
632 """ |
600 super().setCurrentWidget(assembly) |
633 super().setCurrentWidget(assembly) |
601 |
634 |
602 def indexOf(self, widget): |
635 def indexOf(self, widget): |
603 """ |
636 """ |
604 Public method to get the tab index of the given editor. |
637 Public method to get the tab index of the given editor. |
605 |
638 |
606 @param widget widget to get the index for |
639 @param widget widget to get the index for |
607 @type QLabel or Editor |
640 @type QLabel or Editor |
608 @return tab index of the editor |
641 @return tab index of the editor |
609 @rtype int |
642 @rtype int |
610 """ |
643 """ |
611 if isinstance(widget, QScintilla.Editor.Editor): |
644 if isinstance(widget, QScintilla.Editor.Editor): |
612 widget = widget.parent() |
645 widget = widget.parent() |
613 return super().indexOf(widget) |
646 return super().indexOf(widget) |
614 |
647 |
615 def hasEditor(self, editor): |
648 def hasEditor(self, editor): |
616 """ |
649 """ |
617 Public method to check for an editor. |
650 Public method to check for an editor. |
618 |
651 |
619 @param editor editor object to check for |
652 @param editor editor object to check for |
620 @type Editor |
653 @type Editor |
621 @return flag indicating, whether the editor to be checked belongs |
654 @return flag indicating, whether the editor to be checked belongs |
622 to the list of editors managed by this tab widget. |
655 to the list of editors managed by this tab widget. |
623 @rtype bool |
656 @rtype bool |
624 """ |
657 """ |
625 return editor in self.editors |
658 return editor in self.editors |
626 |
659 |
627 def hasEditors(self): |
660 def hasEditors(self): |
628 """ |
661 """ |
629 Public method to test, if any editor is managed. |
662 Public method to test, if any editor is managed. |
630 |
663 |
631 @return flag indicating editors are managed |
664 @return flag indicating editors are managed |
632 @rtype bool |
665 @rtype bool |
633 """ |
666 """ |
634 return len(self.editors) > 0 |
667 return len(self.editors) > 0 |
635 |
668 |
636 def __contextMenuClose(self): |
669 def __contextMenuClose(self): |
637 """ |
670 """ |
638 Private method to close the selected tab. |
671 Private method to close the selected tab. |
639 """ |
672 """ |
640 if self.contextMenuEditor: |
673 if self.contextMenuEditor: |
641 self.vm.closeEditorWindow(self.contextMenuEditor) |
674 self.vm.closeEditorWindow(self.contextMenuEditor) |
642 |
675 |
643 def __contextMenuCloseOthers(self): |
676 def __contextMenuCloseOthers(self): |
644 """ |
677 """ |
645 Private method to close the other tabs. |
678 Private method to close the other tabs. |
646 """ |
679 """ |
647 index = self.contextMenuIndex |
680 index = self.contextMenuIndex |
648 for i in ( |
681 for i in list(range(self.count() - 1, index, -1)) + list( |
649 list(range(self.count() - 1, index, -1)) + |
682 range(index - 1, -1, -1) |
650 list(range(index - 1, -1, -1)) |
|
651 ): |
683 ): |
652 editor = self.widget(i).getEditor() |
684 editor = self.widget(i).getEditor() |
653 self.vm.closeEditorWindow(editor) |
685 self.vm.closeEditorWindow(editor) |
654 |
686 |
655 def __contextMenuCloseAll(self): |
687 def __contextMenuCloseAll(self): |
656 """ |
688 """ |
657 Private method to close all tabs. |
689 Private method to close all tabs. |
658 """ |
690 """ |
659 savedEditors = self.editors[:] |
691 savedEditors = self.editors[:] |
660 for editor in savedEditors: |
692 for editor in savedEditors: |
661 self.vm.closeEditorWindow(editor) |
693 self.vm.closeEditorWindow(editor) |
662 |
694 |
663 def __contextMenuSave(self): |
695 def __contextMenuSave(self): |
664 """ |
696 """ |
665 Private method to save the selected tab. |
697 Private method to save the selected tab. |
666 """ |
698 """ |
667 if self.contextMenuEditor: |
699 if self.contextMenuEditor: |
668 self.vm.saveEditorEd(self.contextMenuEditor) |
700 self.vm.saveEditorEd(self.contextMenuEditor) |
669 |
701 |
670 def __contextMenuSaveAs(self): |
702 def __contextMenuSaveAs(self): |
671 """ |
703 """ |
672 Private method to save the selected tab to a new file. |
704 Private method to save the selected tab to a new file. |
673 """ |
705 """ |
674 if self.contextMenuEditor: |
706 if self.contextMenuEditor: |
675 self.vm.saveAsEditorEd(self.contextMenuEditor) |
707 self.vm.saveAsEditorEd(self.contextMenuEditor) |
676 |
708 |
677 def __contextMenuSaveAll(self): |
709 def __contextMenuSaveAll(self): |
678 """ |
710 """ |
679 Private method to save all tabs. |
711 Private method to save all tabs. |
680 """ |
712 """ |
681 self.vm.saveEditorsList(self.editors) |
713 self.vm.saveEditorsList(self.editors) |
682 |
714 |
683 def __contextMenuOpenRejections(self): |
715 def __contextMenuOpenRejections(self): |
684 """ |
716 """ |
685 Private slot to open a rejections file associated with the selected |
717 Private slot to open a rejections file associated with the selected |
686 tab. |
718 tab. |
687 """ |
719 """ |
689 fileName = self.contextMenuEditor.getFileName() |
721 fileName = self.contextMenuEditor.getFileName() |
690 if fileName: |
722 if fileName: |
691 rej = "{0}.rej".format(fileName) |
723 rej = "{0}.rej".format(fileName) |
692 if os.path.exists(rej): |
724 if os.path.exists(rej): |
693 self.vm.openSourceFile(rej) |
725 self.vm.openSourceFile(rej) |
694 |
726 |
695 def __contextMenuPrintFile(self): |
727 def __contextMenuPrintFile(self): |
696 """ |
728 """ |
697 Private method to print the selected tab. |
729 Private method to print the selected tab. |
698 """ |
730 """ |
699 if self.contextMenuEditor: |
731 if self.contextMenuEditor: |
700 self.vm.printEditor(self.contextMenuEditor) |
732 self.vm.printEditor(self.contextMenuEditor) |
701 |
733 |
702 def __contextMenuPrintPreviewFile(self): |
734 def __contextMenuPrintPreviewFile(self): |
703 """ |
735 """ |
704 Private method to show a print preview of the selected tab. |
736 Private method to show a print preview of the selected tab. |
705 """ |
737 """ |
706 if self.contextMenuEditor: |
738 if self.contextMenuEditor: |
707 self.vm.printPreviewEditor(self.contextMenuEditor) |
739 self.vm.printPreviewEditor(self.contextMenuEditor) |
708 |
740 |
709 def __contextMenuCopyPathToClipboard(self): |
741 def __contextMenuCopyPathToClipboard(self): |
710 """ |
742 """ |
711 Private method to copy the file name of the selected tab to the |
743 Private method to copy the file name of the selected tab to the |
712 clipboard. |
744 clipboard. |
713 """ |
745 """ |
714 if self.contextMenuEditor: |
746 if self.contextMenuEditor: |
715 fn = self.contextMenuEditor.getFileName() |
747 fn = self.contextMenuEditor.getFileName() |
716 if fn: |
748 if fn: |
717 cb = QApplication.clipboard() |
749 cb = QApplication.clipboard() |
718 cb.setText(fn) |
750 cb.setText(fn) |
719 |
751 |
720 def __contextMenuMoveLeft(self): |
752 def __contextMenuMoveLeft(self): |
721 """ |
753 """ |
722 Private method to move a tab one position to the left. |
754 Private method to move a tab one position to the left. |
723 """ |
755 """ |
724 self.moveTab(self.contextMenuIndex, self.contextMenuIndex - 1) |
756 self.moveTab(self.contextMenuIndex, self.contextMenuIndex - 1) |
725 |
757 |
726 def __contextMenuMoveRight(self): |
758 def __contextMenuMoveRight(self): |
727 """ |
759 """ |
728 Private method to move a tab one position to the right. |
760 Private method to move a tab one position to the right. |
729 """ |
761 """ |
730 self.moveTab(self.contextMenuIndex, self.contextMenuIndex + 1) |
762 self.moveTab(self.contextMenuIndex, self.contextMenuIndex + 1) |
731 |
763 |
732 def __contextMenuMoveFirst(self): |
764 def __contextMenuMoveFirst(self): |
733 """ |
765 """ |
734 Private method to move a tab to the first position. |
766 Private method to move a tab to the first position. |
735 """ |
767 """ |
736 self.moveTab(self.contextMenuIndex, 0) |
768 self.moveTab(self.contextMenuIndex, 0) |
737 |
769 |
738 def __contextMenuMoveLast(self): |
770 def __contextMenuMoveLast(self): |
739 """ |
771 """ |
740 Private method to move a tab to the last position. |
772 Private method to move a tab to the last position. |
741 """ |
773 """ |
742 self.moveTab(self.contextMenuIndex, self.count() - 1) |
774 self.moveTab(self.contextMenuIndex, self.count() - 1) |
743 |
775 |
744 def __contextMenuRunScript(self): |
776 def __contextMenuRunScript(self): |
745 """ |
777 """ |
746 Private method to run the editor script. |
778 Private method to run the editor script. |
747 """ |
779 """ |
748 if self.contextMenuEditor: |
780 if self.contextMenuEditor: |
749 fn = self.contextMenuEditor.getFileName() |
781 fn = self.contextMenuEditor.getFileName() |
750 if fn: |
782 if fn: |
751 ericApp().getObject("DebugUI").doRun(False, script=fn) |
783 ericApp().getObject("DebugUI").doRun(False, script=fn) |
752 |
784 |
753 def __contextMenuDebugScript(self): |
785 def __contextMenuDebugScript(self): |
754 """ |
786 """ |
755 Private method to debug the editor script. |
787 Private method to debug the editor script. |
756 """ |
788 """ |
757 if self.contextMenuEditor: |
789 if self.contextMenuEditor: |
758 fn = self.contextMenuEditor.getFileName() |
790 fn = self.contextMenuEditor.getFileName() |
759 if fn: |
791 if fn: |
760 ericApp().getObject("DebugUI").doDebug(False, script=fn) |
792 ericApp().getObject("DebugUI").doDebug(False, script=fn) |
761 |
793 |
762 def __contextMenuProfileScript(self): |
794 def __contextMenuProfileScript(self): |
763 """ |
795 """ |
764 Private method to profile the editor script. |
796 Private method to profile the editor script. |
765 """ |
797 """ |
766 if self.contextMenuEditor: |
798 if self.contextMenuEditor: |
767 fn = self.contextMenuEditor.getFileName() |
799 fn = self.contextMenuEditor.getFileName() |
768 if fn: |
800 if fn: |
769 ericApp().getObject("DebugUI").doProfile(False, script=fn) |
801 ericApp().getObject("DebugUI").doProfile(False, script=fn) |
770 |
802 |
771 def __contextMenuCoverageScript(self): |
803 def __contextMenuCoverageScript(self): |
772 """ |
804 """ |
773 Private method to run a coverage test of the editor script. |
805 Private method to run a coverage test of the editor script. |
774 """ |
806 """ |
775 if self.contextMenuEditor: |
807 if self.contextMenuEditor: |
776 fn = self.contextMenuEditor.getFileName() |
808 fn = self.contextMenuEditor.getFileName() |
777 if fn: |
809 if fn: |
778 ericApp().getObject("DebugUI").doCoverage(False, script=fn) |
810 ericApp().getObject("DebugUI").doCoverage(False, script=fn) |
779 |
811 |
780 def __closeButtonClicked(self): |
812 def __closeButtonClicked(self): |
781 """ |
813 """ |
782 Private method to handle the press of the close button. |
814 Private method to handle the press of the close button. |
783 """ |
815 """ |
784 self.vm.closeEditorWindow(self.currentWidget().getEditor()) |
816 self.vm.closeEditorWindow(self.currentWidget().getEditor()) |
785 |
817 |
786 def __closeRequested(self, index): |
818 def __closeRequested(self, index): |
787 """ |
819 """ |
788 Private method to handle the press of the individual tab close button. |
820 Private method to handle the press of the individual tab close button. |
789 |
821 |
790 @param index index of the tab (integer) |
822 @param index index of the tab (integer) |
791 """ |
823 """ |
792 if index >= 0: |
824 if index >= 0: |
793 self.vm.closeEditorWindow(self.widget(index).getEditor()) |
825 self.vm.closeEditorWindow(self.widget(index).getEditor()) |
794 |
826 |
795 def mouseDoubleClickEvent(self, event): |
827 def mouseDoubleClickEvent(self, event): |
796 """ |
828 """ |
797 Protected method handling double click events. |
829 Protected method handling double click events. |
798 |
830 |
799 @param event reference to the event object (QMouseEvent) |
831 @param event reference to the event object (QMouseEvent) |
800 """ |
832 """ |
801 self.vm.newEditor() |
833 self.vm.newEditor() |
802 |
834 |
803 |
835 |
804 class Tabview(ViewManager): |
836 class Tabview(ViewManager): |
805 """ |
837 """ |
806 Class implementing a tabbed viewmanager class embedded in a splitter. |
838 Class implementing a tabbed viewmanager class embedded in a splitter. |
807 |
839 |
808 @signal changeCaption(str) emitted if a change of the caption is necessary |
840 @signal changeCaption(str) emitted if a change of the caption is necessary |
809 @signal editorChanged(str) emitted when the current editor has changed |
841 @signal editorChanged(str) emitted when the current editor has changed |
810 @signal editorChangedEd(Editor) emitted when the current editor has changed |
842 @signal editorChangedEd(Editor) emitted when the current editor has changed |
811 @signal lastEditorClosed() emitted after the last editor window was closed |
843 @signal lastEditorClosed() emitted after the last editor window was closed |
812 @signal editorOpened(str) emitted after an editor window was opened |
844 @signal editorOpened(str) emitted after an editor window was opened |
861 astViewerStateChanged = pyqtSignal(bool) |
894 astViewerStateChanged = pyqtSignal(bool) |
862 editorLanguageChanged = pyqtSignal(Editor) |
895 editorLanguageChanged = pyqtSignal(Editor) |
863 editorTextChanged = pyqtSignal(Editor) |
896 editorTextChanged = pyqtSignal(Editor) |
864 editorLineChanged = pyqtSignal(str, int) |
897 editorLineChanged = pyqtSignal(str, int) |
865 editorLineChangedEd = pyqtSignal(Editor, int) |
898 editorLineChangedEd = pyqtSignal(Editor, int) |
866 |
899 |
867 def __init__(self, parent): |
900 def __init__(self, parent): |
868 """ |
901 """ |
869 Constructor |
902 Constructor |
870 |
903 |
871 @param parent parent widget |
904 @param parent parent widget |
872 @type QWidget |
905 @type QWidget |
873 """ |
906 """ |
874 self.tabWidgets = [] |
907 self.tabWidgets = [] |
875 |
908 |
876 self.__splitter = QSplitter(parent) |
909 self.__splitter = QSplitter(parent) |
877 ViewManager.__init__(self) |
910 ViewManager.__init__(self) |
878 self.__splitter.setChildrenCollapsible(False) |
911 self.__splitter.setChildrenCollapsible(False) |
879 |
912 |
880 tw = TabWidget(self) |
913 tw = TabWidget(self) |
881 self.__splitter.addWidget(tw) |
914 self.__splitter.addWidget(tw) |
882 self.tabWidgets.append(tw) |
915 self.tabWidgets.append(tw) |
883 self.currentTabWidget = tw |
916 self.currentTabWidget = tw |
884 self.currentTabWidget.showIndicator(True) |
917 self.currentTabWidget.showIndicator(True) |
885 tw.currentChanged.connect(self.__currentChanged) |
918 tw.currentChanged.connect(self.__currentChanged) |
886 tw.installEventFilter(self) |
919 tw.installEventFilter(self) |
887 tw.tabBar().installEventFilter(self) |
920 tw.tabBar().installEventFilter(self) |
888 self.__splitter.setOrientation(Qt.Orientation.Vertical) |
921 self.__splitter.setOrientation(Qt.Orientation.Vertical) |
889 self.__inRemoveView = False |
922 self.__inRemoveView = False |
890 |
923 |
891 self.maxFileNameChars = Preferences.getUI( |
924 self.maxFileNameChars = Preferences.getUI("TabViewManagerFilenameLength") |
892 "TabViewManagerFilenameLength") |
|
893 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly") |
925 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly") |
894 |
926 |
895 def mainWidget(self): |
927 def mainWidget(self): |
896 """ |
928 """ |
897 Public method to return a reference to the main Widget of a |
929 Public method to return a reference to the main Widget of a |
898 specific view manager subclass. |
930 specific view manager subclass. |
899 |
931 |
900 @return reference to the main widget |
932 @return reference to the main widget |
901 @rtype QWidget |
933 @rtype QWidget |
902 """ |
934 """ |
903 return self.__splitter |
935 return self.__splitter |
904 |
936 |
905 def canCascade(self): |
937 def canCascade(self): |
906 """ |
938 """ |
907 Public method to signal if cascading of managed windows is available. |
939 Public method to signal if cascading of managed windows is available. |
908 |
940 |
909 @return flag indicating cascading of windows is available |
941 @return flag indicating cascading of windows is available |
910 @rtype bool |
942 @rtype bool |
911 """ |
943 """ |
912 return False |
944 return False |
913 |
945 |
914 def canTile(self): |
946 def canTile(self): |
915 """ |
947 """ |
916 Public method to signal if tiling of managed windows is available. |
948 Public method to signal if tiling of managed windows is available. |
917 |
949 |
918 @return flag indicating tiling of windows is available |
950 @return flag indicating tiling of windows is available |
919 @rtype bool |
951 @rtype bool |
920 """ |
952 """ |
921 return False |
953 return False |
922 |
954 |
923 def canSplit(self): |
955 def canSplit(self): |
924 """ |
956 """ |
925 public method to signal if splitting of the view is available. |
957 public method to signal if splitting of the view is available. |
926 |
958 |
927 @return flag indicating splitting of the view is available. |
959 @return flag indicating splitting of the view is available. |
928 @rtype bool |
960 @rtype bool |
929 """ |
961 """ |
930 return True |
962 return True |
931 |
963 |
932 def tile(self): |
964 def tile(self): |
933 """ |
965 """ |
934 Public method to tile the managed windows. |
966 Public method to tile the managed windows. |
935 """ |
967 """ |
936 pass |
968 pass |
937 |
969 |
938 def cascade(self): |
970 def cascade(self): |
939 """ |
971 """ |
940 Public method to cascade the managed windows. |
972 Public method to cascade the managed windows. |
941 """ |
973 """ |
942 pass |
974 pass |
943 |
975 |
944 def _removeAllViews(self): |
976 def _removeAllViews(self): |
945 """ |
977 """ |
946 Protected method to remove all views (i.e. windows). |
978 Protected method to remove all views (i.e. windows). |
947 """ |
979 """ |
948 for win in self.editors: |
980 for win in self.editors: |
949 self._removeView(win) |
981 self._removeView(win) |
950 |
982 |
951 def _removeView(self, win): |
983 def _removeView(self, win): |
952 """ |
984 """ |
953 Protected method to remove a view (i.e. window). |
985 Protected method to remove a view (i.e. window). |
954 |
986 |
955 @param win editor window to be removed |
987 @param win editor window to be removed |
956 @type Editor |
988 @type Editor |
957 """ |
989 """ |
958 self.__inRemoveView = True |
990 self.__inRemoveView = True |
959 for tw in self.tabWidgets: |
991 for tw in self.tabWidgets: |
960 if tw.hasEditor(win): |
992 if tw.hasEditor(win): |
961 tw.removeWidget(win) |
993 tw.removeWidget(win) |
962 break |
994 break |
963 win.closeIt() |
995 win.closeIt() |
964 self.__inRemoveView = False |
996 self.__inRemoveView = False |
965 |
997 |
966 # if this was the last editor in this view, switch to the next, that |
998 # if this was the last editor in this view, switch to the next, that |
967 # still has open editors |
999 # still has open editors |
968 for i in ( |
1000 for i in list(range(self.tabWidgets.index(tw), -1, -1)) + list( |
969 list(range(self.tabWidgets.index(tw), -1, -1)) + |
1001 range(self.tabWidgets.index(tw) + 1, len(self.tabWidgets)) |
970 list(range(self.tabWidgets.index(tw) + 1, |
|
971 len(self.tabWidgets))) |
|
972 ): |
1002 ): |
973 if self.tabWidgets[i].hasEditors(): |
1003 if self.tabWidgets[i].hasEditors(): |
974 self.currentTabWidget.showIndicator(False) |
1004 self.currentTabWidget.showIndicator(False) |
975 self.currentTabWidget = self.tabWidgets[i] |
1005 self.currentTabWidget = self.tabWidgets[i] |
976 self.currentTabWidget.showIndicator(True) |
1006 self.currentTabWidget.showIndicator(True) |
977 self.activeWindow().setFocus() |
1007 self.activeWindow().setFocus() |
978 break |
1008 break |
979 |
1009 |
980 aw = self.activeWindow() |
1010 aw = self.activeWindow() |
981 fn = aw and aw.getFileName() or None |
1011 fn = aw and aw.getFileName() or None |
982 if fn: |
1012 if fn: |
983 self.changeCaption.emit(fn) |
1013 self.changeCaption.emit(fn) |
984 self.editorChanged.emit(fn) |
1014 self.editorChanged.emit(fn) |
985 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1) |
1015 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1) |
986 else: |
1016 else: |
987 self.changeCaption.emit("") |
1017 self.changeCaption.emit("") |
988 self.editorChangedEd.emit(aw) |
1018 self.editorChangedEd.emit(aw) |
989 |
1019 |
990 def _addView(self, win, fn=None, noName="", addNext=False, indexes=None): |
1020 def _addView(self, win, fn=None, noName="", addNext=False, indexes=None): |
991 """ |
1021 """ |
992 Protected method to add a view (i.e. window). |
1022 Protected method to add a view (i.e. window). |
993 |
1023 |
994 @param win editor assembly to be added |
1024 @param win editor assembly to be added |
995 @type EditorAssembly |
1025 @type EditorAssembly |
996 @param fn filename of this editor |
1026 @param fn filename of this editor |
997 @type str |
1027 @type str |
998 @param noName name to be used for an unnamed editor |
1028 @param noName name to be used for an unnamed editor |
1291 if len(self.tabWidgets) == 1: |
1321 if len(self.tabWidgets) == 1: |
1292 self.splitRemoveAct.setEnabled(False) |
1322 self.splitRemoveAct.setEnabled(False) |
1293 self.nextSplitAct.setEnabled(False) |
1323 self.nextSplitAct.setEnabled(False) |
1294 self.prevSplitAct.setEnabled(False) |
1324 self.prevSplitAct.setEnabled(False) |
1295 return True |
1325 return True |
1296 |
1326 |
1297 return False |
1327 return False |
1298 |
1328 |
1299 def splitCount(self): |
1329 def splitCount(self): |
1300 """ |
1330 """ |
1301 Public method to get the number of splitted views. |
1331 Public method to get the number of splitted views. |
1302 |
1332 |
1303 @return number of splitted views |
1333 @return number of splitted views |
1304 @rtype int |
1334 @rtype int |
1305 """ |
1335 """ |
1306 return len(self.tabWidgets) |
1336 return len(self.tabWidgets) |
1307 |
1337 |
1308 def setSplitCount(self, count): |
1338 def setSplitCount(self, count): |
1309 """ |
1339 """ |
1310 Public method to set the number of split views. |
1340 Public method to set the number of split views. |
1311 |
1341 |
1312 @param count number of split views |
1342 @param count number of split views |
1313 @type int |
1343 @type int |
1314 """ |
1344 """ |
1315 if count > self.splitCount(): |
1345 if count > self.splitCount(): |
1316 while self.splitCount() < count: |
1346 while self.splitCount() < count: |
1317 self.addSplit() |
1347 self.addSplit() |
1318 elif count < self.splitCount(): |
1348 elif count < self.splitCount(): |
1319 while self.splitCount() > count: |
1349 while self.splitCount() > count: |
1320 # use an arbitrarily large index to remove the last one |
1350 # use an arbitrarily large index to remove the last one |
1321 self.removeSplit(index=100) |
1351 self.removeSplit(index=100) |
1322 |
1352 |
1323 def getSplitOrientation(self): |
1353 def getSplitOrientation(self): |
1324 """ |
1354 """ |
1325 Public method to get the orientation of the split view. |
1355 Public method to get the orientation of the split view. |
1326 |
1356 |
1327 @return orientation of the split |
1357 @return orientation of the split |
1328 @rtype Qt.Orientation.Horizontal or Qt.Orientation.Vertical |
1358 @rtype Qt.Orientation.Horizontal or Qt.Orientation.Vertical |
1329 """ |
1359 """ |
1330 return self.__splitter.orientation() |
1360 return self.__splitter.orientation() |
1331 |
1361 |
1332 def setSplitOrientation(self, orientation): |
1362 def setSplitOrientation(self, orientation): |
1333 """ |
1363 """ |
1334 Public method used to set the orientation of the split view. |
1364 Public method used to set the orientation of the split view. |
1335 |
1365 |
1336 @param orientation orientation of the split |
1366 @param orientation orientation of the split |
1337 @type Qt.Orientation.Horizontal or Qt.Orientation.Vertical |
1367 @type Qt.Orientation.Horizontal or Qt.Orientation.Vertical |
1338 """ |
1368 """ |
1339 self.__splitter.setOrientation(orientation) |
1369 self.__splitter.setOrientation(orientation) |
1340 |
1370 |
1341 def nextSplit(self): |
1371 def nextSplit(self): |
1342 """ |
1372 """ |
1343 Public slot used to move to the next split. |
1373 Public slot used to move to the next split. |
1344 """ |
1374 """ |
1345 aw = self.activeWindow() |
1375 aw = self.activeWindow() |
1346 _hasFocus = aw and aw.hasFocus() |
1376 _hasFocus = aw and aw.hasFocus() |
1347 ind = self.tabWidgets.index(self.currentTabWidget) + 1 |
1377 ind = self.tabWidgets.index(self.currentTabWidget) + 1 |
1348 if ind == len(self.tabWidgets): |
1378 if ind == len(self.tabWidgets): |
1349 ind = 0 |
1379 ind = 0 |
1350 |
1380 |
1351 self.currentTabWidget.showIndicator(False) |
1381 self.currentTabWidget.showIndicator(False) |
1352 self.currentTabWidget = self.tabWidgets[ind] |
1382 self.currentTabWidget = self.tabWidgets[ind] |
1353 self.currentTabWidget.showIndicator(True) |
1383 self.currentTabWidget.showIndicator(True) |
1354 if _hasFocus: |
1384 if _hasFocus: |
1355 aw = self.activeWindow() |
1385 aw = self.activeWindow() |
1356 if aw: |
1386 if aw: |
1357 aw.setFocus() |
1387 aw.setFocus() |
1358 |
1388 |
1359 def prevSplit(self): |
1389 def prevSplit(self): |
1360 """ |
1390 """ |
1361 Public slot used to move to the previous split. |
1391 Public slot used to move to the previous split. |
1362 """ |
1392 """ |
1363 aw = self.activeWindow() |
1393 aw = self.activeWindow() |
1364 _hasFocus = aw and aw.hasFocus() |
1394 _hasFocus = aw and aw.hasFocus() |
1365 ind = self.tabWidgets.index(self.currentTabWidget) - 1 |
1395 ind = self.tabWidgets.index(self.currentTabWidget) - 1 |
1366 if ind == -1: |
1396 if ind == -1: |
1367 ind = len(self.tabWidgets) - 1 |
1397 ind = len(self.tabWidgets) - 1 |
1368 |
1398 |
1369 self.currentTabWidget.showIndicator(False) |
1399 self.currentTabWidget.showIndicator(False) |
1370 self.currentTabWidget = self.tabWidgets[ind] |
1400 self.currentTabWidget = self.tabWidgets[ind] |
1371 self.currentTabWidget.showIndicator(True) |
1401 self.currentTabWidget.showIndicator(True) |
1372 if _hasFocus: |
1402 if _hasFocus: |
1373 aw = self.activeWindow() |
1403 aw = self.activeWindow() |
1374 if aw: |
1404 if aw: |
1375 aw.setFocus() |
1405 aw.setFocus() |
1376 |
1406 |
1377 def __currentChanged(self, index): |
1407 def __currentChanged(self, index): |
1378 """ |
1408 """ |
1379 Private slot to handle the currentChanged signal. |
1409 Private slot to handle the currentChanged signal. |
1380 |
1410 |
1381 @param index index of the current tab |
1411 @param index index of the current tab |
1382 @type int |
1412 @type int |
1383 """ |
1413 """ |
1384 if index == -1 or not self.editors: |
1414 if index == -1 or not self.editors: |
1385 return |
1415 return |
1386 |
1416 |
1387 editor = self.activeWindow() |
1417 editor = self.activeWindow() |
1388 if editor is None: |
1418 if editor is None: |
1389 return |
1419 return |
1390 |
1420 |
1391 self._checkActions(editor) |
1421 self._checkActions(editor) |
1392 editor.setFocus() |
1422 editor.setFocus() |
1393 fn = editor.getFileName() |
1423 fn = editor.getFileName() |
1394 if fn: |
1424 if fn: |
1395 self.changeCaption.emit(fn) |
1425 self.changeCaption.emit(fn) |
1396 if not self.__inRemoveView: |
1426 if not self.__inRemoveView: |
1397 self.editorChanged.emit(fn) |
1427 self.editorChanged.emit(fn) |
1398 self.editorLineChanged.emit( |
1428 self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1) |
1399 fn, editor.getCursorPosition()[0] + 1) |
|
1400 else: |
1429 else: |
1401 self.changeCaption.emit("") |
1430 self.changeCaption.emit("") |
1402 self.editorChangedEd.emit(editor) |
1431 self.editorChangedEd.emit(editor) |
1403 |
1432 |
1404 def eventFilter(self, watched, event): |
1433 def eventFilter(self, watched, event): |
1405 """ |
1434 """ |
1406 Public method called to filter the event queue. |
1435 Public method called to filter the event queue. |
1407 |
1436 |
1408 @param watched the QObject being watched |
1437 @param watched the QObject being watched |
1409 @type QObject |
1438 @type QObject |
1410 @param event the event that occurred |
1439 @param event the event that occurred |
1411 @type QEvent |
1440 @type QEvent |
1412 @return always False |
1441 @return always False |
1413 @rtype bool |
1442 @rtype bool |
1414 """ |
1443 """ |
1415 if ( |
1444 if ( |
1416 event.type() == QEvent.Type.MouseButtonPress and |
1445 event.type() == QEvent.Type.MouseButtonPress |
1417 isinstance(event, QMouseEvent) and |
1446 and isinstance(event, QMouseEvent) |
1418 event.button() != Qt.MouseButton.RightButton |
1447 and event.button() != Qt.MouseButton.RightButton |
1419 ): |
1448 ): |
1420 switched = True |
1449 switched = True |
1421 self.currentTabWidget.showIndicator(False) |
1450 self.currentTabWidget.showIndicator(False) |
1422 if isinstance(watched, EricTabWidget): |
1451 if isinstance(watched, EricTabWidget): |
1423 switched = watched is not self.currentTabWidget |
1452 switched = watched is not self.currentTabWidget |
1424 self.currentTabWidget = watched |
1453 self.currentTabWidget = watched |
1425 elif isinstance(watched, QTabBar): |
1454 elif isinstance(watched, QTabBar): |
1426 switched = watched.parent() is not self.currentTabWidget |
1455 switched = watched.parent() is not self.currentTabWidget |
1427 self.currentTabWidget = watched.parent() |
1456 self.currentTabWidget = watched.parent() |
1428 if switched: |
1457 if switched: |
1429 index = self.currentTabWidget.selectTab( |
1458 index = self.currentTabWidget.selectTab(event.position().toPoint()) |
1430 event.position().toPoint()) |
|
1431 switched = ( |
1459 switched = ( |
1432 self.currentTabWidget.widget(index) is |
1460 self.currentTabWidget.widget(index) is self.activeWindow() |
1433 self.activeWindow() |
|
1434 ) |
1461 ) |
1435 elif isinstance(watched, QScintilla.Editor.Editor): |
1462 elif isinstance(watched, QScintilla.Editor.Editor): |
1436 for tw in self.tabWidgets: |
1463 for tw in self.tabWidgets: |
1437 if tw.hasEditor(watched): |
1464 if tw.hasEditor(watched): |
1438 switched = tw is not self.currentTabWidget |
1465 switched = tw is not self.currentTabWidget |
1439 self.currentTabWidget = tw |
1466 self.currentTabWidget = tw |
1440 break |
1467 break |
1441 self.currentTabWidget.showIndicator(True) |
1468 self.currentTabWidget.showIndicator(True) |
1442 |
1469 |
1443 aw = self.activeWindow() |
1470 aw = self.activeWindow() |
1444 if aw is not None: |
1471 if aw is not None: |
1445 self._checkActions(aw) |
1472 self._checkActions(aw) |
1446 aw.setFocus() |
1473 aw.setFocus() |
1447 fn = aw.getFileName() |
1474 fn = aw.getFileName() |
1448 if fn: |
1475 if fn: |
1449 self.changeCaption.emit(fn) |
1476 self.changeCaption.emit(fn) |
1450 if switched: |
1477 if switched: |
1451 self.editorChanged.emit(fn) |
1478 self.editorChanged.emit(fn) |
1452 self.editorLineChanged.emit( |
1479 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1) |
1453 fn, aw.getCursorPosition()[0] + 1) |
|
1454 else: |
1480 else: |
1455 self.changeCaption.emit("") |
1481 self.changeCaption.emit("") |
1456 self.editorChangedEd.emit(aw) |
1482 self.editorChangedEd.emit(aw) |
1457 |
1483 |
1458 return False |
1484 return False |
1459 |
1485 |
1460 def preferencesChanged(self): |
1486 def preferencesChanged(self): |
1461 """ |
1487 """ |
1462 Public slot to handle the preferencesChanged signal. |
1488 Public slot to handle the preferencesChanged signal. |
1463 """ |
1489 """ |
1464 ViewManager.preferencesChanged(self) |
1490 ViewManager.preferencesChanged(self) |
1465 |
1491 |
1466 self.maxFileNameChars = Preferences.getUI( |
1492 self.maxFileNameChars = Preferences.getUI("TabViewManagerFilenameLength") |
1467 "TabViewManagerFilenameLength") |
|
1468 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly") |
1493 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly") |
1469 |
1494 |
1470 for tabWidget in self.tabWidgets: |
1495 for tabWidget in self.tabWidgets: |
1471 for index in range(tabWidget.count()): |
1496 for index in range(tabWidget.count()): |
1472 editor = tabWidget.widget(index) |
1497 editor = tabWidget.widget(index) |
1473 if isinstance(editor, QScintilla.Editor.Editor): |
1498 if isinstance(editor, QScintilla.Editor.Editor): |
1474 fn = editor.getFileName() |
1499 fn = editor.getFileName() |
1475 if fn: |
1500 if fn: |
1476 if self.filenameOnly: |
1501 if self.filenameOnly: |
1477 txt = os.path.basename(fn) |
1502 txt = os.path.basename(fn) |
1478 else: |
1503 else: |
1479 txt = ericApp().getObject( |
1504 txt = ericApp().getObject("Project").getRelativePath(fn) |
1480 "Project").getRelativePath(fn) |
|
1481 if len(txt) > self.maxFileNameChars: |
1505 if len(txt) > self.maxFileNameChars: |
1482 txt = "...{0}".format(txt[-self.maxFileNameChars:]) |
1506 txt = "...{0}".format(txt[-self.maxFileNameChars :]) |
1483 if not os.access(fn, os.W_OK): |
1507 if not os.access(fn, os.W_OK): |
1484 txt = self.tr("{0} (ro)").format(txt) |
1508 txt = self.tr("{0} (ro)").format(txt) |
1485 tabWidget.setTabText(index, txt) |
1509 tabWidget.setTabText(index, txt) |
1486 |
1510 |
1487 def getTabWidgetById(self, id_): |
1511 def getTabWidgetById(self, id_): |
1488 """ |
1512 """ |
1489 Public method to get a reference to a tab widget knowing its ID. |
1513 Public method to get a reference to a tab widget knowing its ID. |
1490 |
1514 |
1491 @param id_ id of the tab widget |
1515 @param id_ id of the tab widget |
1492 @type int |
1516 @type int |
1493 @return reference to the tab widget |
1517 @return reference to the tab widget |
1494 @rtype TabWidget |
1518 @rtype TabWidget |
1495 """ |
1519 """ |
1496 for tw in self.tabWidgets: |
1520 for tw in self.tabWidgets: |
1497 if id(tw) == id_: |
1521 if id(tw) == id_: |
1498 return tw |
1522 return tw |
1499 return None |
1523 return None |
1500 |
1524 |
1501 def getOpenEditorsForSession(self): |
1525 def getOpenEditorsForSession(self): |
1502 """ |
1526 """ |
1503 Public method to get a lists of all open editors. |
1527 Public method to get a lists of all open editors. |
1504 |
1528 |
1505 The returned list contains one list per split view. If the view manager |
1529 The returned list contains one list per split view. If the view manager |
1506 cannot split the view, only one list of editors is returned. |
1530 cannot split the view, only one list of editors is returned. |
1507 |
1531 |
1508 @return list of list of editor references |
1532 @return list of list of editor references |
1509 @rtype list of list of Editor |
1533 @rtype list of list of Editor |
1510 """ |
1534 """ |
1511 editorLists = [] |
1535 editorLists = [] |
1512 for tabWidget in self.tabWidgets: |
1536 for tabWidget in self.tabWidgets: |