--- a/TextViewer.py Tue Nov 13 17:21:30 2007 +0100
+++ b/TextViewer.py Fri Nov 16 17:43:32 2007 +0100
@@ -89,6 +89,24 @@
else:
return None
+if wx.VERSION >= (2, 8, 0):
+ import wx.aui
+
+ class TextMDIViewer(wx.aui.AuiMDIChildFrame):
+ def __init__(self, parent, tagname, window, controler):
+ wx.aui.AuiMDIChildFrame.__init__(self, parent, -1, title = "")
+
+ sizer = wx.BoxSizer(wx.HORIZONTAL)
+
+ self.Viewer = TextViewer(self, tagname, window, controler)
+
+ sizer.AddWindow(self.Viewer, 1, border=0, flag=wx.GROW)
+
+ self.SetSizer(sizer)
+
+ def GetViewer(self):
+ return self.Viewer
+
class TextViewer(wx.stc.StyledTextCtrl):
if wx.VERSION < (2, 6, 0):
@@ -98,7 +116,7 @@
else:
event(self, function)
- def __init__(self, parent, window, controler):
+ def __init__(self, parent, tagname, window, controler):
wx.stc.StyledTextCtrl.__init__(self, parent, ID_TEXTVIEWER, size=wx.Size(0, 0), style=0)
self.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN)
@@ -146,6 +164,7 @@
self.DisableEvents = True
self.TextSyntax = "ST"
self.CurrentAction = None
+ self.TagName = tagname
self.ParentWindow = window
self.Controler = controler
@@ -159,6 +178,18 @@
self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_TEXTVIEWER)
+ def SetTagName(self, tagname):
+ self.TagName = tagname
+
+ def GetTagName(self):
+ return self.TagName
+
+ def IsViewing(self, tagname):
+ return self.TagName == tagname
+
+ def SetMode(self, mode):
+ pass
+
def OnModification(self, event):
if not self.DisableEvents:
mod_type = event.GetModificationType()
@@ -187,8 +218,14 @@
if isinstance(values, tuple):
if values[1] in ["functionBlock", "program", "location"]:
event.SetDragText("")
- else:
- event.SetDragText(values[0])
+ elif values[1] != "location":
+ if values[3] == self.TagName:
+ event.SetDragText(values[0])
+ else:
+ event.SetDragText("")
+ message = wx.MessageDialog(self.ParentWindow, "Variable don't belong to this POU!", "Error", wx.OK|wx.ICON_ERROR)
+ message.ShowModal()
+ message.Destroy()
event.Skip()
def SetTextSyntax(self, syntax):
@@ -198,18 +235,6 @@
self.Keywords = [keyword.upper() for keyword in keywords]
self.Colourise(0, -1)
- def SetVariables(self, variables):
- self.Variables = [variable.upper() for variable in variables]
- self.Colourise(0, -1)
-
- def SetFunctions(self, blocktypes):
- self.Functions = []
- for category in blocktypes:
- for blocktype in category["list"]:
- if blocktype["type"] == "function" and blocktype["name"] not in self.Keywords and blocktype["name"] not in self.Variables:
- self.Functions.append(blocktype["name"].upper())
- self.Colourise(0, -1)
-
def RefreshJumpList(self):
self.Jumps = [jump.upper() for jump in LABEL_MODEL.findall(self.GetText())]
self.Colourise(0, -1)
@@ -237,7 +262,7 @@
self.DisableEvents = True
old_cursor_pos = self.GetCurrentPos()
old_text = self.GetText()
- new_text = self.Controler.GetCurrentElementEditingText()
+ new_text = self.Controler.GetEditedElementText(self.TagName)
self.SetText(new_text)
new_cursor_pos = GetCursorPos(old_text, new_text)
if new_cursor_pos != None:
@@ -248,9 +273,19 @@
self.RefreshJumpList()
self.EmptyUndoBuffer()
self.DisableEvents = False
-
- def VerifyVariableTypeCompatibility(self):
- pass
+
+ words = self.TagName.split("::")
+ self.Variables = [variable["Name"].upper() for variable in self.Controler.GetEditedElementInterfaceVars(self.TagName)]
+ if self.Controler.GetEditedElementType(self.TagName)[1] == "function" or words[0] == "T" and self.TextSyntax == "IL":
+ self.Variables.append(words[-1].upper())
+
+ self.Functions = []
+ for category in self.Controler.GetBlockTypes(self.TagName):
+ for blocktype in category["list"]:
+ if blocktype["type"] == "function" and blocktype["name"] not in self.Keywords and blocktype["name"] not in self.Variables:
+ self.Functions.append(blocktype["name"].upper())
+
+ self.Colourise(0, -1)
def OnStyleNeeded(self, event):
self.TextChanged = True
@@ -380,12 +415,12 @@
def RefreshModel(self):
if self.TextChanged:
self.RefreshJumpList()
- self.Controler.SetCurrentElementEditingText(self.GetText())
+ self.Controler.SetEditedElementText(self.TagName, self.GetText())
def OnKeyDown(self, event):
if self.CallTipActive():
self.CallTipCancel()
- key = event.KeyCode()
+ key = event.GetKeyCode()
# Code completion
if key == wx.WXK_SPACE and event.ControlDown():