author | Edouard Tisserant <edouard@beremiz.fr> |
Thu, 19 Sep 2024 15:12:45 +0200 | |
changeset 4017 | 3977d55217ec |
parent 3750 | f62625418bff |
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 |
|
1853
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
26 |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3303
diff
changeset
|
27 |
|
814 | 28 |
import wx |
29 |
||
1850
614396cbffbf
fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
30 |
from graphics.GraphicCommons import LEFTRAIL, RIGHTRAIL |
1249 | 31 |
from graphics.LD_Objects import LD_PowerRail |
1853
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
32 |
from dialogs.BlockPreviewDialog import BlockPreviewDialog |
814 | 33 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
34 |
# ------------------------------------------------------------------------------- |
1249 | 35 |
# Set Ladder Power Rail Parameters Dialog |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
36 |
# ------------------------------------------------------------------------------- |
814 | 37 |
|
1249 | 38 |
|
39 |
class LDPowerRailDialog(BlockPreviewDialog): |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
40 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
41 |
Class that implements a dialog for defining parameters of a power rail graphic |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
42 |
element |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
43 |
""" |
1249 | 44 |
def __init__(self, parent, controller, tagname): |
45 |
""" |
|
46 |
Constructor |
|
47 |
@param parent: Parent wx.Window of dialog for modal |
|
48 |
@param controller: Reference to project controller |
|
49 |
@param tagname: Tagname of project POU edited |
|
50 |
""" |
|
51 |
BlockPreviewDialog.__init__(self, parent, controller, tagname, |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
52 |
title=_('Power Rail Properties')) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
53 |
|
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
54 |
# Init common sizers |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
55 |
self._init_sizers(2, 0, 5, None, 2, 1) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
56 |
|
1249 | 57 |
# Create label for connection type |
814 | 58 |
type_label = wx.StaticText(self, label=_('Type:')) |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
59 |
self.LeftGridSizer.Add(type_label, flag=wx.GROW) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
60 |
|
1249 | 61 |
# Create radio buttons for selecting power rail type |
62 |
self.TypeRadioButtons = {} |
|
63 |
first = True |
|
64 |
for type, label in [(LEFTRAIL, _('Left PowerRail')), |
|
65 |
(RIGHTRAIL, _('Right PowerRail'))]: |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
66 |
radio_button = wx.RadioButton(self, label=label, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
67 |
style=(wx.RB_GROUP if first else 0)) |
1249 | 68 |
radio_button.SetValue(first) |
69 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button) |
|
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
70 |
self.LeftGridSizer.Add(radio_button, flag=wx.GROW) |
1249 | 71 |
self.TypeRadioButtons[type] = radio_button |
72 |
first = False |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
73 |
|
1249 | 74 |
# Create label for power rail pin number |
814 | 75 |
pin_number_label = wx.StaticText(self, label=_('Pin number:')) |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
76 |
self.LeftGridSizer.Add(pin_number_label, flag=wx.GROW) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
77 |
|
1249 | 78 |
# Create spin control for defining power rail pin number |
814 | 79 |
self.PinNumber = wx.SpinCtrl(self, min=1, max=50, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
80 |
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
|
81 |
self.PinNumber.SetValue(1) |
814 | 82 |
self.Bind(wx.EVT_SPINCTRL, self.OnPinNumberChanged, self.PinNumber) |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
83 |
self.LeftGridSizer.Add(self.PinNumber, flag=wx.GROW) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
84 |
|
1249 | 85 |
# Add preview panel and associated label to sizers |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
86 |
self.RightGridSizer.Add(self.PreviewLabel, flag=wx.GROW) |
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
87 |
self.RightGridSizer.Add(self.Preview, flag=wx.GROW) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
88 |
|
1249 | 89 |
# Add buttons sizer to sizers |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
90 |
self.MainSizer.Add( |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
91 |
self.ButtonSizer, border=20, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
92 |
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
|
93 |
self.Fit() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
94 |
|
1249 | 95 |
# Left Power Rail radio button is default control having keyboard focus |
96 |
self.TypeRadioButtons[LEFTRAIL].SetFocus() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
97 |
|
1249 | 98 |
def GetMinElementSize(self): |
99 |
""" |
|
100 |
Get minimal graphic element size |
|
101 |
@return: Tuple containing minimal size (width, height) or None if no |
|
102 |
element defined |
|
103 |
""" |
|
1259
8350222a81c3
Added support for adding graphic element when dropping wire in midair
Laurent Bessard
parents:
1251
diff
changeset
|
104 |
return self.Element.GetMinSize(True) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
105 |
|
1249 | 106 |
def GetPowerRailType(self): |
107 |
""" |
|
108 |
Return type selected for power rail |
|
109 |
@return: Type selected (LEFTRAIL or RIGHTRAIL) |
|
110 |
""" |
|
111 |
return (LEFTRAIL |
|
112 |
if self.TypeRadioButtons[LEFTRAIL].GetValue() |
|
113 |
else RIGHTRAIL) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
114 |
|
1249 | 115 |
def SetValues(self, values): |
116 |
""" |
|
117 |
Set default power rail parameters |
|
118 |
@param values: Power rail parameters values |
|
119 |
""" |
|
120 |
# For each parameters defined, set corresponding control value |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3303
diff
changeset
|
121 |
for name, value in list(values.items()): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
122 |
|
1249 | 123 |
# Parameter is power rail type |
124 |
if name == "type": |
|
125 |
self.TypeRadioButtons[value].SetValue(True) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
126 |
|
1249 | 127 |
# Parameter is power rail pin number |
128 |
elif name == "pin_number": |
|
129 |
self.PinNumber.SetValue(value) |
|
814 | 130 |
|
131 |
def GetValues(self): |
|
1249 | 132 |
""" |
133 |
Return power rail parameters defined in dialog |
|
134 |
@return: {parameter_name: parameter_value,...} |
|
135 |
""" |
|
136 |
values = { |
|
137 |
"type": self.GetPowerRailType(), |
|
138 |
"pin_number": self.PinNumber.GetValue()} |
|
139 |
values["width"], values["height"] = self.Element.GetSize() |
|
814 | 140 |
return values |
141 |
||
142 |
def OnTypeChanged(self, event): |
|
1249 | 143 |
""" |
144 |
Called when power rail type changed |
|
145 |
@param event: wx.RadioButtonEvent |
|
146 |
""" |
|
2591
5f685bcd3ad6
Fixed refresh problem following 9c5f835b031e, 9622418ac28c, c67488bd8134 : force redraw only through EVT_PAINT event and use wxPaintDC, as described in wx documentation
Edouard Tisserant
parents:
2587
diff
changeset
|
147 |
self.RefreshPreview() |
814 | 148 |
event.Skip() |
149 |
||
150 |
def OnPinNumberChanged(self, event): |
|
1249 | 151 |
""" |
152 |
Called when power rail pin number value changed |
|
153 |
@param event: wx.SpinEvent |
|
154 |
""" |
|
2591
5f685bcd3ad6
Fixed refresh problem following 9c5f835b031e, 9622418ac28c, c67488bd8134 : force redraw only through EVT_PAINT event and use wxPaintDC, as described in wx documentation
Edouard Tisserant
parents:
2587
diff
changeset
|
155 |
self.RefreshPreview() |
814 | 156 |
event.Skip() |
157 |
||
2572
9622418ac28c
Fix problem introduced in 9c5f835b031e : Exception in LDPowerRailDialog.py because of change in OnPaint/RefreshView/DrawPreview.
Edouard Tisserant
parents:
1853
diff
changeset
|
158 |
def DrawPreview(self): |
1249 | 159 |
""" |
160 |
Refresh preview panel of graphic element |
|
161 |
Override BlockPreviewDialog function |
|
162 |
""" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
163 |
|
1249 | 164 |
# Set graphic element displayed, creating a power rail element |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
165 |
self.Element = LD_PowerRail(self.Preview, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
166 |
self.GetPowerRailType(), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
167 |
connectors=self.PinNumber.GetValue()) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
168 |
|
2572
9622418ac28c
Fix problem introduced in 9c5f835b031e : Exception in LDPowerRailDialog.py because of change in OnPaint/RefreshView/DrawPreview.
Edouard Tisserant
parents:
1853
diff
changeset
|
169 |
return BlockPreviewDialog.DrawPreview(self) |