Source code for sas.qtgui.Utilities.ModelEditor
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from sas.qtgui.Utilities.UI.ModelEditor import Ui_ModelEditor
from sas.qtgui.Utilities import GuiUtils
[docs]class ModelEditor(QtWidgets.QDialog, Ui_ModelEditor):
"""
Class describing the "advanced" model editor.
This is a simple text browser allowing for editing python and
supporting simple highlighting.
"""
modelModified = QtCore.pyqtSignal()
def __init__(self, parent=None, is_python=True):
super(ModelEditor, self).__init__(parent)
self.setupUi(self)
# disable the context help icon
self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint)
self.is_python = is_python
self.setupWidgets()
self.addSignals()
[docs] def addSignals(self):
"""
Respond to signals in the widget
"""
self.txtEditor.textChanged.connect(self.onEdit)
[docs] def onEdit(self):
"""
Respond to changes in the text browser.
"""
# We have edited the model - notify the parent.
if self.txtEditor.toPlainText() != "":
self.modelModified.emit()
[docs] def getModel(self):
"""
Return the current model, as displayed in the window
"""
model = {'text':self.txtEditor.toPlainText()}
model['filename'] = ""
return model