editors/TextViewer.py
branchpython3
changeset 3750 f62625418bff
parent 3688 c2992796a859
child 3752 9f6f46dbe3ae
equal deleted inserted replaced
3749:fda6c1a37662 3750:f62625418bff
    21 # You should have received a copy of the GNU General Public License
    21 # You should have received a copy of the GNU General Public License
    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 
    27 from __future__ import division
    27 
    28 import re
    28 import re
    29 from functools import reduce
    29 from functools import reduce
    30 
    30 
    31 import wx
    31 import wx
    32 import wx.stc
    32 import wx.stc
    41 #                         Textual programs Viewer class
    41 #                         Textual programs Viewer class
    42 # -------------------------------------------------------------------------------
    42 # -------------------------------------------------------------------------------
    43 
    43 
    44 
    44 
    45 NEWLINE = "\n"
    45 NEWLINE = "\n"
    46 NUMBERS = [str(i) for i in xrange(10)]
    46 NUMBERS = [str(i) for i in range(10)]
    47 LETTERS = ['_']
    47 LETTERS = ['_']
    48 for i in xrange(26):
    48 for i in range(26):
    49     LETTERS.append(chr(ord('a') + i))
    49     LETTERS.append(chr(ord('a') + i))
    50     LETTERS.append(chr(ord('A') + i))
    50     LETTERS.append(chr(ord('A') + i))
    51 
    51 
    52 [STC_PLC_WORD, STC_PLC_COMMENT, STC_PLC_NUMBER, STC_PLC_STRING,
    52 [STC_PLC_WORD, STC_PLC_COMMENT, STC_PLC_NUMBER, STC_PLC_STRING,
    53  STC_PLC_VARIABLE, STC_PLC_PARAMETER, STC_PLC_FUNCTION, STC_PLC_JUMP,
    53  STC_PLC_VARIABLE, STC_PLC_PARAMETER, STC_PLC_FUNCTION, STC_PLC_JUMP,
    54  STC_PLC_ERROR, STC_PLC_SEARCH_RESULT,
    54  STC_PLC_ERROR, STC_PLC_SEARCH_RESULT,
    55  STC_PLC_EMPTY] = range(11)
    55  STC_PLC_EMPTY] = list(range(11))
    56 [SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT, PRAGMA, DPRAGMA] = range(8)
    56 [SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT, PRAGMA, DPRAGMA] = list(range(8))
    57 
    57 
    58 re_texts = {}
    58 re_texts = {}
    59 re_texts["letter"] = "[A-Za-z]"
    59 re_texts["letter"] = "[A-Za-z]"
    60 re_texts["digit"] = "[0-9]"
    60 re_texts["digit"] = "[0-9]"
    61 re_texts["identifier"] = "((?:%(letter)s|(?:_(?:%(letter)s|%(digit)s)))(?:_?(?:%(letter)s|%(digit)s))*)" % re_texts
    61 re_texts["identifier"] = "((?:%(letter)s|(?:_(?:%(letter)s|%(digit)s)))(?:_?(?:%(letter)s|%(digit)s))*)" % re_texts
    68     SEARCH_RESULT_HIGHLIGHT: STC_PLC_SEARCH_RESULT,
    68     SEARCH_RESULT_HIGHLIGHT: STC_PLC_SEARCH_RESULT,
    69 }
    69 }
    70 
    70 
    71 
    71 
    72 def LineStartswith(line, symbols):
    72 def LineStartswith(line, symbols):
    73     return reduce(lambda x, y: x or y, map(line.startswith, symbols), False)
    73     return reduce(lambda x, y: x or y, list(map(line.startswith, symbols)), False)
    74 
    74 
    75 
    75 
    76 class TextViewer(EditorPanel):
    76 class TextViewer(EditorPanel):
    77 
    77 
    78     def _init_Editor(self, prnt):
    78     def _init_Editor(self, prnt):
   494 
   494 
   495             self.Functions = {}
   495             self.Functions = {}
   496             for category in self.Controler.GetBlockTypes(self.TagName, self.Debug):
   496             for category in self.Controler.GetBlockTypes(self.TagName, self.Debug):
   497                 for blocktype in category["list"]:
   497                 for blocktype in category["list"]:
   498                     blockname = blocktype["name"].upper()
   498                     blockname = blocktype["name"].upper()
   499                     if blocktype["type"] == "function" and blockname not in self.Keywords and blockname not in self.Variables.keys():
   499                     if blocktype["type"] == "function" and blockname not in self.Keywords and blockname not in list(self.Variables.keys()):
   500                         interface = dict([(name, {}) for name, _type, _modifier in blocktype["inputs"] + blocktype["outputs"] if name != ''])
   500                         interface = dict([(name, {}) for name, _type, _modifier in blocktype["inputs"] + blocktype["outputs"] if name != ''])
   501                         for param in ["EN", "ENO"]:
   501                         for param in ["EN", "ENO"]:
   502                             if param not in interface:
   502                             if param not in interface:
   503                                 interface[param] = {}
   503                                 interface[param] = {}
   504                         if blockname in self.Functions:
   504                         if blockname in self.Functions:
   897                         if words[0].upper() in ["CAL", "CALC", "CALNC"]:
   897                         if words[0].upper() in ["CAL", "CALC", "CALNC"]:
   898                             kw = self.Functions
   898                             kw = self.Functions
   899                         elif words[0].upper() in ["JMP", "JMPC", "JMPNC"]:
   899                         elif words[0].upper() in ["JMP", "JMPC", "JMPNC"]:
   900                             kw = self.Jumps
   900                             kw = self.Jumps
   901                         else:
   901                         else:
   902                             kw = self.Variables.keys()
   902                             kw = list(self.Variables.keys())
   903                 else:
   903                 else:
   904                     kw = self.Keywords + self.Variables.keys() + self.Functions.keys()
   904                     kw = self.Keywords + list(self.Variables.keys()) + list(self.Functions.keys())
   905                 if len(kw) > 0:
   905                 if len(kw) > 0:
   906                     if len(words[-1]) > 0:
   906                     if len(words[-1]) > 0:
   907                         kw = [keyword for keyword in kw if keyword.startswith(words[-1])]
   907                         kw = [keyword for keyword in kw if keyword.startswith(words[-1])]
   908                     kw.sort()
   908                     kw.sort()
   909                     self.Editor.AutoCompSetIgnoreCase(True)
   909                     self.Editor.AutoCompSetIgnoreCase(True)