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