Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug introduced by #51913 - Proxy EditorTab attributes to Editor #52036

Merged
merged 2 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions python/console/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,13 @@ def allowExit(self):
# iterate backwards through tabs, as we may be closing some as we go
tab_index = tab_count - i - 1
tab_widget = self.tabEditorWidget.widget(tab_index)
if tab_widget.editor.isModified():
if tab_widget.isModified():
ret = QMessageBox.question(self, self.tr("Save {}").format(self.tabEditorWidget.tabText(tab_index)),
self.tr("There are unsaved changes in this script. Do you want to keep those?"),
QMessageBox.Save | QMessageBox.Cancel | QMessageBox.Discard, QMessageBox.Cancel)
if ret == QMessageBox.Save:
tab_widget.edisave()
if tab_widget.editor.isModified():
tab_widget.save()
if tab_widget.isModified():
# save failed, treat as cancel
return False
elif ret == QMessageBox.Discard:
Expand All @@ -577,36 +577,36 @@ def allowExit(self):
return True

def _toggleFind(self):
self.tabEditorWidget.currentWidget().editor.toggleFindWidget()
self.tabEditorWidget.currentWidget().toggleFindWidget()

def _openFind(self):
self.tabEditorWidget.currentWidget().editor.openFindWidget()
self.tabEditorWidget.currentWidget().openFindWidget()

def _closeFind(self):
self.tabEditorWidget.currentWidget().editor.closeFindWidget()
self.tabEditorWidget.currentWidget().closeFindWidget()

def _findNext(self):
self.tabEditorWidget.currentWidget().editor.findText(True)
self.tabEditorWidget.currentWidget().findText(True)

def _findPrev(self):
self.tabEditorWidget.currentWidget().editor.findText(False)
self.tabEditorWidget.currentWidget().findText(False)

def _textFindChanged(self):
if self.lineEditFind.text():
self.findNextButton.setEnabled(True)
self.findPrevButton.setEnabled(True)
self.tabEditorWidget.currentWidget().editor.findText(True, showMessage=False, findFirst=True)
self.tabEditorWidget.currentWidget().findText(True, showMessage=False, findFirst=True)
else:
self.lineEditFind.setStyleSheet('')
self.findNextButton.setEnabled(False)
self.findPrevButton.setEnabled(False)

def onClickGoToLine(self, item, column):
tabEditor = self.tabEditorWidget.currentWidget().editor
tabEditor = self.tabEditorWidget.currentWidget()
if item.text(1) == 'syntaxError':
check = tabEditor.syntaxCheck()
if check and not tabEditor.isReadOnly():
self.tabEditorWidget.currentWidget().edisave()
self.tabEditorWidget.currentWidget().save()
return
linenr = int(item.text(1))
itemName = str(item.text(0))
Expand All @@ -627,19 +627,19 @@ def toggleObjectListWidget(self, checked):
self.listClassMethod.show() if checked else self.listClassMethod.hide()

def pasteEditor(self):
self.tabEditorWidget.currentWidget().editor.paste()
self.tabEditorWidget.currentWidget().paste()

def cutEditor(self):
self.tabEditorWidget.currentWidget().editor.cut()
self.tabEditorWidget.currentWidget().cut()

def copyEditor(self):
self.tabEditorWidget.currentWidget().editor.copy()
self.tabEditorWidget.currentWidget().copy()

def runScriptEditor(self):
self.tabEditorWidget.currentWidget().editor.runScriptCode()
self.tabEditorWidget.currentWidget().runScriptCode()

def toggleComment(self):
self.tabEditorWidget.currentWidget().editor.toggleComment()
self.tabEditorWidget.currentWidget().toggleComment()

