controls/VariablePanel.py
changeset 1784 64beb9e9c749
parent 1782 5b6ad7a7fd9d
child 1833 2269739dd098
equal deleted inserted replaced
1729:31e63e25b4cc 1784:64beb9e9c749
    36 from CustomGrid import CustomGrid
    36 from CustomGrid import CustomGrid
    37 from CustomTable import CustomTable
    37 from CustomTable import CustomTable
    38 from LocationCellEditor import LocationCellEditor
    38 from LocationCellEditor import LocationCellEditor
    39 from util.BitmapLibrary import GetBitmap
    39 from util.BitmapLibrary import GetBitmap
    40 from PLCControler import _VariableInfos
    40 from PLCControler import _VariableInfos
    41 
    41 from util.TranslationCatalogs import NoTranslate
    42 #-------------------------------------------------------------------------------
    42 
       
    43 
       
    44 # -------------------------------------------------------------------------------
    43 #                                 Helpers
    45 #                                 Helpers
    44 #-------------------------------------------------------------------------------
    46 # -------------------------------------------------------------------------------
    45 
    47 
    46 [TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE,
    48 
    47  POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES
    49 [
       
    50     TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE,
       
    51     POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES
    48 ] = range(10)
    52 ] = range(10)
    49 
    53 
       
    54 
    50 def GetVariableTableColnames(location):
    55 def GetVariableTableColnames(location):
    51     _ = lambda x : x
    56     _ = NoTranslate
    52     if location:
    57     cols = ["#",
    53     	return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Option"), _("Documentation")]
    58             _("Name"),
    54     return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Option"), _("Documentation")]
    59             _("Class"),
       
    60             _("Type"),
       
    61             _("Location"),
       
    62             _("Initial Value"),
       
    63             _("Option"),
       
    64             _("Documentation")]
       
    65     if not location:
       
    66         del cols[4]  # remove 'Location' column
       
    67     return cols
       
    68 
    55 
    69 
    56 def GetOptions(constant=True, retain=True, non_retain=True):
    70 def GetOptions(constant=True, retain=True, non_retain=True):
    57     _ = lambda x : x
    71     _ = NoTranslate
    58     options = [""]
    72     options = [""]
    59     if constant:
    73     if constant:
    60         options.append(_("Constant"))
    74         options.append(_("Constant"))
    61     if retain:
    75     if retain:
    62         options.append(_("Retain"))
    76         options.append(_("Retain"))
    63     if non_retain:
    77     if non_retain:
    64         options.append(_("Non-Retain"))
    78         options.append(_("Non-Retain"))
    65     return options
    79     return options
       
    80 
       
    81 
    66 OPTIONS_DICT = dict([(_(option), option) for option in GetOptions()])
    82 OPTIONS_DICT = dict([(_(option), option) for option in GetOptions()])
    67 
    83 
       
    84 
    68 def GetFilterChoiceTransfer():
    85 def GetFilterChoiceTransfer():
    69     _ = lambda x : x
    86     _ = NoTranslate
    70     return {_("All"): _("All"), _("Interface"): _("Interface"),
    87     return {_("All"): _("All"), _("Interface"): _("Interface"),
    71             _("   Input"): _("Input"), _("   Output"): _("Output"), _("   InOut"): _("InOut"),
    88             _("   Input"): _("Input"), _("   Output"): _("Output"), _("   InOut"): _("InOut"),
    72             _("   External"): _("External"), _("Variables"): _("Variables"), _("   Local"): _("Local"),
    89             _("   External"): _("External"), _("Variables"): _("Variables"), _("   Local"): _("Local"),
    73             _("   Temp"): _("Temp"), _("Global"): _("Global")}#, _("Access") : _("Access")}
    90             _("   Temp"): _("Temp"), _("Global"): _("Global")}  # , _("Access") : _("Access")}
       
    91 
       
    92 
    74 VARIABLE_CHOICES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().iterkeys()])
    93 VARIABLE_CHOICES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().iterkeys()])
    75 VARIABLE_CLASSES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().itervalues()])
    94 VARIABLE_CLASSES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().itervalues()])
    76 
    95 
    77 CheckOptionForClass = {"Local": lambda x: x,
    96 CheckOptionForClass = {
    78                        "Temp": lambda x: "",
    97     "Local": lambda x: x,
    79                        "Input": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""),
    98     "Temp": lambda x: "",
    80                        "InOut": lambda x: "",
    99     "Input": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""),
    81                        "Output": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""),
   100     "InOut": lambda x: "",
    82                        "Global": lambda x: {"Constant": "Constant", "Retain": "Retain"}.get(x, ""),
   101     "Output": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""),
    83                        "External": lambda x: {"Constant": "Constant"}.get(x, "")
   102     "Global": lambda x: {"Constant": "Constant", "Retain": "Retain"}.get(x, ""),
    84                       }
   103     "External": lambda x: {"Constant": "Constant"}.get(x, "")
       
   104 }
    85 
   105 
    86 LOCATION_MODEL = re.compile("((?:%[IQM](?:\*|(?:[XBWLD]?[0-9]+(?:\.[0-9]+)*)))?)$")
   106 LOCATION_MODEL = re.compile("((?:%[IQM](?:\*|(?:[XBWLD]?[0-9]+(?:\.[0-9]+)*)))?)$")
    87 VARIABLE_NAME_SUFFIX_MODEL = re.compile("([0-9]*)$")
   107 VARIABLE_NAME_SUFFIX_MODEL = re.compile("([0-9]*)$")
    88 
   108 
    89 #-------------------------------------------------------------------------------
   109 
       
   110 # -------------------------------------------------------------------------------
    90 #                            Variables Panel Table
   111 #                            Variables Panel Table
    91 #-------------------------------------------------------------------------------
   112 # -------------------------------------------------------------------------------
       
   113 
    92 
   114 
    93 class VariableTable(CustomTable):
   115 class VariableTable(CustomTable):
    94 
   116 
    95     """
   117     """
    96     A custom wx.grid.Grid Table using user supplied data
   118     A custom wx.grid.Grid Table using user supplied data
   116             if colname == "Initial Value":
   138             if colname == "Initial Value":
   117                 colname = "InitialValue"
   139                 colname = "InitialValue"
   118             value = getattr(self.data[row], colname, "")
   140             value = getattr(self.data[row], colname, "")
   119             if colname == "Type" and isinstance(value, TupleType):
   141             if colname == "Type" and isinstance(value, TupleType):
   120                 if value[0] == "array":
   142                 if value[0] == "array":
   121                     return "ARRAY [%s] OF %s" % (",".join(map(lambda x : "..".join(x), value[2])), value[1])
   143                     return "ARRAY [%s] OF %s" % (",".join(map(lambda x: "..".join(x), value[2])), value[1])
   122             if not isinstance(value, (StringType, UnicodeType)):
   144             if not isinstance(value, (StringType, UnicodeType)):
   123                 value = str(value)
   145                 value = str(value)
   124             if colname in ["Class", "Option"]:
   146             if colname in ["Class", "Option"]:
   125                 return _(value)
   147                 return _(value)
   126             return value
   148             return value
   147     def _GetRowEdit(self, row):
   169     def _GetRowEdit(self, row):
   148         row_edit = self.GetValueByName(row, "Edit")
   170         row_edit = self.GetValueByName(row, "Edit")
   149         var_type = self.Parent.GetTagName()
   171         var_type = self.Parent.GetTagName()
   150         bodytype = self.Parent.Controler.GetEditedElementBodyType(var_type)
   172         bodytype = self.Parent.Controler.GetEditedElementBodyType(var_type)
   151         if bodytype in ["ST", "IL"]:
   173         if bodytype in ["ST", "IL"]:
   152             row_edit = True;
   174             row_edit = True
   153         return row_edit
   175         return row_edit
   154 
   176 
   155     def _updateColAttrs(self, grid):
   177     def _updateColAttrs(self, grid):
   156         """
   178         """
   157         wx.grid.Grid -> update the column attributes to add the
   179         wx.grid.Grid -> update the column attributes to add the
   169                 colname = self.GetColLabelValue(col, False)
   191                 colname = self.GetColLabelValue(col, False)
   170                 if self.Parent.Debug:
   192                 if self.Parent.Debug:
   171                     grid.SetReadOnly(row, col, True)
   193                     grid.SetReadOnly(row, col, True)
   172                 else:
   194                 else:
   173                     if colname == "Option":
   195                     if colname == "Option":
   174                         options = GetOptions(constant = var_class in ["Local", "External", "Global"],
   196                         options = GetOptions(constant=var_class in ["Local", "External", "Global"],
   175                                              retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"],
   197                                              retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"],
   176                                              non_retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"])
   198                                              non_retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"])
   177                         if len(options) > 1:
   199                         if len(options) > 1:
   178                             editor = wx.grid.GridCellChoiceEditor()
   200                             editor = wx.grid.GridCellChoiceEditor()
   179                             editor.SetParameters(",".join(map(_, options)))
   201                             editor.SetParameters(",".join(map(_, options)))
   180                         else:
   202                         else:
   181                             grid.SetReadOnly(row, col, True)
   203                             grid.SetReadOnly(row, col, True)
   205                                 grid.SetReadOnly(row, col, True)
   227                                 grid.SetReadOnly(row, col, True)
   206                             else:
   228                             else:
   207                                 editor = wx.grid.GridCellChoiceEditor()
   229                                 editor = wx.grid.GridCellChoiceEditor()
   208                                 excluded = []
   230                                 excluded = []
   209                                 if self.Parent.IsFunctionBlockType(var_type):
   231                                 if self.Parent.IsFunctionBlockType(var_type):
   210                                     excluded.extend(["Local","Temp"])
   232                                     excluded.extend(["Local", "Temp"])
   211                                 editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded]))
   233                                 editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded]))
   212                     elif colname != "Documentation":
   234                     elif colname != "Documentation":
   213                         grid.SetReadOnly(row, col, True)
   235                         grid.SetReadOnly(row, col, True)
   214 
   236 
   215                 grid.SetCellEditor(row, col, editor)
   237                 grid.SetCellEditor(row, col, editor)
   221                     highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
   243                     highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
   222                 grid.SetCellBackgroundColour(row, col, highlight_colours[0])
   244                 grid.SetCellBackgroundColour(row, col, highlight_colours[0])
   223                 grid.SetCellTextColour(row, col, highlight_colours[1])
   245                 grid.SetCellTextColour(row, col, highlight_colours[1])
   224             self.ResizeRow(grid, row)
   246             self.ResizeRow(grid, row)
   225 
   247 
   226 #-------------------------------------------------------------------------------
   248 
       
   249 # -------------------------------------------------------------------------------
   227 #                         Variable Panel Drop Target
   250 #                         Variable Panel Drop Target
   228 #-------------------------------------------------------------------------------
   251 # -------------------------------------------------------------------------------
       
   252 
   229 
   253 
   230 class VariableDropTarget(wx.TextDropTarget):
   254 class VariableDropTarget(wx.TextDropTarget):
   231     '''
   255     '''
   232     This allows dragging a variable location from somewhere to the Location
   256     This allows dragging a variable location from somewhere to the Location
   233     column of a variable row.
   257     column of a variable row.
   249         row = self.ParentWindow.VariablesGrid.YToRow(y)
   273         row = self.ParentWindow.VariablesGrid.YToRow(y)
   250         message = None
   274         message = None
   251         element_type = self.ParentWindow.ElementType
   275         element_type = self.ParentWindow.ElementType
   252         try:
   276         try:
   253             values = eval(data)
   277             values = eval(data)
   254         except:
   278         except Exception:
   255             message = _("Invalid value \"%s\" for variable grid element")%data
   279             message = _("Invalid value \"%s\" for variable grid element") % data
   256             values = None
   280             values = None
   257         if not isinstance(values, TupleType):
   281         if not isinstance(values, TupleType):
   258             message = _("Invalid value \"%s\" for variable grid element")%data
   282             message = _("Invalid value \"%s\" for variable grid element") % data
   259             values = None
   283             values = None
   260         if values is not None:
   284         if values is not None:
   261             if col != wx.NOT_FOUND and row != wx.NOT_FOUND:
   285             if col != wx.NOT_FOUND and row != wx.NOT_FOUND:
   262                 colname = self.ParentWindow.Table.GetColLabelValue(col, False)
   286                 colname = self.ParentWindow.Table.GetColLabelValue(col, False)
   263                 if colname == "Location" and values[1] == "location":
   287                 if colname == "Location" and values[1] == "location":
   272 
   296 
   273                         if values[2] is not None:
   297                         if values[2] is not None:
   274                             base_location_type = self.ParentWindow.Controler.GetBaseType(values[2])
   298                             base_location_type = self.ParentWindow.Controler.GetBaseType(values[2])
   275                             if values[2] != variable_type and base_type != base_location_type:
   299                             if values[2] != variable_type and base_type != base_location_type:
   276                                 message = _("Incompatible data types between \"{a1}\" and \"{a2}\"").\
   300                                 message = _("Incompatible data types between \"{a1}\" and \"{a2}\"").\
   277                                           format(a1 = values[2], a2 = variable_type)
   301                                           format(a1=values[2], a2=variable_type)
   278 
   302 
   279                         if message is None:
   303                         if message is None:
   280                             if not location.startswith("%"):
   304                             if not location.startswith("%"):
   281                                 if location[0].isdigit() and base_type != "BOOL":
   305                                 if location[0].isdigit() and base_type != "BOOL":
   282                                     message = _("Incompatible size of data between \"%s\" and \"BOOL\"")%location
   306                                     message = _("Incompatible size of data between \"%s\" and \"BOOL\"") % location
   283                                 elif location[0] not in LOCATIONDATATYPES:
   307                                 elif location[0] not in LOCATIONDATATYPES:
   284                                     message = _("Unrecognized data size \"%s\"")%location[0]
   308                                     message = _("Unrecognized data size \"%s\"") % location[0]
   285                                 elif base_type not in LOCATIONDATATYPES[location[0]]:
   309                                 elif base_type not in LOCATIONDATATYPES[location[0]]:
   286                                     message = _("Incompatible size of data between \"{a1}\" and \"{a2}\"").\
   310                                     message = _("Incompatible size of data between \"{a1}\" and \"{a2}\"").\
   287                                               format(a1 = location, a2 = variable_type)
   311                                               format(a1=location, a2=variable_type)
   288                                 else:
   312                                 else:
   289                                     dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow.ParentWindow,
   313                                     dialog = wx.SingleChoiceDialog(
   290                                           _("Select a variable class:"), _("Variable class"),
   314                                         self.ParentWindow.ParentWindow.ParentWindow,
   291                                           [_("Input"), _("Output"), _("Memory")],
   315                                         _("Select a variable class:"),
   292                                           wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL)
   316                                         _("Variable class"),
       
   317                                         [_("Input"), _("Output"), _("Memory")],
       
   318                                         wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL)
   293                                     if dialog.ShowModal() == wx.ID_OK:
   319                                     if dialog.ShowModal() == wx.ID_OK:
   294                                         selected = dialog.GetSelection()
   320                                         selected = dialog.GetSelection()
   295                                     else:
   321                                     else:
   296                                         selected = None
   322                                         selected = None
   297                                     dialog.Destroy()
   323                                     dialog.Destroy()
   316                         self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
   342                         self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
   317                         self.ParentWindow.SaveValues()
   343                         self.ParentWindow.SaveValues()
   318             elif (element_type not in ["config", "resource", "function"] and values[1] == "Global" and
   344             elif (element_type not in ["config", "resource", "function"] and values[1] == "Global" and
   319                   self.ParentWindow.Filter in ["All", "Interface", "External"] or
   345                   self.ParentWindow.Filter in ["All", "Interface", "External"] or
   320                   element_type != "function" and values[1] in ["location", "NamedConstant"]):
   346                   element_type != "function" and values[1] in ["location", "NamedConstant"]):
   321                 if values[1] in  ["location","NamedConstant"]:
   347                 if values[1] in ["location", "NamedConstant"]:
   322                     var_name = values[3]
   348                     var_name = values[3]
   323                 else:
   349                 else:
   324                     var_name = values[0]
   350                     var_name = values[0]
   325                 tagname = self.ParentWindow.GetTagName()
   351                 tagname = self.ParentWindow.GetTagName()
   326                 dlg = wx.TextEntryDialog(
   352                 dlg = wx.TextEntryDialog(
   330                 dlg.SetValue(var_name)
   356                 dlg.SetValue(var_name)
   331                 var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None
   357                 var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None
   332                 dlg.Destroy()
   358                 dlg.Destroy()
   333                 if var_name is None:
   359                 if var_name is None:
   334                     return
   360                     return
   335                 elif var_name.upper() in [name.upper()
   361                 elif var_name.upper() in [
   336                         for name in self.ParentWindow.Controler.\
   362                         name.upper() for name in
   337                             GetProjectPouNames(self.ParentWindow.Debug)]:
   363                         self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
   338                     message = _("\"%s\" pou already exists!")%var_name
   364                     message = _("\"%s\" pou already exists!") % var_name
   339                 elif not var_name.upper() in [name.upper()
   365                 elif not var_name.upper() in [
   340                         for name in self.ParentWindow.Controler.\
   366                         name.upper()
   341                             GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
   367                         for name in self.ParentWindow.Controler.
       
   368                         GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
   342                     var_infos = self.ParentWindow.DefaultValue.copy()
   369                     var_infos = self.ParentWindow.DefaultValue.copy()
   343                     var_infos.Name = var_name
   370                     var_infos.Name = var_name
   344                     var_infos.Type = values[2]
   371                     var_infos.Type = values[2]
   345                     var_infos.Documentation = values[4]
   372                     var_infos.Documentation = values[4]
   346                     if values[1] == "location":
   373                     if values[1] == "location":
   347                         location = values[0]
   374                         location = values[0]
   348                         if not location.startswith("%"):
   375                         if not location.startswith("%"):
   349                             dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow.ParentWindow,
   376                             dialog = wx.SingleChoiceDialog(
   350                                   _("Select a variable class:"), _("Variable class"),
   377                                 self.ParentWindow.ParentWindow.ParentWindow,
   351                                   [_("Input"), _("Output"), _("Memory")],
   378                                 _("Select a variable class:"),
   352                                   wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL)
   379                                 _("Variable class"),
       
   380                                 [_("Input"), _("Output"), _("Memory")],
       
   381                                 wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL)
   353                             if dialog.ShowModal() == wx.ID_OK:
   382                             if dialog.ShowModal() == wx.ID_OK:
   354                                 selected = dialog.GetSelection()
   383                                 selected = dialog.GetSelection()
   355                             else:
   384                             else:
   356                                 selected = None
   385                                 selected = None
   357                             dialog.Destroy()
   386                             dialog.Destroy()
   366                         if element_type == "functionBlock":
   395                         if element_type == "functionBlock":
   367                             configs = self.ParentWindow.Controler.GetProjectConfigNames(
   396                             configs = self.ParentWindow.Controler.GetProjectConfigNames(
   368                                                                 self.ParentWindow.Debug)
   397                                                                 self.ParentWindow.Debug)
   369                             if len(configs) == 0:
   398                             if len(configs) == 0:
   370                                 return
   399                                 return
   371                             if not var_name.upper() in [name.upper()
   400                             if not var_name.upper() in [
   372                                 for name in self.ParentWindow.Controler.\
   401                                     name.upper() for name in
   373                                     GetConfigurationVariableNames(configs[0])]:
   402                                     self.ParentWindow.Controler.GetConfigurationVariableNames(configs[0])]:
   374                                 self.ParentWindow.Controler.AddConfigurationGlobalVar(
   403                                 self.ParentWindow.Controler.AddConfigurationGlobalVar(
   375                                     configs[0], values[2], var_name, location, "")
   404                                     configs[0], values[2], var_name, location, "")
   376                             var_infos.Class = "External"
   405                             var_infos.Class = "External"
   377                         else:
   406                         else:
   378                             if element_type == "program":
   407                             if element_type == "program":
   379                                 var_infos.Class = "Local"
   408                                 var_infos.Class = "Local"
   380                             else:
   409                             else:
   381                                 var_infos.Class = "Global"
   410                                 var_infos.Class = "Global"
   382                             var_infos.Location = location
   411                             var_infos.Location = location
   383                     elif values[1] == "NamedConstant":
   412                     elif values[1] == "NamedConstant":
   384                         if element_type in ["functionBlock","program"]:
   413                         if element_type in ["functionBlock", "program"]:
   385                             var_infos.Class = "Local"
   414                             var_infos.Class = "Local"
   386                             var_infos.InitialValue = values[0]
   415                             var_infos.InitialValue = values[0]
   387                         else :
   416                         else:
   388                             return
   417                             return
   389                     else:
   418                     else:
   390                         var_infos.Class = "External"
   419                         var_infos.Class = "External"
   391                     var_infos.Number = len(self.ParentWindow.Values)
   420                     var_infos.Number = len(self.ParentWindow.Values)
   392                     self.ParentWindow.Values.append(var_infos)
   421                     self.ParentWindow.Values.append(var_infos)
   393                     self.ParentWindow.SaveValues()
   422                     self.ParentWindow.SaveValues()
   394                     self.ParentWindow.RefreshValues()
   423                     self.ParentWindow.RefreshValues()
   395                 else:
   424                 else:
   396                     message = _("\"%s\" element for this pou already exists!")%var_name
   425                     message = _("\"%s\" element for this pou already exists!") % var_name
   397 
   426 
   398         if message is not None:
   427         if message is not None:
   399             wx.CallAfter(self.ShowMessage, message)
   428             wx.CallAfter(self.ShowMessage, message)
   400 
   429 
   401     def ShowMessage(self, message):
   430     def ShowMessage(self, message):
   402         message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
   431         message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK | wx.ICON_ERROR)
   403         message.ShowModal()
   432         message.ShowModal()
   404         message.Destroy()
   433         message.Destroy()
   405 
   434 
   406 #-------------------------------------------------------------------------------
   435 
       
   436 # -------------------------------------------------------------------------------
   407 #                               Variable Panel
   437 #                               Variable Panel
   408 #-------------------------------------------------------------------------------
   438 # -------------------------------------------------------------------------------
       
   439 
   409 
   440 
   410 class VariablePanel(wx.Panel):
   441 class VariablePanel(wx.Panel):
   411 
   442 
   412     def __init__(self, parent, window, controler, element_type, debug=False):
   443     def __init__(self, parent, window, controler, element_type, debug=False):
   413         wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
   444         wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
   417         self.MainSizer.AddGrowableRow(1)
   448         self.MainSizer.AddGrowableRow(1)
   418 
   449 
   419         controls_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=5)
   450         controls_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=5)
   420         controls_sizer.AddGrowableCol(5)
   451         controls_sizer.AddGrowableCol(5)
   421         controls_sizer.AddGrowableRow(0)
   452         controls_sizer.AddGrowableRow(0)
   422         self.MainSizer.AddSizer(controls_sizer, border=5, flag=wx.GROW|wx.ALL)
   453         self.MainSizer.AddSizer(controls_sizer, border=5, flag=wx.GROW | wx.ALL)
   423 
   454 
   424         self.ReturnTypeLabel = wx.StaticText(self, label=_('Return Type:'))
   455         self.ReturnTypeLabel = wx.StaticText(self, label=_('Return Type:'))
   425         controls_sizer.AddWindow(self.ReturnTypeLabel, flag=wx.ALIGN_CENTER_VERTICAL)
   456         controls_sizer.AddWindow(self.ReturnTypeLabel, flag=wx.ALIGN_CENTER_VERTICAL)
   426 
   457 
   427         self.ReturnType = wx.ComboBox(self,
   458         self.ReturnType = wx.ComboBox(self,
   428               size=wx.Size(145, -1), style=wx.CB_READONLY)
   459                                       size=wx.Size(145, -1), style=wx.CB_READONLY)
   429         self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, self.ReturnType)
   460         self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, self.ReturnType)
   430         controls_sizer.AddWindow(self.ReturnType)
   461         controls_sizer.AddWindow(self.ReturnType)
   431 
   462 
   432         self.DescriptionLabel = wx.StaticText(self, label=_('Description:'))
   463         self.DescriptionLabel = wx.StaticText(self, label=_('Description:'))
   433         controls_sizer.AddWindow(self.DescriptionLabel, flag=wx.ALIGN_CENTER_VERTICAL)
   464         controls_sizer.AddWindow(self.DescriptionLabel, flag=wx.ALIGN_CENTER_VERTICAL)
   434 
   465 
   435         self.Description = wx.TextCtrl(self,
   466         self.Description = wx.TextCtrl(self,
   436               size=wx.Size(250, -1), style=wx.TE_PROCESS_ENTER)
   467                                        size=wx.Size(250, -1), style=wx.TE_PROCESS_ENTER)
   437         self.Bind(wx.EVT_TEXT_ENTER, self.OnDescriptionChanged, self.Description)
   468         self.Bind(wx.EVT_TEXT_ENTER, self.OnDescriptionChanged, self.Description)
   438         self.Description.Bind(wx.EVT_KILL_FOCUS, self.OnDescriptionChanged)
   469         self.Description.Bind(wx.EVT_KILL_FOCUS, self.OnDescriptionChanged)
   439         controls_sizer.AddWindow(self.Description)
   470         controls_sizer.AddWindow(self.Description)
   440 
   471 
   441         class_filter_label = wx.StaticText(self, label=_('Class Filter:'))
   472         class_filter_label = wx.StaticText(self, label=_('Class Filter:'))
   442         controls_sizer.AddWindow(class_filter_label, flag=wx.ALIGN_CENTER_VERTICAL)
   473         controls_sizer.AddWindow(class_filter_label, flag=wx.ALIGN_CENTER_VERTICAL)
   443 
   474 
   444         self.ClassFilter = wx.ComboBox(self,
   475         self.ClassFilter = wx.ComboBox(self,
   445               size=wx.Size(145, -1), style=wx.CB_READONLY)
   476                                        size=wx.Size(145, -1), style=wx.CB_READONLY)
   446         self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, self.ClassFilter)
   477         self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, self.ClassFilter)
   447         controls_sizer.AddWindow(self.ClassFilter)
   478         controls_sizer.AddWindow(self.ClassFilter)
   448 
   479 
   449         for name, bitmap, help in [
   480         for name, bitmap, help in [
   450                 ("AddButton", "add_element", _("Add variable")),
   481                 ("AddButton", "add_element", _("Add variable")),
   451                 ("DeleteButton", "remove_element", _("Remove variable")),
   482                 ("DeleteButton", "remove_element", _("Remove variable")),
   452                 ("UpButton", "up", _("Move variable up")),
   483                 ("UpButton", "up", _("Move variable up")),
   453                 ("DownButton", "down", _("Move variable down"))]:
   484                 ("DownButton", "down", _("Move variable down"))]:
   454             button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap),
   485             button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap),
   455                   size=wx.Size(28, 28), style=wx.NO_BORDER)
   486                                                     size=wx.Size(28, 28), style=wx.NO_BORDER)
   456             button.SetToolTipString(help)
   487             button.SetToolTipString(help)
   457             setattr(self, name, button)
   488             setattr(self, name, button)
   458             controls_sizer.AddWindow(button)
   489             controls_sizer.AddWindow(button)
   459 
   490 
   460         self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL | wx.HSCROLL)
   491         self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL | wx.HSCROLL)
   461         self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
   492         self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
   462         self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
   493         self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
   463               self.OnVariablesGridCellChange)
   494                                 self.OnVariablesGridCellChange)
   464         self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK,
   495         self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK,
   465               self.OnVariablesGridCellLeftClick)
   496                                 self.OnVariablesGridCellLeftClick)
   466         self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN,
   497         self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN,
   467               self.OnVariablesGridEditorShown)
   498                                 self.OnVariablesGridEditorShown)
   468         self.MainSizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
   499         self.MainSizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
   469 
   500 
   470         self.SetSizer(self.MainSizer)
   501         self.SetSizer(self.MainSizer)
   471 
   502 
   472         self.ParentWindow = window
   503         self.ParentWindow = window
   474         self.ElementType = element_type
   505         self.ElementType = element_type
   475         self.Debug = debug
   506         self.Debug = debug
   476 
   507 
   477         self.RefreshHighlightsTimer = wx.Timer(self, -1)
   508         self.RefreshHighlightsTimer = wx.Timer(self, -1)
   478         self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer,
   509         self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer,
   479               self.RefreshHighlightsTimer)
   510                   self.RefreshHighlightsTimer)
   480 
   511 
   481         self.Filter = "All"
   512         self.Filter = "All"
   482         self.FilterChoices = []
   513         self.FilterChoices = []
   483         self.FilterChoiceTransfer = GetFilterChoiceTransfer()
   514         self.FilterChoiceTransfer = GetFilterChoiceTransfer()
   484 
   515 
   485         self.DefaultValue = _VariableInfos("", "", "", "", "", True, "", DefaultType, ([], []), 0)
   516         self.DefaultValue = _VariableInfos("", "", "", "", "", True, "", DefaultType, ([], []), 0)
   486 
   517 
   487         if element_type in ["config", "resource"]:
   518         if element_type in ["config", "resource"]:
   488             self.DefaultTypes = {"All" : "Global"}
   519             self.DefaultTypes = {"All": "Global"}
   489         else:
   520         else:
   490             self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"}
   521             self.DefaultTypes = {"All": "Local", "Interface": "Input", "Variables": "Local"}
   491 
   522 
   492         if element_type in ["config", "resource"] \
   523         if element_type in ["config", "resource"] \
   493         or element_type in ["program", "transition", "action"]:
   524            or element_type in ["program", "transition", "action"]:
   494             # this is an element that can have located variables
   525             # this is an element that can have located variables
   495             self.Table = VariableTable(self, [], GetVariableTableColnames(True))
   526             self.Table = VariableTable(self, [], GetVariableTableColnames(True))
   496 
   527 
   497             if element_type in ["config", "resource"]:
   528             if element_type in ["config", "resource"]:
   498                 self.FilterChoices = ["All", "Global"]#,"Access"]
   529                 self.FilterChoices = ["All", "Global"]  # ,"Access"]
   499             else:
   530             else:
   500                 self.FilterChoices = ["All",
   531                 self.FilterChoices = ["All",
   501                                         "Interface", "   Input", "   Output", "   InOut", "   External",
   532                                       "Interface", "   Input", "   Output", "   InOut", "   External",
   502                                         "Variables", "   Local", "   Temp"]#,"Access"]
   533                                       "Variables", "   Local", "   Temp"]  # ,"Access"]
   503 
   534 
   504             # these condense the ColAlignements list
   535             # these condense the ColAlignements list
   505             l = wx.ALIGN_LEFT
   536             left = wx.ALIGN_LEFT
   506             c = wx.ALIGN_CENTER
   537             center = wx.ALIGN_CENTER
   507 
   538 
   508             #                      Num  Name    Class   Type    Loc     Init    Option   Doc
   539             #                        Num     Name    Class   Type    Loc     Init    Option   Doc
   509             self.ColSizes       = [40,  80,     100,    80,     110,     120,    100,     160]
   540             self.ColSettings = {
   510             self.ColAlignements = [c,   l,      l,      l,      l,      l,      l,       l]
   541                 "size":             [40,     80,     100,    80,     110,    120,    100,     160],
   511             self.ColFixedSizeFlag=[True,False,  True,   False,  True,   True,   True,    False]
   542                 "alignement":       [center, left,   left,   left,   left,   left,   left,    left],
       
   543                 "fixed_size":       [True,   False,  True,   False,  True,   True,   True,    False],
       
   544             }
   512 
   545 
   513         else:
   546         else:
   514             # this is an element that cannot have located variables
   547             # this is an element that cannot have located variables
   515             self.Table = VariableTable(self, [], GetVariableTableColnames(False))
   548             self.Table = VariableTable(self, [], GetVariableTableColnames(False))
   516 
   549 
   517             if element_type == "function":
   550             if element_type == "function":
   518                 self.FilterChoices = ["All",
   551                 self.FilterChoices = ["All",
   519                                         "Interface", "   Input", "   Output", "   InOut",
   552                                       "Interface", "   Input", "   Output", "   InOut",
   520                                         "Variables", "   Local"]
   553                                       "Variables", "   Local"]
   521             else:
   554             else:
   522                 self.FilterChoices = ["All",
   555                 self.FilterChoices = ["All",
   523                                         "Interface", "   Input", "   Output", "   InOut", "   External",
   556                                       "Interface", "   Input", "   Output", "   InOut", "   External",
   524                                         "Variables", "   Local", "   Temp"]
   557                                       "Variables", "   Local", "   Temp"]
   525 
   558 
   526             # these condense the ColAlignements list
   559             # these condense the alignements list
   527             l = wx.ALIGN_LEFT
   560             left = wx.ALIGN_LEFT
   528             c = wx.ALIGN_CENTER
   561             center = wx.ALIGN_CENTER
   529 
   562 
   530             #                      Num  Name    Class   Type    Init    Option   Doc
   563             #                        Num     Name    Class   Type    Init    Option   Doc
   531             self.ColSizes       = [40,  80,     100,    80,     120,    100,     160]
   564             self.ColSettings = {
   532             self.ColAlignements = [c,   l,      l,      l,      l,      l,       l]
   565                 "size":             [40,     80,     100,    80,     120,    100,     160],
   533             self.ColFixedSizeFlag=[True,False,  True,   False,  True,   True,    False]
   566                 "alignement":       [center, left,   left,   left,   left,   left,    left],
   534 
   567                 "fixed_size":       [True,   False,  True,   False,  True,   True,    False],
   535         self.PanelWidthMin = sum(self.ColSizes)
   568             }
   536         
   569 
       
   570         self.PanelWidthMin = sum(self.ColSettings["size"])
       
   571 
   537         self.ElementType = element_type
   572         self.ElementType = element_type
   538         self.BodyType = None
   573         self.BodyType = None
   539 
   574 
   540         for choice in self.FilterChoices:
   575         for choice in self.FilterChoices:
   541             self.ClassFilter.Append(_(choice))
   576             self.ClassFilter.Append(_(choice))
   590             else:
   625             else:
   591                 self.Values.append(row_content)
   626                 self.Values.append(row_content)
   592                 new_row = self.Table.GetNumberRows()
   627                 new_row = self.Table.GetNumberRows()
   593             self.SaveValues()
   628             self.SaveValues()
   594             if self.ElementType == "resource":
   629             if self.ElementType == "resource":
   595                 self.ParentWindow.RefreshView(variablepanel = False)
   630                 self.ParentWindow.RefreshView(variablepanel=False)
   596             self.RefreshValues()
   631             self.RefreshValues()
   597             return new_row
   632             return new_row
   598         setattr(self.VariablesGrid, "_AddRow", _AddVariable)
   633         setattr(self.VariablesGrid, "_AddRow", _AddVariable)
   599 
   634 
   600         def _DeleteVariable(row):
   635         def _DeleteVariable(row):
   601             if _GetRowEdit(row):
   636             if _GetRowEdit(row):
   602                 self.Values.remove(self.Table.GetRow(row))
   637                 self.Values.remove(self.Table.GetRow(row))
   603                 self.SaveValues()
   638                 self.SaveValues()
   604                 if self.ElementType == "resource":
   639                 if self.ElementType == "resource":
   605                     self.ParentWindow.RefreshView(variablepanel = False)
   640                     self.ParentWindow.RefreshView(variablepanel=False)
   606                 self.RefreshValues()
   641                 self.RefreshValues()
   607         setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
   642         setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
   608 
   643 
   609         def _MoveVariable(row, move):
   644         def _MoveVariable(row, move):
   610             if self.Filter == "All":
   645             if self.Filter == "All":
   641         setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons)
   676         setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons)
   642 
   677 
   643         panel_width = window.Parent.ScreenRect.Width - 35
   678         panel_width = window.Parent.ScreenRect.Width - 35
   644         if panel_width > self.PanelWidthMin:
   679         if panel_width > self.PanelWidthMin:
   645             stretch_cols_width = panel_width
   680             stretch_cols_width = panel_width
   646             stretch_cols_sum = 0            
   681             stretch_cols_sum = 0
   647             for col in range(len(self.ColFixedSizeFlag)):
   682             for col in range(len(self.ColSettings["fixed_size"])):
   648                 if self.ColFixedSizeFlag[col]:
   683                 if self.ColSettings["fixed_size"][col]:
   649                     stretch_cols_width -= self.ColSizes[col]
   684                     stretch_cols_width -= self.ColSettings["size"][col]
   650                 else:
   685                 else:
   651                     stretch_cols_sum += self.ColSizes[col]
   686                     stretch_cols_sum += self.ColSettings["size"][col]
   652 
   687 
   653         self.VariablesGrid.SetRowLabelSize(0)
   688         self.VariablesGrid.SetRowLabelSize(0)
   654         for col in range(self.Table.GetNumberCols()):
   689         for col in range(self.Table.GetNumberCols()):
   655             attr = wx.grid.GridCellAttr()
   690             attr = wx.grid.GridCellAttr()
   656             attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
   691             attr.SetAlignment(self.ColSettings["alignement"][col], wx.ALIGN_CENTRE)
   657             self.VariablesGrid.SetColAttr(col, attr)
   692             self.VariablesGrid.SetColAttr(col, attr)
   658             self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col])
   693             self.VariablesGrid.SetColMinimalWidth(col, self.ColSettings["size"][col])
   659             if (panel_width > self.PanelWidthMin) and not self.ColFixedSizeFlag[col]:
   694             if (panel_width > self.PanelWidthMin) and not self.ColSettings["fixed_size"][col]:
   660                 self.VariablesGrid.SetColSize(col, int((float(self.ColSizes[col])/stretch_cols_sum)*stretch_cols_width))
   695                 self.VariablesGrid.SetColSize(col, int((float(self.ColSettings["size"][col])/stretch_cols_sum)*stretch_cols_width))
   661             else:
   696             else:
   662                 self.VariablesGrid.SetColSize(col, self.ColSizes[col])
   697                 self.VariablesGrid.SetColSize(col, self.ColSettings["size"][col])
   663 
   698 
   664     def __del__(self):
   699     def __del__(self):
   665         self.RefreshHighlightsTimer.Stop()
   700         self.RefreshHighlightsTimer.Stop()
   666 
   701 
   667     def SetTagName(self, tagname):
   702     def SetTagName(self, tagname):
   670 
   705 
   671     def GetTagName(self):
   706     def GetTagName(self):
   672         return self.TagName
   707         return self.TagName
   673 
   708 
   674     def IsFunctionBlockType(self, name):
   709     def IsFunctionBlockType(self, name):
   675         if (isinstance(name, TupleType) or
   710         if isinstance(name, TupleType) or \
   676             self.ElementType != "function" and self.BodyType in ["ST", "IL"]):
   711            self.ElementType != "function" and self.BodyType in ["ST", "IL"]:
   677             return False
   712             return False
   678         else:
   713         else:
   679             return self.Controler.GetBlockType(name, debug=self.Debug) is not None
   714             return self.Controler.GetBlockType(name, debug=self.Debug) is not None
   680 
   715 
   681     def RefreshView(self):
   716     def RefreshView(self):
   723 
   758 
   724     def OnReturnTypeChanged(self, event):
   759     def OnReturnTypeChanged(self, event):
   725         words = self.TagName.split("::")
   760         words = self.TagName.split("::")
   726         self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection())
   761         self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection())
   727         self.Controler.BufferProject()
   762         self.Controler.BufferProject()
   728         self.ParentWindow.RefreshView(variablepanel = False)
   763         self.ParentWindow.RefreshView(variablepanel=False)
   729         self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
   764         self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
   730         event.Skip()
   765         event.Skip()
   731 
   766 
   732     def OnDescriptionChanged(self, event):
   767     def OnDescriptionChanged(self, event):
   733         words = self.TagName.split("::")
   768         words = self.TagName.split("::")
   745         self.VariablesGrid.RefreshButtons()
   780         self.VariablesGrid.RefreshButtons()
   746         event.Skip()
   781         event.Skip()
   747 
   782 
   748     def RefreshTypeList(self):
   783     def RefreshTypeList(self):
   749         if self.Filter == "All":
   784         if self.Filter == "All":
   750             self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All","Interface","Variables"]]
   785             self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All", "Interface", "Variables"]]
   751         elif self.Filter == "Interface":
   786         elif self.Filter == "Interface":
   752             self.ClassList = ["Input","Output","InOut","External"]
   787             self.ClassList = ["Input", "Output", "InOut", "External"]
   753         elif self.Filter == "Variables":
   788         elif self.Filter == "Variables":
   754             self.ClassList = ["Local","Temp"]
   789             self.ClassList = ["Local", "Temp"]
   755         else:
   790         else:
   756             self.ClassList = [self.Filter]
   791             self.ClassList = [self.Filter]
   757 
   792 
   758     def ShowErrorMessage(self, message):
   793     def ShowErrorMessage(self, message):
   759         dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
   794         dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR)
   760         dialog.ShowModal()
   795         dialog.ShowModal()
   761         dialog.Destroy()
   796         dialog.Destroy()
   762             
   797 
   763     def OnVariablesGridCellChange(self, event):
   798     def OnVariablesGridCellChange(self, event):
   764         row, col = event.GetRow(), event.GetCol()
   799         row, col = event.GetRow(), event.GetCol()
   765         colname = self.Table.GetColLabelValue(col, False)
   800         colname = self.Table.GetColLabelValue(col, False)
   766         value = self.Table.GetValue(row, col)
   801         value = self.Table.GetValue(row, col)
   767         message = None
   802         message = None
   791             elif colname == "Location":
   826             elif colname == "Location":
   792                 wx.CallAfter(self.ParentWindow.RefreshView)
   827                 wx.CallAfter(self.ParentWindow.RefreshView)
   793 
   828 
   794         if message is not None:
   829         if message is not None:
   795             wx.CallAfter(self.ShowErrorMessage, message)
   830             wx.CallAfter(self.ShowErrorMessage, message)
   796             event.Veto()            
   831             event.Veto()
   797         else:
   832         else:
   798             event.Skip()
   833             event.Skip()
   799 
   834 
   800     def ClearLocation(self, row, col, value):
   835     def ClearLocation(self, row, col, value):
   801         if self.Values[row].Location != '':
   836         if self.Values[row].Location != '':
   803                self.Table.GetColLabelValue(col, False) == 'Type' and not self.Controler.IsLocatableType(value):
   838                self.Table.GetColLabelValue(col, False) == 'Type' and not self.Controler.IsLocatableType(value):
   804                 self.Values[row].Location = ''
   839                 self.Values[row].Location = ''
   805                 self.RefreshValues()
   840                 self.RefreshValues()
   806                 self.SaveValues()
   841                 self.SaveValues()
   807 
   842 
   808     def BuildStdIECTypesMenu(self,type_menu):
   843     def BuildStdIECTypesMenu(self, type_menu):
   809             # build a submenu containing standard IEC types
   844             # build a submenu containing standard IEC types
   810             base_menu = wx.Menu(title='')
   845             base_menu = wx.Menu(title='')
   811             for base_type in self.Controler.GetBaseTypes():
   846             for base_type in self.Controler.GetBaseTypes():
   812                 new_id = wx.NewId()
   847                 new_id = wx.NewId()
   813                 base_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
   848                 base_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
   814                 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id)
   849                 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id)
   815 
   850 
   816             type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu)
   851             type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu)
   817 
   852 
   818     def BuildUserTypesMenu(self,type_menu):
   853     def BuildUserTypesMenu(self, type_menu):
   819             # build a submenu containing user-defined types
   854             # build a submenu containing user-defined types
   820             datatype_menu = wx.Menu(title='')
   855             datatype_menu = wx.Menu(title='')
   821             datatypes = self.Controler.GetDataTypes(basetypes = False, confnodetypes = False)
   856             datatypes = self.Controler.GetDataTypes(basetypes=False, confnodetypes=False)
   822             for datatype in datatypes:
   857             for datatype in datatypes:
   823                 new_id = wx.NewId()
   858                 new_id = wx.NewId()
   824                 datatype_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
   859                 datatype_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
   825                 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id)
   860                 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id)
   826 
   861 
   841     def BuildProjectTypesMenu(self, type_menu, classtype):
   876     def BuildProjectTypesMenu(self, type_menu, classtype):
   842         # build a submenu containing function block types
   877         # build a submenu containing function block types
   843         bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
   878         bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
   844         pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
   879         pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
   845         if classtype in ["Input", "Output", "InOut", "External", "Global"] or \
   880         if classtype in ["Input", "Output", "InOut", "External", "Global"] or \
   846         poutype != "function" and bodytype in ["ST", "IL"]:
   881            poutype != "function" and bodytype in ["ST", "IL"]:
   847             functionblock_menu = wx.Menu(title='')
   882             functionblock_menu = wx.Menu(title='')
   848             fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName)
   883             fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName)
   849             for functionblock_type in fbtypes:
   884             for functionblock_type in fbtypes:
   850                 new_id = wx.NewId()
   885                 new_id = wx.NewId()
   851                 functionblock_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type)
   886                 functionblock_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type)
   871 
   906 
   872             self.BuildUserTypesMenu(type_menu)
   907             self.BuildUserTypesMenu(type_menu)
   873 
   908 
   874             self.BuildLibsTypesMenu(type_menu)
   909             self.BuildLibsTypesMenu(type_menu)
   875 
   910 
   876             self.BuildProjectTypesMenu(type_menu,classtype)
   911             self.BuildProjectTypesMenu(type_menu, classtype)
   877 
   912 
   878             self.BuildArrayTypesMenu(type_menu)
   913             self.BuildArrayTypesMenu(type_menu)
   879 
   914 
   880             rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
   915             rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
   881             corner_x = rect.x + rect.width
   916             corner_x = rect.x + rect.width
   895         def VariableTypeFunction(event):
   930         def VariableTypeFunction(event):
   896             row = self.VariablesGrid.GetGridCursorRow()
   931             row = self.VariablesGrid.GetGridCursorRow()
   897             self.Table.SetValueByName(row, "Type", base_type)
   932             self.Table.SetValueByName(row, "Type", base_type)
   898             self.Table.ResetView(self.VariablesGrid)
   933             self.Table.ResetView(self.VariablesGrid)
   899             self.SaveValues(False)
   934             self.SaveValues(False)
   900             self.ParentWindow.RefreshView(variablepanel = False)
   935             self.ParentWindow.RefreshView(variablepanel=False)
   901             self.Controler.BufferProject()
   936             self.Controler.BufferProject()
   902             self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
   937             self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
   903         return VariableTypeFunction
   938         return VariableTypeFunction
   904 
   939 
   905     def VariableArrayTypeFunction(self, event):
   940     def VariableArrayTypeFunction(self, event):
   909                                  self.Table.GetValueByName(row, "Type"))
   944                                  self.Table.GetValueByName(row, "Type"))
   910         if dialog.ShowModal() == wx.ID_OK:
   945         if dialog.ShowModal() == wx.ID_OK:
   911             self.Table.SetValueByName(row, "Type", dialog.GetValue())
   946             self.Table.SetValueByName(row, "Type", dialog.GetValue())
   912             self.Table.ResetView(self.VariablesGrid)
   947             self.Table.ResetView(self.VariablesGrid)
   913             self.SaveValues(False)
   948             self.SaveValues(False)
   914             self.ParentWindow.RefreshView(variablepanel = False)
   949             self.ParentWindow.RefreshView(variablepanel=False)
   915             self.Controler.BufferProject()
   950             self.Controler.BufferProject()
   916             self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
   951             self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
   917         dialog.Destroy()
   952         dialog.Destroy()
   918 
   953 
   919     def OnVariablesGridCellLeftClick(self, event):
   954     def OnVariablesGridCellLeftClick(self, event):
   935                 variable.Number = num + 1
   970                 variable.Number = num + 1
   936                 data.append(variable)
   971                 data.append(variable)
   937         self.Table.SetData(data)
   972         self.Table.SetData(data)
   938         self.Table.ResetView(self.VariablesGrid)
   973         self.Table.ResetView(self.VariablesGrid)
   939 
   974 
   940     def SaveValues(self, buffer = True):
   975     def SaveValues(self, buffer=True):
   941         words = self.TagName.split("::")
   976         words = self.TagName.split("::")
   942         if self.ElementType == "config":
   977         if self.ElementType == "config":
   943             self.Controler.SetConfigurationGlobalVars(words[1], self.Values)
   978             self.Controler.SetConfigurationGlobalVars(words[1], self.Values)
   944         elif self.ElementType == "resource":
   979         elif self.ElementType == "resource":
   945             self.Controler.SetConfigurationResourceGlobalVars(words[1], words[2], self.Values)
   980             self.Controler.SetConfigurationResourceGlobalVars(words[1], words[2], self.Values)
   949             self.Controler.SetPouInterfaceVars(words[1], self.Values)
   984             self.Controler.SetPouInterfaceVars(words[1], self.Values)
   950         if buffer:
   985         if buffer:
   951             self.Controler.BufferProject()
   986             self.Controler.BufferProject()
   952             self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
   987             self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
   953 
   988 
   954 #-------------------------------------------------------------------------------
   989     # -------------------------------------------------------------------------------
   955 #                        Highlights showing functions
   990     #                        Highlights showing functions
   956 #-------------------------------------------------------------------------------
   991     # -------------------------------------------------------------------------------
   957 
   992 
   958     def OnRefreshHighlightsTimer(self, event):
   993     def OnRefreshHighlightsTimer(self, event):
   959         self.Table.ResetView(self.VariablesGrid)
   994         self.Table.ResetView(self.VariablesGrid)
   960         event.Skip()
   995         event.Skip()
   961 
   996