dialogs/LDPowerRailDialog.py
changeset 1784 64beb9e9c749
parent 1782 5b6ad7a7fd9d
child 1850 614396cbffbf
equal deleted inserted replaced
1729:31e63e25b4cc 1784:64beb9e9c749
    27 
    27 
    28 from graphics.GraphicCommons import LEFTRAIL, RIGHTRAIL, LD_LINE_SIZE
    28 from graphics.GraphicCommons import LEFTRAIL, RIGHTRAIL, LD_LINE_SIZE
    29 from graphics.LD_Objects import LD_PowerRail
    29 from graphics.LD_Objects import LD_PowerRail
    30 from BlockPreviewDialog import BlockPreviewDialog
    30 from BlockPreviewDialog import BlockPreviewDialog
    31 
    31 
    32 #-------------------------------------------------------------------------------
    32 # -------------------------------------------------------------------------------
    33 #                    Set Ladder Power Rail Parameters Dialog
    33 #                    Set Ladder Power Rail Parameters Dialog
    34 #-------------------------------------------------------------------------------
    34 # -------------------------------------------------------------------------------
    35 
    35 
    36 """
       
    37 Class that implements a dialog for defining parameters of a power rail graphic
       
    38 element
       
    39 """
       
    40 
    36 
    41 class LDPowerRailDialog(BlockPreviewDialog):
    37 class LDPowerRailDialog(BlockPreviewDialog):
    42     
    38     """
       
    39     Class that implements a dialog for defining parameters of a power rail graphic
       
    40     element
       
    41     """
    43     def __init__(self, parent, controller, tagname):
    42     def __init__(self, parent, controller, tagname):
    44         """
    43         """
    45         Constructor
    44         Constructor
    46         @param parent: Parent wx.Window of dialog for modal
    45         @param parent: Parent wx.Window of dialog for modal
    47         @param controller: Reference to project controller
    46         @param controller: Reference to project controller
    48         @param tagname: Tagname of project POU edited
    47         @param tagname: Tagname of project POU edited
    49         """
    48         """
    50         BlockPreviewDialog.__init__(self, parent, controller, tagname,
    49         BlockPreviewDialog.__init__(self, parent, controller, tagname,
    51               title=_('Power Rail Properties'))
    50                                     title=_('Power Rail Properties'))
    52         
    51 
    53         # Init common sizers
    52         # Init common sizers
    54         self._init_sizers(2, 0, 5, None, 2, 1)
    53         self._init_sizers(2, 0, 5, None, 2, 1)
    55         
    54 
    56         # Create label for connection type
    55         # Create label for connection type
    57         type_label = wx.StaticText(self, label=_('Type:'))
    56         type_label = wx.StaticText(self, label=_('Type:'))
    58         self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW)
    57         self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW)
    59         
    58 
    60         # Create radio buttons for selecting power rail type
    59         # Create radio buttons for selecting power rail type
    61         self.TypeRadioButtons = {}
    60         self.TypeRadioButtons = {}
    62         first = True
    61         first = True
    63         for type, label in [(LEFTRAIL, _('Left PowerRail')),
    62         for type, label in [(LEFTRAIL, _('Left PowerRail')),
    64                             (RIGHTRAIL, _('Right PowerRail'))]:
    63                             (RIGHTRAIL, _('Right PowerRail'))]:
    65             radio_button = wx.RadioButton(self, label=label, 
    64             radio_button = wx.RadioButton(self, label=label,
    66                   style=(wx.RB_GROUP if first else 0))
    65                                           style=(wx.RB_GROUP if first else 0))
    67             radio_button.SetValue(first)
    66             radio_button.SetValue(first)
    68             self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button)
    67             self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button)
    69             self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW)
    68             self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW)
    70             self.TypeRadioButtons[type] = radio_button
    69             self.TypeRadioButtons[type] = radio_button
    71             first = False
    70             first = False
    72         
    71 
    73         # Create label for power rail pin number
    72         # Create label for power rail pin number
    74         pin_number_label = wx.StaticText(self, label=_('Pin number:'))
    73         pin_number_label = wx.StaticText(self, label=_('Pin number:'))
    75         self.LeftGridSizer.AddWindow(pin_number_label, flag=wx.GROW)
    74         self.LeftGridSizer.AddWindow(pin_number_label, flag=wx.GROW)
    76         
    75 
    77         # Create spin control for defining power rail pin number
    76         # Create spin control for defining power rail pin number
    78         self.PinNumber = wx.SpinCtrl(self, min=1, max=50,
    77         self.PinNumber = wx.SpinCtrl(self, min=1, max=50,
    79               style=wx.SP_ARROW_KEYS)
    78                                      style=wx.SP_ARROW_KEYS)
    80         self.PinNumber.SetValue(1)
    79         self.PinNumber.SetValue(1)
    81         self.Bind(wx.EVT_SPINCTRL, self.OnPinNumberChanged, self.PinNumber)
    80         self.Bind(wx.EVT_SPINCTRL, self.OnPinNumberChanged, self.PinNumber)
    82         self.LeftGridSizer.AddWindow(self.PinNumber, flag=wx.GROW)
    81         self.LeftGridSizer.AddWindow(self.PinNumber, flag=wx.GROW)
    83         
    82 
    84         # Add preview panel and associated label to sizers
    83         # Add preview panel and associated label to sizers
    85         self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
    84         self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
    86         self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW)
    85         self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW)
    87         
    86 
    88         # Add buttons sizer to sizers
    87         # Add buttons sizer to sizers
    89         self.MainSizer.AddSizer(self.ButtonSizer, border=20, 
    88         self.MainSizer.AddSizer(
    90               flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
    89             self.ButtonSizer, border=20,
       
    90             flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT)
    91         self.Fit()
    91         self.Fit()
    92         
    92 
    93         # Left Power Rail radio button is default control having keyboard focus
    93         # Left Power Rail radio button is default control having keyboard focus
    94         self.TypeRadioButtons[LEFTRAIL].SetFocus()
    94         self.TypeRadioButtons[LEFTRAIL].SetFocus()
    95     
    95 
    96     def GetMinElementSize(self):
    96     def GetMinElementSize(self):
    97         """
    97         """
    98         Get minimal graphic element size
    98         Get minimal graphic element size
    99         @return: Tuple containing minimal size (width, height) or None if no
    99         @return: Tuple containing minimal size (width, height) or None if no
   100         element defined
   100         element defined
   101         """
   101         """
   102         return self.Element.GetMinSize(True)
   102         return self.Element.GetMinSize(True)
   103     
   103 
   104     def GetPowerRailType(self):
   104     def GetPowerRailType(self):
   105         """
   105         """
   106         Return type selected for power rail
   106         Return type selected for power rail
   107         @return: Type selected (LEFTRAIL or RIGHTRAIL)
   107         @return: Type selected (LEFTRAIL or RIGHTRAIL)
   108         """
   108         """
   109         return (LEFTRAIL
   109         return (LEFTRAIL
   110                 if self.TypeRadioButtons[LEFTRAIL].GetValue()
   110                 if self.TypeRadioButtons[LEFTRAIL].GetValue()
   111                 else RIGHTRAIL)
   111                 else RIGHTRAIL)
   112     
   112 
   113     def SetValues(self, values):
   113     def SetValues(self, values):
   114         """
   114         """
   115         Set default power rail parameters
   115         Set default power rail parameters
   116         @param values: Power rail parameters values
   116         @param values: Power rail parameters values
   117         """
   117         """
   118         # For each parameters defined, set corresponding control value
   118         # For each parameters defined, set corresponding control value
   119         for name, value in values.items():
   119         for name, value in values.items():
   120             
   120 
   121             # Parameter is power rail type
   121             # Parameter is power rail type
   122             if name == "type":
   122             if name == "type":
   123                 self.TypeRadioButtons[value].SetValue(True)
   123                 self.TypeRadioButtons[value].SetValue(True)
   124             
   124 
   125             # Parameter is power rail pin number
   125             # Parameter is power rail pin number
   126             elif name == "pin_number":
   126             elif name == "pin_number":
   127                 self.PinNumber.SetValue(value)
   127                 self.PinNumber.SetValue(value)
   128 
   128 
   129     def GetValues(self):
   129     def GetValues(self):
   156     def RefreshPreview(self):
   156     def RefreshPreview(self):
   157         """
   157         """
   158         Refresh preview panel of graphic element
   158         Refresh preview panel of graphic element
   159         Override BlockPreviewDialog function
   159         Override BlockPreviewDialog function
   160         """
   160         """
   161         
   161 
   162         # Set graphic element displayed, creating a power rail element
   162         # Set graphic element displayed, creating a power rail element
   163         self.Element = LD_PowerRail(self.Preview, 
   163         self.Element = LD_PowerRail(self.Preview,
   164                 self.GetPowerRailType(), 
   164                                     self.GetPowerRailType(),
   165                 connectors = self.PinNumber.GetValue())
   165                                     connectors=self.PinNumber.GetValue())
   166         
   166 
   167         # Call BlockPreviewDialog function
   167         # Call BlockPreviewDialog function
   168         BlockPreviewDialog.RefreshPreview(self)
   168         BlockPreviewDialog.RefreshPreview(self)