22 # along with this program; if not, write to the Free Software |
22 # along with this program; if not, write to the Free Software |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
24 |
25 |
25 |
26 from __future__ import absolute_import |
26 from __future__ import absolute_import |
|
27 from __future__ import division |
27 import re |
28 import re |
28 from types import * |
29 from functools import reduce |
29 |
30 |
30 import wx |
31 import wx |
31 import wx.stc |
32 import wx.stc |
|
33 from six.moves import xrange |
32 |
34 |
33 from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD |
35 from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD |
34 from plcopen.structures import ST_BLOCK_START_KEYWORDS, IEC_BLOCK_START_KEYWORDS, LOCATIONDATATYPES |
36 from plcopen.structures import ST_BLOCK_START_KEYWORDS, IEC_BLOCK_START_KEYWORDS, LOCATIONDATATYPES |
35 from editors.EditorPanel import EditorPanel |
37 from editors.EditorPanel import EditorPanel |
36 from controls.CustomStyledTextCtrl import CustomStyledTextCtrl, faces, GetCursorPos |
38 from controls.CustomStyledTextCtrl import CustomStyledTextCtrl, faces, GetCursorPos |
890 key_handled = True |
892 key_handled = True |
891 elif key == wx.WXK_RETURN or key == wx.WXK_NUMPAD_ENTER: |
893 elif key == wx.WXK_RETURN or key == wx.WXK_NUMPAD_ENTER: |
892 if self.TextSyntax in ["ST", "ALL"]: |
894 if self.TextSyntax in ["ST", "ALL"]: |
893 indent = self.Editor.GetLineIndentation(line) |
895 indent = self.Editor.GetLineIndentation(line) |
894 if LineStartswith(lineText.strip(), self.BlockStartKeywords): |
896 if LineStartswith(lineText.strip(), self.BlockStartKeywords): |
895 indent = (indent / 2 + 1) * 2 |
897 indent = (indent // 2 + 1) * 2 |
896 self.Editor.AddText("\n" + " " * indent) |
898 self.Editor.AddText("\n" + " " * indent) |
897 key_handled = True |
899 key_handled = True |
898 elif key == wx.WXK_BACK: |
900 elif key == wx.WXK_BACK: |
899 if self.TextSyntax in ["ST", "ALL"]: |
901 if self.TextSyntax in ["ST", "ALL"]: |
900 if not self.Editor.GetSelectedText(): |
902 if not self.Editor.GetSelectedText(): |
901 indent = self.Editor.GetColumn(self.Editor.GetCurrentPos()) |
903 indent = self.Editor.GetColumn(self.Editor.GetCurrentPos()) |
902 if lineText.strip() == "" and len(lineText) > 0 and indent > 0: |
904 if lineText.strip() == "" and len(lineText) > 0 and indent > 0: |
903 self.Editor.DelLineLeft() |
905 self.Editor.DelLineLeft() |
904 self.Editor.AddText(" " * ((max(0, indent - 1) / 2) * 2)) |
906 self.Editor.AddText(" " * ((max(0, indent - 1) // 2) * 2)) |
905 key_handled = True |
907 key_handled = True |
906 if not key_handled: |
908 if not key_handled: |
907 event.Skip() |
909 event.Skip() |
908 else: |
910 else: |
909 event.Skip() |
911 event.Skip() |