ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change
on this file since ce67f35 was
f2e199e,
checked in by Piotr Rozyczko <piotr.rozyczko@…>, 6 years ago
|
Allow editing models with corresponding C-files. SASVIEW-1208
|
-
Property mode set to
100644
|
File size:
1.7 KB
|
Line | |
---|
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 | |
---|
18 | self.is_python = is_python |
---|
19 | |
---|
20 | self.setupWidgets() |
---|
21 | |
---|
22 | self.addSignals() |
---|
23 | |
---|
24 | def setupWidgets(self): |
---|
25 | """ |
---|
26 | Set up dialog widgets. |
---|
27 | Here - just the highlighter connected to the text edit. |
---|
28 | """ |
---|
29 | # Weird import location - workaround for a bug in Sphinx choking on |
---|
30 | # importing QSyntaxHighlighter |
---|
31 | # DO NOT MOVE TO TOP |
---|
32 | from sas.qtgui.Utilities.PythonSyntax import PythonHighlighter |
---|
33 | self.highlight = PythonHighlighter(self.txtEditor.document(), is_python=self.is_python) |
---|
34 | |
---|
35 | self.txtEditor.setFont(GuiUtils.getMonospaceFont()) |
---|
36 | |
---|
37 | def addSignals(self): |
---|
38 | """ |
---|
39 | Respond to signals in the widget |
---|
40 | """ |
---|
41 | self.txtEditor.textChanged.connect(self.onEdit) |
---|
42 | |
---|
43 | def onEdit(self): |
---|
44 | """ |
---|
45 | Respond to changes in the text browser. |
---|
46 | """ |
---|
47 | # We have edited the model - notify the parent. |
---|
48 | if self.txtEditor.toPlainText() != "": |
---|
49 | self.modelModified.emit() |
---|
50 | |
---|
51 | def getModel(self): |
---|
52 | """ |
---|
53 | Return the current model, as displayed in the window |
---|
54 | """ |
---|
55 | model = {'text':self.txtEditor.toPlainText()} |
---|
56 | model['filename'] = "" |
---|
57 | return model |
---|
58 | |
---|
Note: See
TracBrowser
for help on using the repository browser.