229 self.SelectedElement = wire |
232 self.SelectedElement = wire |
230 self.Refresh() |
233 self.Refresh() |
231 event.Skip() |
234 event.Skip() |
232 |
235 |
233 def OnViewerLeftUp(self, event): |
236 def OnViewerLeftUp(self, event): |
234 if self.rubberBand.IsShown(): |
237 if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
238 Viewer.OnViewerLeftUp(self, event) |
|
239 elif self.rubberBand.IsShown(): |
235 if self.Mode == MODE_SELECTION: |
240 if self.Mode == MODE_SELECTION: |
236 elements = self.SearchElements(self.rubberBand.GetCurrentExtent()) |
241 elements = self.SearchElements(self.rubberBand.GetCurrentExtent()) |
237 self.rubberBand.OnLeftUp(event, self.Scaling) |
242 self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
238 if len(elements) > 0: |
243 if len(elements) > 0: |
239 self.SelectedElement = Graphic_Group(self) |
244 self.SelectedElement = Graphic_Group(self) |
240 self.SelectedElement.SetElements(elements) |
245 self.SelectedElement.SetElements(elements) |
241 self.SelectedElement.SetSelected(True) |
246 self.SelectedElement.SetSelected(True) |
242 self.Refresh() |
247 self.Refresh() |
243 elif self.Mode == MODE_COMMENT: |
248 elif self.Mode == MODE_COMMENT: |
244 bbox = self.rubberBand.GetCurrentExtent() |
249 bbox = self.rubberBand.GetCurrentExtent() |
245 self.rubberBand.OnLeftUp(event, self.Scaling) |
250 self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
246 wxCallAfter(self.AddComment, bbox) |
251 wxCallAfter(self.AddComment, bbox) |
247 elif self.Mode == MODE_INITIAL_STEP: |
252 elif self.Mode == MODE_INITIALSTEP: |
248 wxCallAfter(self.AddInitialStep, GetScaledEventPosition(event, self.Scaling)) |
253 wxCallAfter(self.AddInitialStep, GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling)) |
249 elif self.Mode == MODE_SELECTION and self.SelectedElement: |
254 elif self.Mode == MODE_SELECTION and self.SelectedElement: |
250 if self.SelectedElement in self.Wires: |
255 if self.SelectedElement in self.Wires: |
251 self.SelectedElement.SetSelectedSegment(0) |
256 self.SelectedElement.SetSelectedSegment(0) |
252 else: |
257 else: |
253 self.SelectedElement.OnLeftUp(event, self.Scaling) |
258 self.SelectedElement.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
254 wxCallAfter(self.SetCursor, wxNullCursor) |
259 wxCallAfter(self.SetCursor, wxNullCursor) |
255 self.ReleaseMouse() |
260 self.ReleaseMouse() |
256 self.Refresh() |
261 self.Refresh() |
257 elif self.Mode == MODE_WIRE and self.SelectedElement: |
262 elif self.Mode == MODE_WIRE and self.SelectedElement: |
258 self.SelectedElement.ResetPoints() |
263 self.SelectedElement.ResetPoints() |
259 self.SelectedElement.OnMotion(event, self.Scaling) |
264 self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
260 self.SelectedElement.GeneratePoints() |
265 self.SelectedElement.GeneratePoints() |
261 self.SelectedElement.RefreshModel() |
266 self.SelectedElement.RefreshModel() |
262 self.SelectedElement.SetSelected(True) |
267 self.SelectedElement.SetSelected(True) |
263 self.Refresh() |
268 self.Refresh() |
264 event.Skip() |
269 event.Skip() |
265 |
270 |
266 def OnViewerRightUp(self, event): |
271 def OnViewerRightUp(self, event): |
267 pos = event.GetPosition() |
272 if self.GetDrawingMode() == FREEDRAWING_MODE: |
268 element = self.FindElement(pos) |
273 Viewer.OnViewerRightUp(self, event) |
269 if element: |
274 else: |
270 if self.SelectedElement and self.SelectedElement != element: |
275 dc = self.GetLogicalDC() |
271 self.SelectedElement.SetSelected(False) |
276 pos = event.GetLogicalPosition(dc) |
272 self.SelectedElement = element |
277 element = self.FindElement(pos) |
273 if self.SelectedElement in self.Wires: |
278 if element: |
274 self.SelectedElement.SetSelectedSegment(0) |
279 if self.SelectedElement and self.SelectedElement != element: |
275 else: |
280 self.SelectedElement.SetSelected(False) |
276 self.SelectedElement.SetSelected(True) |
281 self.SelectedElement = element |
277 self.SelectedElement.OnRightUp(event, self.Scaling) |
282 if self.SelectedElement in self.Wires: |
278 wxCallAfter(self.SetCursor, wxNullCursor) |
283 self.SelectedElement.SetSelectedSegment(0) |
279 self.ReleaseMouse() |
284 else: |
280 self.Refresh() |
285 self.SelectedElement.SetSelected(True) |
|
286 self.SelectedElement.OnRightUp(event, dc, self.Scaling) |
|
287 wxCallAfter(self.SetCursor, wxNullCursor) |
|
288 self.ReleaseMouse() |
|
289 self.Refresh() |
281 event.Skip() |
290 event.Skip() |
282 |
291 |
283 def OnViewerLeftDClick(self, event): |
292 def OnViewerLeftDClick(self, event): |
284 if self.Mode == MODE_SELECTION and self.SelectedElement: |
293 if self.GetDrawingMode() == FREEDRAWING_MODE: |
285 self.SelectedElement.OnLeftDClick(event, self.Scaling) |
294 Viewer.OnViewerLeftDClick(self, event) |
|
295 elif self.Mode == MODE_SELECTION and self.SelectedElement: |
|
296 self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling) |
286 self.Refresh() |
297 self.Refresh() |
287 event.Skip() |
298 event.Skip() |
288 |
299 |
289 def OnViewerMotion(self, event): |
300 def OnViewerMotion(self, event): |
290 if self.rubberBand.IsShown(): |
301 if self.GetDrawingMode() == FREEDRAWING_MODE: |
291 self.rubberBand.OnMotion(event, self.Scaling) |
302 Viewer.OnViewerMotion(self, event) |
|
303 elif self.rubberBand.IsShown(): |
|
304 self.rubberBand.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
292 elif self.Mode == MODE_SELECTION and self.SelectedElement: |
305 elif self.Mode == MODE_SELECTION and self.SelectedElement: |
293 if self.SelectedElement not in self.Wires: |
306 if self.SelectedElement not in self.Wires: |
294 self.SelectedElement.OnMotion(event, self.Scaling) |
307 self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
295 self.Refresh() |
308 self.Refresh() |
296 elif self.Mode == MODE_WIRE and self.SelectedElement: |
309 elif self.Mode == MODE_WIRE and self.SelectedElement: |
297 self.SelectedElement.ResetPoints() |
310 self.SelectedElement.ResetPoints() |
298 self.SelectedElement.OnMotion(event, self.Scaling) |
311 self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
299 self.SelectedElement.GeneratePoints() |
312 self.SelectedElement.GeneratePoints() |
300 self.Refresh() |
313 self.Refresh() |
|
314 Viewer.OnViewerMotion(self, event) |
301 event.Skip() |
315 event.Skip() |
302 |
316 |
303 #------------------------------------------------------------------------------- |
317 #------------------------------------------------------------------------------- |
304 # Keyboard event functions |
318 # Keyboard event functions |
305 #------------------------------------------------------------------------------- |
319 #------------------------------------------------------------------------------- |
1015 self.Controler.RemoveCurrentElementEditingInstance(comment.GetId()) |
1029 self.Controler.RemoveCurrentElementEditingInstance(comment.GetId()) |
1016 |
1030 |
1017 def DeleteWire(self, wire): |
1031 def DeleteWire(self, wire): |
1018 pass |
1032 pass |
1019 |
1033 |
1020 |
|
1021 #------------------------------------------------------------------------------- |
|
1022 # Edit Transition Content Dialog |
|
1023 #------------------------------------------------------------------------------- |
|
1024 |
|
1025 [wxID_TRANSITIONCONTENTDIALOG, wxID_TRANSITIONCONTENTDIALOGMAINPANEL, |
|
1026 wxID_TRANSITIONCONTENTDIALOGREFERENCE, wxID_TRANSITIONCONTENTDIALOGINLINE, |
|
1027 wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, |
|
1028 ] = [wx.NewId() for _init_ctrls in range(6)] |
|
1029 |
|
1030 class TransitionContentDialog(wx.Dialog): |
|
1031 def _init_coll_flexGridSizer1_Items(self, parent): |
|
1032 # generated method, don't edit |
|
1033 |
|
1034 parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1035 |
|
1036 def _init_sizers(self): |
|
1037 # generated method, don't edit |
|
1038 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1039 |
|
1040 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1041 |
|
1042 self.SetSizer(self.flexGridSizer1) |
|
1043 |
|
1044 def _init_ctrls(self, prnt): |
|
1045 # generated method, don't edit |
|
1046 wx.Dialog.__init__(self, id=wxID_TRANSITIONCONTENTDIALOG, |
|
1047 name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223), |
|
1048 size=wx.Size(300, 200), style=wx.DEFAULT_DIALOG_STYLE, |
|
1049 title='Edit transition') |
|
1050 self.SetClientSize(wx.Size(300, 200)) |
|
1051 |
|
1052 self.MainPanel = wx.Panel(id=wxID_TRANSITIONCONTENTDIALOGMAINPANEL, |
|
1053 name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1054 size=wx.Size(300, 200), style=wx.TAB_TRAVERSAL) |
|
1055 self.MainPanel.SetAutoLayout(True) |
|
1056 |
|
1057 self.radioButton1 = wx.RadioButton(id=wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, |
|
1058 label='Reference', name='radioButton1', parent=self.MainPanel, |
|
1059 pos=wx.Point(24, 24), size=wx.Size(114, 24), style=0) |
|
1060 EVT_RADIOBUTTON(self, wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, self.OnTypeChanged) |
|
1061 self.radioButton1.SetValue(True) |
|
1062 |
|
1063 self.Reference = wx.Choice(id=wxID_TRANSITIONCONTENTDIALOGREFERENCE, |
|
1064 name='Reference', parent=self.MainPanel, pos=wx.Point(48, 48), |
|
1065 size=wx.Size(200, 24), style=0) |
|
1066 |
|
1067 self.radioButton2 = wx.RadioButton(id=wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, |
|
1068 label='Inline', name='radioButton2', parent=self.MainPanel, |
|
1069 pos=wx.Point(24, 72), size=wx.Size(114, 24), style=0) |
|
1070 EVT_RADIOBUTTON(self, wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, self.OnTypeChanged) |
|
1071 self.radioButton2.SetValue(False) |
|
1072 |
|
1073 self.Inline = wx.TextCtrl(id=wxID_TRANSITIONCONTENTDIALOGINLINE, |
|
1074 name='Inline', parent=self.MainPanel, pos=wx.Point(48, 96), |
|
1075 size=wx.Size(200, 24), style=0) |
|
1076 |
|
1077 self._init_sizers() |
|
1078 |
|
1079 def __init__(self, parent): |
|
1080 self._init_ctrls(parent) |
|
1081 self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
|
1082 self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
|
1083 |
|
1084 EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
|
1085 |
|
1086 def OnOK(self, event): |
|
1087 error = [] |
|
1088 if self.radioButton1.GetValue() and self.Reference.GetStringSelection() == "": |
|
1089 error.append("Reference") |
|
1090 if self.radioButton2.GetValue() and self.Inline.GetValue() == "": |
|
1091 error.append("Inline") |
|
1092 if len(error) > 0: |
|
1093 text = "" |
|
1094 for i, item in enumerate(error): |
|
1095 if i == 0: |
|
1096 text += item |
|
1097 elif i == len(error) - 1: |
|
1098 text += " and %s"%item |
|
1099 else: |
|
1100 text += ", %s"%item |
|
1101 message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) |
|
1102 message.ShowModal() |
|
1103 message.Destroy() |
|
1104 else: |
|
1105 self.EndModal(wxID_OK) |
|
1106 |
|
1107 def OnTypeChanged(self, event): |
|
1108 if self.radioButton1.GetValue(): |
|
1109 self.Reference.Enable(True) |
|
1110 self.Inline.Enable(False) |
|
1111 else: |
|
1112 self.Reference.Enable(False) |
|
1113 self.Inline.Enable(True) |
|
1114 event.Skip() |
|
1115 |
|
1116 def SetTransitions(self, transitions): |
|
1117 for transition in transitions: |
|
1118 self.Reference.Append(transition) |
|
1119 |
|
1120 def SetValues(self, values): |
|
1121 if values["type"] == "reference": |
|
1122 self.radioButton1.SetValue(True) |
|
1123 self.radioButton2.SetValue(False) |
|
1124 self.Reference.Enable(True) |
|
1125 self.Inline.Enable(False) |
|
1126 self.Reference.SetStringSelection(values["value"]) |
|
1127 elif values["type"] == "inline": |
|
1128 self.radioButton1.SetValue(False) |
|
1129 self.radioButton2.SetValue(True) |
|
1130 self.Reference.Enable(False) |
|
1131 self.Inline.Enable(True) |
|
1132 self.Inline.SetValue(values["value"]) |
|
1133 |
|
1134 def GetValues(self): |
|
1135 values = {} |
|
1136 if self.radioButton1.GetValue(): |
|
1137 values["type"] = "reference" |
|
1138 values["value"] = self.Reference.GetStringSelection() |
|
1139 else: |
|
1140 values["type"] = "inline" |
|
1141 values["value"] = self.Inline.GetValue() |
|
1142 return values |
|
1143 |
|
1144 #------------------------------------------------------------------------------- |
|
1145 # Create New Divergence Dialog |
|
1146 #------------------------------------------------------------------------------- |
|
1147 |
|
1148 [wxID_DIVERGENCECREATEDIALOG, wxID_DIVERGENCECREATEDIALOGMAINPANEL, |
|
1149 wxID_DIVERGENCECREATEDIALOGRADIOBUTTON1, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON2, |
|
1150 wxID_DIVERGENCECREATEDIALOGRADIOBUTTON3, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON4, |
|
1151 wxID_DIVERGENCECREATEDIALOGSEQUENCES, wxID_DIVERGENCECREATEDIALOGPREVIEW, |
|
1152 wxID_DIVERGENCECREATEDIALOGSTATICTEXT1, wxID_DIVERGENCECREATEDIALOGSTATICTEXT2, |
|
1153 wxID_DIVERGENCECREATEDIALOGSTATICTEXT3, |
|
1154 ] = [wx.NewId() for _init_ctrls in range(11)] |
|
1155 |
|
1156 class DivergenceCreateDialog(wx.Dialog): |
|
1157 def _init_coll_flexGridSizer1_Items(self, parent): |
|
1158 # generated method, don't edit |
|
1159 |
|
1160 parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1161 |
|
1162 def _init_sizers(self): |
|
1163 # generated method, don't edit |
|
1164 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1165 |
|
1166 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1167 |
|
1168 self.SetSizer(self.flexGridSizer1) |
|
1169 |
|
1170 def _init_ctrls(self, prnt): |
|
1171 # generated method, don't edit |
|
1172 wx.Dialog.__init__(self, id=wxID_DIVERGENCECREATEDIALOG, |
|
1173 name='DivergencePropertiesDialog', parent=prnt, pos=wx.Point(376, 223), |
|
1174 size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE, |
|
1175 title='Create a new divergence or convergence') |
|
1176 self.SetClientSize(wx.Size(500, 260)) |
|
1177 |
|
1178 self.MainPanel = wx.Panel(id=wxID_DIVERGENCECREATEDIALOGMAINPANEL, |
|
1179 name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1180 size=wx.Size(600, 220), style=wx.TAB_TRAVERSAL) |
|
1181 self.MainPanel.SetAutoLayout(True) |
|
1182 |
|
1183 self.staticText1 = wx.StaticText(id=wxID_DIVERGENCECREATEDIALOGSTATICTEXT1, |
|
1184 label='Type:', name='staticText1', parent=self.MainPanel, |
|
1185 pos=wx.Point(24, 24), size=wx.Size(200, 17), style=0) |
|
1186 |
|
1187 self.radioButton1 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON1, |
|
1188 label='Selection Divergence', name='radioButton1', parent=self.MainPanel, |
|
1189 pos=wx.Point(24, 48), size=wx.Size(200, 24), style=0) |
|
1190 EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON1, self.OnTypeChanged) |
|
1191 self.radioButton1.SetValue(True) |
|
1192 |
|
1193 self.radioButton2 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON2, |
|
1194 label='Selection Convergence', name='radioButton2', parent=self.MainPanel, |
|
1195 pos=wx.Point(24, 72), size=wx.Size(200, 24), style=0) |
|
1196 EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON2, self.OnTypeChanged) |
|
1197 self.radioButton2.SetValue(False) |
|
1198 |
|
1199 self.radioButton3 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON3, |
|
1200 label='Simultaneous Divergence', name='radioButton3', parent=self.MainPanel, |
|
1201 pos=wx.Point(24, 96), size=wx.Size(200, 24), style=0) |
|
1202 EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON3, self.OnTypeChanged) |
|
1203 self.radioButton3.SetValue(False) |
|
1204 |
|
1205 self.radioButton4 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON4, |
|
1206 label='Simultaneous Convergence', name='radioButton4', parent=self.MainPanel, |
|
1207 pos=wx.Point(24, 120), size=wx.Size(200, 24), style=0) |
|
1208 EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON4, self.OnTypeChanged) |
|
1209 self.radioButton4.SetValue(False) |
|
1210 |
|
1211 self.staticText2 = wx.StaticText(id=wxID_DIVERGENCECREATEDIALOGSTATICTEXT2, |
|
1212 label='Number of sequences:', name='staticText2', parent=self.MainPanel, |
|
1213 pos=wx.Point(24, 150), size=wx.Size(200, 17), style=0) |
|
1214 |
|
1215 self.Sequences = wx.SpinCtrl(id=wxID_DIVERGENCECREATEDIALOGSEQUENCES, |
|
1216 name='Sequences', parent=self.MainPanel, pos=wx.Point(24, 174), |
|
1217 size=wx.Size(200, 24), style=0, min=2, max=20) |
|
1218 EVT_SPINCTRL(self, wxID_DIVERGENCECREATEDIALOGSEQUENCES, self.OnSequencesChanged) |
|
1219 |
|
1220 self.staticText3 = wx.StaticText(id=wxID_DIVERGENCECREATEDIALOGSTATICTEXT3, |
|
1221 label='Preview:', name='staticText3', parent=self.MainPanel, |
|
1222 pos=wx.Point(250, 24), size=wx.Size(100, 17), style=0) |
|
1223 |
|
1224 self.Preview = wx.Panel(id=wxID_DIVERGENCECREATEDIALOGPREVIEW, |
|
1225 name='Preview', parent=self.MainPanel, pos=wx.Point(250, 48), |
|
1226 size=wx.Size(225, 150), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) |
|
1227 self.Preview.SetBackgroundColour(wxColour(255,255,255)) |
|
1228 |
|
1229 self._init_sizers() |
|
1230 |
|
1231 def __init__(self, parent): |
|
1232 self._init_ctrls(parent) |
|
1233 self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
|
1234 self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
|
1235 |
|
1236 self.Divergence = None |
|
1237 |
|
1238 EVT_PAINT(self, self.OnPaint) |
|
1239 |
|
1240 def GetValues(self): |
|
1241 values = {} |
|
1242 if self.radioButton1.GetValue(): |
|
1243 values["type"] = SELECTION_DIVERGENCE |
|
1244 elif self.radioButton2.GetValue(): |
|
1245 values["type"] = SELECTION_CONVERGENCE |
|
1246 elif self.radioButton3.GetValue(): |
|
1247 values["type"] = SIMULTANEOUS_DIVERGENCE |
|
1248 else: |
|
1249 values["type"] = SIMULTANEOUS_CONVERGENCE |
|
1250 values["number"] = self.Sequences.GetValue() |
|
1251 return values |
|
1252 |
|
1253 def OnTypeChanged(self, event): |
|
1254 self.RefreshPreview() |
|
1255 event.Skip() |
|
1256 |
|
1257 def OnSequencesChanged(self, event): |
|
1258 self.RefreshPreview() |
|
1259 event.Skip() |
|
1260 |
|
1261 def RefreshPreview(self): |
|
1262 dc = wxClientDC(self.Preview) |
|
1263 dc.Clear() |
|
1264 if self.radioButton1.GetValue(): |
|
1265 self.Divergence = SFC_Divergence(self.Preview, SELECTION_DIVERGENCE, self.Sequences.GetValue()) |
|
1266 elif self.radioButton2.GetValue(): |
|
1267 self.Divergence = SFC_Divergence(self.Preview, SELECTION_CONVERGENCE, self.Sequences.GetValue()) |
|
1268 elif self.radioButton3.GetValue(): |
|
1269 self.Divergence = SFC_Divergence(self.Preview, SIMULTANEOUS_DIVERGENCE, self.Sequences.GetValue()) |
|
1270 else: |
|
1271 self.Divergence = SFC_Divergence(self.Preview, SIMULTANEOUS_CONVERGENCE, self.Sequences.GetValue()) |
|
1272 width, height = self.Divergence.GetSize() |
|
1273 clientsize = self.Preview.GetClientSize() |
|
1274 x = (clientsize.width - width) / 2 |
|
1275 y = (clientsize.height - height) / 2 |
|
1276 self.Divergence.SetPosition(x, y) |
|
1277 self.Divergence.Draw(dc) |
|
1278 |
|
1279 def OnPaint(self, event): |
|
1280 self.RefreshPreview() |
|
1281 |
|
1282 |
|
1283 #------------------------------------------------------------------------------- |
|
1284 # Action Block Dialog |
|
1285 #------------------------------------------------------------------------------- |
|
1286 |
|
1287 class ActionTable(wxPyGridTableBase): |
|
1288 |
|
1289 """ |
|
1290 A custom wxGrid Table using user supplied data |
|
1291 """ |
|
1292 def __init__(self, parent, data, colnames): |
|
1293 # The base class must be initialized *first* |
|
1294 wxPyGridTableBase.__init__(self) |
|
1295 self.data = data |
|
1296 self.colnames = colnames |
|
1297 self.Parent = parent |
|
1298 # XXX |
|
1299 # we need to store the row length and collength to |
|
1300 # see if the table has changed size |
|
1301 self._rows = self.GetNumberRows() |
|
1302 self._cols = self.GetNumberCols() |
|
1303 |
|
1304 def GetNumberCols(self): |
|
1305 return len(self.colnames) |
|
1306 |
|
1307 def GetNumberRows(self): |
|
1308 return len(self.data) |
|
1309 |
|
1310 def GetColLabelValue(self, col): |
|
1311 if col < len(self.colnames): |
|
1312 return self.colnames[col] |
|
1313 |
|
1314 def GetRowLabelValues(self, row): |
|
1315 return row |
|
1316 |
|
1317 def GetValue(self, row, col): |
|
1318 if row < self.GetNumberRows(): |
|
1319 name = str(self.data[row].get(self.GetColLabelValue(col), "")) |
|
1320 return name |
|
1321 |
|
1322 def GetValueByName(self, row, colname): |
|
1323 return self.data[row].get(colname) |
|
1324 |
|
1325 def SetValue(self, row, col, value): |
|
1326 if col < len(self.colnames): |
|
1327 self.data[row][self.GetColLabelValue(col)] = value |
|
1328 |
|
1329 def ResetView(self, grid): |
|
1330 """ |
|
1331 (wxGrid) -> Reset the grid view. Call this to |
|
1332 update the grid if rows and columns have been added or deleted |
|
1333 """ |
|
1334 grid.BeginBatch() |
|
1335 for current, new, delmsg, addmsg in [ |
|
1336 (self._rows, self.GetNumberRows(), wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_NOTIFY_ROWS_APPENDED), |
|
1337 (self._cols, self.GetNumberCols(), wxGRIDTABLE_NOTIFY_COLS_DELETED, wxGRIDTABLE_NOTIFY_COLS_APPENDED), |
|
1338 ]: |
|
1339 if new < current: |
|
1340 msg = wxGridTableMessage(self,delmsg,new,current-new) |
|
1341 grid.ProcessTableMessage(msg) |
|
1342 elif new > current: |
|
1343 msg = wxGridTableMessage(self,addmsg,new-current) |
|
1344 grid.ProcessTableMessage(msg) |
|
1345 self.UpdateValues(grid) |
|
1346 grid.EndBatch() |
|
1347 |
|
1348 self._rows = self.GetNumberRows() |
|
1349 self._cols = self.GetNumberCols() |
|
1350 # update the column rendering scheme |
|
1351 self._updateColAttrs(grid) |
|
1352 |
|
1353 # update the scrollbars and the displayed part of the grid |
|
1354 grid.AdjustScrollbars() |
|
1355 grid.ForceRefresh() |
|
1356 |
|
1357 def UpdateValues(self, grid): |
|
1358 """Update all displayed values""" |
|
1359 # This sends an event to the grid table to update all of the values |
|
1360 msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES) |
|
1361 grid.ProcessTableMessage(msg) |
|
1362 |
|
1363 def _updateColAttrs(self, grid): |
|
1364 """ |
|
1365 wxGrid -> update the column attributes to add the |
|
1366 appropriate renderer given the column name. |
|
1367 |
|
1368 Otherwise default to the default renderer. |
|
1369 """ |
|
1370 |
|
1371 for col in range(self.GetNumberCols()): |
|
1372 attr = wxGridCellAttr() |
|
1373 attr.SetAlignment(self.Parent.ColAlignements[col], wxALIGN_CENTRE) |
|
1374 grid.SetColAttr(col, attr) |
|
1375 grid.SetColSize(col, self.Parent.ColSizes[col]) |
|
1376 |
|
1377 typelist = None |
|
1378 accesslist = None |
|
1379 for row in range(self.GetNumberRows()): |
|
1380 for col in range(self.GetNumberCols()): |
|
1381 editor = None |
|
1382 renderer = None |
|
1383 readonly = False |
|
1384 colname = self.GetColLabelValue(col) |
|
1385 if colname == "Qualifier": |
|
1386 editor = wxGridCellChoiceEditor() |
|
1387 editor.SetParameters(self.Parent.QualifierList) |
|
1388 if colname == "Duration": |
|
1389 editor = wxGridCellTextEditor() |
|
1390 renderer = wxGridCellStringRenderer() |
|
1391 if self.Parent.DurationList[self.data[row]["Qualifier"]]: |
|
1392 readonly = False |
|
1393 else: |
|
1394 readonly = True |
|
1395 self.data[row]["Duration"] = "" |
|
1396 elif colname == "Type": |
|
1397 editor = wxGridCellChoiceEditor() |
|
1398 editor.SetParameters(self.Parent.TypeList) |
|
1399 elif colname == "Value": |
|
1400 type = self.data[row]["Type"] |
|
1401 if type == "Action": |
|
1402 editor = wxGridCellChoiceEditor() |
|
1403 editor.SetParameters(self.Parent.ActionList) |
|
1404 elif type == "Variable": |
|
1405 editor = wxGridCellChoiceEditor() |
|
1406 editor.SetParameters(self.Parent.VariableList) |
|
1407 elif type == "Inline": |
|
1408 editor = wxGridCellTextEditor() |
|
1409 renderer = wxGridCellStringRenderer() |
|
1410 elif colname == "Indicator": |
|
1411 editor = wxGridCellChoiceEditor() |
|
1412 editor.SetParameters(self.Parent.VariableList) |
|
1413 |
|
1414 grid.SetCellEditor(row, col, editor) |
|
1415 grid.SetCellRenderer(row, col, renderer) |
|
1416 grid.SetReadOnly(row, col, readonly) |
|
1417 |
|
1418 grid.SetCellBackgroundColour(row, col, wxWHITE) |
|
1419 |
|
1420 def SetData(self, data): |
|
1421 self.data = data |
|
1422 |
|
1423 def GetData(self): |
|
1424 return self.data |
|
1425 |
|
1426 def GetCurrentIndex(self): |
|
1427 return self.CurrentIndex |
|
1428 |
|
1429 def SetCurrentIndex(self, index): |
|
1430 self.CurrentIndex = index |
|
1431 |
|
1432 def AppendRow(self, row_content): |
|
1433 self.data.append(row_content) |
|
1434 |
|
1435 def RemoveRow(self, row_index): |
|
1436 self.data.pop(row_index) |
|
1437 |
|
1438 def MoveRow(self, row_index, move, grid): |
|
1439 new_index = max(0, min(row_index + move, len(self.data) - 1)) |
|
1440 if new_index != row_index: |
|
1441 self.data.insert(new_index, self.data.pop(row_index)) |
|
1442 grid.SetGridCursor(new_index, grid.GetGridCursorCol()) |
|
1443 |
|
1444 def Empty(self): |
|
1445 self.data = [] |
|
1446 self.editors = [] |
|
1447 |
|
1448 [wxID_ACTIONBLOCKDIALOG, wxID_ACTIONBLOCKDIALOGMAINPANEL, |
|
1449 wxID_ACTIONBLOCKDIALOGVARIABLESGRID, wxID_ACTIONBLOCKDIALOGSTATICTEXT1, |
|
1450 wxID_ACTIONBLOCKDIALOGADDBUTTON,wxID_ACTIONBLOCKDIALOGDELETEBUTTON, |
|
1451 wxID_ACTIONBLOCKDIALOGUPBUTTON, wxID_ACTIONBLOCKDIALOGDOWNBUTTON, |
|
1452 ] = [wx.NewId() for _init_ctrls in range(8)] |
|
1453 |
|
1454 class ActionBlockDialog(wx.Dialog): |
|
1455 def _init_coll_flexGridSizer1_Items(self, parent): |
|
1456 # generated method, don't edit |
|
1457 |
|
1458 parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1459 |
|
1460 def _init_sizers(self): |
|
1461 # generated method, don't edit |
|
1462 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1463 |
|
1464 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1465 |
|
1466 self.SetSizer(self.flexGridSizer1) |
|
1467 |
|
1468 def _init_ctrls(self, prnt): |
|
1469 # generated method, don't edit |
|
1470 wx.Dialog.__init__(self, id=wxID_ACTIONBLOCKDIALOG, |
|
1471 name='ActionBlockDialog', parent=prnt, pos=wx.Point(376, 223), |
|
1472 size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE, |
|
1473 title='Edit action block properties') |
|
1474 self.SetClientSize(wx.Size(500, 300)) |
|
1475 |
|
1476 self.MainPanel = wx.Panel(id=wxID_ACTIONBLOCKDIALOGMAINPANEL, |
|
1477 name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1478 size=wx.Size(500, 300), style=wx.TAB_TRAVERSAL) |
|
1479 self.MainPanel.SetAutoLayout(True) |
|
1480 |
|
1481 self.staticText1 = wx.StaticText(id=wxID_ACTIONBLOCKDIALOGSTATICTEXT1, |
|
1482 label='Actions:', name='staticText1', parent=self.MainPanel, |
|
1483 pos=wx.Point(24, 24), size=wx.Size(95, 17), style=0) |
|
1484 |
|
1485 self.ActionsGrid = wx.grid.Grid(id=wxID_ACTIONBLOCKDIALOGVARIABLESGRID, |
|
1486 name='ActionsGrid', parent=self.MainPanel, pos=wx.Point(24, 44), |
|
1487 size=wx.Size(450, 150), style=wxVSCROLL) |
|
1488 self.ActionsGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
|
1489 'Sans')) |
|
1490 self.ActionsGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
1491 False, 'Sans')) |
|
1492 self.ActionsGrid.DisableDragGridSize() |
|
1493 self.ActionsGrid.EnableScrolling(False, True) |
|
1494 EVT_GRID_CELL_CHANGE(self.ActionsGrid, self.OnActionsGridCellChange) |
|
1495 |
|
1496 self.AddButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGADDBUTTON, label='Add', |
|
1497 name='AddButton', parent=self.MainPanel, pos=wx.Point(245, 204), |
|
1498 size=wx.Size(72, 32), style=0) |
|
1499 EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGADDBUTTON, self.OnAddButton) |
|
1500 |
|
1501 self.DeleteButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGDELETEBUTTON, label='Delete', |
|
1502 name='DeleteButton', parent=self.MainPanel, pos=wx.Point(325, 204), |
|
1503 size=wx.Size(72, 32), style=0) |
|
1504 EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGDELETEBUTTON, self.OnDeleteButton) |
|
1505 |
|
1506 self.UpButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGUPBUTTON, label='^', |
|
1507 name='UpButton', parent=self.MainPanel, pos=wx.Point(405, 204), |
|
1508 size=wx.Size(32, 32), style=0) |
|
1509 EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGUPBUTTON, self.OnUpButton) |
|
1510 |
|
1511 self.DownButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGDOWNBUTTON, label='v', |
|
1512 name='DownButton', parent=self.MainPanel, pos=wx.Point(445, 204), |
|
1513 size=wx.Size(32, 32), style=0) |
|
1514 EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGDOWNBUTTON, self.OnDownButton) |
|
1515 |
|
1516 self._init_sizers() |
|
1517 |
|
1518 def __init__(self, parent): |
|
1519 self._init_ctrls(parent) |
|
1520 self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
|
1521 self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
|
1522 |
|
1523 self.DefaultValue = {"Qualifier" : "N", "Duration" : "", "Type" : "Action", "Value" : "", "Indicator" : ""} |
|
1524 self.Table = ActionTable(self, [], ["Qualifier","Duration","Type","Value","Indicator"]) |
|
1525 self.TypeList = "Action,Variable,Inline" |
|
1526 self.ColSizes = [60, 90, 80, 110, 80] |
|
1527 self.ColAlignements = [wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT] |
|
1528 |
|
1529 self.ActionsGrid.SetTable(self.Table) |
|
1530 self.ActionsGrid.SetRowLabelSize(0) |
|
1531 |
|
1532 self.Table.ResetView(self.ActionsGrid) |
|
1533 |
|
1534 def OnAddButton(self, event): |
|
1535 self.Table.AppendRow(self.DefaultValue.copy()) |
|
1536 self.Table.ResetView(self.ActionsGrid) |
|
1537 event.Skip() |
|
1538 |
|
1539 def OnDeleteButton(self, event): |
|
1540 row = self.ActionsGrid.GetGridCursorRow() |
|
1541 self.Table.RemoveRow(row) |
|
1542 self.Table.ResetView(self.ActionsGrid) |
|
1543 event.Skip() |
|
1544 |
|
1545 def OnUpButton(self, event): |
|
1546 row = self.ActionsGrid.GetGridCursorRow() |
|
1547 self.Table.MoveRow(row, -1, self.ActionsGrid) |
|
1548 self.Table.ResetView(self.ActionsGrid) |
|
1549 event.Skip() |
|
1550 |
|
1551 def OnDownButton(self, event): |
|
1552 row = self.ActionsGrid.GetGridCursorRow() |
|
1553 self.Table.MoveRow(row, 1, self.ActionsGrid) |
|
1554 self.Table.ResetView(self.ActionsGrid) |
|
1555 event.Skip() |
|
1556 |
|
1557 def OnActionsGridCellChange(self, event): |
|
1558 self.Table.ResetView(self.ActionsGrid) |
|
1559 event.Skip() |
|
1560 |
|
1561 def SetQualifierList(self, list): |
|
1562 self.QualifierList = "" |
|
1563 sep = "" |
|
1564 for qualifier in list.keys(): |
|
1565 self.QualifierList += "%s%s"%(sep, qualifier) |
|
1566 sep = "," |
|
1567 self.DurationList = list |
|
1568 |
|
1569 def SetVariableList(self, list): |
|
1570 self.VariableList = "" |
|
1571 sep = "" |
|
1572 for variable in list: |
|
1573 self.VariableList += "%s%s"%(sep, variable["Name"]) |
|
1574 sep = "," |
|
1575 |
|
1576 def SetActionList(self, list): |
|
1577 self.ActionList = "" |
|
1578 sep = "" |
|
1579 for action in list: |
|
1580 self.ActionList += "%s%s"%(sep, action) |
|
1581 sep = "," |
|
1582 |
|
1583 def SetValues(self, actions): |
|
1584 for action in actions: |
|
1585 row = {"Qualifier" : action["qualifier"], "Value" : action["value"]} |
|
1586 if action["type"] == "reference": |
|
1587 if action["value"] in self.ActionList: |
|
1588 row["Type"] = "Action" |
|
1589 elif action["value"] in self.VariableList: |
|
1590 row["Type"] = "Variable" |
|
1591 else: |
|
1592 row["Type"] = "Inline" |
|
1593 else: |
|
1594 row["Type"] = "Inline" |
|
1595 if "duration" in action: |
|
1596 row["Duration"] = action["duration"] |
|
1597 else: |
|
1598 row["Duration"] = "" |
|
1599 if "indicator" in action: |
|
1600 row["Indicator"] = action["indicator"] |
|
1601 else: |
|
1602 row["Indicator"] = "" |
|
1603 self.Table.AppendRow(row) |
|
1604 self.Table.ResetView(self.ActionsGrid) |
|
1605 |
|
1606 def GetValues(self): |
|
1607 values = [] |
|
1608 for data in self.Table.GetData(): |
|
1609 print data |
|
1610 action = {"qualifier" : data["Qualifier"], "value" : data["Value"]} |
|
1611 if data["Type"] in ["Action", "Variable"]: |
|
1612 action["type"] = "reference" |
|
1613 else: |
|
1614 action["type"] = "inline" |
|
1615 if data["Duration"] != "": |
|
1616 action["duration"] = data["Duration"] |
|
1617 if data["Indicator"] != "": |
|
1618 action["indicator"] = data["Indicator"] |
|
1619 values.append(action) |
|
1620 return values |
|
1621 |
|
1622 |
|
1623 #------------------------------------------------------------------------------- |
|
1624 # Edit Step Name Dialog |
|
1625 #------------------------------------------------------------------------------- |
|
1626 |
|
1627 class StepNameDialog(wxTextEntryDialog): |
|
1628 |
|
1629 def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", |
|
1630 style = wxOK|wxCANCEL|wxCENTRE, pos = wxDefaultPosition): |
|
1631 wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
|
1632 |
|
1633 self.PouNames = [] |
|
1634 self.Variables = [] |
|
1635 self.StepNames = [] |
|
1636 |
|
1637 EVT_BUTTON(self, self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId(), self.OnOK) |
|
1638 |
|
1639 def OnOK(self, event): |
|
1640 step_name = self.GetSizer().GetItem(1).GetWindow().GetValue() |
|
1641 if step_name == "": |
|
1642 message = wxMessageDialog(self, "You must type a name!", "Error", wxOK|wxICON_ERROR) |
|
1643 message.ShowModal() |
|
1644 message.Destroy() |
|
1645 elif not TestIdentifier(step_name): |
|
1646 message = wxMessageDialog(self, "\"%s\" is not a valid identifier!"%step_name, "Error", wxOK|wxICON_ERROR) |
|
1647 message.ShowModal() |
|
1648 message.Destroy() |
|
1649 elif step_name.upper() in IEC_KEYWORDS: |
|
1650 message = wxMessageDialog(self, "\"%s\" is a keyword. It can't be used!"%step_name, "Error", wxOK|wxICON_ERROR) |
|
1651 message.ShowModal() |
|
1652 message.Destroy() |
|
1653 elif step_name.upper() in self.PouNames: |
|
1654 message = wxMessageDialog(self, "A pou with \"%s\" as name exists!"%step_name, "Error", wxOK|wxICON_ERROR) |
|
1655 message.ShowModal() |
|
1656 message.Destroy() |
|
1657 elif step_name.upper() in self.Variables: |
|
1658 message = wxMessageDialog(self, "A variable with \"%s\" as name exists!"%step_name, "Error", wxOK|wxICON_ERROR) |
|
1659 message.ShowModal() |
|
1660 message.Destroy() |
|
1661 elif step_name.upper() in self.StepNames: |
|
1662 message = wxMessageDialog(self, "\"%s\" step already exists!"%step_name, "Error", wxOK|wxICON_ERROR) |
|
1663 message.ShowModal() |
|
1664 message.Destroy() |
|
1665 else: |
|
1666 self.EndModal(wxID_OK) |
|
1667 |
|
1668 def SetPouNames(self, pou_names): |
|
1669 self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
1670 |
|
1671 def SetVariables(self, variables): |
|
1672 self.Variables = [var["Name"].upper() for var in variables] |
|
1673 |
|
1674 def SetStepNames(self, step_names): |
|
1675 self.StepNames = [step_name.upper() for step_name in step_names] |
|