source: sasview/src/sas/qtgui/Utilities/ModelEditor.py @ 12dfce6

ESS_GUIESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_opencl
Last change on this file since 12dfce6 was 33c0561, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 6 years ago

Replace Apply button menu driven functionality with additional button.
Removed Cancel.
Removed the window system context help button from all affected widgets.
SASVIEW-1239

  • Property mode set to 100644
File size: 1.8 KB
Line 
1from PyQt5 import QtCore
2from PyQt5 import QtWidgets
3
4from sas.qtgui.Utilities.UI.ModelEditor import Ui_ModelEditor
5from sas.qtgui.Utilities import GuiUtils
6
7class ModelEditor(QtWidgets.QDialog, Ui_ModelEditor):
8    """
9    Class describing the "advanced" model editor.
10    This is a simple text browser allowing for editing python and
11    supporting simple highlighting.
12    """
13    modelModified = QtCore.pyqtSignal()
14    def __init__(self, parent=None, is_python=True):
15        super(ModelEditor, self).__init__(parent)
16        self.setupUi(self)
17        # disable the context help icon
18        self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint)
19
20        self.is_python = is_python
21
22        self.setupWidgets()
23
24        self.addSignals()
25
26    def setupWidgets(self):
27        """
28        Set up dialog widgets.
29        Here - just the highlighter connected to the text edit.
30        """
31        # Weird import location - workaround for a bug in Sphinx choking on
32        # importing QSyntaxHighlighter
33        # DO NOT MOVE TO TOP
34        from sas.qtgui.Utilities.PythonSyntax import PythonHighlighter
35        self.highlight = PythonHighlighter(self.txtEditor.document(), is_python=self.is_python)
36
37        self.txtEditor.setFont(GuiUtils.getMonospaceFont())
38
39    def addSignals(self):
40        """
41        Respond to signals in the widget
42        """
43        self.txtEditor.textChanged.connect(self.onEdit)
44
45    def onEdit(self):
46        """
47        Respond to changes in the text browser.
48        """
49        # We have edited the model - notify the parent.
50        if self.txtEditor.toPlainText() != "":
51            self.modelModified.emit()
52
53    def getModel(self):
54        """
55        Return the current model, as displayed in the window
56        """
57        model = {'text':self.txtEditor.toPlainText()}
58        model['filename'] = ""
59        return model
60
Note: See TracBrowser for help on using the repository browser.