Changes merged
author'Laurent Bessard <laurent.bessard@lolitech.fr>'
Tue, 22 Sep 2009 09:56:02 +0200
changeset 431 c1c92d068ac5
parent 411 9ab97d517ae8 (current diff)
parent 430 8efd4c6874cd (diff)
child 433 26bc7d5d4264
Changes merged
DataTypeEditor.py
GraphicViewer.py
PLCControler.py
PLCOpenEditor.py
VariablePanel.py
Viewer.py
examples/example.xml
plcopen/structures.py
--- a/DataTypeEditor.py	Mon Sep 21 12:06:51 2009 +0200
+++ b/DataTypeEditor.py	Tue Sep 22 09:56:02 2009 +0200
@@ -772,7 +772,7 @@
 ##                message.Destroy()
 ##                event.Veto()
             elif value.upper() in [var["Name"].upper() for idx, var in enumerate(self.StructureElementsTable.GetData()) if idx != row]:
-                message = wx.MessageDialog(self, _("A element with \"%s\" as name exists in this structure!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
+                message = wx.MessageDialog(self, _("An element named \"%s\" already exists in this structure!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
                 message.ShowModal()
                 message.Destroy()
                 event.Veto()
--- a/GraphicViewer.py	Mon Sep 21 12:06:51 2009 +0200
+++ b/GraphicViewer.py	Tue Sep 22 09:56:02 2009 +0200
@@ -144,12 +144,11 @@
         
         self._init_sizers()
 
-    def __init__(self, parent, window, controler, instancepath = ""):
+    def __init__(self, parent, window, producer, instancepath = ""):
         self._init_ctrls(parent)
-        DebugViewer.__init__(self, controler, True, False)
+        DebugViewer.__init__(self, producer, True, False)
         
         self.ParentWindow = window
-        self.Controler = controler
         self.InstancePath = instancepath
 
         self.Datas = []
--- a/LDViewer.py	Mon Sep 21 12:06:51 2009 +0200
+++ b/LDViewer.py	Tue Sep 22 09:56:02 2009 +0200
@@ -181,8 +181,8 @@
         self.RungComments = []
         Viewer.ResetView(self)
 
-    def RefreshView(self):
-        Viewer.RefreshView(self)
+    def RefreshView(self, selection=None):
+        Viewer.RefreshView(self, selection)
         for i, rung in enumerate(self.Rungs):
             bbox = rung.GetBoundingBox()
             if i < len(self.RungComments):
--- a/PLCControler.py	Mon Sep 21 12:06:51 2009 +0200
+++ b/PLCControler.py	Tue Sep 22 09:56:02 2009 +0200
@@ -251,7 +251,7 @@
     def GetProjectConfigNames(self, debug = False):
         project = self.GetProject(debug)
         if project is not None:
-            return [config.getName() for config in project.getconfigurations()]
+            return [config.getname() for config in project.getconfigurations()]
         return []
     
     # Return project pou variables
@@ -599,6 +599,51 @@
                 self.Project.insertpou(-1, new_pou)
                 self.BufferProject()
     
+    def PastePou(self, pou_type, pou_xml):
+        '''
+        Adds the POU defined by 'pou_xml' to the current project with type 'pou_type'
+        '''
+        try:
+            tree = minidom.parseString(pou_xml)
+            root = tree.childNodes[0]
+        except:
+            return _("Couldn't paste non-POU object.")
+
+        if root.nodeName == "pou":
+            new_pou = plcopen.pous_pou()
+            new_pou.loadXMLTree(root)
+
+            name = new_pou.getname()
+            orig_type = new_pou.getpouType()
+
+            # prevent violations of POU content restrictions:
+            # function blocks cannot be pasted as functions,
+            # programs cannot be pasted as functions or function blocks
+            if orig_type == 'functionBlock' and pou_type == 'function' or \
+            orig_type == 'program' and pou_type in ['function', 'functionBlock']:
+                return _('''%s "%s" can't be pasted as a %s.''') % (orig_type, name, pou_type)
+ 
+            while self.Project.getpou(name):
+                # a POU with that name already exists.
+                # make a new name and test if a POU with that name exists.
+
+                # append an incrementing numeric suffix to the POU name. it
+                # doesn't count up perfectly, but as long as it's unique who cares?
+                if name[-1] >= '0' and name[-1] <= '9':
+                    last_digit = int(name[-1])
+                    name = name[0:-1] + str(last_digit+1)
+                else:
+                    name = name + '1'
+
+            # we've found a name that does not already exist, use it
+            new_pou.setname(name)
+            new_pou.setpouType(pou_type)
+
+            self.Project.insertpou(-1, new_pou)
+            self.BufferProject()
+        else:
+            return _("Couldn't paste non-POU object.")
+
     # Remove a Pou from project
     def ProjectRemovePou(self, pou_name):
         if self.Project is not None:
@@ -737,9 +782,9 @@
     def ChangeConfigurationResourceName(self, config_name, old_name, new_name):
         if self.Project is not None:
             # Found the resource corresponding to old name and change its name to new name
-            resource = self.Project.getconfigurationResource(config_name)
+            resource = self.Project.getconfigurationResource(config_name, old_name)
             if resource is not None:
-                resource.setName(new_name)
+                resource.setname(new_name)
                 self.BufferProject()
     
     # Return the type of the pou given by its name
@@ -850,6 +895,7 @@
             # Create variable and change its properties
             tempvar = plcopen.varListPlain_variable()
             tempvar.setname(var["Name"])
+
             var_type = plcopen.dataType()
             if var["Type"] in self.GetBaseTypes():
                 if var["Type"] == "STRING":
@@ -863,6 +909,7 @@
                 derived_type.setname(var["Type"])
                 var_type.setcontent({"name" : "derived", "value" : derived_type})
             tempvar.settype(var_type)
+
             if var["Initial Value"] != "":
                 value = plcopen.value()
                 value.setvalue(var["Initial Value"])
@@ -871,9 +918,62 @@
                 tempvar.setaddress(var["Location"])
             else:
                 tempvar.setaddress(None)
+            if var['Documentation'] != "":
+                ft = plcopen.formattedText()
+                ft.settext(var['Documentation'])
+                tempvar.setdocumentation(ft)
+
             # Add variable to varList
             current_varlist.appendvariable(tempvar)
         return varlist_list
+    
+    def GetVariableDictionary(self, varlist, var):
+        '''
+        convert a PLC variable to the dictionary representation
+        returned by Get*Vars)
+        '''
+
+        tempvar = {"Name" : var.getname()}
+
+        vartype_content = var.gettype().getcontent()
+        if vartype_content["name"] == "derived":
+            tempvar["Type"] = vartype_content["value"].getname()
+        elif vartype_content["name"] in ["string", "wstring"]:
+            tempvar["Type"] = vartype_content["name"].upper()
+        else:
+            tempvar["Type"] = vartype_content["name"]
+
+        tempvar["Edit"] = True
+
+        initial = var.getinitialValue()
+        if initial:
+            tempvar["Initial Value"] = initial.getvalue()
+        else:
+            tempvar["Initial Value"] = ""
+
+        address = var.getaddress()
+        if address:
+            tempvar["Location"] = address
+        else:
+            tempvar["Location"] = ""
+
+        if varlist.getretain():
+            tempvar["Retain"] = "Yes"
+        else:
+            tempvar["Retain"] = "No"
+
+        if varlist.getconstant():
+            tempvar["Constant"] = "Yes"
+        else:
+            tempvar["Constant"] = "No"
+
+        doc = var.getdocumentation()
+        if doc:
+            tempvar["Documentation"] = doc.gettext()
+        else:
+            tempvar["Documentation"] = ""
+
+        return tempvar
 
     # Replace the configuration globalvars by those given
     def SetConfigurationGlobalVars(self, name, vars):
@@ -897,33 +997,8 @@
                 # Extract variables from every varLists
                 for varlist in configuration.getglobalVars():
                     for var in varlist.getvariable():
-                        tempvar = {"Name" : var.getname(), "Class" : "Global"}
-                        vartype_content = var.gettype().getcontent()
-                        if vartype_content["name"] == "derived":
-                            tempvar["Type"] = vartype_content["value"].getname()
-                        elif vartype_content["name"] in ["string", "wstring"]:
-                            tempvar["Type"] = vartype_content["name"].upper()
-                        else:
-                            tempvar["Type"] = vartype_content["name"]
-                        tempvar["Edit"] = True
-                        initial = var.getinitialValue()
-                        if initial:
-                            tempvar["Initial Value"] = initial.getvalue()
-                        else:
-                            tempvar["Initial Value"] = ""
-                        address = var.getaddress()
-                        if address:
-                            tempvar["Location"] = address
-                        else:
-                            tempvar["Location"] = ""
-                        if varlist.getretain():
-                            tempvar["Retain"] = "Yes"
-                        else:
-                            tempvar["Retain"] = "No"
-                        if varlist.getconstant():
-                            tempvar["Constant"] = "Yes"
-                        else:
-                            tempvar["Constant"] = "No"
+                        tempvar = self.GetVariableDictionary(varlist, var)
+                        tempvar["Class"] = "Global"
                         vars.append(tempvar)
         return vars
 
@@ -949,33 +1024,8 @@
                 # Extract variables from every varLists
                 for varlist in resource.getglobalVars():
                     for var in varlist.getvariable():
-                        tempvar = {"Name" : var.getname(), "Class" : "Global"}
-                        vartype_content = var.gettype().getcontent()
-                        if vartype_content["name"] == "derived":
-                            tempvar["Type"] = vartype_content["value"].getname()
-                        elif vartype_content["name"] in ["string", "wstring"]:
-                            tempvar["Type"] = vartype_content["name"].upper()
-                        else:
-                            tempvar["Type"] = vartype_content["name"]
-                        tempvar["Edit"] = True
-                        initial = var.getinitialValue()
-                        if initial:
-                            tempvar["Initial Value"] = initial.getvalue()
-                        else:
-                            tempvar["Initial Value"] = ""
-                        address = var.getaddress()
-                        if address:
-                            tempvar["Location"] = address
-                        else:
-                            tempvar["Location"] = ""
-                        if varlist.getretain():
-                            tempvar["Retain"] = "Yes"
-                        else:
-                            tempvar["Retain"] = "No"
-                        if varlist.getconstant():
-                            tempvar["Constant"] = "Yes"
-                        else:
-                            tempvar["Constant"] = "No"
+                        tempvar = self.GetVariableDictionary(varlist, var)
+                        tempvar["Class"] = "Global"
                         vars.append(tempvar)
         return vars
     
@@ -1014,7 +1064,7 @@
                             tree.append((element.getname(), element_type["name"], ([], [])))
                     return tree, []
         return [], []
-    
+
     # Return the interface for the given pou
     def GetPouInterfaceVars(self, pou, debug = False):
         vars = []
@@ -1023,36 +1073,16 @@
             # Extract variables from every varLists
             for type, varlist in pou.getvars():
                 for var in varlist.getvariable():
-                    tempvar = {"Name" : var.getname(), "Class" : type, "Tree" : ([], [])}
+                    tempvar = self.GetVariableDictionary(varlist, var)
+
+                    tempvar["Class"] = type
+                    tempvar["Tree"] = ([], [])
+
                     vartype_content = var.gettype().getcontent()
                     if vartype_content["name"] == "derived":
-                        tempvar["Type"] = vartype_content["value"].getname()
                         tempvar["Edit"] = not pou.hasblock(tempvar["Name"])
                         tempvar["Tree"] = self.GenerateVarTree(tempvar["Type"], debug)
-                    else:
-                        if vartype_content["name"] in ["string", "wstring"]:
-                            tempvar["Type"] = vartype_content["name"].upper()
-                        else:
-                            tempvar["Type"] = vartype_content["name"]
-                        tempvar["Edit"] = True
-                    initial = var.getinitialValue()
-                    if initial:
-                        tempvar["Initial Value"] = initial.getvalue()
-                    else:
-                        tempvar["Initial Value"] = ""
-                    address = var.getaddress()
-                    if address:
-                        tempvar["Location"] = address
-                    else:
-                        tempvar["Location"] = ""
-                    if varlist.getretain():
-                        tempvar["Retain"] = "Yes"
-                    else:
-                        tempvar["Retain"] = "No"
-                    if varlist.getconstant():
-                        tempvar["Constant"] = "Yes"
-                    else:
-                        tempvar["Constant"] = "No"
+
                     vars.append(tempvar)
         return vars
 
@@ -1231,9 +1261,13 @@
             return project.GetBaseType(type)
         return None
 
-    # Return Base Types
     def GetBaseTypes(self):
-        return [value for value in TypeHierarchy.keys() if not value.startswith("ANY")]
+        '''
+        return the list of datatypes defined in IEC 61131-3.
+        TypeHierarchy_list has a rough order to it (e.g. SINT, INT, DINT, ...),
+        which makes it easy for a user to find a type in a menu.
+        '''
+        return [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]
 
     def IsOfType(self, type, reference, debug = False):
         project = self.GetProject(debug)
@@ -1661,9 +1695,13 @@
                 if root.nodeType == tree.ELEMENT_NODE and root.nodeName == "paste":
                     for child in root.childNodes:
                         if child.nodeType == tree.ELEMENT_NODE:
+                            if not child.nodeName in plcopen.ElementNameToClass:
+                                return _("\"%s\" element can't be pasted here!!!")%child.nodeName
+
                             classname = plcopen.ElementNameToClass[child.nodeName]
                             if not self.CheckPasteCompatibility[bodytype](classname):
-                                return _("\"%s\" element can't be paste here!!!")%child.nodeName
+                                return _("\"%s\" element can't be pasted here!!!")%child.nodeName
+
                             classobj = getattr(plcopen, classname, None)
                             if classobj is not None:
                                 instance = classobj()
@@ -1673,7 +1711,7 @@
                                     if blockname is not None:
                                         blocktype = instance.gettypeName()
                                         if element_type == "function":
-                                            return _("FunctionBlock \"%s\" can't be paste in a Function!!!")%blocktype
+                                            return _("FunctionBlock \"%s\" can't be pasted in a Function!!!")%blocktype
                                         blockname = self.GenerateNewName(tagname, blockname, "Block%d", debug=debug)
                                         exclude[blockname] = True
                                         instance.setinstanceName(blockname)
--- a/PLCOpenEditor.py	Mon Sep 21 12:06:51 2009 +0200
+++ b/PLCOpenEditor.py	Tue Sep 22 09:56:02 2009 +0200
@@ -108,7 +108,7 @@
 from RessourceEditor import *
 from DataTypeEditor import *
 from PLCControler import *
-from plcopen.structures import LOCATIONDATATYPES
+from VariablePanel import VariablePanel
 
 # Define PLCOpenEditor controls id
 [ID_PLCOPENEDITOR, ID_PLCOPENEDITORLEFTNOTEBOOK, 
@@ -251,7 +251,7 @@
 
 [TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, TYPESTREE, 
  INSTANCESTREE, LIBRARYTREE, SCALING
-] = [wx.NewId() for _refresh_elements in range(9)]
+] = range(9)
 
 def GetShortcutKeyCallbackFunction(viewer_function):
     def ShortcutKeyFunction(self, event):
@@ -260,7 +260,6 @@
             getattr(control, viewer_function)()
         elif isinstance(control, wx.TextCtrl):
             control.ProcessEvent(event)
-        event.Skip()
     return ShortcutKeyFunction
 
 def GetParentName(tree, item, parent_type):
@@ -961,7 +960,8 @@
 
     def OnQuitMenu(self, event):
         self.Close()
-        event.Skip()
+        # don't call event.Skip() here or it will attempt to close the
+        # frame twice for some reason
 
 #-------------------------------------------------------------------------------
 #                            Edit Menu Functions
@@ -1381,7 +1381,7 @@
                         message = _("\"%s\" pou already exists!")%new_name
                         abort = True
                     elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables()]:
-                        messageDialog = wx.MessageDialog(self, _("A pou has an element with \"%s\" as name. It can generate a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION)
+                        messageDialog = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION)
                         if messageDialog.ShowModal() == wx.ID_NO:
                             abort = True
                         messageDialog.Destroy()
@@ -1394,7 +1394,7 @@
                 elif itemtype == ITEM_TRANSITION:
                     pou_name = GetParentName(self.TypesTree, item, ITEM_POU)
                     if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]:
-                        message = _("A pou with \"%s\" as name exists!")%new_name
+                        message = _("A POU named \"%s\" already exists!")%new_name
                     elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables(pou_name) if name != old_name]:
                         message = _("A variable with \"%s\" as name already exists in this pou!")%new_name
                     else:
@@ -1405,7 +1405,7 @@
                 elif itemtype == ITEM_ACTION:
                     pou_name = GetParentName(self.TypesTree, item, ITEM_POU)
                     if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]:
-                        message = _("A pou with \"%s\" as name exists!")%new_name
+                        message = _("A POU named \"%s\" already exists!")%new_name
                     elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables(pou_name) if name != old_name]:
                         message = _("A variable with \"%s\" as name already exists in this pou!")%new_name
                     else:
