1
0
forked from IPKM/nmreval

Fit: Ignore complex_state, if no complex function is selected; closes #144

This commit is contained in:
Dominik Demuth
2023-11-30 19:21:21 +01:00
parent aa0d14a322
commit 843866be45
3 changed files with 36 additions and 7 deletions

View File

@ -1,5 +1,6 @@
# CodeEditor based on QT example, Python syntax highlighter found on Python site
import typing
from ast import parse
from ..Qt import QtGui, QtCore, QtWidgets
@ -184,6 +185,7 @@ class CodeEditor(QtWidgets.QPlainTextEdit):
self.update_width_linenumber(0)
self.highlight = PythonHighlighter(self.document())
self.textChanged.connect(self._check_syntax)
def keyPressEvent(self, evt):
if evt.key() == QtCore.Qt.Key_Tab:
@ -260,3 +262,23 @@ class CodeEditor(QtWidgets.QPlainTextEdit):
extra_selections.append(selection)
self.setExtraSelections(extra_selections)
def color_line(self, color):
# is_valid, exception = self._check_syntax()
# if is_valid == 1:
doc = self.document()
print(doc.findBlockByLineNumber(color))
def _check_syntax(self) -> (int, tuple[typing.Any]):
# Compile into an AST and check for syntax errors.
try:
_ = parse(self.toPlainText(), filename='<string>')
except SyntaxError as e:
print('SyntaxError', e, e.args[0], e.lineno, e.offset, e.text)
self.color_line(e.lineno)
return 1, (e.lineno, e.offset)
except Exception as e:
print('Unexpected error', e)
return 2, (e.args[0],)
return 0, tuple()