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