author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Wed, 09 Aug 2017 14:13:17 +0300 | |
changeset 1724 | fde6ad246866 |
parent 1696 | 8043f32de7b8 |
child 1730 | 64d8f52bc8c8 |
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 |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
8 |
# Copyright (C) 2017: Andrey Skvortsov <andrej.skvortzov@gmail.com> |
814 | 9 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1357
diff
changeset
|
10 |
# See COPYING file for copyrights details. |
814 | 11 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1357
diff
changeset
|
12 |
# 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
|
13 |
# 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
|
14 |
# 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
|
15 |
# of the License, or (at your option) any later version. |
814 | 16 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1357
diff
changeset
|
17 |
# 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
|
18 |
# 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
|
19 |
# 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
|
20 |
# GNU General Public License for more details. |
814 | 21 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1357
diff
changeset
|
22 |
# 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
|
23 |
# 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
|
24 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 25 |
|
26 |
import wx |
|
27 |
||
1249 | 28 |
from graphics.GraphicCommons import LEFTRAIL, RIGHTRAIL, LD_LINE_SIZE |
29 |
from graphics.LD_Objects import LD_PowerRail |
|
30 |
from BlockPreviewDialog import BlockPreviewDialog |
|
814 | 31 |
|
32 |
#------------------------------------------------------------------------------- |
|
1249 | 33 |
# Set Ladder Power Rail Parameters Dialog |
814 | 34 |
#------------------------------------------------------------------------------- |
35 |
||
1249 | 36 |
""" |
37 |
Class that implements a dialog for defining parameters of a power rail graphic |
|
38 |
element |
|
39 |
""" |
|
40 |
||
41 |
class LDPowerRailDialog(BlockPreviewDialog): |
|
814 | 42 |
|
1249 | 43 |
def __init__(self, parent, controller, tagname): |
44 |
""" |
|
45 |
Constructor |
|
46 |
@param parent: Parent wx.Window of dialog for modal |
|
47 |
@param controller: Reference to project controller |
|
48 |
@param tagname: Tagname of project POU edited |
|
49 |
""" |
|
50 |
BlockPreviewDialog.__init__(self, parent, controller, tagname, |
|
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
51 |
title=_('Power Rail Properties')) |
814 | 52 |
|
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
53 |
# Init common sizers |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
54 |
self._init_sizers(2, 0, 5, None, 2, 1) |
814 | 55 |
|
1249 | 56 |
# Create label for connection type |
814 | 57 |
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
|
58 |
self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW) |
814 | 59 |
|
1249 | 60 |
# Create radio buttons for selecting power rail type |
61 |
self.TypeRadioButtons = {} |
|
62 |
first = True |
|
63 |
for type, label in [(LEFTRAIL, _('Left PowerRail')), |
|
64 |
(RIGHTRAIL, _('Right PowerRail'))]: |
|
65 |
radio_button = wx.RadioButton(self, label=label, |
|
66 |
style=(wx.RB_GROUP if first else 0)) |
|
67 |
radio_button.SetValue(first) |
|
68 |
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
|
69 |
self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) |
1249 | 70 |
self.TypeRadioButtons[type] = radio_button |
71 |
first = False |
|
814 | 72 |
|
1249 | 73 |
# Create label for power rail pin number |
814 | 74 |
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
|
75 |
self.LeftGridSizer.AddWindow(pin_number_label, flag=wx.GROW) |
814 | 76 |
|
1249 | 77 |
# Create spin control for defining power rail pin number |
814 | 78 |
self.PinNumber = wx.SpinCtrl(self, min=1, max=50, |
79 |
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
|
80 |
self.PinNumber.SetValue(1) |
814 | 81 |
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
|
82 |
self.LeftGridSizer.AddWindow(self.PinNumber, flag=wx.GROW) |
814 | 83 |
|
1249 | 84 |
# 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
|
85 |
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
|
86 |
self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) |
814 | 87 |
|
1249 | 88 |
# Add buttons sizer to sizers |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
89 |
self.MainSizer.AddSizer(self.ButtonSizer, border=20, |
814 | 90 |
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
91 |
self.Fit() |
814 | 92 |
|
1249 | 93 |
# Left Power Rail radio button is default control having keyboard focus |
94 |
self.TypeRadioButtons[LEFTRAIL].SetFocus() |
|
95 |
||
96 |
def GetMinElementSize(self): |
|
97 |
""" |
|
98 |
Get minimal graphic element size |
|
99 |
@return: Tuple containing minimal size (width, height) or None if no |
|
100 |
element defined |
|
101 |
""" |
|
1259
8350222a81c3
Added support for adding graphic element when dropping wire in midair
Laurent Bessard
parents:
1251
diff
changeset
|
102 |
return self.Element.GetMinSize(True) |
1249 | 103 |
|
104 |
def GetPowerRailType(self): |
|
105 |
""" |
|
106 |
Return type selected for power rail |
|
107 |
@return: Type selected (LEFTRAIL or RIGHTRAIL) |
|
108 |
""" |
|
109 |
return (LEFTRAIL |
|
110 |
if self.TypeRadioButtons[LEFTRAIL].GetValue() |
|
111 |
else RIGHTRAIL) |
|
112 |
||
113 |
def SetValues(self, values): |
|
114 |
""" |
|
115 |
Set default power rail parameters |
|
116 |
@param values: Power rail parameters values |
|
117 |
""" |
|
118 |
# For each parameters defined, set corresponding control value |
|
119 |
for name, value in values.items(): |
|
120 |
||
121 |
# Parameter is power rail type |
|
122 |
if name == "type": |
|
123 |
self.TypeRadioButtons[value].SetValue(True) |
|
124 |
||
125 |
# Parameter is power rail pin number |
|
126 |
elif name == "pin_number": |
|
127 |
self.PinNumber.SetValue(value) |
|
814 | 128 |
|
129 |
def GetValues(self): |
|
1249 | 130 |
""" |
131 |
Return power rail parameters defined in dialog |
|
132 |
@return: {parameter_name: parameter_value,...} |
|
133 |
""" |
|
134 |
values = { |
|
135 |
"type": self.GetPowerRailType(), |
|
136 |
"pin_number": self.PinNumber.GetValue()} |
|
137 |
values["width"], values["height"] = self.Element.GetSize() |
|
814 | 138 |
return values |
139 |
||
140 |
def OnTypeChanged(self, event): |
|
1249 | 141 |
""" |
142 |
Called when power rail type changed |
|
143 |
@param event: wx.RadioButtonEvent |
|
144 |
""" |
|
814 | 145 |
self.RefreshPreview() |
146 |
event.Skip() |
|
147 |
||
148 |
def OnPinNumberChanged(self, event): |
|
1249 | 149 |
""" |
150 |
Called when power rail pin number value changed |
|
151 |
@param event: wx.SpinEvent |
|
152 |
""" |
|
814 | 153 |
self.RefreshPreview() |
154 |
event.Skip() |
|
155 |
||
156 |
def RefreshPreview(self): |
|
1249 | 157 |
""" |
158 |
Refresh preview panel of graphic element |
|
159 |
Override BlockPreviewDialog function |
|
160 |
""" |
|
161 |
||
162 |
# Set graphic element displayed, creating a power rail element |
|
163 |
self.Element = LD_PowerRail(self.Preview, |
|
164 |
self.GetPowerRailType(), |
|
165 |
connectors = self.PinNumber.GetValue()) |
|
166 |
||
167 |
# Call BlockPreviewDialog function |
|
168 |
BlockPreviewDialog.RefreshPreview(self) |