1 | from PyQt5 import QtCore |
---|
2 | from PyQt5 import QtWidgets |
---|
3 | |
---|
4 | from sas.qtgui.Utilities.UI.ModelEditor import Ui_ModelEditor |
---|
5 | from sas.qtgui.Utilities import GuiUtils |
---|
6 | |
---|
7 | class 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 | |
---|