VariablePanel.py
changeset 507 42150e041dbe
parent 496 5ff24ccff2c7
child 509 6f72513bc074
--- a/VariablePanel.py	Tue Feb 22 17:05:07 2011 +0100
+++ b/VariablePanel.py	Wed Mar 30 15:49:09 2011 +0200
@@ -28,6 +28,7 @@
 
 from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS
 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
+from dialogs import ArrayTypeDialog
 
 CWD = os.path.split(os.path.realpath(__file__))[0]
 
@@ -120,7 +121,11 @@
             if col == 0:
                 return self.data[row]["Number"]
             colname = self.GetColLabelValue(col, False)
-            value = str(self.data[row].get(colname, ""))
+            value = self.data[row].get(colname, "")
+            if colname == "Type" and isinstance(value, TupleType):
+                if value[0] == "array":
+                    return "ARRAY [%s] OF %s" % (",".join(map(lambda x : "..".join(x), value[2])), value[1])
+            value = str(value)
             if colname in ["Class", "Option"]:
                 return _(value)
             return value
@@ -774,7 +779,11 @@
             bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
             pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
             classtype = self.Table.GetValueByName(row, "Class")
-
+            
+            #new_id = wx.NewId()
+            #AppendMenu(type_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Array"))
+            #self.Bind(wx.EVT_MENU, self.VariableArrayTypeFunction, id=new_id)
+            
             if classtype in ["Input", "Output", "InOut", "External", "Global"] or \
             poutype != "function" and bodytype in ["ST", "IL"]:
                 functionblock_menu = wx.Menu(title='')
@@ -807,6 +816,20 @@
             self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE)
         return VariableTypeFunction
     
+    def VariableArrayTypeFunction(self, event):
+        row = self.VariablesGrid.GetGridCursorRow()
+        dialog = ArrayTypeDialog(self, 
+                                 self.Controler.GetDataTypes(self.TagName), 
+                                 self.Table.GetValueByName(row, "Type"))
+        if dialog.ShowModal() == wx.ID_OK:
+            self.Table.SetValueByName(row, "Type", dialog.GetValue())
+            self.Table.ResetView(self.VariablesGrid)
+            self.SaveValues(False)
+            self.ParentWindow.RefreshEditor(variablepanel = False)
+            self.Controler.BufferProject()
+            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE)
+        dialog.Destroy()
+    
     def OnVariablesGridCellLeftClick(self, event):
         row = event.GetRow()
         if event.GetCol() == 0 and self.Table.GetValueByName(row, "Edit"):
@@ -1204,4 +1227,3 @@
             message.Destroy()
         else:
             self.EndModal(wx.ID_OK)
-        
\ No newline at end of file