VariablePanel.py
changeset 507 42150e041dbe
parent 496 5ff24ccff2c7
child 509 6f72513bc074
equal deleted inserted replaced
504:f88e0ebd8fe4 507:42150e041dbe
    26 
    26 
    27 from types import TupleType
    27 from types import TupleType
    28 
    28 
    29 from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS
    29 from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS
    30 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
    30 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
       
    31 from dialogs import ArrayTypeDialog
    31 
    32 
    32 CWD = os.path.split(os.path.realpath(__file__))[0]
    33 CWD = os.path.split(os.path.realpath(__file__))[0]
    33 
    34 
    34 # Compatibility function for wx versions < 2.6
    35 # Compatibility function for wx versions < 2.6
    35 def AppendMenu(parent, help, id, kind, text):
    36 def AppendMenu(parent, help, id, kind, text):
   118     def GetValue(self, row, col):
   119     def GetValue(self, row, col):
   119         if row < self.GetNumberRows():
   120         if row < self.GetNumberRows():
   120             if col == 0:
   121             if col == 0:
   121                 return self.data[row]["Number"]
   122                 return self.data[row]["Number"]
   122             colname = self.GetColLabelValue(col, False)
   123             colname = self.GetColLabelValue(col, False)
   123             value = str(self.data[row].get(colname, ""))
   124             value = self.data[row].get(colname, "")
       
   125             if colname == "Type" and isinstance(value, TupleType):
       
   126                 if value[0] == "array":
       
   127                     return "ARRAY [%s] OF %s" % (",".join(map(lambda x : "..".join(x), value[2])), value[1])
       
   128             value = str(value)
   124             if colname in ["Class", "Option"]:
   129             if colname in ["Class", "Option"]:
   125                 return _(value)
   130                 return _(value)
   126             return value
   131             return value
   127     
   132     
   128     def SetValue(self, row, col, value):
   133     def SetValue(self, row, col, value):
   772 
   777 
   773             # build a submenu containing function block types
   778             # build a submenu containing function block types
   774             bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
   779             bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
   775             pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
   780             pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
   776             classtype = self.Table.GetValueByName(row, "Class")
   781             classtype = self.Table.GetValueByName(row, "Class")
   777 
   782             
       
   783             #new_id = wx.NewId()
       
   784             #AppendMenu(type_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Array"))
       
   785             #self.Bind(wx.EVT_MENU, self.VariableArrayTypeFunction, id=new_id)
       
   786             
   778             if classtype in ["Input", "Output", "InOut", "External", "Global"] or \
   787             if classtype in ["Input", "Output", "InOut", "External", "Global"] or \
   779             poutype != "function" and bodytype in ["ST", "IL"]:
   788             poutype != "function" and bodytype in ["ST", "IL"]:
   780                 functionblock_menu = wx.Menu(title='')
   789                 functionblock_menu = wx.Menu(title='')
   781                 fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName)
   790                 fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName)
   782                 for functionblock_type in fbtypes:
   791                 for functionblock_type in fbtypes:
   804             self.SaveValues(False)
   813             self.SaveValues(False)
   805             self.ParentWindow.RefreshEditor(variablepanel = False)
   814             self.ParentWindow.RefreshEditor(variablepanel = False)
   806             self.Controler.BufferProject()
   815             self.Controler.BufferProject()
   807             self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE)
   816             self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE)
   808         return VariableTypeFunction
   817         return VariableTypeFunction
       
   818     
       
   819     def VariableArrayTypeFunction(self, event):
       
   820         row = self.VariablesGrid.GetGridCursorRow()
       
   821         dialog = ArrayTypeDialog(self, 
       
   822                                  self.Controler.GetDataTypes(self.TagName), 
       
   823                                  self.Table.GetValueByName(row, "Type"))
       
   824         if dialog.ShowModal() == wx.ID_OK:
       
   825             self.Table.SetValueByName(row, "Type", dialog.GetValue())
       
   826             self.Table.ResetView(self.VariablesGrid)
       
   827             self.SaveValues(False)
       
   828             self.ParentWindow.RefreshEditor(variablepanel = False)
       
   829             self.Controler.BufferProject()
       
   830             self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE)
       
   831         dialog.Destroy()
   809     
   832     
   810     def OnVariablesGridCellLeftClick(self, event):
   833     def OnVariablesGridCellLeftClick(self, event):
   811         row = event.GetRow()
   834         row = event.GetRow()
   812         if event.GetCol() == 0 and self.Table.GetValueByName(row, "Edit"):
   835         if event.GetCol() == 0 and self.Table.GetValueByName(row, "Edit"):
   813             row = event.GetRow()
   836             row = event.GetRow()
  1202             message = wx.MessageDialog(self, _("A location must be selected!"), _("Error"), wx.OK|wx.ICON_ERROR)
  1225             message = wx.MessageDialog(self, _("A location must be selected!"), _("Error"), wx.OK|wx.ICON_ERROR)
  1203             message.ShowModal()
  1226             message.ShowModal()
  1204             message.Destroy()
  1227             message.Destroy()
  1205         else:
  1228         else:
  1206             self.EndModal(wx.ID_OK)
  1229             self.EndModal(wx.ID_OK)
  1207