dialogs/SFCDivergenceDialog.py
changeset 1911 c1298e7ffe3a
parent 1585 60c0db313ec9
child 1696 8043f32de7b8
equal deleted inserted replaced
1910:a375e31bf312 1911:c1298e7ffe3a
       
     1 #!/usr/bin/env python
     1 # -*- coding: utf-8 -*-
     2 # -*- coding: utf-8 -*-
     2 
     3 
     3 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
     4 # This file is part of Beremiz, a Integrated Development Environment for
     4 #based on the plcopen standard. 
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
     5 #
     6 #
     6 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     7 #
     8 #
     8 #See COPYING file for copyrights details.
     9 # See COPYING file for copyrights details.
     9 #
    10 #
    10 #This library is free software; you can redistribute it and/or
    11 # This program is free software; you can redistribute it and/or
    11 #modify it under the terms of the GNU General Public
    12 # modify it under the terms of the GNU General Public License
    12 #License as published by the Free Software Foundation; either
    13 # as published by the Free Software Foundation; either version 2
    13 #version 2.1 of the License, or (at your option) any later version.
    14 # of the License, or (at your option) any later version.
    14 #
    15 #
    15 #This library is distributed in the hope that it will be useful,
    16 # This program is distributed in the hope that it will be useful,
    16 #but WITHOUT ANY WARRANTY; without even the implied warranty of
    17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    17 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    18 #General Public License for more details.
    19 # GNU General Public License for more details.
    19 #
    20 #
    20 #You should have received a copy of the GNU General Public
    21 # You should have received a copy of the GNU General Public License
    21 #License along with this library; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    23 
    24 
    24 import wx
    25 import wx
    25 
    26 
    26 from graphics.GraphicCommons import SELECTION_DIVERGENCE, \
    27 from graphics.GraphicCommons import SELECTION_DIVERGENCE, \
    27     SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE
    28     SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE
    37 divergence graphic element
    38 divergence graphic element
    38 """
    39 """
    39 
    40 
    40 class SFCDivergenceDialog(BlockPreviewDialog):
    41 class SFCDivergenceDialog(BlockPreviewDialog):
    41     
    42     
    42     def __init__(self, parent, controller, tagname):
    43     def __init__(self, parent, controller, tagname, poss_div_types = None):
    43         """
    44         """
    44         Constructor
    45         Constructor
    45         @param parent: Parent wx.Window of dialog for modal
    46         @param parent: Parent wx.Window of dialog for modal
    46         @param controller: Reference to project controller
    47         @param controller: Reference to project controller
    47         @param tagname: Tagname of project POU edited
    48         @param tagname: Tagname of project POU edited
       
    49         @param poss_div_types: Types of divergence that will be available in the dialog window
    48         """
    50         """
    49         BlockPreviewDialog.__init__(self, parent, controller, tagname, 
    51         BlockPreviewDialog.__init__(self, parent, controller, tagname, 
    50               size=wx.Size(500, 300), 
    52               size=wx.Size(500, 300), 
    51               title=_('Create a new divergence or convergence'))
    53               title=_('Create a new divergence or convergence'))
    52         
    54         
    56         # Create label for divergence type
    58         # Create label for divergence type
    57         type_label = wx.StaticText(self, label=_('Type:'))
    59         type_label = wx.StaticText(self, label=_('Type:'))
    58         self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW)
    60         self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW)
    59         
    61         
    60         # Create radio buttons for selecting divergence type
    62         # Create radio buttons for selecting divergence type
       
    63         divergence_buttons = [
       
    64             (SELECTION_DIVERGENCE, _('Selection Divergence')),
       
    65             (SELECTION_CONVERGENCE, _('Selection Convergence')),
       
    66             (SIMULTANEOUS_DIVERGENCE, _('Simultaneous Divergence')),
       
    67             (SIMULTANEOUS_CONVERGENCE, _('Simultaneous Convergence'))]
       
    68         poss_div_btns = []
       
    69         if poss_div_types is not None:
       
    70              for val in poss_div_types:
       
    71                  poss_div_btns.append(divergence_buttons[val])
       
    72         else:
       
    73             poss_div_btns = divergence_buttons
    61         self.TypeRadioButtons = {}
    74         self.TypeRadioButtons = {}
    62         first = True
    75         first = True
    63         for type, label in [
    76         focusbtn = None
    64                 (SELECTION_DIVERGENCE, _('Selection Divergence')),
    77         for type, label in poss_div_btns:
    65                 (SELECTION_CONVERGENCE, _('Selection Convergence')),
       
    66                 (SIMULTANEOUS_DIVERGENCE, _('Simultaneous Divergence')),
       
    67                 (SIMULTANEOUS_CONVERGENCE, _('Simultaneous Convergence'))]:
       
    68             radio_button = wx.RadioButton(self, label=label, 
    78             radio_button = wx.RadioButton(self, label=label, 
    69                   style=(wx.RB_GROUP if first else 0))
    79                   style=(wx.RB_GROUP if first else 0))
    70             radio_button.SetValue(first)
    80             radio_button.SetValue(first)
    71             self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button)
    81             self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button)
    72             self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW)
    82             self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW)
    73             self.TypeRadioButtons[type] = radio_button
    83             self.TypeRadioButtons[type] = radio_button
       
    84             if first: focusbtn = type
    74             first = False
    85             first = False
    75 
    86 
    76         # Create label for number of divergence sequences
    87         # Create label for number of divergence sequences
    77         sequences_label = wx.StaticText(self, 
    88         sequences_label = wx.StaticText(self, 
    78               label=_('Number of sequences:'))
    89               label=_('Number of sequences:'))
    79         self.LeftGridSizer.AddWindow(sequences_label, flag=wx.GROW)
    90         self.LeftGridSizer.AddWindow(sequences_label, flag=wx.GROW)
    80         
    91         
    81         # Create spin control for defining number of divergence sequences
    92         # Create spin control for defining number of divergence sequences
    82         self.Sequences = wx.SpinCtrl(self, min=2, max=20)
    93         self.Sequences = wx.SpinCtrl(self, min=2, max=20, initial=2)
    83         self.Bind(wx.EVT_SPINCTRL, self.OnSequencesChanged, self.Sequences)
    94         self.Bind(wx.EVT_SPINCTRL, self.OnSequencesChanged, self.Sequences)
    84         self.LeftGridSizer.AddWindow(self.Sequences, flag=wx.GROW)
    95         self.LeftGridSizer.AddWindow(self.Sequences, flag=wx.GROW)
    85         
    96         
    86         # Add preview panel and associated label to sizers
    97         # Add preview panel and associated label to sizers
    87         self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
    98         self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
    91         self.MainSizer.AddSizer(self.ButtonSizer, border=20, 
   102         self.MainSizer.AddSizer(self.ButtonSizer, border=20, 
    92               flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
   103               flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
    93         
   104         
    94         # Selection divergence radio button is default control having keyboard
   105         # Selection divergence radio button is default control having keyboard
    95         # focus
   106         # focus
    96         self.TypeRadioButtons[SELECTION_DIVERGENCE].SetFocus()
   107         self.TypeRadioButtons[focusbtn].SetFocus()
    97     
   108     
    98     def GetMinElementSize(self):
   109     def GetMinElementSize(self):
    99         """
   110         """
   100         Get minimal graphic element size
   111         Get minimal graphic element size
   101         @return: Tuple containing minimal size (width, height) or None if no
   112         @return: Tuple containing minimal size (width, height) or None if no