dialogs/LDPowerRailDialog.py
author Laurent Bessard
Wed, 12 Jun 2013 09:36:59 +0200
changeset 1249 b956c924cbbd
parent 814 5743cbdff669
child 1250 7e6de17c687a
permissions -rw-r--r--
Rewrite LDPowerRailDialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     4
#based on the plcopen standard. 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     5
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     7
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    26
from graphics.GraphicCommons import LEFTRAIL, RIGHTRAIL, LD_LINE_SIZE
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    27
from graphics.LD_Objects import LD_PowerRail
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    28
from BlockPreviewDialog import BlockPreviewDialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
#-------------------------------------------------------------------------------
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    31
#                    Set Ladder Power Rail Parameters Dialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    34
"""
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    35
Class that implements a dialog for defining parameters of a power rail graphic
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    36
element
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    37
"""
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    38
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    39
class LDPowerRailDialog(BlockPreviewDialog):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
    
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    41
    def __init__(self, parent, controller, tagname):
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    42
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    43
        Constructor
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    44
        @param parent: Parent wx.Window of dialog for modal
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    45
        @param controller: Reference to project controller
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    46
        @param tagname: Tagname of project POU edited
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    47
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    48
        BlockPreviewDialog.__init__(self, parent, controller, tagname,
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    49
              size=wx.Size(350, 260), title=_('Power Rail Properties'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    50
        
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    51
        # Create dialog main sizer
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    52
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
        main_sizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
        main_sizer.AddGrowableRow(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
        
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    56
        # Create a sizer for dividing power rail parameters in two columns
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
        column_sizer = wx.BoxSizer(wx.HORIZONTAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
        main_sizer.AddSizer(column_sizer, border=20, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
              flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
        
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    61
        # Create a sizer for left column
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
        left_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=5, vgap=5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
        left_gridsizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
        column_sizer.AddSizer(left_gridsizer, 1, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
              flag=wx.GROW|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
        
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    67
        # Create label for connection type
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
        type_label = wx.StaticText(self, label=_('Type:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
        left_gridsizer.AddWindow(type_label, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
        
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    71
        # Create radio buttons for selecting power rail type
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    72
        self.TypeRadioButtons = {}
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    73
        first = True
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    74
        for type, label in [(LEFTRAIL, _('Left PowerRail')),
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    75
                            (RIGHTRAIL, _('Right PowerRail'))]:
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    76
            radio_button = wx.RadioButton(self, label=label, 
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    77
                  style=(wx.RB_GROUP if first else 0))
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    78
            radio_button.SetValue(first)
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    79
            self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button)
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    80
            left_gridsizer.AddWindow(radio_button, flag=wx.GROW)
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    81
            self.TypeRadioButtons[type] = radio_button
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    82
            first = False
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
        
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    84
        # Create label for power rail pin number
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
        pin_number_label = wx.StaticText(self, label=_('Pin number:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
        left_gridsizer.AddWindow(pin_number_label, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
        
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    88
        # Create spin control for defining power rail pin number
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
        self.PinNumber = wx.SpinCtrl(self, min=1, max=50,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
              style=wx.SP_ARROW_KEYS)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
        self.Bind(wx.EVT_SPINCTRL, self.OnPinNumberChanged, self.PinNumber)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
        left_gridsizer.AddWindow(self.PinNumber, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
        
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
    94
        # Create a sizer for right column
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
        right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
        right_gridsizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
        right_gridsizer.AddGrowableRow(1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
        column_sizer.AddSizer(right_gridsizer, 1, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
              flag=wx.GROW|wx.LEFT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
        
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   101
        # Add preview panel and associated label to sizers
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   102
        right_gridsizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
        right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
        
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   105
        # Add buttons sizer to sizers
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   106
        main_sizer.AddSizer(self.ButtonSizer, border=20, 
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
        self.SetSizer(main_sizer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
        
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   111
        # Left Power Rail radio button is default control having keyboard focus
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   112
        self.TypeRadioButtons[LEFTRAIL].SetFocus()
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   113
    
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   114
    def GetMinElementSize(self):
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   115
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   116
        Get minimal graphic element size
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   117
        @return: Tuple containing minimal size (width, height) or None if no
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   118
        element defined
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   119
        May be overridden by inherited classes
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   120
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   121
        return (2, LD_LINE_SIZE * self.PinNumber.GetValue())
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   122
    
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   123
    def GetPowerRailType(self):
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   124
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   125
        Return type selected for power rail
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   126
        @return: Type selected (LEFTRAIL or RIGHTRAIL)
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   127
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   128
        return (LEFTRAIL
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   129
                if self.TypeRadioButtons[LEFTRAIL].GetValue()
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   130
                else RIGHTRAIL)
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   131
    
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   132
    def SetValues(self, values):
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   133
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   134
        Set default power rail parameters
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   135
        @param values: Power rail parameters values
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   136
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   137
        # For each parameters defined, set corresponding control value
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   138
        for name, value in values.items():
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   139
            
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   140
            # Parameter is power rail type
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   141
            if name == "type":
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   142
                self.TypeRadioButtons[value].SetValue(True)
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   143
            
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   144
            # Parameter is power rail pin number
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   145
            elif name == "pin_number":
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   146
                self.PinNumber.SetValue(value)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
    def GetValues(self):
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   149
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   150
        Return power rail parameters defined in dialog
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   151
        @return: {parameter_name: parameter_value,...}
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   152
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   153
        values = {
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   154
            "type": self.GetPowerRailType(),
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   155
            "pin_number": self.PinNumber.GetValue()}
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   156
        values["width"], values["height"] = self.Element.GetSize()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
        return values
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
    def OnTypeChanged(self, event):
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   160
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   161
        Called when power rail type changed
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   162
        @param event: wx.RadioButtonEvent
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   163
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   166
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
    def OnPinNumberChanged(self, event):
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   168
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   169
        Called when power rail pin number value changed
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   170
        @param event: wx.SpinEvent
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   171
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   172
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   173
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   175
    def RefreshPreview(self):
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   176
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   177
        Refresh preview panel of graphic element
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   178
        Override BlockPreviewDialog function
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   179
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   180
        
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   181
        # Set graphic element displayed, creating a power rail element
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   182
        self.Element = LD_PowerRail(self.Preview, 
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   183
                self.GetPowerRailType(), 
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   184
                connectors = self.PinNumber.GetValue())
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   185
        
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   186
        # Call BlockPreviewDialog function
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 814
diff changeset
   187
        BlockPreviewDialog.RefreshPreview(self)