dialogs/FBDBlockDialog.py
changeset 1250 7e6de17c687a
parent 1244 336d515096b1
child 1327 632780979432
equal deleted inserted replaced
1249:b956c924cbbd 1250:7e6de17c687a
    56         @param tagname: Tagname of project POU edited
    56         @param tagname: Tagname of project POU edited
    57         """
    57         """
    58         BlockPreviewDialog.__init__(self, parent, controller, tagname,
    58         BlockPreviewDialog.__init__(self, parent, controller, tagname,
    59               size=wx.Size(600, 450), title=_('Block Properties'))
    59               size=wx.Size(600, 450), title=_('Block Properties'))
    60         
    60         
    61         # Create dialog main sizer
    61         # Init common sizers
    62         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=10)
    62         self._init_sizers(2, 0, 1, 0, 3, 2)
    63         main_sizer.AddGrowableCol(0)
       
    64         main_sizer.AddGrowableRow(0)
       
    65         
       
    66         # Create a sizer for dividing FBD block parameters in two columns
       
    67         column_sizer = wx.BoxSizer(wx.HORIZONTAL)
       
    68         main_sizer.AddSizer(column_sizer, border=20, 
       
    69               flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
       
    70         
    63         
    71         # Create static box around library panel
    64         # Create static box around library panel
    72         type_staticbox = wx.StaticBox(self, label=_('Type:'))
    65         type_staticbox = wx.StaticBox(self, label=_('Type:'))
    73         left_staticboxsizer = wx.StaticBoxSizer(type_staticbox, wx.VERTICAL)
    66         left_staticboxsizer = wx.StaticBoxSizer(type_staticbox, wx.VERTICAL)
    74         column_sizer.AddSizer(left_staticboxsizer, 1, border=5, 
    67         self.LeftGridSizer.AddSizer(left_staticboxsizer, border=5, flag=wx.GROW)
    75               flag=wx.GROW|wx.RIGHT)
       
    76         
    68         
    77         # Create Library panel and add it to static box
    69         # Create Library panel and add it to static box
    78         self.LibraryPanel = LibraryPanel(self)
    70         self.LibraryPanel = LibraryPanel(self)
    79         # Set function to call when selection in Library panel changed
    71         # Set function to call when selection in Library panel changed
    80         setattr(self.LibraryPanel, "_OnTreeItemSelected", 
    72         setattr(self.LibraryPanel, "_OnTreeItemSelected", 
    81               self.OnLibraryTreeItemSelected)
    73               self.OnLibraryTreeItemSelected)
    82         left_staticboxsizer.AddWindow(self.LibraryPanel, 1, border=5, 
    74         left_staticboxsizer.AddWindow(self.LibraryPanel, 1, border=5, 
    83               flag=wx.GROW|wx.TOP)
    75               flag=wx.GROW|wx.TOP)
    84         
    76         
    85         # Create sizer for other block parameters and preview panle
       
    86         right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5)
       
    87         right_gridsizer.AddGrowableCol(0)
       
    88         right_gridsizer.AddGrowableRow(2)
       
    89         column_sizer.AddSizer(right_gridsizer, 1, border=5, 
       
    90               flag=wx.GROW|wx.LEFT)
       
    91         
       
    92         # Create sizer for other block parameters
    77         # Create sizer for other block parameters
    93         top_right_gridsizer = wx.FlexGridSizer(cols=2, hgap=0, rows=4, vgap=5)
    78         top_right_gridsizer = wx.FlexGridSizer(cols=2, hgap=0, rows=4, vgap=5)
    94         top_right_gridsizer.AddGrowableCol(1)
    79         top_right_gridsizer.AddGrowableCol(1)
    95         right_gridsizer.AddSizer(top_right_gridsizer, flag=wx.GROW)
    80         self.RightGridSizer.AddSizer(top_right_gridsizer, flag=wx.GROW)
    96         
    81         
    97         # Create label for block name
    82         # Create label for block name
    98         name_label = wx.StaticText(self, label=_('Name:'))
    83         name_label = wx.StaticText(self, label=_('Name:'))
    99         top_right_gridsizer.AddWindow(name_label, 
    84         top_right_gridsizer.AddWindow(name_label, 
   100               flag=wx.ALIGN_CENTER_VERTICAL)
    85               flag=wx.ALIGN_CENTER_VERTICAL)
   138         self.Bind(wx.EVT_CHECKBOX, self.OnExecutionOrderChanged, 
   123         self.Bind(wx.EVT_CHECKBOX, self.OnExecutionOrderChanged, 
   139                   self.ExecutionControl)
   124                   self.ExecutionControl)
   140         top_right_gridsizer.AddWindow(self.ExecutionControl, flag=wx.GROW)
   125         top_right_gridsizer.AddWindow(self.ExecutionControl, flag=wx.GROW)
   141         
   126         
   142         # Add preview panel and associated label to sizers
   127         # Add preview panel and associated label to sizers
   143         right_gridsizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
   128         self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
   144         right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
   129         self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW)
   145         
   130         
   146         # Add buttons sizer to sizers
   131         # Add buttons sizer to sizers
   147         main_sizer.AddSizer(self.ButtonSizer, border=20, 
   132         self.MainSizer.AddSizer(self.ButtonSizer, border=20, 
   148               flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
   133               flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
   149         
       
   150         self.SetSizer(main_sizer)
       
   151         
   134         
   152         # Dictionary containing correspondence between parameter exchanged and
   135         # Dictionary containing correspondence between parameter exchanged and
   153         # control to fill with parameter value
   136         # control to fill with parameter value
   154         self.ParamsControl = {
   137         self.ParamsControl = {
   155             "extension": self.Inputs,
   138             "extension": self.Inputs,
   166         self.CurrentBlockName = None
   149         self.CurrentBlockName = None
   167         
   150         
   168         # Refresh Library panel values
   151         # Refresh Library panel values
   169         self.LibraryPanel.SetBlockList(controller.GetBlockTypes(tagname))
   152         self.LibraryPanel.SetBlockList(controller.GetBlockTypes(tagname))
   170         self.LibraryPanel.SetFocus()
   153         self.LibraryPanel.SetFocus()
   171     
       
   172     def OnOK(self, event):
       
   173         """
       
   174         Called when dialog OK button is pressed
       
   175         Test if parameters defined are valid
       
   176         @param event: wx.Event from OK button
       
   177         """
       
   178         message = None
       
   179         
       
   180         # Get block type selected
       
   181         selected = self.LibraryPanel.GetSelectedBlock()
       
   182         
       
   183         # Get block type name and if block is a function block
       
   184         block_name = self.BlockName.GetValue()
       
   185         name_enabled = self.BlockName.IsEnabled()
       
   186         
       
   187         # Test that a type has been selected for block
       
   188         if selected is None:
       
   189             message = _("Form isn't complete. Valid block type must be selected!")
       
   190         
       
   191         # Test, if block is a function block, that a name have been defined
       
   192         elif name_enabled and block_name == "":
       
   193             message = _("Form isn't complete. Name must be filled!")
       
   194         
       
   195         # Show error message if an error is detected
       
   196         if message is not None:
       
   197             self.ShowErrorMessage(message)
       
   198         
       
   199         # Test block name validity if necessary
       
   200         elif not name_enabled or self.TestElementName(block_name):
       
   201             # Call BlockPreviewDialog function
       
   202             BlockPreviewDialog.OnOK(self, event)
       
   203     
   154     
   204     def SetValues(self, values):
   155     def SetValues(self, values):
   205         """
   156         """
   206         Set default block parameters
   157         Set default block parameters
   207         @param values: Block parameters values
   158         @param values: Block parameters values
   254         values["width"], values["height"] = self.Element.GetSize()
   205         values["width"], values["height"] = self.Element.GetSize()
   255         values.update({
   206         values.update({
   256             name: control.GetValue()
   207             name: control.GetValue()
   257             for name, control in self.ParamsControl.iteritems()})
   208             for name, control in self.ParamsControl.iteritems()})
   258         return values
   209         return values
   259         
   210     
       
   211     def OnOK(self, event):
       
   212         """
       
   213         Called when dialog OK button is pressed
       
   214         Test if parameters defined are valid
       
   215         @param event: wx.Event from OK button
       
   216         """
       
   217         message = None
       
   218         
       
   219         # Get block type selected
       
   220         selected = self.LibraryPanel.GetSelectedBlock()
       
   221         
       
   222         # Get block type name and if block is a function block
       
   223         block_name = self.BlockName.GetValue()
       
   224         name_enabled = self.BlockName.IsEnabled()
       
   225         
       
   226         # Test that a type has been selected for block
       
   227         if selected is None:
       
   228             message = _("Form isn't complete. Valid block type must be selected!")
       
   229         
       
   230         # Test, if block is a function block, that a name have been defined
       
   231         elif name_enabled and block_name == "":
       
   232             message = _("Form isn't complete. Name must be filled!")
       
   233         
       
   234         # Show error message if an error is detected
       
   235         if message is not None:
       
   236             self.ShowErrorMessage(message)
       
   237         
       
   238         # Test block name validity if necessary
       
   239         elif not name_enabled or self.TestElementName(block_name):
       
   240             # Call BlockPreviewDialog function
       
   241             BlockPreviewDialog.OnOK(self, event)
       
   242     
   260     def OnLibraryTreeItemSelected(self, event):
   243     def OnLibraryTreeItemSelected(self, event):
   261         """
   244         """
   262         Called when block type selected in library panel
   245         Called when block type selected in library panel
   263         @param event: wx.TreeEvent
   246         @param event: wx.TreeEvent
   264         """
   247         """