editors/TextViewer.py
changeset 2737 38afed869ff6
parent 2456 7373e3048167
child 3303 0ffb41625592
child 3319 e6c758e41f82
equal deleted inserted replaced
2736:a81b72ef156c 2737:38afed869ff6
    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] = range(11)
    56 [SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT, PRAGMA, DPRAGMA] = range(8)
    56 [SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT, PRAGMA, DPRAGMA] = range(8)
    57 
    57 
    58 [
       
    59     ID_TEXTVIEWER, ID_TEXTVIEWERTEXTCTRL,
       
    60 ] = [wx.NewId() for _init_ctrls in range(2)]
       
    61 
       
    62 re_texts = {}
    58 re_texts = {}
    63 re_texts["letter"] = "[A-Za-z]"
    59 re_texts["letter"] = "[A-Za-z]"
    64 re_texts["digit"] = "[0-9]"
    60 re_texts["digit"] = "[0-9]"
    65 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
    66 IDENTIFIER_MODEL = re.compile(re_texts["identifier"])
    62 IDENTIFIER_MODEL = re.compile(re_texts["identifier"])
    77     return reduce(lambda x, y: x or y, map(line.startswith, symbols), False)
    73     return reduce(lambda x, y: x or y, map(line.startswith, symbols), False)
    78 
    74 
    79 
    75 
    80 class TextViewer(EditorPanel):
    76 class TextViewer(EditorPanel):
    81 
    77 
    82     ID = ID_TEXTVIEWER
       
    83 
       
    84     def _init_Editor(self, prnt):
    78     def _init_Editor(self, prnt):
    85         self.Editor = CustomStyledTextCtrl(id=ID_TEXTVIEWERTEXTCTRL,
    79         self.Editor = CustomStyledTextCtrl(parent=prnt, name="TextViewer", size=wx.Size(0, 0), style=0)
    86                                            parent=prnt, name="TextViewer", size=wx.Size(0, 0), style=0)
       
    87         self.Editor.ParentWindow = self
    80         self.Editor.ParentWindow = self
    88 
    81 
    89         self.Editor.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN)
    82         self.Editor.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN)
    90         self.Editor.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT)
    83         self.Editor.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT)
    91 
    84 
   138 
   131 
   139         self.Editor.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT |
   132         self.Editor.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT |
   140                                     wx.stc.STC_MOD_BEFOREDELETE |
   133                                     wx.stc.STC_MOD_BEFOREDELETE |
   141                                     wx.stc.STC_PERFORMED_USER)
   134                                     wx.stc.STC_PERFORMED_USER)
   142 
   135 
   143         self.Bind(wx.stc.EVT_STC_STYLENEEDED, self.OnStyleNeeded, id=ID_TEXTVIEWERTEXTCTRL)
   136         self.Bind(wx.stc.EVT_STC_STYLENEEDED, self.OnStyleNeeded, self.Editor)
   144         self.Editor.Bind(wx.stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
   137         self.Editor.Bind(wx.stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
   145         self.Editor.Bind(wx.stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
   138         self.Editor.Bind(wx.stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
   146         self.Editor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
   139         self.Editor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
   147         if self.Controler is not None:
   140         if self.Controler is not None:
   148             self.Editor.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
   141             self.Editor.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
   149             self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_TEXTVIEWERTEXTCTRL)
   142             self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, self.Editor)
   150             self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_TEXTVIEWERTEXTCTRL)
   143             self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, self.Editor)
   151 
   144 
   152     def __init__(self, parent, tagname, window, controler, debug=False, instancepath=""):
   145     def __init__(self, parent, tagname, window, controler, debug=False, instancepath=""):
   153         if tagname != "" and controler is not None:
   146         if tagname != "" and controler is not None:
   154             self.VARIABLE_PANEL_TYPE = controler.GetPouType(tagname.split("::")[1])
   147             self.VARIABLE_PANEL_TYPE = controler.GetPouType(tagname.split("::")[1])
   155 
   148