1128 |
1128 |
1129 def OnPaint(self, event): |
1129 def OnPaint(self, event): |
1130 self.RefreshPreview() |
1130 self.RefreshPreview() |
1131 event.Skip() |
1131 event.Skip() |
1132 |
1132 |
|
1133 |
|
1134 #------------------------------------------------------------------------------- |
|
1135 # Edit Step Content Dialog |
|
1136 #------------------------------------------------------------------------------- |
|
1137 |
|
1138 [ID_STEPCONTENTDIALOG, ID_STEPCONTENTDIALOGSPACER, |
|
1139 ID_STEPCONTENTDIALOGNAME, ID_STEPCONTENTDIALOGPREVIEW, |
|
1140 ID_STEPCONTENTDIALOGCHECKBOX1, ID_STEPCONTENTDIALOGCHECKBOX2, |
|
1141 ID_STEPCONTENTDIALOGCHECKBOX3, ID_STEPCONTENTDIALOGSTATICTEXT1, |
|
1142 ID_STEPCONTENTDIALOGSTATICTEXT2, ID_STEPCONTENTDIALOGSTATICTEXT3, |
|
1143 ] = [wx.NewId() for _init_ctrls in range(10)] |
|
1144 |
|
1145 class StepContentDialog(wx.Dialog): |
|
1146 def _init_coll_flexGridSizer1_Items(self, parent): |
|
1147 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
|
1148 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
|
1149 |
|
1150 def _init_coll_flexGridSizer1_Growables(self, parent): |
|
1151 parent.AddGrowableCol(0) |
|
1152 parent.AddGrowableRow(0) |
|
1153 |
|
1154 def _init_coll_MainSizer_Items(self, parent): |
|
1155 parent.AddSizer(self.LeftGridSizer, 1, border=5, flag=wx.GROW|wx.RIGHT) |
|
1156 parent.AddSizer(self.RightGridSizer, 1, border=5, flag=wx.GROW|wx.LEFT) |
|
1157 |
|
1158 def _init_coll_LeftGridSizer_Items(self, parent): |
|
1159 parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) |
|
1160 parent.AddWindow(self.Name, 0, border=0, flag=wx.GROW) |
|
1161 parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) |
|
1162 parent.AddWindow(self.checkBox1, 0, border=0, flag=wx.GROW) |
|
1163 parent.AddWindow(self.checkBox2, 0, border=0, flag=wx.GROW) |
|
1164 parent.AddWindow(self.checkBox3, 0, border=0, flag=wx.GROW) |
|
1165 parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW) |
|
1166 |
|
1167 def _init_coll_LeftGridSizer_Growables(self, parent): |
|
1168 parent.AddGrowableCol(0) |
|
1169 parent.AddGrowableRow(6) |
|
1170 |
|
1171 def _init_coll_RightGridSizer_Items(self, parent): |
|
1172 parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW) |
|
1173 parent.AddWindow(self.Preview, 0, border=0, flag=wx.GROW) |
|
1174 |
|
1175 def _init_coll_RightGridSizer_Growables(self, parent): |
|
1176 parent.AddGrowableCol(0) |
|
1177 parent.AddGrowableRow(1) |
|
1178 |
|
1179 def _init_sizers(self): |
|
1180 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
|
1181 self.MainSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
1182 self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=7, vgap=5) |
|
1183 self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
|
1184 |
|
1185 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1186 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) |
|
1187 self._init_coll_MainSizer_Items(self.MainSizer) |
|
1188 self._init_coll_LeftGridSizer_Items(self.LeftGridSizer) |
|
1189 self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer) |
|
1190 self._init_coll_RightGridSizer_Items(self.RightGridSizer) |
|
1191 self._init_coll_RightGridSizer_Growables(self.RightGridSizer) |
|
1192 |
|
1193 self.SetSizer(self.flexGridSizer1) |
|
1194 |
|
1195 def _init_ctrls(self, prnt): |
|
1196 wx.Dialog.__init__(self, id=ID_STEPCONTENTDIALOG, |
|
1197 name='StepContentDialog', parent=prnt, pos=wx.Point(376, 223), |
|
1198 size=wx.Size(400, 250), style=wx.DEFAULT_DIALOG_STYLE, |
|
1199 title='Edit Step') |
|
1200 self.SetClientSize(wx.Size(400, 250)) |
|
1201 |
|
1202 self.staticText1 = wx.StaticText(id=ID_STEPCONTENTDIALOGSTATICTEXT1, |
|
1203 label='Name:', name='staticText1', parent=self, |
|
1204 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) |
|
1205 |
|
1206 self.staticText2 = wx.StaticText(id=ID_STEPCONTENTDIALOGSTATICTEXT2, |
|
1207 label='Connectors:', name='staticText2', parent=self, |
|
1208 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) |
|
1209 |
|
1210 self.staticText3 = wx.StaticText(id=ID_STEPCONTENTDIALOGSTATICTEXT3, |
|
1211 label='Preview:', name='staticText4', parent=self, |
|
1212 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) |
|
1213 |
|
1214 self.Name = wx.TextCtrl(id=ID_STEPCONTENTDIALOGNAME, |
|
1215 name='Name', parent=self, pos=wx.Point(0, 0), |
|
1216 size=wx.Size(0, 24), style=0) |
|
1217 self.Bind(wx.EVT_TEXT, self.OnNameChanged, id=ID_STEPCONTENTDIALOGNAME) |
|
1218 |
|
1219 self.checkBox1 = wx.CheckBox(id=ID_STEPCONTENTDIALOGCHECKBOX1, |
|
1220 label="Input", name='checkBox1', parent=self, |
|
1221 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) |
|
1222 self.Bind(wx.EVT_CHECKBOX, self.OnConnectorsChanged, id=ID_STEPCONTENTDIALOGCHECKBOX1) |
|
1223 |
|
1224 self.checkBox2 = wx.CheckBox(id=ID_STEPCONTENTDIALOGCHECKBOX2, |
|
1225 label="Output", name='checkBox2', parent=self, |
|
1226 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) |
|
1227 self.Bind(wx.EVT_CHECKBOX, self.OnConnectorsChanged, id=ID_STEPCONTENTDIALOGCHECKBOX2) |
|
1228 |
|
1229 self.checkBox3 = wx.CheckBox(id=ID_STEPCONTENTDIALOGCHECKBOX3, |
|
1230 label="Action", name='checkBox3', parent=self, |
|
1231 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) |
|
1232 self.Bind(wx.EVT_CHECKBOX, self.OnConnectorsChanged, id=ID_STEPCONTENTDIALOGCHECKBOX3) |
|
1233 |
|
1234 self.Spacer = wx.Panel(id=ID_STEPCONTENTDIALOGSPACER, |
|
1235 name='Spacer', parent=self, pos=wx.Point(0, 0), |
|
1236 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
1237 |
|
1238 self.Preview = wx.Panel(id=ID_STEPCONTENTDIALOGPREVIEW, |
|
1239 name='Preview', parent=self, pos=wx.Point(0, 0), |
|
1240 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) |
|
1241 self.Preview.SetBackgroundColour(wx.Colour(255,255,255)) |
|
1242 setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) |
|
1243 setattr(self.Preview, "RefreshStepModel", lambda x:None) |
|
1244 |
|
1245 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
|
1246 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
|
1247 |
|
1248 self.Bind(wx.EVT_PAINT, self.OnPaint) |
|
1249 |
|
1250 self._init_sizers() |
|
1251 |
|
1252 def __init__(self, parent, initial = False): |
|
1253 self._init_ctrls(parent) |
|
1254 self.Step = None |
|
1255 self.Initial = initial |
|
1256 self.MinStepSize = None |
|
1257 |
|
1258 self.PouNames = [] |
|
1259 self.Variables = [] |
|
1260 self.StepNames = [] |
|
1261 |
|
1262 def OnOK(self, event): |
|
1263 step_name = self.Name.GetValue() |
|
1264 if step_name == "": |
|
1265 message = wx.MessageDialog(self, "You must type a name!", "Error", wx.OK|wx.ICON_ERROR) |
|
1266 message.ShowModal() |
|
1267 message.Destroy() |
|
1268 elif not TestIdentifier(step_name): |
|
1269 message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%step_name, "Error", wx.OK|wx.ICON_ERROR) |
|
1270 message.ShowModal() |
|
1271 message.Destroy() |
|
1272 elif step_name.upper() in IEC_KEYWORDS: |
|
1273 message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%step_name, "Error", wx.OK|wx.ICON_ERROR) |
|
1274 message.ShowModal() |
|
1275 message.Destroy() |
|
1276 elif step_name.upper() in self.PouNames: |
|
1277 message = wx.MessageDialog(self, "A pou with \"%s\" as name exists!"%step_name, "Error", wx.OK|wx.ICON_ERROR) |
|
1278 message.ShowModal() |
|
1279 message.Destroy() |
|
1280 elif step_name.upper() in self.Variables: |
|
1281 message = wx.MessageDialog(self, "A variable with \"%s\" as name exists!"%step_name, "Error", wx.OK|wx.ICON_ERROR) |
|
1282 message.ShowModal() |
|
1283 message.Destroy() |
|
1284 elif step_name.upper() in self.StepNames: |
|
1285 message = wx.MessageDialog(self, "\"%s\" step already exists!"%step_name, "Error", wx.OK|wx.ICON_ERROR) |
|
1286 message.ShowModal() |
|
1287 message.Destroy() |
|
1288 else: |
|
1289 self.EndModal(wx.ID_OK) |
|
1290 |
|
1291 def SetMinStepSize(self, size): |
|
1292 self.MinStepSize = size |
|
1293 |
|
1294 def SetPouNames(self, pou_names): |
|
1295 self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
1296 |
|
1297 def SetVariables(self, variables): |
|
1298 self.Variables = [var["Name"].upper() for var in variables] |
|
1299 |
|
1300 def SetStepNames(self, step_names): |
|
1301 self.StepNames = [step_name.upper() for step_name in step_names] |
|
1302 |
|
1303 def SetValues(self, values): |
|
1304 value_name = values.get("name", None) |
|
1305 if value_name: |
|
1306 self.Name.SetValue(value_name) |
|
1307 else: |
|
1308 self.Name.SetValue("") |
|
1309 self.checkBox1.SetValue(values.get("input", False)) |
|
1310 self.checkBox2.SetValue(values.get("output", False)) |
|
1311 self.checkBox3.SetValue(values.get("action", False)) |
|
1312 self.RefreshPreview() |
|
1313 |
|
1314 def GetValues(self): |
|
1315 values = {} |
|
1316 values["name"] = self.Name.GetValue() |
|
1317 values["input"] = self.checkBox1.IsChecked() |
|
1318 values["output"] = self.checkBox2.IsChecked() |
|
1319 values["action"] = self.checkBox3.IsChecked() |
|
1320 values["width"], values["height"] = self.Step.GetSize() |
|
1321 return values |
|
1322 |
|
1323 def OnConnectorsChanged(self, event): |
|
1324 self.RefreshPreview() |
|
1325 event.Skip() |
|
1326 |
|
1327 def OnNameChanged(self, event): |
|
1328 self.RefreshPreview() |
|
1329 event.Skip() |
|
1330 |
|
1331 def RefreshPreview(self): |
|
1332 dc = wx.ClientDC(self.Preview) |
|
1333 dc.Clear() |
|
1334 self.Step = SFC_Step(self.Preview, self.Name.GetValue(), self.Initial) |
|
1335 if self.checkBox1.IsChecked(): |
|
1336 self.Step.AddInput() |
|
1337 else: |
|
1338 self.Step.RemoveInput() |
|
1339 if self.checkBox2.IsChecked(): |
|
1340 self.Step.AddOutput() |
|
1341 else: |
|
1342 self.Step.RemoveOutput() |
|
1343 if self.checkBox3.IsChecked(): |
|
1344 self.Step.AddAction() |
|
1345 else: |
|
1346 self.Step.RemoveAction() |
|
1347 width, height = self.MinStepSize |
|
1348 min_width, min_height = self.Step.GetMinSize() |
|
1349 width, height = max(min_width, width), max(min_height, height) |
|
1350 self.Step.SetSize(width, height) |
|
1351 clientsize = self.Preview.GetClientSize() |
|
1352 x = (clientsize.width - width) / 2 |
|
1353 y = (clientsize.height - height) / 2 |
|
1354 self.Step.SetPosition(x, y) |
|
1355 self.Step.Draw(dc) |
|
1356 |
|
1357 def OnPaint(self, event): |
|
1358 self.RefreshPreview() |
1133 |
1359 |
1134 #------------------------------------------------------------------------------- |
1360 #------------------------------------------------------------------------------- |
1135 # Edit Transition Content Dialog |
1361 # Edit Transition Content Dialog |
1136 #------------------------------------------------------------------------------- |
1362 #------------------------------------------------------------------------------- |
1137 |
1363 |