@@ -1418,12 +1418,12 @@
                         message = _("\"%s\" config already exists!")%new_name
                         abort = True
                     elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]:
-                        messageDialog = wx.MessageDialog(self, _("A pou is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION)
+                        messageDialog = wx.MessageDialog(self, _("There is a POU named \"%s\". This could cause a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION)
                         if messageDialog.ShowModal() == wx.ID_NO:
                             abort = True
                         messageDialog.Destroy()
                     elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables()]:
-                        messageDialog = wx.MessageDialog(self, _("A pou has an element with \"%s\" as name. It can generate a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION)
+                        messageDialog = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION)
                         if messageDialog.ShowModal() == wx.ID_NO:
                             abort = True
                         messageDialog.Destroy()
@@ -1438,12 +1438,12 @@
                         message = _("\"%s\" config already exists!")%new_name
                         abort = True
                     elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]:
-                        messageDialog = wx.MessageDialog(self, _("A pou is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION)
+                        messageDialog = wx.MessageDialog(self, _("There is a POU named \"%s\". This could cause a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION)
                         if messageDialog.ShowModal() == wx.ID_NO:
                             abort = True
                         messageDialog.Destroy()
                     elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables()]:
-                        messageDialog = wx.MessageDialog(self, _("A pou has an element with \"%s\" as name. It can generate a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION)
+                        messageDialog = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION)
                         if messageDialog.ShowModal() == wx.ID_NO:
                             abort = True
                         messageDialog.Destroy()
@@ -1587,6 +1587,7 @@
     def OnTypesTreeRightUp(self, event):
         if wx.Platform == '__WXMSW__':
             item = event.GetItem()
+            self.TypesTree.SelectItem(item)
         else:
             item = self.TypesTree.GetSelection()
         name = self.TypesTree.GetItemText(item)
@@ -1601,9 +1602,14 @@
                 AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Action"))
                 self.Bind(wx.EVT_MENU, self.GenerateAddActionFunction(name), id=new_id)
                 menu.AppendSeparator()
+
             new_id = wx.NewId()
             AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Create a new POU from"))
             self.Bind(wx.EVT_MENU, self.OnCreatePouFromMenu, id=new_id)
+
+            AppendMenu(menu, help='', id=wx.ID_COPY, kind=wx.ITEM_NORMAL, text=_("Copy"))
+            self.Bind(wx.EVT_MENU, self.OnCopyPou, id=wx.ID_COPY)
+
             pou_type = self.Controler.GetPouType(name)
             if pou_type in ["function", "functionBlock"]:
                 change_menu = wx.Menu(title='')
@@ -1647,9 +1653,17 @@
                 self.PopupMenu(menu)
             elif name in ["Functions", "Function Blocks", "Programs"]:
                 menu = wx.Menu(title='')
+
                 new_id = wx.NewId()
                 AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Pou"))
                 self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction({"Functions" : "function", "Function Blocks" : "functionBlock", "Programs" : "program"}[name]), id=new_id)
+
+                AppendMenu(menu, help='', id=wx.ID_PASTE, kind=wx.ITEM_NORMAL, text=_("Paste"))
+                self.Bind(wx.EVT_MENU, self.OnPastePou, id=wx.ID_PASTE)
+
+                if self.GetCopyBuffer() is None:
+                    menu.Enable(wx.ID_PASTE, False)
+
                 self.PopupMenu(menu)
             elif name == "Configurations":
                 menu = wx.Menu(title='')
@@ -2250,6 +2264,37 @@
                 self._Refresh(TITLE, TOOLBAR, EDITMENU, TYPESTREE, LIBRARYTREE)
         event.Skip()
 
+    def OnCopyPou(self, event):
+        selected = self.TypesTree.GetSelection()
+
+        pou_name = self.TypesTree.GetItemText(selected)
+        pou = self.Controler.Project.getpou(pou_name)
+
+        pou_xml = pou.generateXMLText('pou', 0)
+        self.SetCopyBuffer(pou_xml)
+
+    def OnPastePou(self, event):
+        selected = self.TypesTree.GetSelection()
+
+        pou_type = self.TypesTree.GetItemText(selected)
+        pou_type = UNEDITABLE_NAMES_DICT[pou_type] # one of 'Functions', 'Function Blocks' or 'Programs'
+        pou_type = {'Functions': 'function', 'Function Blocks': 'functionBlock', 'Programs': 'program'}[pou_type]
+
+        pou_xml = self.GetCopyBuffer()
+
+        result = self.Controler.PastePou(pou_type, pou_xml)
+
+        if result is not None:
+            message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
+            message.ShowModal()
+            message.Destroy()
+        else:
+            self.RefreshTitle()
+            self.RefreshEditMenu()
+            self.RefreshTypesTree()
+            self.RefreshLibraryTree()
+            self.RefreshToolBar()
+
 #-------------------------------------------------------------------------------
 #                        Remove Project Elements Functions
 #-------------------------------------------------------------------------------
@@ -3288,7 +3333,7 @@
             message.ShowModal()
             message.Destroy()
         elif pou_name.upper() in self.PouElementNames:
-            message = wx.MessageDialog(self, _("A pou has an element with \"%s\" as name. It can generate a conflict. Do you wish to continue?")%pou_name, _("Warning"), wx.YES_NO|wx.ICON_EXCLAMATION)
+            message = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%pou_name, _("Warning"), wx.YES_NO|wx.ICON_EXCLAMATION)
             result = message.ShowModal()
             message.Destroy()
             if result == wx.ID_YES:
@@ -3447,7 +3492,7 @@
             message.ShowModal()
             message.Destroy()
         elif transition_name.upper() in self.PouNames:
-            message = wx.MessageDialog(self, _("A pou with \"%s\" as name exists!")%transition_name, _("Error"), wx.OK|wx.ICON_ERROR)
+            message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%transition_name, _("Error"), wx.OK|wx.ICON_ERROR)
             message.ShowModal()
             message.Destroy()
         elif transition_name.upper() in self.PouElementNames:
@@ -3591,7 +3636,7 @@
             message.ShowModal()
             message.Destroy()
         elif action_name.upper() in self.PouNames:
-            message = wx.MessageDialog(self, _("A pou with \"%s\" as name exists!")%action_name, _("Error"), wx.OK|wx.ICON_ERROR)
+            message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%action_name, _("Error"), wx.OK|wx.ICON_ERROR)
             message.ShowModal()
             message.Destroy()
         elif action_name.upper() in self.PouElementNames:
@@ -3662,11 +3707,11 @@
             message.ShowModal()
             message.Destroy()
         elif config_name.upper() in self.PouNames:
-            message = wx.MessageDialog(self, _("A pou with \"%s\" as name exists!")%config_name, _("Error"), wx.OK|wx.ICON_ERROR)
+            message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%config_name, _("Error"), wx.OK|wx.ICON_ERROR)
             message.ShowModal()
             message.Destroy()
         elif config_name.upper() in self.PouElementNames:
-            message = wx.MessageDialog(self, _("A pou has an element with \"%s\" as name. It can generate a conflict. Do you wish to continue?")%config_name, _("Warning"), wx.YES_NO|wx.ICON_EXCLAMATION)
+            message = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%config_name, _("Warning"), wx.YES_NO|wx.ICON_EXCLAMATION)
             result = message.ShowModal()
             message.Destroy()
             if result == wx.ID_YES:
@@ -3725,11 +3770,11 @@
             message.ShowModal()
             message.Destroy()
         elif resource_name.upper() in self.PouNames:
-            message = wx.MessageDialog(self, _("A pou with \"%s\" as name exists!")%resource_name, _("Error"), wx.OK|wx.ICON_ERROR)
+            message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%resource_name, _("Error"), wx.OK|wx.ICON_ERROR)
             message.ShowModal()
             message.Destroy()
         elif resource_name.upper() in self.PouElementNames:
-            message = wx.MessageDialog(self, _("A pou has an element with \"%s\" as name. It can generate a conflict. Do you wish to continue?")%resource_name, _("Warning"), wx.YES_NO|wx.ICON_EXCLAMATION)
+            message = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%resource_name, _("Warning"), wx.YES_NO|wx.ICON_EXCLAMATION)
             result = message.ShowModal()
             message.Destroy()
             if result == wx.ID_YES:
@@ -3827,763 +3872,8 @@
             panel.ClearErrors()
 
 #-------------------------------------------------------------------------------
-#                            Variables Editor Panel
-#-------------------------------------------------------------------------------
-
-def GetVariableTableColnames(location):
-    _ = lambda x : x
-    if location:
-    	return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Retain"), _("Constant")]
-    return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Retain"), _("Constant")]
-
-def GetAlternativeOptions():
-    _ = lambda x : x
-    return [_("Yes"), _("No")]
-ALTERNATIVE_OPTIONS_DICT = dict([(_(option), option) for option in GetAlternativeOptions()])
-
-def GetFilterChoiceTransfer():
-    _ = lambda x : x
-    return {_("All"): _("All"), _("Interface"): _("Interface"), 
-            _("   Input"): _("Input"), _("   Output"): _("Output"), _("   InOut"): _("InOut"), 
-            _("   External"): _("External"), _("Variables"): _("Variables"), _("   Local"): _("Local"),
-            _("   Temp"): _("Temp"), _("Global"): _("Global")}#, _("Access") : _("Access")}
-VARIABLE_CLASSES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().itervalues()])
-
-class VariableTable(wx.grid.PyGridTableBase):
-    
-    """
-    A custom wx.grid.Grid Table using user supplied data
-    """
-    def __init__(self, parent, data, colnames):
-        # The base class must be initialized *first*
-        wx.grid.PyGridTableBase.__init__(self)
-        self.data = data
-        self.old_value = None
-        self.colnames = colnames
-        self.Errors = {}
-        self.Parent = parent
-        # XXX
-        # we need to store the row length and collength to
-        # see if the table has changed size
-        self._rows = self.GetNumberRows()
-        self._cols = self.GetNumberCols()
-    
-    def GetNumberCols(self):
-        return len(self.colnames)
-        
-    def GetNumberRows(self):
-        return len(self.data)
-
-    def GetColLabelValue(self, col, translate=True):
-        if col < len(self.colnames):
-            if translate:
-                return _(self.colnames[col])
-            return self.colnames[col]
-
-    def GetRowLabelValues(self, row, translate=True):
-        return row
-
-    def GetValue(self, row, col):
-        if row < self.GetNumberRows():
-            if col == 0:
-                return self.data[row]["Number"]
-            colname = self.GetColLabelValue(col, False)
-            value = str(self.data[row].get(colname, ""))
-            if colname in ["Class", "Retain", "Constant"]:
-                return _(value)
-            return value
-    
-    def SetValue(self, row, col, value):
-        if col < len(self.colnames):
-            colname = self.GetColLabelValue(col, False)
-            if colname == "Name":
-                self.old_value = self.data[row][colname]
-            elif colname == "Class":
-                value = VARIABLE_CLASSES_DICT[value]
-            elif colname in ["Retain", "Constant"]:
-                value = ALTERNATIVE_OPTIONS_DICT[value]
-            self.data[row][colname] = value
-    
-    def GetValueByName(self, row, colname):
-        if row < self.GetNumberRows():
-            return self.data[row].get(colname)
-
-    def SetValueByName(self, row, colname, value):
-        if row < self.GetNumberRows():
-            self.data[row][colname] = value
-
-    def GetOldValue(self):
-        return self.old_value
-    
-    def ResetView(self, grid):
-        """
-        (wx.grid.Grid) -> Reset the grid view.   Call this to
-        update the grid if rows and columns have been added or deleted
-        """
-        grid.BeginBatch()
-        for current, new, delmsg, addmsg in [
-            (self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED),
-            (self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED),
-        ]:
-            if new < current:
-                msg = wx.grid.GridTableMessage(self,delmsg,new,current-new)
-                grid.ProcessTableMessage(msg)
-            elif new > current:
-                msg = wx.grid.GridTableMessage(self,addmsg,new-current)
-                grid.ProcessTableMessage(msg)
-                self.UpdateValues(grid)
-        grid.EndBatch()
-
-        self._rows = self.GetNumberRows()
-        self._cols = self.GetNumberCols()
-        # update the column rendering scheme
-        self._updateColAttrs(grid)
-
-        # update the scrollbars and the displayed part of the grid
-        grid.AdjustScrollbars()
-        grid.ForceRefresh()
-
-    def UpdateValues(self, grid):
-        """Update all displayed values"""
-        # This sends an event to the grid table to update all of the values
-        msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
-        grid.ProcessTableMessage(msg)
-
-    def _updateColAttrs(self, grid):
-        """
-        wx.grid.Grid -> update the column attributes to add the
-        appropriate renderer given the column name.
-
-        Otherwise default to the default renderer.
-        """
-        
-        for row in range(self.GetNumberRows()):
             grid.SetRowMinimalHeight(row, 28)
             grid.AutoSizeRow(row, False)
