--- a/VariablePanel.py Thu Dec 10 16:37:11 2009 +0100
+++ b/VariablePanel.py Sat Dec 12 20:37:35 2009 +0100
@@ -52,9 +52,16 @@
return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Option"), _("Documentation")]
return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Option"), _("Documentation")]
-def GetOptions():
+def GetOptions(constant=True, retain=True, non_retain=True):
_ = lambda x : x
- return ["", _("Constant"), _("Retain"), _("Non-Retain")]
+ options = [""]
+ if constant:
+ options.append(_("Constant"))
+ if retain:
+ options.append(_("Retain"))
+ if non_retain:
+ options.append(_("Non-Retain"))
+ return options
OPTIONS_DICT = dict([(_(option), option) for option in GetOptions()])
def GetFilterChoiceTransfer():
@@ -65,6 +72,15 @@
_(" Temp"): _("Temp"), _("Global"): _("Global")}#, _("Access") : _("Access")}
VARIABLE_CLASSES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().itervalues()])
+CheckOptionForClass = {"Local": lambda x: x,
+ "Temp": lambda x: "",
+ "Input": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""),
+ "InOut": lambda x: "",
+ "Output": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""),
+ "Global": lambda x: {"Constant": "Constant", "Retain": "Retain"}.get(x, ""),
+ "External": lambda x: {"Constant": "Constant"}.get(x, "")
+ }
+
class VariableTable(wx.grid.PyGridTableBase):
"""
@@ -116,6 +132,9 @@
self.old_value = self.data[row][colname]
elif colname == "Class":
value = VARIABLE_CLASSES_DICT[value]
+ self.SetValueByName(row, "Option", CheckOptionForClass[value](self.GetValueByName(row, "Option")))
+ if value == "External":
+ self.SetValueByName(row, "Initial Value", "")
elif colname == "Option":
value = OPTIONS_DICT[value]
self.data[row][colname] = value
@@ -173,32 +192,42 @@
Otherwise default to the default renderer.
"""
for row in range(self.GetNumberRows()):
+ var_class = self.GetValueByName(row, "Class")
for col in range(self.GetNumberCols()):
editor = None
renderer = None
colname = self.GetColLabelValue(col, False)
if colname == "Option":
- editor = wx.grid.GridCellChoiceEditor()
- editor.SetParameters(",".join(map(_, self.Parent.OptionList)))
+ options = GetOptions(constant = var_class in ["Local", "External", "Global"],
+ retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"],
+ non_retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"])
+ if len(options) > 1:
+ editor = wx.grid.GridCellChoiceEditor()
+ editor.SetParameters(",".join(map(_, options)))
+ else:
+ grid.SetReadOnly(row, col, True)
elif 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"]:
+ if self.Parent.PouIsUsed and var_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()
+ if var_class != "External":
+ editor = wx.grid.GridCellTextEditor()
+ renderer = wx.grid.GridCellStringRenderer()
+ else:
+ grid.SetReadOnly(row, col, True)
elif colname == "Location":
- if self.GetValueByName(row, "Class") in ["Local", "Global"]:
+ if var_class in ["Local", "Global"]:
editor = LocationCellEditor(self, self.Parent.Controler)
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"]:
+ if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and var_class in ["Input", "Output", "InOut"]:
grid.SetReadOnly(row, col, True)
else:
editor = wx.grid.GridCellChoiceEditor()
@@ -520,7 +549,7 @@
if element_type == "function":
self.FilterChoices = ["All",
"Interface", " Input", " Output", " InOut",
- "Variables", " Local", " Temp"]
+ "Variables", " Local"]
else:
self.FilterChoices = ["All",
"Interface", " Input", " Output", " InOut", " External",
@@ -543,8 +572,6 @@
self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
self.RefreshTypeList()
- self.OptionList = GetOptions()
-
if element_type == "function":
for base_type in self.Controler.GetBaseTypes():
self.ReturnType.Append(base_type)
@@ -732,7 +759,10 @@
# build a submenu containing user-defined types
datatype_menu = wx.Menu(title='')
- datatypes = self.Controler.GetDataTypes(basetypes = False)
+
+ # TODO : remove complextypes argument when matiec can manage complex types in pou interface
+ datatypes = self.Controler.GetDataTypes(basetypes = False,
+ complextypes = self.Table.GetValueByName(row, "Class") not in ["Input", "Ouput", "InOut"])
for datatype in datatypes:
new_id = wx.NewId()
AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)