controls/VariablePanel.py
changeset 1768 691083b5682a
parent 1767 c74815729afd
child 1772 c3679f96020b
equal deleted inserted replaced
1767:c74815729afd 1768:691083b5682a
   293                                     message = _("Unrecognized data size \"%s\"") % location[0]
   293                                     message = _("Unrecognized data size \"%s\"") % location[0]
   294                                 elif base_type not in LOCATIONDATATYPES[location[0]]:
   294                                 elif base_type not in LOCATIONDATATYPES[location[0]]:
   295                                     message = _("Incompatible size of data between \"{a1}\" and \"{a2}\"").\
   295                                     message = _("Incompatible size of data between \"{a1}\" and \"{a2}\"").\
   296                                               format(a1=location, a2=variable_type)
   296                                               format(a1=location, a2=variable_type)
   297                                 else:
   297                                 else:
   298                                     dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow.ParentWindow,
   298                                     dialog = wx.SingleChoiceDialog(
   299                                           _("Select a variable class:"), _("Variable class"),
   299                                         self.ParentWindow.ParentWindow.ParentWindow,
   300                                           [_("Input"), _("Output"), _("Memory")],
   300                                         _("Select a variable class:"),
   301                                           wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL)
   301                                         _("Variable class"),
       
   302                                         [_("Input"), _("Output"), _("Memory")],
       
   303                                         wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL)
   302                                     if dialog.ShowModal() == wx.ID_OK:
   304                                     if dialog.ShowModal() == wx.ID_OK:
   303                                         selected = dialog.GetSelection()
   305                                         selected = dialog.GetSelection()
   304                                     else:
   306                                     else:
   305                                         selected = None
   307                                         selected = None
   306                                     dialog.Destroy()
   308                                     dialog.Destroy()
   339                 dlg.SetValue(var_name)
   341                 dlg.SetValue(var_name)
   340                 var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None
   342                 var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None
   341                 dlg.Destroy()
   343                 dlg.Destroy()
   342                 if var_name is None:
   344                 if var_name is None:
   343                     return
   345                     return
   344                 elif var_name.upper() in [name.upper()
   346                 elif var_name.upper() in [
   345                         for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
   347                         name.upper() for name in
       
   348                         self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
   346                     message = _("\"%s\" pou already exists!") % var_name
   349                     message = _("\"%s\" pou already exists!") % var_name
   347                 elif not var_name.upper() in [name.upper()
   350                 elif not var_name.upper() in [
       
   351                         name.upper()
   348                         for name in self.ParentWindow.Controler.
   352                         for name in self.ParentWindow.Controler.
   349                             GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
   353                         GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
   350                     var_infos = self.ParentWindow.DefaultValue.copy()
   354                     var_infos = self.ParentWindow.DefaultValue.copy()
   351                     var_infos.Name = var_name
   355                     var_infos.Name = var_name
   352                     var_infos.Type = values[2]
   356                     var_infos.Type = values[2]
   353                     var_infos.Documentation = values[4]
   357                     var_infos.Documentation = values[4]
   354                     if values[1] == "location":
   358                     if values[1] == "location":
   355                         location = values[0]
   359                         location = values[0]
   356                         if not location.startswith("%"):
   360                         if not location.startswith("%"):
   357                             dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow.ParentWindow,
   361                             dialog = wx.SingleChoiceDialog(
   358                                   _("Select a variable class:"), _("Variable class"),
   362                                 self.ParentWindow.ParentWindow.ParentWindow,
   359                                   [_("Input"), _("Output"), _("Memory")],
   363                                 _("Select a variable class:"),
   360                                   wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL)
   364                                 _("Variable class"),
       
   365                                 [_("Input"), _("Output"), _("Memory")],
       
   366                                 wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL)
   361                             if dialog.ShowModal() == wx.ID_OK:
   367                             if dialog.ShowModal() == wx.ID_OK:
   362                                 selected = dialog.GetSelection()
   368                                 selected = dialog.GetSelection()
   363                             else:
   369                             else:
   364                                 selected = None
   370                                 selected = None
   365                             dialog.Destroy()
   371                             dialog.Destroy()
   374                         if element_type == "functionBlock":
   380                         if element_type == "functionBlock":
   375                             configs = self.ParentWindow.Controler.GetProjectConfigNames(
   381                             configs = self.ParentWindow.Controler.GetProjectConfigNames(
   376                                                                 self.ParentWindow.Debug)
   382                                                                 self.ParentWindow.Debug)
   377                             if len(configs) == 0:
   383                             if len(configs) == 0:
   378                                 return
   384                                 return
   379                             if not var_name.upper() in [name.upper()
   385                             if not var_name.upper() in [
   380                                 for name in self.ParentWindow.Controler.GetConfigurationVariableNames(configs[0])]:
   386                                     name.upper() for name in
       
   387                                     self.ParentWindow.Controler.GetConfigurationVariableNames(configs[0])]:
   381                                 self.ParentWindow.Controler.AddConfigurationGlobalVar(
   388                                 self.ParentWindow.Controler.AddConfigurationGlobalVar(
   382                                     configs[0], values[2], var_name, location, "")
   389                                     configs[0], values[2], var_name, location, "")
   383                             var_infos.Class = "External"
   390                             var_infos.Class = "External"
   384                         else:
   391                         else:
   385                             if element_type == "program":
   392                             if element_type == "program":
   431 
   438 
   432         self.ReturnTypeLabel = wx.StaticText(self, label=_('Return Type:'))
   439         self.ReturnTypeLabel = wx.StaticText(self, label=_('Return Type:'))
   433         controls_sizer.AddWindow(self.ReturnTypeLabel, flag=wx.ALIGN_CENTER_VERTICAL)
   440         controls_sizer.AddWindow(self.ReturnTypeLabel, flag=wx.ALIGN_CENTER_VERTICAL)
   434 
   441 
   435         self.ReturnType = wx.ComboBox(self,
   442         self.ReturnType = wx.ComboBox(self,
   436               size=wx.Size(145, -1), style=wx.CB_READONLY)
   443                                       size=wx.Size(145, -1), style=wx.CB_READONLY)
   437         self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, self.ReturnType)
   444         self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, self.ReturnType)
   438         controls_sizer.AddWindow(self.ReturnType)
   445         controls_sizer.AddWindow(self.ReturnType)
   439 
   446 
   440         self.DescriptionLabel = wx.StaticText(self, label=_('Description:'))
   447         self.DescriptionLabel = wx.StaticText(self, label=_('Description:'))
   441         controls_sizer.AddWindow(self.DescriptionLabel, flag=wx.ALIGN_CENTER_VERTICAL)
   448         controls_sizer.AddWindow(self.DescriptionLabel, flag=wx.ALIGN_CENTER_VERTICAL)
   442 
   449 
   443         self.Description = wx.TextCtrl(self,
   450         self.Description = wx.TextCtrl(self,
   444               size=wx.Size(250, -1), style=wx.TE_PROCESS_ENTER)
   451                                        size=wx.Size(250, -1), style=wx.TE_PROCESS_ENTER)
   445         self.Bind(wx.EVT_TEXT_ENTER, self.OnDescriptionChanged, self.Description)
   452         self.Bind(wx.EVT_TEXT_ENTER, self.OnDescriptionChanged, self.Description)
   446         self.Description.Bind(wx.EVT_KILL_FOCUS, self.OnDescriptionChanged)
   453         self.Description.Bind(wx.EVT_KILL_FOCUS, self.OnDescriptionChanged)
   447         controls_sizer.AddWindow(self.Description)
   454         controls_sizer.AddWindow(self.Description)
   448 
   455 
   449         class_filter_label = wx.StaticText(self, label=_('Class Filter:'))
   456         class_filter_label = wx.StaticText(self, label=_('Class Filter:'))
   450         controls_sizer.AddWindow(class_filter_label, flag=wx.ALIGN_CENTER_VERTICAL)
   457         controls_sizer.AddWindow(class_filter_label, flag=wx.ALIGN_CENTER_VERTICAL)
   451 
   458 
   452         self.ClassFilter = wx.ComboBox(self,
   459         self.ClassFilter = wx.ComboBox(self,
   453               size=wx.Size(145, -1), style=wx.CB_READONLY)
   460                                        size=wx.Size(145, -1), style=wx.CB_READONLY)
   454         self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, self.ClassFilter)
   461         self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, self.ClassFilter)
   455         controls_sizer.AddWindow(self.ClassFilter)
   462         controls_sizer.AddWindow(self.ClassFilter)
   456 
   463 
   457         for name, bitmap, help in [
   464         for name, bitmap, help in [
   458                 ("AddButton", "add_element", _("Add variable")),
   465                 ("AddButton", "add_element", _("Add variable")),
   459                 ("DeleteButton", "remove_element", _("Remove variable")),
   466                 ("DeleteButton", "remove_element", _("Remove variable")),
   460                 ("UpButton", "up", _("Move variable up")),
   467                 ("UpButton", "up", _("Move variable up")),
   461                 ("DownButton", "down", _("Move variable down"))]:
   468                 ("DownButton", "down", _("Move variable down"))]:
   462             button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap),
   469             button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap),
   463                   size=wx.Size(28, 28), style=wx.NO_BORDER)
   470                                                     size=wx.Size(28, 28), style=wx.NO_BORDER)
   464             button.SetToolTipString(help)
   471             button.SetToolTipString(help)
   465             setattr(self, name, button)
   472             setattr(self, name, button)
   466             controls_sizer.AddWindow(button)
   473             controls_sizer.AddWindow(button)
   467 
   474 
   468         self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL | wx.HSCROLL)
   475         self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL | wx.HSCROLL)
   469         self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
   476         self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
   470         self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
   477         self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
   471               self.OnVariablesGridCellChange)
   478                                 self.OnVariablesGridCellChange)
   472         self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK,
   479         self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK,
   473               self.OnVariablesGridCellLeftClick)
   480                                 self.OnVariablesGridCellLeftClick)
   474         self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN,
   481         self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN,
   475               self.OnVariablesGridEditorShown)
   482                                 self.OnVariablesGridEditorShown)
   476         self.MainSizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
   483         self.MainSizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
   477 
   484 
   478         self.SetSizer(self.MainSizer)
   485         self.SetSizer(self.MainSizer)
   479 
   486 
   480         self.ParentWindow = window
   487         self.ParentWindow = window
   482         self.ElementType = element_type
   489         self.ElementType = element_type
   483         self.Debug = debug
   490         self.Debug = debug
   484 
   491 
   485         self.RefreshHighlightsTimer = wx.Timer(self, -1)
   492         self.RefreshHighlightsTimer = wx.Timer(self, -1)
   486         self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer,
   493         self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer,
   487               self.RefreshHighlightsTimer)
   494                   self.RefreshHighlightsTimer)
   488 
   495 
   489         self.Filter = "All"
   496         self.Filter = "All"
   490         self.FilterChoices = []
   497         self.FilterChoices = []
   491         self.FilterChoiceTransfer = GetFilterChoiceTransfer()
   498         self.FilterChoiceTransfer = GetFilterChoiceTransfer()
   492 
   499