TextViewer.py
changeset 249 d8425712acef
parent 235 7b58a3b5b6ec
child 295 c6ef6d92ce16
equal deleted inserted replaced
248:f7df265edd54 249:d8425712acef
    97             if id is not None:
    97             if id is not None:
    98                 event(self, id, function)
    98                 event(self, id, function)
    99             else:
    99             else:
   100                 event(self, function)
   100                 event(self, function)
   101     
   101     
   102     def __init__(self, parent, tagname, window, controler):
   102     def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""):
   103         wx.stc.StyledTextCtrl.__init__(self, parent, ID_TEXTVIEWER, size=wx.Size(0, 0), style=0)
   103         wx.stc.StyledTextCtrl.__init__(self, parent, ID_TEXTVIEWER, size=wx.Size(0, 0), style=0)
   104         
   104         
   105         self.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN)
   105         self.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN)
   106         self.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT)
   106         self.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT)
   107         
   107         
   148         self.DisableEvents = True
   148         self.DisableEvents = True
   149         self.TextSyntax = "ST"
   149         self.TextSyntax = "ST"
   150         self.CurrentAction = None
   150         self.CurrentAction = None
   151         self.TagName = tagname
   151         self.TagName = tagname
   152         self.Errors = []
   152         self.Errors = []
       
   153         self.Debug = debug
       
   154         self.InstancePath = instancepath
   153         
   155         
   154         self.ParentWindow = window
   156         self.ParentWindow = window
   155         self.Controler = controler
   157         self.Controler = controler
   156 
   158 
   157         self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|wx.stc.STC_MOD_BEFOREDELETE)
   159         self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|wx.stc.STC_MOD_BEFOREDELETE)
   167         self.TagName = tagname
   169         self.TagName = tagname
   168         
   170         
   169     def GetTagName(self):
   171     def GetTagName(self):
   170         return self.TagName
   172         return self.TagName
   171     
   173     
       
   174     def GetInstancePath(self):
       
   175         return self.InstancePath
       
   176     
   172     def IsViewing(self, tagname):
   177     def IsViewing(self, tagname):
   173         return self.TagName == tagname
   178         if self.Debug:
       
   179             return self.InstancePath == tagname
       
   180         else:
       
   181             return self.TagName == tagname
   174     
   182     
   175     def SetMode(self, mode):
   183     def SetMode(self, mode):
   176         pass
   184         pass
   177     
   185     
   178     def OnModification(self, event):
   186     def OnModification(self, event):
   199         try:
   207         try:
   200             values = eval(event.GetDragText())
   208             values = eval(event.GetDragText())
   201         except:
   209         except:
   202             values = event.GetDragText()
   210             values = event.GetDragText()
   203         if isinstance(values, tuple):
   211         if isinstance(values, tuple):
   204             if values[1] in ["functionBlock", "program", "location"]:
   212             if values[1] in ["functionBlock", "program", "location", "debug"]:
   205                 event.SetDragText("")
   213                 event.SetDragText("")
   206             elif values[1] == "function":
   214             elif values[1] == "function":
   207                 event.SetDragText(values[0])
   215                 event.SetDragText(values[0])
   208             elif values[1] != "location":
   216             elif values[1] != "location":
   209                 if values[3] == self.TagName:
   217                 if values[3] == self.TagName:
   249     def RefreshView(self):
   257     def RefreshView(self):
   250         self.ResetBuffer()
   258         self.ResetBuffer()
   251         self.DisableEvents = True
   259         self.DisableEvents = True
   252         old_cursor_pos = self.GetCurrentPos()
   260         old_cursor_pos = self.GetCurrentPos()
   253         old_text = self.GetText()
   261         old_text = self.GetText()
   254         new_text = self.Controler.GetEditedElementText(self.TagName)
   262         new_text = self.Controler.GetEditedElementText(self.TagName, self.Debug)
   255         self.SetText(new_text)
   263         self.SetText(new_text)
   256         new_cursor_pos = GetCursorPos(old_text, new_text)
   264         new_cursor_pos = GetCursorPos(old_text, new_text)
   257         if new_cursor_pos != None:
   265         if new_cursor_pos != None:
   258             self.GotoPos(new_cursor_pos)
   266             self.GotoPos(new_cursor_pos)
   259         else:
   267         else:
   262         self.RefreshJumpList()
   270         self.RefreshJumpList()
   263         self.EmptyUndoBuffer()
   271         self.EmptyUndoBuffer()
   264         self.DisableEvents = False
   272         self.DisableEvents = False
   265         
   273         
   266         words = self.TagName.split("::")
   274         words = self.TagName.split("::")
   267         self.Variables = [variable["Name"].upper() for variable in self.Controler.GetEditedElementInterfaceVars(self.TagName)]
   275         self.Variables = [variable["Name"].upper() for variable in self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)]
   268         if self.Controler.GetEditedElementType(self.TagName)[1] == "function" or words[0] == "T" and self.TextSyntax == "IL":
   276         if self.Controler.GetEditedElementType(self.TagName, self.Debug)[1] == "function" or words[0] == "T" and self.TextSyntax == "IL":
   269             self.Variables.append(words[-1].upper())
   277             self.Variables.append(words[-1].upper())
   270         
   278         
   271         self.Functions = []
   279         self.Functions = []
   272         for category in self.Controler.GetBlockTypes(self.TagName):
   280         for category in self.Controler.GetBlockTypes(self.TagName, self.Debug):
   273             for blocktype in category["list"]:
   281             for blocktype in category["list"]:
   274                 if blocktype["type"] == "function" and blocktype["name"] not in self.Keywords and blocktype["name"] not in self.Variables:
   282                 if blocktype["type"] == "function" and blocktype["name"] not in self.Keywords and blocktype["name"] not in self.Variables:
   275                     self.Functions.append(blocktype["name"].upper())
   283                     self.Functions.append(blocktype["name"].upper())
   276         
   284         
   277         self.EnumeratedValues = []
   285         self.EnumeratedValues = []