TextViewer.py
changeset 671 47b9ad1471cc
parent 654 f8445d00613d
child 675 0ea836add01f
equal deleted inserted replaced
670:c9ccacf35cf1 671:47b9ad1471cc
    45     LETTERS.append(chr(ord('A') + i))
    45     LETTERS.append(chr(ord('A') + i))
    46 
    46 
    47 [STC_PLC_WORD, STC_PLC_COMMENT, STC_PLC_NUMBER, STC_PLC_STRING, 
    47 [STC_PLC_WORD, STC_PLC_COMMENT, STC_PLC_NUMBER, STC_PLC_STRING, 
    48  STC_PLC_VARIABLE, STC_PLC_PARAMETER, STC_PLC_FUNCTION, STC_PLC_JUMP, 
    48  STC_PLC_VARIABLE, STC_PLC_PARAMETER, STC_PLC_FUNCTION, STC_PLC_JUMP, 
    49  STC_PLC_ERROR, STC_PLC_SEARCH_RESULT] = range(10)
    49  STC_PLC_ERROR, STC_PLC_SEARCH_RESULT] = range(10)
    50 [SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT] = range(6)
    50 [SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT, PRAGMA] = range(7)
    51 
    51 
    52 [ID_TEXTVIEWER, ID_TEXTVIEWERTEXTCTRL,
    52 [ID_TEXTVIEWER, ID_TEXTVIEWERTEXTCTRL,
    53 ] = [wx.NewId() for _init_ctrls in range(2)]
    53 ] = [wx.NewId() for _init_ctrls in range(2)]
    54 
    54 
    55 if wx.Platform == '__WXMSW__':
    55 if wx.Platform == '__WXMSW__':
   272         if isinstance(values, tuple):
   272         if isinstance(values, tuple):
   273             message = None
   273             message = None
   274             if values[1] in ["program", "debug"]:
   274             if values[1] in ["program", "debug"]:
   275                 event.SetDragText("")
   275                 event.SetDragText("")
   276             elif values[1] in ["functionBlock", "function"]:
   276             elif values[1] in ["functionBlock", "function"]:
       
   277                 blocktype = values[0]
   277                 blockname = values[2]
   278                 blockname = values[2]
   278                 if len(values) > 3:
   279                 if len(values) > 3:
   279                     blockinputs = values[3]
   280                     blockinputs = values[3]
   280                 else:
   281                 else:
   281                     blockinputs = None
   282                     blockinputs = None
   282                 if values[1] != "function": 
   283                 if values[1] != "function": 
   283                     if  blockname == "":
   284                     if blockname == "":
   284                         dialog = wx.TextEntryDialog(self.ParentWindow, "Block name", "Please enter a block name", "", wx.OK|wx.CANCEL|wx.CENTRE)
   285                         dialog = wx.TextEntryDialog(self.ParentWindow, "Block name", "Please enter a block name", "", wx.OK|wx.CANCEL|wx.CENTRE)
   285                         if dialog.ShowModal() == wx.ID_OK:
   286                         if dialog.ShowModal() == wx.ID_OK:
   286                             blockname = dialog.GetValue()
   287                             blockname = dialog.GetValue()
   287                         else:
   288                         else:
   288                             return
   289                             return
   293                         message = _("\"%s\" element for this pou already exists!")%blockname
   294                         message = _("\"%s\" element for this pou already exists!")%blockname
   294                     else:
   295                     else:
   295                         self.Controler.AddEditedElementPouVar(self.TagName, values[0], blockname)
   296                         self.Controler.AddEditedElementPouVar(self.TagName, values[0], blockname)
   296                         self.RefreshVariablePanel()
   297                         self.RefreshVariablePanel()
   297                         self.RefreshVariableTree()
   298                         self.RefreshVariableTree()
   298                 blockinfo = self.Controler.GetBlockType(values[0], blockinputs, self.Debug)
   299                 blockinfo = self.Controler.GetBlockType(blocktype, blockinputs, self.Debug)
   299                 hint = ',\n    '.join(
   300                 hint = ',\n    '.join(
   300                             [ " " + fctdecl[0]+" := (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["inputs"]] +
   301                             [ " " + fctdecl[0]+" := (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["inputs"]] +
   301                             [ " " + fctdecl[0]+" => (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["outputs"]])
   302                             [ " " + fctdecl[0]+" => (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["outputs"]])
   302                 event.SetDragText(blockname+"(\n    "+hint+")")
   303                 if values[1] == "function":
       
   304                     event.SetDragText(blocktype+"(\n    "+hint+")")
       
   305                 else:
       
   306                     event.SetDragText(blockname+"(\n    "+hint+")")
   303             elif values[1] == "location":
   307             elif values[1] == "location":
   304                 pou_name, pou_type = self.Controler.GetEditedElementType(self.TagName, self.Debug)
   308                 pou_name, pou_type = self.Controler.GetEditedElementType(self.TagName, self.Debug)
   305                 if len(values) > 2 and pou_type == "program":
   309                 if len(values) > 2 and pou_type == "program":
   306                     var_name = values[3]
   310                     var_name = values[3]
   307                     if var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]:
   311                     if var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]:
   556                 self.SetStyling(current_pos - last_styled_pos - 1, 31)
   560                 self.SetStyling(current_pos - last_styled_pos - 1, 31)
   557                 last_styled_pos = current_pos
   561                 last_styled_pos = current_pos
   558                 if state == WORD:
   562                 if state == WORD:
   559                     current_context = self.Variables
   563                     current_context = self.Variables
   560                 state = COMMENT
   564                 state = COMMENT
       
   565             elif line.endswith("{") and state != PRAGMA:
       
   566                 self.SetStyling(current_pos - last_styled_pos - 1, 31)
       
   567                 last_styled_pos = current_pos
       
   568                 if state == WORD:
       
   569                     current_context = self.Variables
       
   570                 state = PRAGMA
   561             elif state == COMMENT:
   571             elif state == COMMENT:
   562                 if line.endswith("*)"):
   572                 if line.endswith("*)"):
   563                     self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT)
   573                     self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT)
   564                     last_styled_pos = current_pos + 1
   574                     last_styled_pos = current_pos + 1
   565                     state = SPACE
   575                     state = SPACE
   566             elif (line.endswith("'") or line.endswith('"')) and state not in [COMMENT, STRING, WSTRING]:
   576             elif state == PRAGMA:
       
   577                 if line.endswith("}"):
       
   578                     self.SetStyling(current_pos - last_styled_pos + 2, 31)
       
   579                     last_styled_pos = current_pos + 1
       
   580                     state = SPACE
       
   581             elif (line.endswith("'") or line.endswith('"')) and state not in [STRING, WSTRING]:
   567                 self.SetStyling(current_pos - last_styled_pos, 31)
   582                 self.SetStyling(current_pos - last_styled_pos, 31)
   568                 last_styled_pos = current_pos
   583                 last_styled_pos = current_pos
   569                 if state == WORD:
   584                 if state == WORD:
   570                     current_context = self.Variables
   585                     current_context = self.Variables
   571                 if line.endswith("'"):
   586                 if line.endswith("'"):