|
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 |
|
26 from graphics import * |
|
27 |
|
28 #------------------------------------------------------------------------------- |
|
29 # Create New Divergence Dialog |
|
30 #------------------------------------------------------------------------------- |
|
31 |
|
32 [ID_SFCDIVERGENCEDIALOG, ID_SFCDIVERGENCEDIALOGSPACER, |
|
33 ID_SFCDIVERGENCEDIALOGRADIOBUTTON1, ID_SFCDIVERGENCEDIALOGRADIOBUTTON2, |
|
34 ID_SFCDIVERGENCEDIALOGRADIOBUTTON3, ID_SFCDIVERGENCEDIALOGRADIOBUTTON4, |
|
35 ID_SFCDIVERGENCEDIALOGSEQUENCES, ID_SFCDIVERGENCEDIALOGPREVIEW, |
|
36 ID_SFCDIVERGENCEDIALOGSTATICTEXT1, ID_SFCDIVERGENCEDIALOGSTATICTEXT2, |
|
37 ID_SFCDIVERGENCEDIALOGSTATICTEXT3, |
|
38 ] = [wx.NewId() for _init_ctrls in range(11)] |
|
39 |
|
40 class SFCDivergenceDialog(wx.Dialog): |
|
41 |
|
42 if wx.VERSION < (2, 6, 0): |
|
43 def Bind(self, event, function, id = None): |
|
44 if id is not None: |
|
45 event(self, id, function) |
|
46 else: |
|
47 event(self, function) |
|
48 |
|
49 def _init_coll_flexGridSizer1_Items(self, parent): |
|
50 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
|
51 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
|
52 |
|
53 def _init_coll_flexGridSizer1_Growables(self, parent): |
|
54 parent.AddGrowableCol(0) |
|
55 parent.AddGrowableRow(0) |
|
56 |
|
57 def _init_coll_MainSizer_Items(self, parent): |
|
58 parent.AddSizer(self.LeftGridSizer, 1, border=5, flag=wx.GROW|wx.RIGHT) |
|
59 parent.AddSizer(self.RightGridSizer, 1, border=5, flag=wx.GROW|wx.LEFT) |
|
60 |
|
61 def _init_coll_LeftGridSizer_Items(self, parent): |
|
62 parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) |
|
63 parent.AddWindow(self.radioButton1, 0, border=0, flag=wx.GROW) |
|
64 parent.AddWindow(self.radioButton2, 0, border=0, flag=wx.GROW) |
|
65 parent.AddWindow(self.radioButton3, 0, border=0, flag=wx.GROW) |
|
66 parent.AddWindow(self.radioButton4, 0, border=0, flag=wx.GROW) |
|
67 parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) |
|
68 parent.AddWindow(self.Sequences, 0, border=0, flag=wx.GROW) |
|
69 parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW) |
|
70 |
|
71 def _init_coll_LeftGridSizer_Growables(self, parent): |
|
72 parent.AddGrowableCol(0) |
|
73 parent.AddGrowableRow(7) |
|
74 |
|
75 def _init_coll_RightGridSizer_Items(self, parent): |
|
76 parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW) |
|
77 parent.AddWindow(self.Preview, 0, border=0, flag=wx.GROW) |
|
78 |
|
79 def _init_coll_RightGridSizer_Growables(self, parent): |
|
80 parent.AddGrowableCol(0) |
|
81 parent.AddGrowableRow(1) |
|
82 |
|
83 def _init_sizers(self): |
|
84 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
|
85 self.MainSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
86 self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=8, vgap=5) |
|
87 self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
|
88 |
|
89 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
90 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) |
|
91 self._init_coll_MainSizer_Items(self.MainSizer) |
|
92 self._init_coll_LeftGridSizer_Items(self.LeftGridSizer) |
|
93 self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer) |
|
94 self._init_coll_RightGridSizer_Items(self.RightGridSizer) |
|
95 self._init_coll_RightGridSizer_Growables(self.RightGridSizer) |
|
96 |
|
97 self.SetSizer(self.flexGridSizer1) |
|
98 |
|
99 def _init_ctrls(self, prnt, ctrler): |
|
100 wx.Dialog.__init__(self, id=ID_SFCDIVERGENCEDIALOG, |
|
101 name='SFCDivergenceDialog', parent=prnt, pos=wx.Point(376, 223), |
|
102 size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE, |
|
103 title=_('Create a new divergence or convergence')) |
|
104 self.SetClientSize(wx.Size(500, 300)) |
|
105 |
|
106 self.staticText1 = wx.StaticText(id=ID_SFCDIVERGENCEDIALOGSTATICTEXT1, |
|
107 label=_('Type:'), name='staticText1', parent=self, |
|
108 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) |
|
109 |
|
110 self.radioButton1 = wx.RadioButton(id=ID_SFCDIVERGENCEDIALOGRADIOBUTTON1, |
|
111 label=_('Selection Divergence'), name='radioButton1', parent=self, |
|
112 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=wx.RB_GROUP) |
|
113 self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_SFCDIVERGENCEDIALOGRADIOBUTTON1) |
|
114 self.radioButton1.SetValue(True) |
|
115 |
|
116 self.radioButton2 = wx.RadioButton(id=ID_SFCDIVERGENCEDIALOGRADIOBUTTON2, |
|
117 label=_('Selection Convergence'), name='radioButton2', parent=self, |
|
118 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) |
|
119 self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_SFCDIVERGENCEDIALOGRADIOBUTTON2) |
|
120 self.radioButton2.SetValue(False) |
|
121 |
|
122 self.radioButton3 = wx.RadioButton(id=ID_SFCDIVERGENCEDIALOGRADIOBUTTON3, |
|
123 label=_('Simultaneous Divergence'), name='radioButton3', parent=self, |
|
124 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) |
|
125 self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_SFCDIVERGENCEDIALOGRADIOBUTTON3) |
|
126 self.radioButton3.SetValue(False) |
|
127 |
|
128 self.radioButton4 = wx.RadioButton(id=ID_SFCDIVERGENCEDIALOGRADIOBUTTON4, |
|
129 label=_('Simultaneous Convergence'), name='radioButton4', parent=self, |
|
130 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) |
|
131 self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_SFCDIVERGENCEDIALOGRADIOBUTTON4) |
|
132 self.radioButton4.SetValue(False) |
|
133 |
|
134 self.staticText2 = wx.StaticText(id=ID_SFCDIVERGENCEDIALOGSTATICTEXT2, |
|
135 label=_('Number of sequences:'), name='staticText2', parent=self, |
|
136 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) |
|
137 |
|
138 self.Sequences = wx.SpinCtrl(id=ID_SFCDIVERGENCEDIALOGSEQUENCES, |
|
139 name='Sequences', parent=self, pos=wx.Point(0, 0), |
|
140 size=wx.Size(0, 24), style=0, min=2, max=20) |
|
141 self.Bind(wx.EVT_SPINCTRL, self.OnSequencesChanged, id=ID_SFCDIVERGENCEDIALOGSEQUENCES) |
|
142 |
|
143 self.staticText3 = wx.StaticText(id=ID_SFCDIVERGENCEDIALOGSTATICTEXT3, |
|
144 label=_('Preview:'), name='staticText3', parent=self, |
|
145 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) |
|
146 |
|
147 self.Preview = wx.Panel(id=ID_SFCDIVERGENCEDIALOGPREVIEW, |
|
148 name='Preview', parent=self, pos=wx.Point(0, 0), |
|
149 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) |
|
150 self.Preview.SetBackgroundColour(wx.Colour(255,255,255)) |
|
151 setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) |
|
152 setattr(self.Preview, "IsOfType", ctrler.IsOfType) |
|
153 |
|
154 self.Spacer = wx.Panel(id=ID_TRANSITIONCONTENTDIALOGSPACER, |
|
155 name='Spacer', parent=self, pos=wx.Point(0, 0), |
|
156 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
157 |
|
158 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
|
159 |
|
160 if wx.VERSION >= (2, 5, 0): |
|
161 self.Preview.Bind(wx.EVT_PAINT, self.OnPaint) |
|
162 else: |
|
163 wx.EVT_PAINT(self.Preview, self.OnPaint) |
|
164 |
|
165 self._init_sizers() |
|
166 |
|
167 def __init__(self, parent, controler): |
|
168 self._init_ctrls(parent, controler) |
|
169 |
|
170 self.Divergence = None |
|
171 self.MinSize = (0, 0) |
|
172 |
|
173 def SetPreviewFont(self, font): |
|
174 self.Preview.SetFont(font) |
|
175 |
|
176 def GetValues(self): |
|
177 values = {} |
|
178 if self.radioButton1.GetValue(): |
|
179 values["type"] = SELECTION_DIVERGENCE |
|
180 elif self.radioButton2.GetValue(): |
|
181 values["type"] = SELECTION_CONVERGENCE |
|
182 elif self.radioButton3.GetValue(): |
|
183 values["type"] = SIMULTANEOUS_DIVERGENCE |
|
184 else: |
|
185 values["type"] = SIMULTANEOUS_CONVERGENCE |
|
186 values["number"] = self.Sequences.GetValue() |
|
187 return values |
|
188 |
|
189 def SetMinSize(self, size): |
|
190 self.MinSize = size |
|
191 |
|
192 def OnTypeChanged(self, event): |
|
193 self.RefreshPreview() |
|
194 event.Skip() |
|
195 |
|
196 def OnSequencesChanged(self, event): |
|
197 self.RefreshPreview() |
|
198 event.Skip() |
|
199 |
|
200 def RefreshPreview(self): |
|
201 dc = wx.ClientDC(self.Preview) |
|
202 dc.SetFont(self.Preview.GetFont()) |
|
203 dc.Clear() |
|
204 if self.radioButton1.GetValue(): |
|
205 self.Divergence = SFC_Divergence(self.Preview, SELECTION_DIVERGENCE, self.Sequences.GetValue()) |
|
206 elif self.radioButton2.GetValue(): |
|
207 self.Divergence = SFC_Divergence(self.Preview, SELECTION_CONVERGENCE, self.Sequences.GetValue()) |
|
208 elif self.radioButton3.GetValue(): |
|
209 self.Divergence = SFC_Divergence(self.Preview, SIMULTANEOUS_DIVERGENCE, self.Sequences.GetValue()) |
|
210 else: |
|
211 self.Divergence = SFC_Divergence(self.Preview, SIMULTANEOUS_CONVERGENCE, self.Sequences.GetValue()) |
|
212 width, height = self.Divergence.GetSize() |
|
213 min_width, min_height = max(width, self.MinSize[0]), max(height, self.MinSize[1]) |
|
214 self.Divergence.SetSize(min_width, min_height) |
|
215 clientsize = self.Preview.GetClientSize() |
|
216 x = (clientsize.width - min_width) / 2 |
|
217 y = (clientsize.height - min_height) / 2 |
|
218 self.Divergence.SetPosition(x, y) |
|
219 self.Divergence.Draw(dc) |
|
220 |
|
221 def OnPaint(self, event): |
|
222 self.RefreshPreview() |
|
223 event.Skip() |