def openScriptFileExtEditor(self):
tabWidget = self.tabEditorWidget.currentWidget()
Expand Down Expand Up @@ -673,7 +673,7 @@ def openScriptFile(self):
def saveScriptFile(self):
tabWidget = self.tabEditorWidget.currentWidget()
try:
tabWidget.editor.save()
tabWidget.save()
except (IOError, OSError) as error:
msgText = QCoreApplication.translate('PythonConsole',
'The file <b>{0}</b> could not be saved. Error: {1}').format(tabWidget.path,
Expand Down
58 changes: 35 additions & 23 deletions python/console/console_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def runScriptCode(self):
deleteTempFile = False
if self.syntaxCheck():
if filename and self.isModified() and autoSave:
self.parent.save(filename)
self.save(filename)
elif not filename or self.isModified():
# Create a new temp file if the file isn't already saved.
filename = self.createTempFile()
Expand Down Expand Up @@ -406,7 +406,7 @@ def save(self, filename=None):
if self.isReadOnly():
return
tabwidget = self.tabwidget
index = tabwidget.indexOf(self)
index = tabwidget.indexOf(self.parent)
YoannQDQ marked this conversation as resolved.
Show resolved Hide resolved
if filename:
self.path = filename
if self.path is None:
Expand Down Expand Up @@ -489,18 +489,16 @@ class EditorTab(QWidget):
def __init__(self, parent, pythonconsole, filename, readOnly):
super().__init__(parent)
self.tabwidget = parent
self.path = None

self.editor = Editor(self)
self.editor.pythonconsole = pythonconsole
self.editor.tabwidget = parent
self._editor = Editor(self)
self._editor.pythonconsole = pythonconsole
self._editor.tabwidget = parent
if filename:
self.path = filename
if QFileInfo(filename).exists():
self.editor.loadFile(filename, readOnly)
self._editor.loadFile(filename, readOnly)

# Creates layout for message bar
self.layout = QGridLayout(self.editor)
self.layout = QGridLayout(self._editor)
self.layout.setContentsMargins(0, 0, 0, 0)
spacerItem = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
self.layout.addItem(spacerItem, 1, 0, 1, 1)
Expand All @@ -512,14 +510,28 @@ def __init__(self, parent, pythonconsole, filename, readOnly):

self.tabLayout = QGridLayout(self)
self.tabLayout.setContentsMargins(0, 0, 0, 0)
self.tabLayout.addWidget(self.editor)
self.tabLayout.addWidget(self._editor)

def modified(self, modified):
self.tabwidget.tabModified(self, modified)

def close(self):
self.tabwidget._removeTab(self, tab2index=True)

def __getattr__(self, name):
""" Forward all missing attribute requests to the editor."""
try:
return super().__getattr__(name)
except AttributeError:
return getattr(self._editor, name)

def __setattr__(self, name, value):
""" Forward all missing attribute requests to the editor."""
try:
return super().__setattr__(name, value)
except AttributeError:
return setattr(self._editor, name, value)


class EditorTabWidget(QTabWidget):

Expand Down Expand Up @@ -644,7 +656,7 @@ def contextMenuEvent(self, e):
menu.addSeparator()
saveAction = menu.addAction(
QCoreApplication.translate("PythonConsole", "Save"),
cW.editor.save)
cW.save)
menu.addAction(
QCoreApplication.translate("PythonConsole", "Save As"),
self.saveAs)
Expand All @@ -656,7 +668,7 @@ def contextMenuEvent(self, e):
closeTabAction.setEnabled(True)
closeAllTabAction.setEnabled(True)
closeOthersTabAction.setEnabled(True)
if self.widget(self.idx).editor.isModified():
if self.widget(self.idx).isModified():
saveAction.setEnabled(True)
menu.exec_(self.mapToGlobal(e.pos()))

Expand All @@ -680,7 +692,7 @@ def saveAs(self):
def enableSaveIfModified(self, tab):
tabWidget = self.widget(tab)
if tabWidget:
self.parent.saveFileButton.setEnabled(tabWidget.editor.isModified())
self.parent.saveFileButton.setEnabled(tabWidget.isModified())

def enableToolBarEditor(self, enable):
if self.topFrame.isVisible():
Expand Down Expand Up @@ -727,8 +739,8 @@ def setTabTitle(self, tab, title):
def _removeTab(self, tab, tab2index=False):
if tab2index:
tab = self.indexOf(tab)
tabWidget = self.widget(tab)
if tabWidget.editor.isModified():
editorTab = self.widget(tab)
if editorTab.isModified():
txtSaveOnRemove = QCoreApplication.translate("PythonConsole",
"Python Console: Save File")
txtMsgSaveOnRemove = QCoreApplication.translate("PythonConsole",
Expand All @@ -739,23 +751,23 @@ def _removeTab(self, tab, tab2index=False):
if res == QMessageBox.Cancel:
return
if res == QMessageBox.Save:
tabWidget.save()
if tabWidget.path:
self.parent.updateTabListScript(tabWidget.path, action='remove')
editorTab.save()
if editorTab.path:
self.parent.updateTabListScript(editorTab.path, action='remove')
self.removeTab(tab)
if self.count() < 1:
self.newTabEditor()
else:
if tabWidget.path:
self.parent.updateTabListScript(tabWidget.path, action='remove')
if editorTab.path:
self.parent.updateTabListScript(editorTab.path, action='remove')
if self.count() <= 1:
self.removeTab(tab)
self.newTabEditor()
else:
self.removeTab(tab)

tabWidget.deleteLater()
self.currentWidget().editor.setFocus(Qt.TabFocusReason)
editorTab.deleteLater()
self.currentWidget().setFocus(Qt.TabFocusReason)
YoannQDQ marked this conversation as resolved.
Show resolved Hide resolved

def buttonClosePressed(self):
self.closeCurrentWidget()
Expand Down Expand Up @@ -800,7 +812,7 @@ def restoreTabs(self):
self.newTabEditor(filename=None)
self.topFrame.close()
self.enableToolBarEditor(True)
self.currentWidget().editor.setFocus(Qt.TabFocusReason)
self.currentWidget().setFocus(Qt.TabFocusReason)

def closeRestore(self):
self.parent.updateTabListScript(None)
Expand Down