-            for col in range(self.GetNumberCols()):
-                editor = None
-                renderer = None
-                colname = self.GetColLabelValue(col, False)
-                if col != 0 and self.GetValueByName(row, "Edit"):
-                    grid.SetReadOnly(row, col, False)
-                    if colname == "Name":
-                        if self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]:
-                            grid.SetReadOnly(row, col, True)
-                        else:
-                            editor = wx.grid.GridCellTextEditor()
-                            renderer = wx.grid.GridCellStringRenderer()
-                    elif colname == "Initial Value":
-                        editor = wx.grid.GridCellTextEditor()
-                        renderer = wx.grid.GridCellStringRenderer()
-                    elif colname == "Location":
-                        if self.GetValueByName(row, "Class") in ["Local", "Global"]:
-                            editor = wx.grid.GridCellTextEditor()
-                            renderer = wx.grid.GridCellStringRenderer()
-                        else:
-                            grid.SetReadOnly(row, col, True)
-                    elif colname == "Class":
-                        if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]:
-                            grid.SetReadOnly(row, col, True)
-                        else:
-                            editor = wx.grid.GridCellChoiceEditor()
-                            excluded = []
-                            if self.Parent.PouIsUsed:
-                                excluded.extend(["Input","Output","InOut"])
-                            if self.Parent.IsFunctionBlockType(self.data[row]["Type"]):
-                                excluded.extend(["Local","Temp"])
-                            editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded]))
-                    elif colname in ["Retain", "Constant"]:
-                        editor = wx.grid.GridCellChoiceEditor()
-                        editor.SetParameters(",".join(map(_, self.Parent.OptionList)))
-                    elif colname == "Type":
-                        editor = wx.grid.GridCellTextEditor()
-                else:
-                    grid.SetReadOnly(row, col, True)
-                
-                grid.SetCellEditor(row, col, editor)
-                grid.SetCellRenderer(row, col, renderer)
-                
-                if row in self.Errors and self.Errors[row][0] == colname.lower():
-                    grid.SetCellBackgroundColour(row, col, wx.Colour(255, 255, 0))
-                    grid.SetCellTextColour(row, col, wx.RED)
-                    grid.MakeCellVisible(row, col)
-                else:
-                    grid.SetCellTextColour(row, col, wx.BLACK)
-                    grid.SetCellBackgroundColour(row, col, wx.WHITE)
-    
-    def SetData(self, data):
-        self.data = data
-    
-    def GetData(self):
-        return self.data
-    
-    def GetCurrentIndex(self):
-        return self.CurrentIndex
-    
-    def SetCurrentIndex(self, index):
-        self.CurrentIndex = index
-    
-    def AppendRow(self, row_content):
-        self.data.append(row_content)
-
-    def RemoveRow(self, row_index):
-        self.data.pop(row_index)
-
-    def GetRow(self, row_index):
-        return self.data[row_index]
-
-    def Empty(self):
-        self.data = []
-        self.editors = []
-
-    def AddError(self, infos):
-        self.Errors[infos[0]] = infos[1:]
-
-    def ClearErrors(self):
-        self.Errors = {}
-
-class VariableDropTarget(wx.TextDropTarget):
-    
-    def __init__(self, parent):
-        wx.TextDropTarget.__init__(self)
-        self.ParentWindow = parent
-    
-    def OnDropText(self, x, y, data):
-        x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y)
-        col = self.ParentWindow.VariablesGrid.XToCol(x)
-        row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize())
-        if col != wx.NOT_FOUND and row != wx.NOT_FOUND:
-            if self.ParentWindow.Table.GetColLabelValue(col, False) != "Location":
-                return
-            message = None
-            if not self.ParentWindow.Table.GetValueByName(row, "Edit"):
-                message = _("Can't affect a location to a function block instance")
-            elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]:
-                message = _("Can affect a location only to local or global variables")
-            else:
-                try:
-                    values = eval(data)    
-                except:
-                    message = _("Invalid value \"%s\" for location")%data
-                    values = None
-                if not isinstance(values, TupleType):
-                    message = _("Invalid value \"%s\" for location")%data
-                    values = None
-                if values is not None and values[1] == "location":
-                    location = values[0]
-                    variable_type = self.ParentWindow.Table.GetValueByName(row, "Type")
-                    base_type = self.ParentWindow.Controler.GetBaseType(variable_type)
-                    message = None
-                    if location.startswith("%"):
-                        if base_type != values[2]:
-                            message = _("Incompatible data types between \"%s\" and \"%s\"")%(values[2], variable_type)
-                        else:
-                            self.ParentWindow.Table.SetValue(row, col, location)
-                            self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
-                            self.ParentWindow.SaveValues()
-                    else:
-                        if location[0].isdigit() and base_type != "BOOL":
-                            message = _("Incompatible size of data between \"%s\" and \"BOOL\"")%location
-                        elif location[0] not in LOCATIONDATATYPES:
-                            message = _("Unrecognized data size \"%s\"")%location[0]
-                        elif base_type not in LOCATIONDATATYPES[location[0]]:
-                            message = _("Incompatible size of data between \"%s\" and \"%s\"")%(location, variable_type)
-                        else:
-                            dialog = wx.SingleChoiceDialog(self.ParentWindow, _("Select a variable class:"), _("Variable class"), ["Input", "Output", "Memory"], wx.OK|wx.CANCEL)
-                            if dialog.ShowModal() == wx.ID_OK:
-                                selected = dialog.GetSelection()
-                                if selected == 0:
-                                    location = "%I" + location
-                                elif selected == 1:
-                                    location = "%Q" + location
-                                else:
-                                    location = "%M" + location
-                                self.ParentWindow.Table.SetValue(row, col, location)
-                                self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
-                                self.ParentWindow.SaveValues()
-                            dialog.Destroy()
-            if message is not None:
-                wx.CallAfter(self.ShowMessage, message)
-            
-    def ShowMessage(self, message):
-        message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
-        message.ShowModal()
-        message.Destroy()
-
-[ID_VARIABLEEDITORPANEL, ID_VARIABLEEDITORPANELVARIABLESGRID, 
- ID_VARIABLEEDITORCONTROLPANEL, ID_VARIABLEEDITORPANELRETURNTYPE, 
- ID_VARIABLEEDITORPANELCLASSFILTER, ID_VARIABLEEDITORPANELADDBUTTON, 
- ID_VARIABLEEDITORPANELDELETEBUTTON, ID_VARIABLEEDITORPANELUPBUTTON, 
- ID_VARIABLEEDITORPANELDOWNBUTTON, ID_VARIABLEEDITORPANELSTATICTEXT1, 
- ID_VARIABLEEDITORPANELSTATICTEXT2, ID_VARIABLEEDITORPANELSTATICTEXT3,
-] = [wx.NewId() for _init_ctrls in range(12)]
-
-class VariablePanel(wx.Panel):
-    
-    if wx.VERSION < (2, 6, 0):
-        def Bind(self, event, function, id = None):
-            if id is not None:
-                event(self, id, function)
-            else:
-                event(self, function)
-    
-    def _init_coll_MainSizer_Items(self, parent):
-        parent.AddWindow(self.VariablesGrid, 0, border=0, flag=wx.GROW)
-        parent.AddWindow(self.ControlPanel, 0, border=5, flag=wx.GROW|wx.ALL)
-    
-    def _init_coll_MainSizer_Growables(self, parent):
-        parent.AddGrowableCol(0)
-        parent.AddGrowableRow(0)
-    
-    def _init_coll_ControlPanelSizer_Items(self, parent):
-        parent.AddSizer(self.ChoicePanelSizer, 0, border=0, flag=wx.GROW)
-        parent.AddSizer(self.ButtonPanelSizer, 0, border=0, flag=wx.ALIGN_CENTER)
-
-    def _init_coll_ControlPanelSizer_Growables(self, parent):
-        parent.AddGrowableCol(0)
-        parent.AddGrowableRow(0)
-        parent.AddGrowableRow(1)
-
-    def _init_coll_ChoicePanelSizer_Items(self, parent):
-        parent.AddWindow(self.staticText1, 0, border=0, flag=wx.ALIGN_BOTTOM)
-        parent.AddWindow(self.ReturnType, 0, border=0, flag=0)
-        parent.AddWindow(self.staticText2, 0, border=0, flag=wx.ALIGN_BOTTOM)
-        parent.AddWindow(self.ClassFilter, 0, border=0, flag=0)
-
-    def _init_coll_ButtonPanelSizer_Items(self, parent):
-        parent.AddWindow(self.UpButton, 0, border=0, flag=0)
-        parent.AddWindow(self.AddButton, 0, border=0, flag=0)
-        parent.AddWindow(self.DownButton, 0, border=0, flag=0)
-        parent.AddWindow(self.DeleteButton, 0, border=0, flag=0)
-        
-    def _init_coll_ButtonPanelSizer_Growables(self, parent):
-        parent.AddGrowableCol(0)
-        parent.AddGrowableCol(1)
-        parent.AddGrowableCol(2)
-        parent.AddGrowableCol(3)
-        parent.AddGrowableRow(0)
-
-    def _init_sizers(self):
-        self.MainSizer = wx.FlexGridSizer(cols=2, hgap=10, rows=1, vgap=0)
-        self.ControlPanelSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
-        self.ChoicePanelSizer = wx.GridSizer(cols=1, hgap=5, rows=4, vgap=5)
-        self.ButtonPanelSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=5)
-        
-        self._init_coll_MainSizer_Items(self.MainSizer)
-        self._init_coll_MainSizer_Growables(self.MainSizer)
-        self._init_coll_ControlPanelSizer_Items(self.ControlPanelSizer)
-        self._init_coll_ControlPanelSizer_Growables(self.ControlPanelSizer)
-        self._init_coll_ChoicePanelSizer_Items(self.ChoicePanelSizer)
-        self._init_coll_ButtonPanelSizer_Items(self.ButtonPanelSizer)
-        self._init_coll_ButtonPanelSizer_Growables(self.ButtonPanelSizer)
-        
-        self.SetSizer(self.MainSizer)
-        self.ControlPanel.SetSizer(self.ControlPanelSizer)
-
-    def _init_ctrls(self, prnt):
-        wx.Panel.__init__(self, id=ID_VARIABLEEDITORPANEL,
-              name='VariableEditorPanel', parent=prnt, pos=wx.Point(0, 0),
-              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
-
-        self.VariablesGrid = wx.grid.Grid(id=ID_VARIABLEEDITORPANELVARIABLESGRID,
-              name='VariablesGrid', parent=self, pos=wx.Point(0, 0), 
-              size=wx.Size(0, 0), style=wx.VSCROLL)
-        self.VariablesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
-              'Sans'))
-        self.VariablesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
-              False, 'Sans'))
-        self.VariablesGrid.SetSelectionBackground(wx.WHITE)
-        self.VariablesGrid.SetSelectionForeground(wx.BLACK)
-        if wx.VERSION >= (2, 6, 0):
-            self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange)
-            self.VariablesGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnVariablesGridSelectCell)
-            self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick)
-            self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown)
-            #self.VariablesGrid.Bind(wx.EVT_KEY_DOWN, self.OnChar)
-        else:
-            wx.grid.EVT_GRID_CELL_CHANGE(self.VariablesGrid, self.OnVariablesGridCellChange)
-            wx.grid.EVT_GRID_SELECT_CELL(self.VariablesGrid, self.OnVariablesGridSelectCell)
-            wx.grid.EVT_GRID_CELL_LEFT_CLICK(self.VariablesGrid, self.OnVariablesGridCellLeftClick)
-            wx.grid.EVT_GRID_EDITOR_SHOWN(self.VariablesGrid, self.OnVariablesGridEditorShown)
-            #wx.EVT_KEY_DOWN(self.VariablesGrid, self.OnChar)
-        self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
-        
-        self.ControlPanel = wx.ScrolledWindow(id=ID_VARIABLEEDITORCONTROLPANEL,
-              name='ControlPanel', parent=self, pos=wx.Point(0, 0),
-              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
-        self.ControlPanel.SetScrollRate(0, 10)
-        
-        self.staticText1 = wx.StaticText(id=ID_VARIABLEEDITORPANELSTATICTEXT1,
-              label=_('Return Type:'), name='staticText1', parent=self.ControlPanel,
-              pos=wx.Point(0, 0), size=wx.Size(145, 17), style=0)
-
-        self.ReturnType = wx.ComboBox(id=ID_VARIABLEEDITORPANELRETURNTYPE,
-              name='ReturnType', parent=self.ControlPanel, pos=wx.Point(0, 0),
-              size=wx.Size(145, 28), style=wx.CB_READONLY)
-        self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, id=ID_VARIABLEEDITORPANELRETURNTYPE)
-
-        self.staticText2 = wx.StaticText(id=ID_VARIABLEEDITORPANELSTATICTEXT2,
-              label=_('Class Filter:'), name='staticText2', parent=self.ControlPanel,
-              pos=wx.Point(0, 0), size=wx.Size(145, 17), style=0)
-
-        self.ClassFilter = wx.ComboBox(id=ID_VARIABLEEDITORPANELCLASSFILTER,
-              name='ClassFilter', parent=self.ControlPanel, pos=wx.Point(0, 0),
-              size=wx.Size(145, 28), style=wx.CB_READONLY)
-        self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, id=ID_VARIABLEEDITORPANELCLASSFILTER)
-
-        self.AddButton = wx.Button(id=ID_VARIABLEEDITORPANELADDBUTTON, label=_('Add'),
-              name='AddButton', parent=self.ControlPanel, pos=wx.Point(0, 0),
-              size=wx.DefaultSize, style=0)
-        self.Bind(wx.EVT_BUTTON, self.OnAddButton, id=ID_VARIABLEEDITORPANELADDBUTTON)
-
-        self.DeleteButton = wx.Button(id=ID_VARIABLEEDITORPANELDELETEBUTTON, label=_('Delete'),
-              name='DeleteButton', parent=self.ControlPanel, pos=wx.Point(0, 0),
-              size=wx.DefaultSize, style=0)
-        self.Bind(wx.EVT_BUTTON, self.OnDeleteButton, id=ID_VARIABLEEDITORPANELDELETEBUTTON)
-
-        self.UpButton = wx.Button(id=ID_VARIABLEEDITORPANELUPBUTTON, label='^',
-              name='UpButton', parent=self.ControlPanel, pos=wx.Point(0, 0),
-              size=wx.Size(32, 32), style=0)
-        self.Bind(wx.EVT_BUTTON, self.OnUpButton, id=ID_VARIABLEEDITORPANELUPBUTTON)
-
-        self.DownButton = wx.Button(id=ID_VARIABLEEDITORPANELDOWNBUTTON, label='v',
-              name='DownButton', parent=self.ControlPanel, pos=wx.Point(0, 0),
-              size=wx.Size(32, 32), style=0)
-        self.Bind(wx.EVT_BUTTON, self.OnDownButton, id=ID_VARIABLEEDITORPANELDOWNBUTTON)
-
-        self._init_sizers()
-
-    def __init__(self, parent, window, controler, element_type):
-        self._init_ctrls(parent)
-        self.ParentWindow = window
-        self.Controler = controler
-        self.ElementType = element_type
-        
-        self.Filter = "All"
-        self.FilterChoices = []
-        self.FilterChoiceTransfer = GetFilterChoiceTransfer()
-        
-        if element_type in ["config", "resource"]:
-            self.DefaultTypes = {"All" : "Global"}
-            self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No", "Edit" : True}
-        else:
-            self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"}
-            self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No", "Edit" : True}
-        if element_type in ["config", "resource"] or element_type in ["program", "transition", "action"]:
-            self.Table = VariableTable(self, [], GetVariableTableColnames(True))
-            if element_type not in ["config", "resource"]:
-                self.FilterChoices = ["All", "Interface", "   Input", "   Output", "   InOut", "   External", "Variables", "   Local", "   Temp"]#,"Access"]
-            else:
-                self.FilterChoices = ["All", "Global"]#,"Access"]
-            self.ColSizes = [40, 80, 70, 80, 80, 80, 60, 70]
-            self.ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_CENTER]
-        else:
-            self.Table = VariableTable(self, [], GetVariableTableColnames(False))
-            if element_type == "function":
-                self.FilterChoices = ["All", "Interface", "   Input", "   Output", "   InOut", "Variables", "   Local", "   Temp"]
-            else:
-                self.FilterChoices = ["All", "Interface", "   Input", "   Output", "   InOut", "   External", "Variables", "   Local", "   Temp"]
-            self.ColSizes = [40, 120, 70, 80, 120, 60, 70]
-            self.ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_CENTER]
-        for choice in self.FilterChoices:
-            self.ClassFilter.Append(_(choice))
-        reverse_transfer = {}
-        for filter, choice in self.FilterChoiceTransfer.items():
-            reverse_transfer[choice] = filter
-        self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
-        self.RefreshTypeList()
-
-        self.OptionList = GetAlternativeOptions()
-        
-        if element_type == "function":
-            for base_type in self.Controler.GetBaseTypes():
-                self.ReturnType.Append(base_type)
-            self.ReturnType.Enable(True)
-        else:
-            self.ReturnType.Enable(False)
-            self.staticText1.Hide()
-            self.ReturnType.Hide()
-            
-        self.VariablesGrid.SetTable(self.Table)
-        self.VariablesGrid.SetRowLabelSize(0)
-        for col in range(self.Table.GetNumberCols()):
-            attr = wx.grid.GridCellAttr()
-            attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
-            self.VariablesGrid.SetColAttr(col, attr)
-            self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col])
-            self.VariablesGrid.AutoSizeColumn(col, False)
-    
-    def SetTagName(self, tagname):
-        self.TagName = tagname
-    
-    def IsFunctionBlockType(self, name):
-        bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
-        pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
-        if poutype != "function" and bodytype in ["ST", "IL"]:
-            return False
-        else:
-            return name in self.Controler.GetFunctionBlockTypes(self.TagName)
-    
-    def RefreshView(self):
-        self.PouNames = self.Controler.GetProjectPouNames()
-        
-        words = self.TagName.split("::")
-        if self.ElementType == "config":
-            self.PouIsUsed = False
-            returnType = None
-            self.Values = self.Controler.GetConfigurationGlobalVars(words[1])
-        elif self.ElementType == "resource":
-            self.PouIsUsed = False
-            returnType = None
-            self.Values = self.Controler.GetConfigurationResourceGlobalVars(words[1], words[2])
-        else:
-            self.PouIsUsed = self.Controler.PouIsUsed(words[1])
-            returnType = self.Controler.GetEditedElementInterfaceReturnType(self.TagName)
-            self.Values = self.Controler.GetEditedElementInterfaceVars(self.TagName)
-        
-        if returnType and self.ReturnType.IsEnabled():
-            self.ReturnType.SetStringSelection(returnType)
-        
-        self.RefreshValues()
-        self.RefreshButtons()
-    
-    def OnReturnTypeChanged(self, event):
-        words = self.TagName.split("::")
-        self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection())
-        self.Controler.BufferProject()
-        self.ParentWindow.RefreshEditor(variablepanel = False)
-        self.ParentWindow._Refresh(TITLE, EDITMENU, INSTANCESTREE, LIBRARYTREE)
-        event.Skip()
-    
-    def OnClassFilter(self, event):
-        self.Filter = self.FilterChoiceTransfer[self.ClassFilter.GetStringSelection()]
-        self.RefreshTypeList()
-        self.RefreshValues()
-        self.RefreshButtons()
-        event.Skip()
-
-    def RefreshTypeList(self):
-        if self.Filter == "All":
-            self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All","Interface","Variables"]]
-        elif self.Filter == "Interface":
-            self.ClassList = ["Input","Output","InOut","External"]
-        elif self.Filter == "Variables":
-            self.ClassList = ["Local","Temp"]
-        else:
-            self.ClassList = [self.Filter]
-
-    def RefreshButtons(self):
-        if getattr(self, "Table", None):
-            table_length = len(self.Table.data)
-            row_class = None
-            row_edit = True
-            if table_length > 0:
-                row = self.VariablesGrid.GetGridCursorRow()
-                row_edit = self.Table.GetValueByName(row, "Edit")
-                if self.PouIsUsed:
-                    row_class = self.Table.GetValueByName(row, "Class")
-            self.AddButton.Enable(not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"])
-            self.DeleteButton.Enable(table_length > 0 and row_edit and row_class not in ["Input", "Output", "InOut"])
-            self.UpButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"])
-            self.DownButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"])
-
-    def OnAddButton(self, event):
-        new_row = self.DefaultValue.copy()
-        if self.Filter in self.DefaultTypes:
-            new_row["Class"] = self.DefaultTypes[self.Filter]
-        else:
-            new_row["Class"] = self.Filter
-        if self.Filter == "All" and len(self.Values) > 0:
-            row_index = self.VariablesGrid.GetGridCursorRow() + 1
-            self.Values.insert(row_index, new_row)
-        else:
-            row_index = -1
-            self.Values.append(new_row)
-        self.SaveValues()
-        self.RefreshValues(row_index)
-        self.RefreshButtons()
-        event.Skip()
-
-    def OnDeleteButton(self, event):
-        row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow())
-        self.Values.remove(row)
-        self.SaveValues()
-        self.RefreshValues()
-        self.RefreshButtons()
-        event.Skip()
-
-    def OnUpButton(self, event):
-        self.MoveValue(self.VariablesGrid.GetGridCursorRow(), -1)
-        self.RefreshButtons()
-        event.Skip()
-
-    def OnDownButton(self, event):
-        self.MoveValue(self.VariablesGrid.GetGridCursorRow(), 1)
-        self.RefreshButtons()
-        event.Skip()
-
-    def OnVariablesGridCellChange(self, event):
-        row, col = event.GetRow(), event.GetCol()
-        colname = self.Table.GetColLabelValue(col, False)
-        value = self.Table.GetValue(row, col)
-        if colname == "Name" and value != "":
-            if not TestIdentifier(value):
-                message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
-                message.ShowModal()
-                message.Destroy()
-                event.Veto()
-            elif value.upper() in IEC_KEYWORDS:
-                message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
-                message.ShowModal()
-                message.Destroy()
-                event.Veto()
-            elif value.upper() in self.PouNames:
-                message = wx.MessageDialog(self, _("A pou with \"%s\" as name exists!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
-                message.ShowModal()
-                message.Destroy()
-                event.Veto()
-            elif value.upper() in [var["Name"].upper() for var in self.Values if var != self.Table.data[row]]:
-                message = wx.MessageDialog(self, _("A variable with \"%s\" as name already exists in this pou!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
-                message.ShowModal()
-                message.Destroy()
-                event.Veto()
-            else:
-                self.SaveValues(False)
-                old_value = self.Table.GetOldValue()
-                if old_value != "":
-                    self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value)
-                self.Controler.BufferProject()
-                self.ParentWindow.RefreshEditor(variablepanel = False)
-                self.ParentWindow._Refresh(TITLE, EDITMENU, INSTANCESTREE, LIBRARYTREE)
-                event.Skip()
-        else:
-            self.SaveValues()
-            if colname == "Class":
-                self.Table.ResetView(self.VariablesGrid)
-            event.Skip()
-    
-    def OnVariablesGridEditorShown(self, event):
-        row, col = event.GetRow(), event.GetCol() 
-        classtype = self.Table.GetValueByName(row, "Class")
-        if self.Table.GetColLabelValue(col) == "Type":
-            type_menu = wx.Menu(title='')
-            base_menu = wx.Menu(title='')
-            for base_type in self.Controler.GetBaseTypes():
-                new_id = wx.NewId()
-                AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
-                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id)
-            type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu)
-            datatype_menu = wx.Menu(title='')
-            for datatype in self.Controler.GetDataTypes(basetypes = False):
-                new_id = wx.NewId()
-                AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
-                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id)
-            type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu)
-            functionblock_menu = wx.Menu(title='')
-            bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
-            pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
-            if classtype in ["Input","Output","InOut","External","Global"] or poutype != "function" and bodytype in ["ST", "IL"]:
-                for functionblock_type in self.Controler.GetFunctionBlockTypes(self.TagName):
-                    new_id = wx.NewId()
-                    AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type)
-                    self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id)
-                type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu)
-            rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
-            self.VariablesGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize())
-            event.Veto()
-        else:
-            event.Skip()
-    
-    def GetVariableTypeFunction(self, base_type):
-        def VariableTypeFunction(event):
-            row = self.VariablesGrid.GetGridCursorRow()
-            self.Table.SetValueByName(row, "Type", base_type)
-            self.Table.ResetView(self.VariablesGrid)
-            self.SaveValues(False)
-            self.ParentWindow.RefreshEditor(variablepanel = False)
-            self.Controler.BufferProject()
-            self.ParentWindow._Refresh(TITLE, EDITMENU, INSTANCESTREE, LIBRARYTREE)
-            event.Skip()
-        return VariableTypeFunction
-    
-    def OnVariablesGridCellLeftClick(self, event):
-        row = event.GetRow()
-        if event.GetCol() == 0 and self.Table.GetValueByName(row, "Edit"):
-            row = event.GetRow()
-            var_name = self.Table.GetValueByName(row, "Name")
-            var_class = self.Table.GetValueByName(row, "Class")
-            var_type = self.Table.GetValueByName(row, "Type")
-            data = wx.TextDataObject(str((var_name, var_class, var_type, self.TagName)))
-            dragSource = wx.DropSource(self.VariablesGrid)
-            dragSource.SetData(data)
-            dragSource.DoDragDrop()
-        event.Skip()
-    
-    def OnVariablesGridSelectCell(self, event):
-        wx.CallAfter(self.RefreshButtons)
-        event.Skip()
-
-    def OnChar(self, event):
-        keycode = event.GetKeyCode()
-        if keycode == wx.WXK_DELETE:
-            row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow())
-            self.Values.remove(row)
-            self.SaveValues()
-            self.RefreshValues()
-            self.RefreshButtons()
-        event.Skip()
-
-    def MoveValue(self, value_index, move):
-        new_index = max(0, min(value_index + move, len(self.Values) - 1))
-        if new_index != value_index:
-            self.Values.insert(new_index, self.Values.pop(value_index))
-            self.SaveValues()
-            self.RefreshValues()
-            self.VariablesGrid.SetGridCursor(new_index, self.VariablesGrid.GetGridCursorCol())
-        
-    def RefreshValues(self, select=0):
-        if len(self.Table.data) > 0:
-            self.VariablesGrid.SetGridCursor(0, 1)
-        data = []
-        for num, variable in enumerate(self.Values):
-            if variable["Class"] in self.ClassList:
-                variable["Number"] = num + 1
-                data.append(variable)
-        self.Table.SetData(data)
-        if len(self.Table.data) > 0:
-            if select == -1:
-                select = len(self.Table.data) - 1
-            self.VariablesGrid.SetGridCursor(select, 1)
-            self.VariablesGrid.MakeCellVisible(select, 1)
-        self.Table.ResetView(self.VariablesGrid)
-
-    def SaveValues(self, buffer = True):
-        words = self.TagName.split("::")
-        if self.ElementType == "config":
-            self.Controler.SetConfigurationGlobalVars(words[1], self.Values)
-        elif self.ElementType == "resource":
-            self.Controler.SetConfigurationResourceGlobalVars(words[1], words[2], self.Values)
-        else:
-            if self.ReturnType.IsEnabled():
-                self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection())
-            self.Controler.SetPouInterfaceVars(words[1], self.Values)
-        if buffer:
-            self.Controler.BufferProject()
-            self.ParentWindow._Refresh(TITLE, EDITMENU, INSTANCESTREE, LIBRARYTREE)
-
-    def AddVariableError(self, infos):
-        if isinstance(infos[0], TupleType):
-            for i in xrange(*infos[0]):
-                self.Table.AddError((i,) + infos[1:])
-        else:
-            self.Table.AddError(infos)
-        self.Table.ResetView(self.VariablesGrid)
-
-    def ClearErrors(self):
-        self.Table.ClearErrors()
-        self.Table.ResetView(self.VariablesGrid)
-
-#-------------------------------------------------------------------------------
 #                            Debug Variables Panel
 #-------------------------------------------------------------------------------
 
