controls/VariablePanel.py
branchwxPython4
changeset 3660 0e41dbe6ddcd
parent 3583 27e7679ddb99
child 3750 f62625418bff
equal deleted inserted replaced
3659:278dc1144059 3660:0e41dbe6ddcd
   320                                         selected = dialog.GetSelection()
   320                                         selected = dialog.GetSelection()
   321                                     else:
   321                                     else:
   322                                         selected = None
   322                                         selected = None
   323                                     dialog.Destroy()
   323                                     dialog.Destroy()
   324                                     if selected is None:
   324                                     if selected is None:
   325                                         return
   325                                         return False
   326                                     if selected == 0:
   326                                     if selected == 0:
   327                                         location = "%I" + location
   327                                         location = "%I" + location
   328                                     elif selected == 1:
   328                                     elif selected == 1:
   329                                         location = "%Q" + location
   329                                         location = "%Q" + location
   330                                     else:
   330                                     else:
   355                     _('Variable Drop'), var_name)
   355                     _('Variable Drop'), var_name)
   356                 dlg.SetValue(var_name)
   356                 dlg.SetValue(var_name)
   357                 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
   358                 dlg.Destroy()
   358                 dlg.Destroy()
   359                 if var_name is None:
   359                 if var_name is None:
   360                     return
   360                     return False
   361                 elif var_name.upper() in [
   361                 elif var_name.upper() in [
   362                         name.upper() for name in
   362                         name.upper() for name in
   363                         self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
   363                         self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
   364                     message = _("\"%s\" pou already exists!") % var_name
   364                     message = _("\"%s\" pou already exists!") % var_name
   365                 elif not var_name.upper() in [
   365                 elif not var_name.upper() in [
   383                                 selected = dialog.GetSelection()
   383                                 selected = dialog.GetSelection()
   384                             else:
   384                             else:
   385                                 selected = None
   385                                 selected = None
   386                             dialog.Destroy()
   386                             dialog.Destroy()
   387                             if selected is None:
   387                             if selected is None:
   388                                 return
   388                                 return False
   389                             if selected == 0:
   389                             if selected == 0:
   390                                 location = "%I" + location
   390                                 location = "%I" + location
   391                             elif selected == 1:
   391                             elif selected == 1:
   392                                 location = "%Q" + location
   392                                 location = "%Q" + location
   393                             else:
   393                             else:
   394                                 location = "%M" + location
   394                                 location = "%M" + location
   395                         if element_type == "functionBlock":
   395                         if element_type == "functionBlock":
   396                             configs = self.ParentWindow.Controler.GetProjectConfigNames(
   396                             configs = self.ParentWindow.Controler.GetProjectConfigNames(
   397                                 self.ParentWindow.Debug)
   397                                 self.ParentWindow.Debug)
   398                             if len(configs) == 0:
   398                             if len(configs) == 0:
   399                                 return
   399                                 return False
   400                             if not var_name.upper() in [
   400                             if not var_name.upper() in [
   401                                     name.upper() for name in
   401                                     name.upper() for name in
   402                                     self.ParentWindow.Controler.GetConfigurationVariableNames(configs[0])]:
   402                                     self.ParentWindow.Controler.GetConfigurationVariableNames(configs[0])]:
   403                                 self.ParentWindow.Controler.AddConfigurationGlobalVar(
   403                                 self.ParentWindow.Controler.AddConfigurationGlobalVar(
   404                                     configs[0], values[2], var_name, location, "")
   404                                     configs[0], values[2], var_name, location, "")
   412                     elif values[1] == "NamedConstant":
   412                     elif values[1] == "NamedConstant":
   413                         if element_type in ["functionBlock", "program"]:
   413                         if element_type in ["functionBlock", "program"]:
   414                             var_infos.Class = "Local"
   414                             var_infos.Class = "Local"
   415                             var_infos.InitialValue = values[0]
   415                             var_infos.InitialValue = values[0]
   416                         else:
   416                         else:
   417                             return
   417                             return False
   418                     else:
   418                     else:
   419                         var_infos.Class = "External"
   419                         var_infos.Class = "External"
   420                     var_infos.Number = len(self.ParentWindow.Values)
   420                     var_infos.Number = len(self.ParentWindow.Values)
   421                     self.ParentWindow.Values.append(var_infos)
   421                     self.ParentWindow.Values.append(var_infos)
   422                     self.ParentWindow.SaveValues()
   422                     self.ParentWindow.SaveValues()
   424                 else:
   424                 else:
   425                     message = _("\"%s\" element for this pou already exists!") % var_name
   425                     message = _("\"%s\" element for this pou already exists!") % var_name
   426 
   426 
   427         if message is not None:
   427         if message is not None:
   428             wx.CallAfter(self.ShowMessage, message)
   428             wx.CallAfter(self.ShowMessage, message)
       
   429             return False
       
   430 
       
   431         return True
   429 
   432 
   430     def ShowMessage(self, message):
   433     def ShowMessage(self, message):
   431         message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK | wx.ICON_ERROR)
   434         message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK | wx.ICON_ERROR)
   432         message.ShowModal()
   435         message.ShowModal()
   433         message.Destroy()
   436         message.Destroy()