@@ -4844,10 +4134,9 @@
         
         self._init_sizers()
     
-    def __init__(self, parent, controler):
+    def __init__(self, parent, producer):
         self._init_ctrls(parent)
-        DebugViewer.__init__(self, controler, True)
-        self.Controler = controler
+        DebugViewer.__init__(self, producer, True)
         self.HasNewData = False
         
         self.Table = DebugVariableTable(self, [], GetDebugVariablesTableColnames())
@@ -5027,9 +4316,9 @@
 
     dlg = wx.SingleChoiceDialog(None, 
         _("""
-An error happens.
-
-Click on OK for saving an error report.
+An error has occurred.
+
+Click OK to save an error report.
 
 Please contact LOLITech at:
 +33 (0)3 29 57 60 42
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VariablePanel.py	Tue Sep 22 09:56:02 2009 +0200
@@ -0,0 +1,1178 @@
+# -*- coding: utf-8 -*-
+
+#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
+#based on the plcopen standard. 
+#
+#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
+#
+#See COPYING file for copyrights details.
+#
+#This library is free software; you can redistribute it and/or
+#modify it under the terms of the GNU General Public
+#License as published by the Free Software Foundation; either
+#version 2.1 of the License, or (at your option) any later version.
+#
+#This library is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#General Public License for more details.
+#
+#You should have received a copy of the GNU General Public
+#License along with this library; if not, write to the Free Software
+#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import wx, wx.grid
+
+from types import TupleType
+
+from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS
+
+# Compatibility function for wx versions < 2.6
+def AppendMenu(parent, help, id, kind, text):
+    if wx.VERSION >= (2, 6, 0):
+        parent.Append(help=help, id=id, kind=kind, text=text)
+    else:
+        parent.Append(helpString=help, id=id, kind=kind, item=text)
+
+[TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, TYPESTREE, 
+ INSTANCESTREE, LIBRARYTREE, SCALING
+] = range(9)
+
+#-------------------------------------------------------------------------------
+#                            Variables Editor Panel
+#-------------------------------------------------------------------------------
+
+def GetVariableTableColnames(location):
+    _ = lambda x : x
+    if location:
+    	return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Retain"), _("Constant"), _("Documentation")]
+    return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Retain"), _("Constant"), _("Documentation")]
+
+def GetAlternativeOptions():
+    _ = lambda x : x
+    return [_("Yes"), _("No")]
+ALTERNATIVE_OPTIONS_DICT = dict([(_(option), option) for option in GetAlternativeOptions()])
+
+def GetFilterChoiceTransfer():
+    _ = lambda x : x
+    return {_("All"): _("All"), _("Interface"): _("Interface"), 
+            _("   Input"): _("Input"), _("   Output"): _("Output"), _("   InOut"): _("InOut"), 
+            _("   External"): _("External"), _("Variables"): _("Variables"), _("   Local"): _("Local"),
+            _("   Temp"): _("Temp"), _("Global"): _("Global")}#, _("Access") : _("Access")}
+VARIABLE_CLASSES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().itervalues()])
+
+class VariableTable(wx.grid.PyGridTableBase):
+    
+    """
+    A custom wx.grid.Grid Table using user supplied data
+    """
+    def __init__(self, parent, data, colnames):
+        # The base class must be initialized *first*
+        wx.grid.PyGridTableBase.__init__(self)
+        self.data = data
+        self.old_value = None
+        self.colnames = colnames
+        self.Errors = {}
+        self.Parent = parent
+        # XXX
+        # we need to store the row length and collength to
+        # see if the table has changed size
+        self._rows = self.GetNumberRows()
+        self._cols = self.GetNumberCols()
+    
+    def GetNumberCols(self):
+        return len(self.colnames)
+        
+    def GetNumberRows(self):
+        return len(self.data)
+
+    def GetColLabelValue(self, col, translate=True):
+        if col < len(self.colnames):
+            if translate:
+                return _(self.colnames[col])
+            return self.colnames[col]
+
+    def GetRowLabelValues(self, row, translate=True):
+        return row
+
+    def GetValue(self, row, col):
+        if row < self.GetNumberRows():
+            if col == 0:
+                return self.data[row]["Number"]
+            colname = self.GetColLabelValue(col, False)
+            value = str(self.data[row].get(colname, ""))
+            if colname in ["Class", "Retain", "Constant"]:
+                return _(value)
+            return value
+    
+    def SetValue(self, row, col, value):
+        if col < len(self.colnames):
+            colname = self.GetColLabelValue(col, False)
+            if colname == "Name":
+                self.old_value = self.data[row][colname]
+            elif colname == "Class":
+                value = VARIABLE_CLASSES_DICT[value]
+            elif colname in ["Retain", "Constant"]:
+                value = ALTERNATIVE_OPTIONS_DICT[value]
+            self.data[row][colname] = value
+    
+    def GetValueByName(self, row, colname):
+        if row < self.GetNumberRows():
+            return self.data[row].get(colname)
+
+    def SetValueByName(self, row, colname, value):
+        if row < self.GetNumberRows():
+            self.data[row][colname] = value
+
+    def GetOldValue(self):
+        return self.old_value
+    
+    def ResetView(self, grid):
+        """
+        (wx.grid.Grid) -> Reset the grid view.   Call this to
+        update the grid if rows and columns have been added or deleted
+        """
+        grid.BeginBatch()
+        for current, new, delmsg, addmsg in [
+            (self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED),
+            (self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED),
+        ]:
+            if new < current:
+                msg = wx.grid.GridTableMessage(self,delmsg,new,current-new)
+                grid.ProcessTableMessage(msg)
+            elif new > current:
+                msg = wx.grid.GridTableMessage(self,addmsg,new-current)
+                grid.ProcessTableMessage(msg)
+                self.UpdateValues(grid)
+        grid.EndBatch()
+
+        self._rows = self.GetNumberRows()
+        self._cols = self.GetNumberCols()
+        # update the column rendering scheme
+        self._updateColAttrs(grid)
+
+        # update the scrollbars and the displayed part of the grid
+        grid.AdjustScrollbars()
+        grid.ForceRefresh()
+
+    def UpdateValues(self, grid):
+        """Update all displayed values"""
+        # This sends an event to the grid table to update all of the values
+        msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
+        grid.ProcessTableMessage(msg)
+
+    def _updateColAttrs(self, grid):
+        """
+        wx.grid.Grid -> update the column attributes to add the
+        appropriate renderer given the column name.
+
+        Otherwise default to the default renderer.
+        """
+        
+        for row in range(self.GetNumberRows()):
+            for col in range(self.GetNumberCols()):
+                editor = None
+                renderer = None
+                colname = self.GetColLabelValue(col, False)
+                if col != 0 and self.GetValueByName(row, "Edit"):
+                    grid.SetReadOnly(row, col, False)
+                    if colname == "Name":
+                        if self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]:
+                            grid.SetReadOnly(row, col, True)
+                        else:
+                            editor = wx.grid.GridCellTextEditor()
+                            renderer = wx.grid.GridCellStringRenderer()
+                    elif colname == "Initial Value":
+                        editor = wx.grid.GridCellTextEditor()
+                        renderer = wx.grid.GridCellStringRenderer()
+                    elif colname == "Location":
+                        if self.GetValueByName(row, "Class") in ["Local", "Global"]:
+                            editor = LocationCellEditor(self.Parent)
+                            renderer = wx.grid.GridCellStringRenderer()
+                        else:
+                            grid.SetReadOnly(row, col, True)
+                    elif colname == "Class":
+                        if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]:
+                            grid.SetReadOnly(row, col, True)
+                        else:
+                            editor = wx.grid.GridCellChoiceEditor()
+                            excluded = []
+                            if self.Parent.PouIsUsed:
+                                excluded.extend(["Input","Output","InOut"])
+                            if self.Parent.IsFunctionBlockType(self.data[row]["Type"]):
+                                excluded.extend(["Local","Temp"])
+                            editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded]))
+                    elif colname in ["Retain", "Constant"]:
+                        editor = wx.grid.GridCellChoiceEditor()
+                        editor.SetParameters(",".join(map(_, self.Parent.OptionList)))
+                    elif colname == "Type":
+                        editor = wx.grid.GridCellTextEditor()
+                else:
+                    grid.SetReadOnly(row, col, True)
+                
+                grid.SetCellEditor(row, col, editor)
+                grid.SetCellRenderer(row, col, renderer)
+                
+                if row in self.Errors and self.Errors[row][0] == colname.lower():
+                    grid.SetCellBackgroundColour(row, col, wx.Colour(255, 255, 0))
+                    grid.SetCellTextColour(row, col, wx.RED)
+                    grid.MakeCellVisible(row, col)
+                else:
+                    grid.SetCellTextColour(row, col, wx.BLACK)
+                    grid.SetCellBackgroundColour(row, col, wx.WHITE)
+    
+    def SetData(self, data):
+        self.data = data
+    
+    def GetData(self):
+        return self.data
+    
+    def GetCurrentIndex(self):
+        return self.CurrentIndex
+    
+    def SetCurrentIndex(self, index):
+        self.CurrentIndex = index
+    
+    def AppendRow(self, row_content):
+        self.data.append(row_content)
+
+    def RemoveRow(self, row_index):
+        self.data.pop(row_index)
+
+    def GetRow(self, row_index):
+        return self.data[row_index]
+
+    def Empty(self):
+        self.data = []
+        self.editors = []
+
+    def AddError(self, infos):
+        self.Errors[infos[0]] = infos[1:]
+
+    def ClearErrors(self):
+        self.Errors = {}
+
+class VariableDropTarget(wx.TextDropTarget):
+    '''
+    This allows dragging a variable location from somewhere to the Location
+    column of a variable row.
+    
+    The drag source should be a TextDataObject containing a Python tuple like:
+        ('%ID0.0.0', 'location', 'REAL')
+    
+    c_ext/CFileEditor.py has an example of this (you can drag a C extension
+    variable to the Location column of the variable panel).
+    '''
+    def __init__(self, parent):
+        wx.TextDropTarget.__init__(self)
+        self.ParentWindow = parent
+    
+    def OnDropText(self, x, y, data):
+        x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y)
+        col = self.ParentWindow.VariablesGrid.XToCol(x)
+        row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize())
+        if col != wx.NOT_FOUND and row != wx.NOT_FOUND:
+            if self.ParentWindow.Table.GetColLabelValue(col, False) != "Location":
+                return
+            message = None
+            if not self.ParentWindow.Table.GetValueByName(row, "Edit"):
+                message = _("Can't give a location to a function block instance")
+            elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]:
+                message = _("Can only give a location to local or global variables")
+            else:
+                try:
+                    values = eval(data)    
+                except:
+                    message = _("Invalid value \"%s\" for location")%data
+                    values = None
+                if not isinstance(values, TupleType):
+                    message = _("Invalid value \"%s\" for location")%data
+                    values = None
+                if values is not None and values[1] == "location":
+                    location = values[0]
+                    variable_type = self.ParentWindow.Table.GetValueByName(row, "Type")
+                    base_type = self.ParentWindow.Controler.GetBaseType(variable_type)
+                    message = None
+                    if location.startswith("%"):
+                        if base_type != values[2]:
+                            message = _("Incompatible data types between \"%s\" and \"%s\"")%(values[2], variable_type)
+                        else:
+                            self.ParentWindow.Table.SetValue(row, col, location)
+                            self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
+                            self.ParentWindow.SaveValues()
+                    else:
+                        if location[0].isdigit() and base_type != "BOOL":
+                            message = _("Incompatible size of data between \"%s\" and \"BOOL\"")%location
+                        elif location[0] not in LOCATIONDATATYPES:
+                            message = _("Unrecognized data size \"%s\"")%location[0]
+                        elif base_type not in LOCATIONDATATYPES[location[0]]:
+                            message = _("Incompatible size of data between \"%s\" and \"%s\"")%(location, variable_type)
+                        else:
+                            dialog = wx.SingleChoiceDialog(self.ParentWindow, _("Select a variable class:"), _("Variable class"), ["Input", "Output", "Memory"], wx.OK|wx.CANCEL)
+                            if dialog.ShowModal() == wx.ID_OK:
+                                selected = dialog.GetSelection()
+                                if selected == 0:
+                                    location = "%I" + location
+                                elif selected == 1:
+                                    location = "%Q" + location
+                                else:
+                                    location = "%M" + location
+                                self.ParentWindow.Table.SetValue(row, col, location)
+                                self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
+                                self.ParentWindow.SaveValues()
+                            dialog.Destroy()
+            if message is not None:
+                wx.CallAfter(self.ShowMessage, message)
+            
+    def ShowMessage(self, message):
+        message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
+        message.ShowModal()
+        message.Destroy()
+
+[ID_VARIABLEEDITORPANEL, ID_VARIABLEEDITORPANELVARIABLESGRID, 
+ ID_VARIABLEEDITORCONTROLPANEL, ID_VARIABLEEDITORPANELRETURNTYPE, 
+ ID_VARIABLEEDITORPANELCLASSFILTER, ID_VARIABLEEDITORPANELADDBUTTON, 
+ ID_VARIABLEEDITORPANELDELETEBUTTON, ID_VARIABLEEDITORPANELUPBUTTON, 
+ ID_VARIABLEEDITORPANELDOWNBUTTON, ID_VARIABLEEDITORPANELSTATICTEXT1, 
+ ID_VARIABLEEDITORPANELSTATICTEXT2, ID_VARIABLEEDITORPANELSTATICTEXT3,
+] = [wx.NewId() for _init_ctrls in range(12)]
+
+class VariablePanel(wx.Panel):
+    
+    if wx.VERSION < (2, 6, 0):
+        def Bind(self, event, function, id = None):
+            if id is not None:
+                event(self, id, function)
+            else:
+                event(self, function)
+    
+    def _init_coll_MainSizer_Items(self, parent):
+        parent.AddWindow(self.VariablesGrid, 0, border=0, flag=wx.GROW)
+        parent.AddWindow(self.ControlPanel, 0, border=5, flag=wx.GROW|wx.ALL)
+    
+    def _init_coll_MainSizer_Growables(self, parent):
+        parent.AddGrowableCol(0)
+        parent.AddGrowableRow(0)
+    
+    def _init_coll_ControlPanelSizer_Items(self, parent):
+        parent.AddSizer(self.ChoicePanelSizer, 0, border=0, flag=wx.GROW)
+        parent.AddSizer(self.ButtonPanelSizer, 0, border=0, flag=wx.ALIGN_CENTER)
+
+    def _init_coll_ControlPanelSizer_Growables(self, parent):
+        parent.AddGrowableCol(0)
+        parent.AddGrowableRow(0)
+        parent.AddGrowableRow(1)
+
+    def _init_coll_ChoicePanelSizer_Items(self, parent):
+        parent.AddWindow(self.staticText1, 0, border=0, flag=wx.ALIGN_BOTTOM)
+        parent.AddWindow(self.ReturnType, 0, border=0, flag=0)
+        parent.AddWindow(self.staticText2, 0, border=0, flag=wx.ALIGN_BOTTOM)
+        parent.AddWindow(self.ClassFilter, 0, border=0, flag=0)
+
+    def _init_coll_ButtonPanelSizer_Items(self, parent):
+        parent.AddWindow(self.UpButton, 0, border=0, flag=0)
+        parent.AddWindow(self.AddButton, 0, border=0, flag=0)
+        parent.AddWindow(self.DownButton, 0, border=0, flag=0)
+        parent.AddWindow(self.DeleteButton, 0, border=0, flag=0)
+        
+    def _init_coll_ButtonPanelSizer_Growables(self, parent):
+        parent.AddGrowableCol(0)
+        parent.AddGrowableCol(1)
+        parent.AddGrowableCol(2)
+        parent.AddGrowableCol(3)
+        parent.AddGrowableRow(0)
+
+    def _init_sizers(self):
+        self.MainSizer = wx.FlexGridSizer(cols=2, hgap=10, rows=1, vgap=0)
+        self.ControlPanelSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
+        self.ChoicePanelSizer = wx.GridSizer(cols=1, hgap=5, rows=4, vgap=5)
+        self.ButtonPanelSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=5)
+        
+        self._init_coll_MainSizer_Items(self.MainSizer)
+        self._init_coll_MainSizer_Growables(self.MainSizer)
+        self._init_coll_ControlPanelSizer_Items(self.ControlPanelSizer)
+        self._init_coll_ControlPanelSizer_Growables(self.ControlPanelSizer)
+        self._init_coll_ChoicePanelSizer_Items(self.ChoicePanelSizer)
+        self._init_coll_ButtonPanelSizer_Items(self.ButtonPanelSizer)
+        self._init_coll_ButtonPanelSizer_Growables(self.ButtonPanelSizer)
+        
+        self.SetSizer(self.MainSizer)
+        self.ControlPanel.SetSizer(self.ControlPanelSizer)
+
+    def _init_ctrls(self, prnt):
+        wx.Panel.__init__(self, id=ID_VARIABLEEDITORPANEL,
+              name='VariableEditorPanel', parent=prnt, pos=wx.Point(0, 0),
+              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
+
+        self.VariablesGrid = wx.grid.Grid(id=ID_VARIABLEEDITORPANELVARIABLESGRID,
+              name='VariablesGrid', parent=self, pos=wx.Point(0, 0), 
+              size=wx.Size(0, 0), style=wx.VSCROLL)
+        self.VariablesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
+              'Sans'))
+        self.VariablesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
+              False, 'Sans'))
+        self.VariablesGrid.SetSelectionBackground(wx.WHITE)
+        self.VariablesGrid.SetSelectionForeground(wx.BLACK)
+        if wx.VERSION >= (2, 6, 0):
+            self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange)
+            self.VariablesGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnVariablesGridSelectCell)
+            self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick)
+            self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown)
+            #self.VariablesGrid.Bind(wx.EVT_KEY_DOWN, self.OnChar)
+        else:
+            wx.grid.EVT_GRID_CELL_CHANGE(self.VariablesGrid, self.OnVariablesGridCellChange)
+            wx.grid.EVT_GRID_SELECT_CELL(self.VariablesGrid, self.OnVariablesGridSelectCell)
+            wx.grid.EVT_GRID_CELL_LEFT_CLICK(self.VariablesGrid, self.OnVariablesGridCellLeftClick)
+            wx.grid.EVT_GRID_EDITOR_SHOWN(self.VariablesGrid, self.OnVariablesGridEditorShown)
+            #wx.EVT_KEY_DOWN(self.VariablesGrid, self.OnChar)
+        self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
+        
+        self.ControlPanel = wx.ScrolledWindow(id=ID_VARIABLEEDITORCONTROLPANEL,
+              name='ControlPanel', parent=self, pos=wx.Point(0, 0),
+              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
+        self.ControlPanel.SetScrollRate(0, 10)
+        
+        self.staticText1 = wx.StaticText(id=ID_VARIABLEEDITORPANELSTATICTEXT1,
+              label=_('Return Type:'), name='staticText1', parent=self.ControlPanel,
+              pos=wx.Point(0, 0), size=wx.Size(145, 17), style=0)
+
+        self.ReturnType = wx.ComboBox(id=ID_VARIABLEEDITORPANELRETURNTYPE,
+              name='ReturnType', parent=self.ControlPanel, pos=wx.Point(0, 0),
+              size=wx.Size(145, 28), style=wx.CB_READONLY)
+        self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, id=ID_VARIABLEEDITORPANELRETURNTYPE)
+
+        self.staticText2 = wx.StaticText(id=ID_VARIABLEEDITORPANELSTATICTEXT2,
+              label=_('Class Filter:'), name='staticText2', parent=self.ControlPanel,
+              pos=wx.Point(0, 0), size=wx.Size(145, 17), style=0)
+
+        self.ClassFilter = wx.ComboBox(id=ID_VARIABLEEDITORPANELCLASSFILTER,
+              name='ClassFilter', parent=self.ControlPanel, pos=wx.Point(0, 0),
+              size=wx.Size(145, 28), style=wx.CB_READONLY)
+        self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, id=ID_VARIABLEEDITORPANELCLASSFILTER)
+
+        self.AddButton = wx.Button(id=ID_VARIABLEEDITORPANELADDBUTTON, label=_('Add'),
+              name='AddButton', parent=self.ControlPanel, pos=wx.Point(0, 0),
+              size=wx.DefaultSize, style=0)
+        self.Bind(wx.EVT_BUTTON, self.OnAddButton, id=ID_VARIABLEEDITORPANELADDBUTTON)
+
+        self.DeleteButton = wx.Button(id=ID_VARIABLEEDITORPANELDELETEBUTTON, label=_('Delete'),
+              name='DeleteButton', parent=self.ControlPanel, pos=wx.Point(0, 0),
+              size=wx.DefaultSize, style=0)
+        self.Bind(wx.EVT_BUTTON, self.OnDeleteButton, id=ID_VARIABLEEDITORPANELDELETEBUTTON)
+
+        self.UpButton = wx.Button(id=ID_VARIABLEEDITORPANELUPBUTTON, label='^',
+              name='UpButton', parent=self.ControlPanel, pos=wx.Point(0, 0),
+              size=wx.Size(32, 32), style=0)
+        self.Bind(wx.EVT_BUTTON, self.OnUpButton, id=ID_VARIABLEEDITORPANELUPBUTTON)
+
+        self.DownButton = wx.Button(id=ID_VARIABLEEDITORPANELDOWNBUTTON, label='v',
+              name='DownButton', parent=self.ControlPanel, pos=wx.Point(0, 0),
+              size=wx.Size(32, 32), style=0)
+        self.Bind(wx.EVT_BUTTON, self.OnDownButton, id=ID_VARIABLEEDITORPANELDOWNBUTTON)
+
+        self._init_sizers()
+
+    def __init__(self, parent, window, controler, element_type):
+        self._init_ctrls(parent)
+        self.ParentWindow = window
+        self.Controler = controler
+        self.ElementType = element_type
+        
+        self.Filter = "All"
+        self.FilterChoices = []
+        self.FilterChoiceTransfer = GetFilterChoiceTransfer()
+        
+        self.DefaultValue = {   "Name" : "", "Class" : "", "Type" : "INT", "Location" : "",
+                                "Initial Value" : "", "Retain" : "No", "Constant" : "No",
+                                "Documentation" : "", "Edit" : True
+                            }
+
+        if element_type in ["config", "resource"]:
+            self.DefaultTypes = {"All" : "Global"}
+        else:
+            self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"}
+
+        if element_type in ["config", "resource"] \
+        or element_type in ["program", "transition", "action"]:
+            # this is an element that can have located variables
+            self.Table = VariableTable(self, [], GetVariableTableColnames(True))
+
+            if element_type in ["config", "resource"]:
+                self.FilterChoices = ["All", "Global"]#,"Access"]
+            else:
+                self.FilterChoices = ["All",
+                                        "Interface", "   Input", "   Output", "   InOut", "   External",
+                                        "Variables", "   Local", "   Temp"]#,"Access"]
+
+            # these condense the ColAlignements list
+            l = wx.ALIGN_LEFT
+            c = wx.ALIGN_CENTER 
+
+            #                      Num  Name    Class   Type    Loc     Init    Retain  Const   Doc
+            self.ColSizes       = [40,  80,     70,     80,     80,     80,     60,     70,     80]
+            self.ColAlignements = [c,   l,      l,      l,      l,      l,      c,      c,      l]
+
+        else:
+            # this is an element that cannot have located variables
+            self.Table = VariableTable(self, [], GetVariableTableColnames(False))
+
+            if element_type == "function":
+                self.FilterChoices = ["All",
+                                        "Interface", "   Input", "   Output", "   InOut",
+                                        "Variables", "   Local", "   Temp"]
+            else:
+                self.FilterChoices = ["All",
+                                        "Interface", "   Input", "   Output", "   InOut", "   External",
+                                        "Variables", "   Local", "   Temp"]
+
+            # these condense the ColAlignements list
+            l = wx.ALIGN_LEFT
+            c = wx.ALIGN_CENTER 
+
+            #                      Num  Name    Class   Type    Init    Retain  Const   Doc
+            self.ColSizes       = [40,  80,     70,     80,     80,     60,     70,     160]
+            self.ColAlignements = [c,   l,      l,      l,      l,      c,      c,      l]
+
+        for choice in self.FilterChoices:
+            self.ClassFilter.Append(_(choice))
+
+        reverse_transfer = {}
+        for filter, choice in self.FilterChoiceTransfer.items():
+            reverse_transfer[choice] = filter
+        self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
+        self.RefreshTypeList()
+
+        self.OptionList = GetAlternativeOptions()
+        
+        if element_type == "function":
+            for base_type in self.Controler.GetBaseTypes():
+                self.ReturnType.Append(base_type)
+            self.ReturnType.Enable(True)
+        else:
+            self.ReturnType.Enable(False)
+            self.staticText1.Hide()
+            self.ReturnType.Hide()
+            
+        self.VariablesGrid.SetTable(self.Table)
+        self.VariablesGrid.SetRowLabelSize(0)
+        for col in range(self.Table.GetNumberCols()):
+            attr = wx.grid.GridCellAttr()
+            attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
+            self.VariablesGrid.SetColAttr(col, attr)
+            self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col])
+            self.VariablesGrid.AutoSizeColumn(col, False)
+    
+    def SetTagName(self, tagname):
+        self.TagName = tagname
+    
+    def IsFunctionBlockType(self, name):
+        bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
+        pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
+        if poutype != "function" and bodytype in ["ST", "IL"]:
+            return False
+        else:
+            return name in self.Controler.GetFunctionBlockTypes(self.TagName)
+    
+    def RefreshView(self):
+        self.PouNames = self.Controler.GetProjectPouNames()
+        
+        words = self.TagName.split("::")
+        if self.ElementType == "config":
+            self.PouIsUsed = False
+            returnType = None
+            self.Values = self.Controler.GetConfigurationGlobalVars(words[1])
+        elif self.ElementType == "resource":
+            self.PouIsUsed = False
+            returnType = None
+            self.Values = self.Controler.GetConfigurationResourceGlobalVars(words[1], words[2])
+        else:
+            self.PouIsUsed = self.Controler.PouIsUsed(words[1])
+            returnType = self.Controler.GetEditedElementInterfaceReturnType(self.TagName)
+            self.Values = self.Controler.GetEditedElementInterfaceVars(self.TagName)
+        
+        if returnType and self.ReturnType.IsEnabled():
+            self.ReturnType.SetStringSelection(returnType)
+        
+        self.RefreshValues()
+        self.RefreshButtons()
+    
+    def OnReturnTypeChanged(self, event):
+        words = self.TagName.split("::")
+        self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection())
+        self.Controler.BufferProject()
+        self.ParentWindow.RefreshEditor(variablepanel = False)
+        self.ParentWindow._Refresh(TITLE, EDITMENU, INSTANCETREE, LIBRARYTREE)
+        event.Skip()
+    
+    def OnClassFilter(self, event):
+        self.Filter = self.FilterChoiceTransfer[self.ClassFilter.GetStringSelection()]
+        self.RefreshTypeList()
+        self.RefreshValues()
+        self.RefreshButtons()
+        event.Skip()
+
+    def RefreshTypeList(self):
+        if self.Filter == "All":
+            self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All","Interface","Variables"]]
+        elif self.Filter == "Interface":
+            self.ClassList = ["Input","Output","InOut","External"]
+        elif self.Filter == "Variables":
+            self.ClassList = ["Local","Temp"]
+        else:
+            self.ClassList = [self.Filter]
+
+    def RefreshButtons(self):
+        if getattr(self, "Table", None):
+            table_length = len(self.Table.data)
+            row_class = None
+            row_edit = True
+            if table_length > 0:
+                row = self.VariablesGrid.GetGridCursorRow()
+                row_edit = self.Table.GetValueByName(row, "Edit")
+                if self.PouIsUsed:
+                    row_class = self.Table.GetValueByName(row, "Class")
+            self.AddButton.Enable(not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"])
+            self.DeleteButton.Enable(table_length > 0 and row_edit and row_class not in ["Input", "Output", "InOut"])
+            self.UpButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"])
+            self.DownButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"])
+
+    def OnAddButton(self, event):
+        new_row = self.DefaultValue.copy()
+        if self.Filter in self.DefaultTypes:
+            new_row["Class"] = self.DefaultTypes[self.Filter]
+        else:
+            new_row["Class"] = self.Filter
+        if self.Filter == "All" and len(self.Values) > 0:
+            row_index = self.VariablesGrid.GetGridCursorRow() + 1
+            self.Values.insert(row_index, new_row)
+        else:
+            row_index = -1
+            self.Values.append(new_row)
+        self.SaveValues()
+        self.RefreshValues(row_index)
+        self.RefreshButtons()
+        event.Skip()
+
+    def OnDeleteButton(self, event):
+        row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow())
+        self.Values.remove(row)
+        self.SaveValues()
+        self.RefreshValues()
+        self.RefreshButtons()
+        event.Skip()
+
+    def OnUpButton(self, event):
+        self.MoveValue(self.VariablesGrid.GetGridCursorRow(), -1)
+        self.RefreshButtons()
+        event.Skip()
+
+    def OnDownButton(self, event):
+        self.MoveValue(self.VariablesGrid.GetGridCursorRow(), 1)
+        self.RefreshButtons()
+        event.Skip()
+
+    def OnVariablesGridCellChange(self, event):
+        row, col = event.GetRow(), event.GetCol()
+        colname = self.Table.GetColLabelValue(col, False)
+        value = self.Table.GetValue(row, col)
+
+        if colname == "Name" and value != "":
+            if not TestIdentifier(value):
+                message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
+                message.ShowModal()
+                message.Destroy()
+                event.Veto()
+            elif value.upper() in IEC_KEYWORDS:
+                message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
+                message.ShowModal()
+                message.Destroy()
+                event.Veto()
+            elif value.upper() in self.PouNames:
+                message = wx.MessageDialog(self, _("A pou with \"%s\" as name exists!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
+                message.ShowModal()
+                message.Destroy()
+                event.Veto()
+            elif value.upper() in [var["Name"].upper() for var in self.Values if var != self.Table.data[row]]:
+                message = wx.MessageDialog(self, _("A variable with \"%s\" as name already exists in this pou!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
+                message.ShowModal()
+                message.Destroy()
+                event.Veto()
+            else:
+                self.SaveValues(False)
+                old_value = self.Table.GetOldValue()
+                if old_value != "":
+                    self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value)
+                self.Controler.BufferProject()
+                self.ParentWindow.RefreshEditor(variablepanel = False)
+                self.ParentWindow._Refresh(TITLE, EDITMENU, INSTANCETREE, LIBRARYTREE)            
+                event.Skip()
+        else:
+            self.SaveValues()
+            if colname == "Class":
+                self.Table.ResetView(self.VariablesGrid)
+            event.Skip()
+    
+    def OnVariablesGridEditorShown(self, event):
+        row, col = event.GetRow(), event.GetCol() 
+
+        label_value = self.Table.GetColLabelValue(col)
+        if label_value == "Type":
+            type_menu = wx.Menu(title='')   # the root menu
+
+            # build a submenu containing standard IEC types
+            base_menu = wx.Menu(title='')
+            for base_type in self.Controler.GetBaseTypes():
+                new_id = wx.NewId()
+                AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
+                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id)
+
+            type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu)
+
+            # build a submenu containing user-defined types
+            datatype_menu = wx.Menu(title='')
+            datatypes = self.Controler.GetDataTypes(basetypes = False)
+            for datatype in datatypes:
+                new_id = wx.NewId()
+                AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
+                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id)
+
+            type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu)
+
+            # build a submenu containing function block types
+            bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
+            pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
+            classtype = self.Table.GetValueByName(row, "Class")
+
+            if classtype in ["Input", "Output", "InOut", "External", "Global"] or \
+            poutype != "function" and bodytype in ["ST", "IL"]:
+                functionblock_menu = wx.Menu(title='')
+                fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName)
+                for functionblock_type in fbtypes:
+                    new_id = wx.NewId()
+                    AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type)
+                    self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id)
+
+                type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu)
+
+            rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
+            corner_x = rect.x + rect.width
+            corner_y = rect.y + self.VariablesGrid.GetColLabelSize()
+
+            # pop up this new menu
+            self.VariablesGrid.PopupMenuXY(type_menu, corner_x, corner_y)
+            event.Veto()
+        else:
+            event.Skip()
+    
+    def GetVariableTypeFunction(self, base_type):
+        def VariableTypeFunction(event):
+            row = self.VariablesGrid.GetGridCursorRow()
+            self.Table.SetValueByName(row, "Type", base_type)
+            self.Table.ResetView(self.VariablesGrid)
+            self.SaveValues(False)
+            self.ParentWindow.RefreshEditor(variablepanel = False)
+            self.Controler.BufferProject()
+            self.ParentWindow._Refresh(TITLE, EDITMENU, INSTANCESTREE, LIBRARYTREE)            
+            event.Skip()
+        return VariableTypeFunction
+    
+    def OnVariablesGridCellLeftClick(self, event):
+        row = event.GetRow()
+        if event.GetCol() == 0 and self.Table.GetValueByName(row, "Edit"):
+            row = event.GetRow()
+            var_name = self.Table.GetValueByName(row, "Name")
+            var_class = self.Table.GetValueByName(row, "Class")
+            var_type = self.Table.GetValueByName(row, "Type")
+            data = wx.TextDataObject(str((var_name, var_class, var_type, self.TagName)))
+            dragSource = wx.DropSource(self.VariablesGrid)
+            dragSource.SetData(data)
+            dragSource.DoDragDrop()
+        event.Skip()
+    
+    def OnVariablesGridSelectCell(self, event):
+        wx.CallAfter(self.RefreshButtons)
+        event.Skip()
+
+    def OnChar(self, event):
+        keycode = event.GetKeyCode()
+        if keycode == wx.WXK_DELETE:
+            row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow())
+            self.Values.remove(row)
+            self.SaveValues()
+            self.RefreshValues()
+            self.RefreshButtons()
+        event.Skip()
+
+    def MoveValue(self, value_index, move):
+        new_index = max(0, min(value_index + move, len(self.Values) - 1))
+        if new_index != value_index:
+            self.Values.insert(new_index, self.Values.pop(value_index))
+            self.SaveValues()
+            self.RefreshValues()
+            self.VariablesGrid.SetGridCursor(new_index, self.VariablesGrid.GetGridCursorCol())
+        
+    def RefreshValues(self, select=0):
+        if len(self.Table.data) > 0:
+            self.VariablesGrid.SetGridCursor(0, 1)
+        data = []
+        for num, variable in enumerate(self.Values):
+            if variable["Class"] in self.ClassList:
+                variable["Number"] = num + 1
+                data.append(variable)
+        self.Table.SetData(data)
+        if len(self.Table.data) > 0:
+            if select == -1:
+                select = len(self.Table.data) - 1
+            self.VariablesGrid.SetGridCursor(select, 1)
+            self.VariablesGrid.MakeCellVisible(select, 1)
+        self.Table.ResetView(self.VariablesGrid)
+
+    def SaveValues(self, buffer = True):
+        words = self.TagName.split("::")
+        if self.ElementType == "config":
+            self.Controler.SetConfigurationGlobalVars(words[1], self.Values)
+        elif self.ElementType == "resource":
+            self.Controler.SetConfigurationResourceGlobalVars(words[1], words[2], self.Values)
+        else:
+            if self.ReturnType.IsEnabled():
+                self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection())
+            self.Controler.SetPouInterfaceVars(words[1], self.Values)
+        if buffer:
+            self.Controler.BufferProject()
+            self.ParentWindow._Refresh(TITLE, EDITMENU, INSTANCESTREE, LIBRARYTREE)            
+
+    def AddVariableError(self, infos):
+        if isinstance(infos[0], TupleType):
+            for i in xrange(*infos[0]):
+                self.Table.AddError((i,) + infos[1:])
+        else:
+            self.Table.AddError(infos)
+        self.Table.ResetView(self.VariablesGrid)
+
+    def ClearErrors(self):
+        self.Table.ClearErrors()
+        self.Table.ResetView(self.VariablesGrid)
+
+class LocationCellControl(wx.PyControl):
+    '''
+    Custom cell editor control with a text box and a button that launches
+    the BrowseVariableLocationsDialog.
+    '''
+    def __init__(self, parent, var_panel):
+        wx.Control.__init__(self, parent, -1)
+        self.ParentWindow = parent
+        self.VarPanel = var_panel
+        self.Row = -1
+
+        self.Bind(wx.EVT_SIZE, self.OnSize)
+
+        # create text control
+        self.txt = wx.TextCtrl(self, -1, '', size=wx.Size(0, 0))
+
+        # create browse button
+        self.btn = wx.Button(self, -1, label='...', size=wx.Size(30, 0))
+        self.btn.Bind(wx.EVT_BUTTON, self.OnBtnBrowseClick)
+
+        self.Sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
+        self.Sizer.AddWindow(self.txt, 0, border=0, flag=wx.ALL|wx.GROW)
+        self.Sizer.AddWindow(self.btn, 0, border=0, flag=wx.ALL|wx.GROW)
+        self.Sizer.AddGrowableCol(0)
+        self.Sizer.AddGrowableRow(0)
+
+        self.SetSizer(self.Sizer)
+
+    def SetRow(self, row):
+        '''set the grid row that we're working on'''
+        self.Row = row
+
+    def OnSize(self, event):
+        '''resize the button and text control to fit'''
+        #overall_width = self.GetSize()[0]
+        #btn_width, btn_height = self.btn.GetSize()
+        #new_txt_width = overall_width - btn_width
+
+        #self.txt.SetSize(wx.Size(new_txt_width, -1))
+        #self.btn.SetDimensions(new_txt_width, -1, btn_width, btn_height)
+        self.Layout()
+
+    def OnBtnBrowseClick(self, event):
+        # pop up the location browser dialog
+        dia = BrowseVariableLocationsDialog(self.ParentWindow, self.VarPanel)
+        dia.ShowModal()
+
+        if dia.Selection:
+            loc, iec_type, doc = dia.Selection
+
+            # set the location
+            self.SetText(loc)
+
+            # set the variable type and documentation
+            # NOTE: this update won't be displayed until editing is complete
+            # (when EndEdit is called).
+            # we can't call VarPanel.RefreshValues() here because it causes
+            # an exception. 
+            self.VarPanel.Table.SetValueByName(self.Row, 'Type', iec_type)
+            self.VarPanel.Table.SetValueByName(self.Row, 'Documentation', doc)
+
+        self.txt.SetFocus()
+
+    def SetText(self, text):
+        self.txt.SetValue(text)
+
+    def SetInsertionPoint(self, i):
+        self.txt.SetInsertionPoint(i)
+
+    def GetText(self):
+        return self.txt.GetValue()
+
+    def SetFocus(self):
+        self.txt.SetFocus()
+
+class LocationCellEditor(wx.grid.PyGridCellEditor):
+    '''
+    Grid cell editor that uses LocationCellControl to display a browse button.
+    '''
+    def __init__(self, var_panel):
+        wx.grid.PyGridCellEditor.__init__(self)
+        self.VarPanel = var_panel
+
+    def Create(self, parent, id, evt_handler):
+        self.text_browse = LocationCellControl(parent, self.VarPanel)
+        self.SetControl(self.text_browse)
+        if evt_handler:
+            self.text_browse.PushEventHandler(evt_handler)
+
+    def BeginEdit(self, row, col, grid):
+        loc = self.VarPanel.Table.GetValueByName(row, 'Location')
+        self.text_browse.SetText(loc)
+        self.text_browse.SetRow(row)
+        self.text_browse.SetFocus()
+
+    def EndEdit(self, row, col, grid):
+        loc = self.text_browse.GetText()
+        old_loc = self.VarPanel.Table.GetValueByName(row, 'Location')
+
+        if loc != old_loc:
+            self.VarPanel.Table.SetValueByName(row, 'Location', loc)
+            
+            # NOTE: this is a really lame hack to force this row's
+            # 'Type' cell to redraw (since it may have changed). 
+            # There's got to be a better way than this.
+            self.VarPanel.VariablesGrid.AutoSizeRow(row)
+            return True
+
+    def SetSize(self, rect):
+        self.text_browse.SetDimensions(rect.x + 1, rect.y,
+                                        rect.width, rect.height,
+                                        wx.SIZE_ALLOW_MINUS_ONE)
+
+    def Clone(self):
+        return LocationCellEditor(self.VarPanel)
+
+class BrowseVariableLocationsDialog(wx.Dialog):
+    # turn LOCATIONDATATYPES inside-out
+    LOCATION_SIZES = {}
+    for size, types in LOCATIONDATATYPES.iteritems():
+        for type in types:
+            LOCATION_SIZES[type] = size
+
+    class PluginData:
+        '''contains a plugin's VariableLocationTree'''
+        def __init__(self, plugin):
+            self.subtree  = plugin.GetVariableLocationTree()
+
+    class SubtreeData:
+        '''contains a subtree of a plugin's VariableLocationTree'''
+        def __init__(self, subtree):
+            self.subtree = subtree
+
+    class VariableData:
+        '''contains all the information about a valid variable location'''
+        def __init__(self, type, dir, loc):
+            self.type   = type
+
+            loc_suffix = '.'.join([str(x) for x in loc])
+
+            size = BrowseVariableLocationsDialog.LOCATION_SIZES[type]
+            self.loc = size + loc_suffix
+
+            # if a direction was given, use it
+            # (if not we'll prompt the user to select one)
+            if dir:
+                self.loc = '%' + dir + self.loc
+
+    def __init__(self, parent, var_panel):
+        self.VarPanel   = var_panel
+        self.Selection  = None
+
+        # create the dialog
+        wx.Dialog.__init__(self, parent=parent, title=_('Browse Variables'),
+                            style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
+                            size=(-1, 400))
+
+        # create the root sizer
+        sizer = wx.BoxSizer(wx.VERTICAL)
+        self.SetSizer(sizer)
+
+        # create the tree control
+        self.tree = wx.TreeCtrl(self, style=wx.TR_DEFAULT_STYLE|wx.TR_HIDE_ROOT)
+        sizer.Add(self.tree, 1, wx.EXPAND|wx.ALL, border=20)
+
+        # create the Direction sizer and field
+        dsizer = wx.BoxSizer(wx.HORIZONTAL)
+        sizer.Add(dsizer, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, border=20)
+
+        #   direction label
+        ltext = wx.StaticText(self, -1, _('Direction:'))
+        dsizer.Add(ltext, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, border=20)
+
+        #   direction choice
+        self.DirChoice = wx.Choice(id=-1, parent=self, choices=[_('Input'), _('Output'), _('Memory')])
+        dsizer.Add(self.DirChoice, flag=wx.EXPAND)
+        #   set a default for the choice   
+        self.SetSelectedDirection('I')
+
+        # create the button sizer
+        btsizer = wx.BoxSizer(wx.HORIZONTAL)
+        sizer.Add(btsizer, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_RIGHT, border=20)
+
+        # add plugins to the tree
+        root = self.tree.AddRoot(_('Plugins'))
+        ctrl = self.VarPanel.Controler
+        self.AddChildPluginsToTree(ctrl, root)
+
+        #       -- buttons --
+
+        # ok button
+        self.OkButton = wx.Button(self, wx.ID_OK, _('Use Location'))
+        self.OkButton.SetDefault()
+        btsizer.Add(self.OkButton, flag=wx.RIGHT, border=5)
+
+        # cancel button
+        b = wx.Button(self, wx.ID_CANCEL, _('Cancel'))
+        btsizer.Add(b)
+
+        #       -- event handlers --
+
+        # accept the location on doubleclick or clicking the Use Location button
+        self.Bind(wx.EVT_BUTTON, self.OnOk, self.OkButton)
+        self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnOk, self.tree)
+
+        # disable the Add button when we're not on a valid variable
+        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChange, self.tree)
+
+        # handle the Expand event. this lets us create the tree as it's expanded
+        # (trying to create it all at once is slow since plugin variable location
+        # trees can be big)
+        wx.EVT_TREE_ITEM_EXPANDING(self.tree, self.tree.GetId(), self.OnExpand)
+
+    def OnExpand(self, event):
+        item = event.GetItem()
+        if not item.IsOk():
+            item = self.tree.GetSelection()
+        
+        data = self.tree.GetPyData(item)
+        self.ExpandTree(item, data.subtree)
+
+    def AddChildPluginsToTree(self, plugin, root):
+        for p in plugin.IECSortedChilds():
+            plug_name = p.BaseParams.getName()
+            new_item = self.tree.AppendItem(root, plug_name)
+
+            # make it look like the tree item has children (since it doesn't yet)
+            self.tree.SetItemHasChildren(new_item) 
+
+            # attach the plugin data to the tree item
+            self.tree.SetPyData(new_item, BrowseVariableLocationsDialog.PluginData(p))
+
+            # add child plugins recursively
+            self.AddChildPluginsToTree(p, new_item)
+
+    def ExpandTree(self, root, subtree):
+            items = subtree.items()
+            items.sort()
+
+            for node_name, data in items:
+                if isinstance(data, dict):
+                    # this is a new subtree
+
+                    new_item = self.tree.AppendItem(root, node_name)
+                    self.tree.SetItemHasChildren(new_item)
+
+                    # attach the new subtree's data to the tree item
+                    new_data = BrowseVariableLocationsDialog.SubtreeData(data)
+                    self.tree.SetPyData(new_item, new_data)
+                else:
+                    # this is a new leaf.
+
+                    # data is a tuple containing (IEC type, I/Q/M/None, IEC path tuple)
+                    type, dir, loc = data
+
+                    node_name = '%s (%s)' % (node_name, type)
+                    new_item = self.tree.AppendItem(root, node_name)
+
+                    vd = BrowseVariableLocationsDialog.VariableData(type, dir, loc)
+                    self.tree.SetPyData(new_item, vd)
+
+    def OnSelChange(self, event):
+        '''updates the text field and the "Use Location"  button.'''
+        item = self.tree.GetSelection()
+        data = self.tree.GetPyData(item)
+
+        if isinstance(data, BrowseVariableLocationsDialog.VariableData):
+            self.OkButton.Enable()
+
+            location = data.loc
+            if location[0] == '%':
+                # location has a fixed direction
+                self.SetSelectedDirection(location[1])
+                self.DirChoice.Disable()
+            else:
+                # this location can have any direction (user selects)
+                self.DirChoice.Enable()
+        else:
+            self.OkButton.Disable()
+            self.DirChoice.Disable()
+
+    def GetSelectedDirection(self):
+        selected = self.DirChoice.GetSelection()
+        if selected == 0:
+            return 'I'
+        elif selected == 1:
+            return 'Q'
+        else:
+            return 'M'
+
+    def SetSelectedDirection(self, dir_letter):
+        if dir_letter == 'I':
+            self.DirChoice.SetSelection(0)
+        elif dir_letter == 'Q':
+            self.DirChoice.SetSelection(1)
+        else:
+            self.DirChoice.SetSelection(2)
+
+    def OnOk(self, event):
+        item = self.tree.GetSelection()
+        data = self.tree.GetPyData(item)
+
+        if not isinstance(data, BrowseVariableLocationsDialog.VariableData):
+            return
+
+        location = data.loc
+
+        if location[0] != '%':
+            # no direction was given, grab the one from the wxChoice
+            dir = self.GetSelectedDirection()
+            location = '%' + dir + location
+
+        # walk up the tree, building documentation for the variable
+        documentation = self.tree.GetItemText(item)
+        parent = self.tree.GetItemParent(item)
+        root = self.tree.GetRootItem()
+        while parent != root:
+            text = self.tree.GetItemText(parent)
+            documentation = text + ":" + documentation
+            parent = self.tree.GetItemParent(parent)
+
+        self.Selection = (location, data.type, documentation)
+        self.Destroy() 
--- a/examples/example.xml	Mon Sep 21 12:06:51 2009 +0200
+++ b/examples/example.xml	Tue Sep 22 09:56:02 2009 +0200
@@ -12,7 +12,7 @@
               contentDescription="Example of PLCOpenEditor usage"/>
   <contentHeader name="Test"
                  version="1"
-                 modificationDateTime="2009-07-24T16:17:59"
+                 modificationDateTime="2009-09-21T17:43:10"
                  author="Laurent Bessard"
                  language="en-US">
     <coordinateInfo>
@@ -527,12 +527,14 @@
       </pou>
       <pou name="SFCTest" pouType="program">
         <interface>
+          <localVars>
+            <variable name="IN1">
+              <type>
+                <BOOL/>
+              </type>
+            </variable>
+          </localVars>
           <inputVars>
-            <variable name="IN1">
-              <type>
-                <BOOL/>
-              </type>
-            </variable>
             <variable name="IN2">
               <type>
                 <BOOL/>
--- a/i18n/PLCOpenEditor_fr_FR.po	Mon Sep 21 12:06:51 2009 +0200
+++ b/i18n/PLCOpenEditor_fr_FR.po	Tue Sep 22 09:56:02 2009 +0200
@@ -18,9 +18,9 @@
 #: ../PLCOpenEditor.py:5046
 msgid ""
 "\n"
-"An error happens.\n"
+"An error has occurred.\n"
 "\n"
-"Click on OK for saving an error report.\n"
+"Click OK to save an error report.\n"
 "\n"
 "Please contact LOLITech at:\n"
 "+33 (0)3 29 57 60 42\n"
@@ -120,7 +120,7 @@
 
 #: ../PLCControler.py:1663
 #, python-format
-msgid "\"%s\" element can't be paste here!!!"
+msgid "\"%s\" element can't be pasted here!!!"
 msgstr "L'élément \"%s\" ne peut être collé ici !!!"
 
 #: ../PLCOpenEditor.py:3467
@@ -282,7 +282,7 @@
 
 #: ../DataTypeEditor.py:772
 #, python-format
-msgid "A element with \"%s\" as name exists in this structure!"
+msgid "An element named \"%s\" already exists in this structure!"
 msgstr "Un élément nommé \"%s\" existe déjà dans la structure !"
 
 #: ../PLCOpenEditor.py:1585
@@ -292,13 +292,13 @@
 #: ../PLCOpenEditor.py:3682
 #: ../PLCOpenEditor.py:3745
 #, python-format
-msgid "A pou has an element with \"%s\" as name. It can generate a conflict. Do you wish to continue?"
+msgid "A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?"
 msgstr "Un POU a un élément nommé \"%s\". Cela peut générer des conflits. Voulez-vous continuer ?"
 
 #: ../PLCOpenEditor.py:1622
 #: ../PLCOpenEditor.py:1642
 #, python-format
-msgid "A pou is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"
+msgid "There is a POU named \"%s\". This could cause a conflict. Do you wish to continue?"
 msgstr "Un POU a pour nom \"%s\". Cela peut générer des conflits. Voulez-vous continuer ?"
 
 #: ../PLCOpenEditor.py:1598
@@ -312,7 +312,7 @@
 #: ../Dialogs.py:2520
 #: ../Dialogs.py:2587
 #, python-format
-msgid "A pou with \"%s\" as name exists!"
+msgid "A POU named \"%s\" already exists!"
 msgstr "Un POU nommé \"%s\" existe déjà !"
 
 #: ../PLCOpenEditor.py:1600
@@ -351,7 +351,7 @@
 
 #: ../plcopen/plcopen.py:1073
 #, python-format
-msgid "Action with name %s doesn't exists!"
+msgid "Action with name %s doesn't exist!"
 msgstr "L'action nommée %s n'existe pas !"
 
 #: ../PLCControler.py:83
@@ -445,7 +445,7 @@
 msgstr "Addition"
 
 #: ../plcopen/structures.py:222
-msgid "Additionnal function blocks"
+msgid "Additional function blocks"
 msgstr "Blocs fonctionnels additionnels"
 
 #: ../Viewer.py:411
@@ -549,7 +549,7 @@
 msgstr "Log CVS"
 
 #: ../PLCOpenEditor.py:4074
-msgid "Can affect a location only to local or global variables"
+msgid "Can only give a location to local or global variables"
 msgstr "Une adresse ne peut être affecté qu'à des variables locales ou globales"
 
 #: ../plcopen/plcopen.py:1218
@@ -560,7 +560,7 @@
 msgstr "L'ordre d'exécution ne peut être généré que dans les FBD !"
 
 #: ../PLCOpenEditor.py:4072
-msgid "Can't affect a location to a function block instance"
+msgid "Can't give a location to a function block instance"
 msgstr "Une adresse ne peut être affectée une instance de Function Block"
 
 #: ../PLCOpenEditor.py:1094
@@ -1160,7 +1160,7 @@
 
 #: ../PLCControler.py:1673
 #, python-format
-msgid "FunctionBlock \"%s\" can't be paste in a Function!!!"
+msgid "FunctionBlock \"%s\" can't be pasted in a Function!!!"
 msgstr "Le bloc fonctionnel \"%s\" ne peuvent être collés dans une function !"
 
 #: ../PLCControler.py:82
@@ -1271,7 +1271,7 @@
 
 #: ../plcopen/plcopen.py:1329
 #, python-format
-msgid "Instance with id %d doesn't exists!"
+msgid "Instance with id %d doesn't exist!"
 msgstr "L'instance dont l'id est %d n'existe pas !"
 
 #: ../PLCOpenEditor.py:561
@@ -2082,7 +2082,7 @@
 
 #: ../plcopen/plcopen.py:1035
 #, python-format
-msgid "Transition with name %s doesn't exists!"
+msgid "Transition with name %s doesn't exist!"
 msgstr "La transition nommée %s n'existe pas !"
 
 #: ../PLCControler.py:83
--- a/i18n/PLCOpenEditor_zh_CN.po	Mon Sep 21 12:06:51 2009 +0200
+++ b/i18n/PLCOpenEditor_zh_CN.po	Tue Sep 22 09:56:02 2009 +0200
@@ -18,9 +18,9 @@
 #: PLCOpenEditor.py:5108
 msgid ""
 "\n"
-"An error happens.\n"
+"An error has occurred.\n"
 "\n"
-"Click on OK for saving an error report.\n"
+"Click OK to save an error report.\n"
 "\n"
 "Please contact LOLITech at:\n"
 "+33 (0)3 29 57 60 42\n"
@@ -120,7 +120,7 @@
 
 #: PLCControler.py:1648
 #, python-format
-msgid "\"%s\" element can't be paste here!!!"
+msgid "\"%s\" element can't be pasted here!!!"
 msgstr "\"%s\" 元素不能粘贴在这里!!!"
 
 #: PLCOpenEditor.py:3528
@@ -282,7 +282,7 @@
 
 #: DataTypeEditor.py:768
 #, python-format
-msgid "A element with \"%s\" as name exists in this structure!"
+msgid "An element named \"%s\" already exists in this structure!"
 msgstr "一个以\"%s\"命名的元素已经在这个结构中存在!"
 
 #: PLCOpenEditor.py:1600
@@ -292,13 +292,13 @@
 #: PLCOpenEditor.py:3743
 #: PLCOpenEditor.py:3806
 #, python-format
-msgid "A pou has an element with \"%s\" as name. It can generate a conflict. Do you wish to continue?"
+msgid "A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?"
 msgstr "一个编程组织单元的成员被命名为\"%s\"。这可能会产生冲突。你希望继续吗?"
 
 #: PLCOpenEditor.py:1647
 #: PLCOpenEditor.py:1672
 #, python-format
-msgid "A pou is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"
+msgid "There is a POU named \"%s\". This could cause a conflict. Do you wish to continue?"
 msgstr "一个编程组织单元被命名为\"%s\"。这可能会产生冲突。你希望继续吗?"
 
 #: PLCOpenEditor.py:1618
@@ -312,7 +312,7 @@
 #: Dialogs.py:2517
 #: Dialogs.py:2584
 #, python-format
-msgid "A pou with \"%s\" as name exists!"
+msgid "A POU named \"%s\" already exists!"
 msgstr "一个以\"%s\"命名的的编程组织单元已经存在!"
 
 #: PLCOpenEditor.py:1620
@@ -351,7 +351,7 @@
 
 #: plcopen/plcopen.py:1028
 #, python-format
-msgid "Action with name %s doesn't exists!"
+msgid "Action with name %s doesn't exist!"
 msgstr "一个以\"%s\"命名的的行动不存在!"
 
 #: PLCControler.py:83
@@ -445,7 +445,7 @@
 msgstr "加法"
 
 #: plcopen/structures.py:222
-msgid "Additionnal function blocks"
+msgid "Additional function blocks"
 msgstr "附加功能类型"
 
 #: Viewer.py:414
@@ -549,7 +549,7 @@
 msgstr "逗号分隔值文件日志"
 
 #: PLCOpenEditor.py:4137
-msgid "Can affect a location only to local or global variables"
+msgid "Can only give a location to local or global variables"
 msgstr "只能影响本地或全局变量的位置"
 
 #: plcopen/plcopen.py:1123
@@ -560,7 +560,7 @@
 msgstr "在功能块网络,只能生成执行命令!"
 
 #: PLCOpenEditor.py:4135
-msgid "Can't affect a location to a function block instance"
+msgid "Can't give a location to a function block instance"
 msgstr "不能影响功能块实例的位置"
 
 #: PLCOpenEditor.py:1093
@@ -1156,7 +1156,7 @@
 
 #: PLCControler.py:1658
 #, python-format
-msgid "FunctionBlock \"%s\" can't be paste in a Function!!!"
+msgid "FunctionBlock \"%s\" can't be pasted in a Function!!!"
 msgstr "功能块 \"%s\" 不能用于功能中!"
 
 #: PLCControler.py:82
@@ -1269,7 +1269,7 @@
 
 #: plcopen/plcopen.py:1234
 #, python-format
-msgid "Instance with id %d doesn't exists!"
+msgid "Instance with id %d doesn't exist!"
 msgstr "有id的实例 %d 尚不存在!"
 
 #: PLCOpenEditor.py:559
@@ -2080,7 +2080,7 @@
 
 #: plcopen/plcopen.py:990
 #, python-format
-msgid "Transition with name %s doesn't exists!"
+msgid "Transition with name %s doesn't exist!"
 msgstr "已命名的跃迁 %s 尚不存在!"
 
 #: PLCControler.py:83
--- a/i18n/messages.pot	Mon Sep 21 12:06:51 2009 +0200
+++ b/i18n/messages.pot	Tue Sep 22 09:56:02 2009 +0200
@@ -19,9 +19,9 @@
 #: ../PLCOpenEditor.py:5046
 msgid ""
 "\n"
-"An error happens.\n"
+"An error has occurred.\n"
 "\n"
-"Click on OK for saving an error report.\n"
+"Click OK to save an error report.\n"
 "\n"
 "Please contact LOLITech at:\n"
 "+33 (0)3 29 57 60 42\n"
@@ -106,7 +106,7 @@
 
 #: ../PLCControler.py:1663
 #, python-format
-msgid "\"%s\" element can't be paste here!!!"
+msgid "\"%s\" element can't be pasted here!!!"
 msgstr ""
 
 #: ../PLCOpenEditor.py:3467 ../PLCOpenEditor.py:3611 ../Viewer.py:248
@@ -229,18 +229,18 @@
 
 #: ../DataTypeEditor.py:772
 #, python-format
-msgid "A element with \"%s\" as name exists in this structure!"
+msgid "A element named \"%s\" already exists in this structure!"
 msgstr ""
 
 #: ../PLCOpenEditor.py:1585 ../PLCOpenEditor.py:1627 ../PLCOpenEditor.py:1647
 #: ../PLCOpenEditor.py:3304 ../PLCOpenEditor.py:3682 ../PLCOpenEditor.py:3745
 #, python-format
-msgid "A pou has an element with \"%s\" as name. It can generate a conflict. Do you wish to continue?"
+msgid "A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?"
 msgstr ""
 
 #: ../PLCOpenEditor.py:1622 ../PLCOpenEditor.py:1642
 #, python-format
-msgid "A pou is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"
+msgid "There is a POU named \"%s\". This could cause a conflict. Do you wish to continue?"
 msgstr ""
 
 #: ../PLCOpenEditor.py:1598 ../PLCOpenEditor.py:1609 ../PLCOpenEditor.py:3463
@@ -248,7 +248,7 @@
 #: ../PLCOpenEditor.py:4456 ../Dialogs.py:1537 ../Dialogs.py:2520
 #: ../Dialogs.py:2587
 #, python-format
-msgid "A pou with \"%s\" as name exists!"
+msgid "A POU named \"%s\" already exists!"
 msgstr ""
 
 #: ../PLCOpenEditor.py:1600 ../PLCOpenEditor.py:1611 ../PLCOpenEditor.py:4461
@@ -283,7 +283,7 @@
 
 #: ../plcopen/plcopen.py:1073
 #, python-format
-msgid "Action with name %s doesn't exists!"
+msgid "Action with name %s doesn't exist!"
 msgstr ""
 
 #: ../PLCControler.py:83
@@ -371,7 +371,7 @@
 msgstr ""
 
 #: ../plcopen/structures.py:222
-msgid "Additionnal function blocks"
+msgid "Additional function blocks"
 msgstr ""
 
 #: ../Viewer.py:411
@@ -471,7 +471,7 @@
 msgstr ""
 
 #: ../PLCOpenEditor.py:4074
-msgid "Can affect a location only to local or global variables"
+msgid "Can only give a location to local or global variables"
 msgstr ""
 
 #: ../plcopen/plcopen.py:1218 ../plcopen/plcopen.py:1232
@@ -480,7 +480,7 @@
 msgstr ""
 
 #: ../PLCOpenEditor.py:4072
-msgid "Can't affect a location to a function block instance"
+msgid "Can't give a location to a function block instance"
 msgstr ""
 
 #: ../PLCOpenEditor.py:1094
@@ -976,7 +976,7 @@
 
 #: ../PLCControler.py:1673
 #, python-format
-msgid "FunctionBlock \"%s\" can't be paste in a Function!!!"
+msgid "FunctionBlock \"%s\" can't be pasted in a Function!!!"
 msgstr ""
 
 #: ../PLCControler.py:82
@@ -1076,7 +1076,7 @@
 
 #: ../plcopen/plcopen.py:1329
 #, python-format
-msgid "Instance with id %d doesn't exists!"
+msgid "Instance with id %d doesn't exist!"
 msgstr ""
 
 #: ../PLCOpenEditor.py:561 ../PLCOpenEditor.py:599
@@ -1814,7 +1814,7 @@
 
 #: ../plcopen/plcopen.py:1035
 #, python-format
-msgid "Transition with name %s doesn't exists!"
+msgid "Transition with name %s doesn't exist!"
 msgstr ""
 
 #: ../PLCControler.py:83
--- a/plcopen/plcopen.py	Mon Sep 21 12:06:51 2009 +0200
+++ b/plcopen/plcopen.py	Tue Sep 22 09:56:02 2009 +0200
@@ -742,8 +742,8 @@
     setattr(cls, "compatibility", compatibility)
     
     def updateElementName(self, old_name, new_name):
-        if self.type == old_name:
-            self.type = new_name
+        if self.typeName == old_name:
+            self.typeName = new_name
     setattr(cls, "updateElementName", updateElementName)
 
 cls = PLCOpenClasses.get("project_types", None)
@@ -1032,7 +1032,7 @@
                     removed = True
                 i += 1
             if not removed:
-                raise ValueError, _("Transition with name %s doesn't exists!")%name
+                raise ValueError, _("Transition with name %s doesn't exist!")%name
     setattr(cls, "removetransition", removetransition)
 
     def addaction(self, name, type):
@@ -1070,7 +1070,7 @@
                     removed = True
                 i += 1
             if not removed:
-                raise ValueError, _("Action with name %s doesn't exists!")%name
+                raise ValueError, _("Action with name %s doesn't exist!")%name
     setattr(cls, "removeaction", removeaction)
 
     def updateElementName(self, old_name, new_name):
@@ -1326,7 +1326,7 @@
                     removed = True
                 i += 1
             if not removed:
-                raise ValueError, _("Instance with id %d doesn't exists!")%id
+                raise ValueError, _("Instance with id %d doesn't exist!")%id
         else:
             raise TypeError, "%s body don't have instances!"%self.content["name"]
     setattr(cls, "removecontentInstance", removecontentInstance)
--- a/plcopen/structures.py	Mon Sep 21 12:06:51 2009 +0200
+++ b/plcopen/structures.py	Tue Sep 22 09:56:02 2009 +0200
@@ -219,7 +219,7 @@
                     "comment" : _("Off-delay timer\nThe off-delay timer can be used to delay setting an output false, for fixed period after input goes false."),
                     "generate" : generate_block, "initialise" : initialise_block},
                 ]},
-              {"name" : _("Additionnal function blocks"), "list":
+              {"name" : _("Additional function blocks"), "list":
 ##                {"name" : "RTC", "type" : "functionBlock", "extensible" : False, 
 ##                    "inputs" : [("EN","BOOL","none"),("PDT","DATE_AND_TIME","none")], 
 ##                    "outputs" : [("Q","BOOL","none"),("CDT","DATE_AND_TIME","none")],