79 if len(word) != 0 and not word.isalnum(): |
80 if len(word) != 0 and not word.isalnum(): |
80 return False |
81 return False |
81 return True |
82 return True |
82 |
83 |
83 [wxID_PLCOPENEDITOR, wxID_PLCOPENEDITORPROJECTTREE, |
84 [wxID_PLCOPENEDITOR, wxID_PLCOPENEDITORPROJECTTREE, |
84 wxID_PLCOPENEDITORSPLITTERWINDOW1, wxID_PLCOPENEDITORTABSOPENED, |
85 wxID_PLCOPENEDITORSPLITTERWINDOW1, wxID_PLCOPENEDITOREDITORPANEL, |
85 wxID_PLCOPENEDITORDEFAULTTOOLBAR, wxID_PLCOPENEDITORSFCTOOLBAR, |
86 wxID_PLCOPENEDITORTABSOPENED, wxID_PLCOPENEDITORTOOLBAR, |
|
87 wxID_PLCOPENEDITORDEFAULTTOOLBAR, wxID_PLCOPENEDITORSFCTOOLBAR, |
86 wxID_PLCOPENEDITORFBDTOOLBAR, wxID_PLCOPENEDITORLDTOOLBAR, |
88 wxID_PLCOPENEDITORFBDTOOLBAR, wxID_PLCOPENEDITORLDTOOLBAR, |
87 ] = [wx.NewId() for _init_ctrls in range(8)] |
89 ] = [wx.NewId() for _init_ctrls in range(10)] |
88 |
90 |
89 [wxID_PLCOPENEDITORDEFAULTTOOLBARITEMS0, |
91 [wxID_PLCOPENEDITORTOOLBARITEMS0, |
90 ] = [wx.NewId() for _init_coll_DefaultToolBar_Items in range(1)] |
92 ] = [wx.NewId() for _init_coll_DefaultToolBar_Items in range(1)] |
91 |
93 |
92 [wxID_PLCOPENEDITORSFCTOOLBARITEMS0, wxID_PLCOPENEDITORSFCTOOLBARITEMS1, |
94 SFC_ITEMS = [wxID_PLCOPENEDITORSFCTOOLBARITEMS1, |
93 wxID_PLCOPENEDITORSFCTOOLBARITEMS2, wxID_PLCOPENEDITORSFCTOOLBARITEMS3, |
95 wxID_PLCOPENEDITORSFCTOOLBARITEMS2, wxID_PLCOPENEDITORSFCTOOLBARITEMS3, |
94 wxID_PLCOPENEDITORSFCTOOLBARITEMS4, wxID_PLCOPENEDITORSFCTOOLBARITEMS5, |
96 wxID_PLCOPENEDITORSFCTOOLBARITEMS4, wxID_PLCOPENEDITORSFCTOOLBARITEMS5, |
95 wxID_PLCOPENEDITORSFCTOOLBARITEMS6, |
97 wxID_PLCOPENEDITORSFCTOOLBARITEMS6, |
96 ] = [wx.NewId() for _init_coll_SFCToolBar_Items in range(7)] |
98 ] = [wx.NewId() for _init_coll_SFCToolBar_Items in range(6)] |
97 |
99 |
98 [wxID_PLCOPENEDITORFBDTOOLBARITEMS0, wxID_PLCOPENEDITORFBDTOOLBARITEMS1, |
100 FBD_ITEMS = [wxID_PLCOPENEDITORFBDTOOLBARITEMS1, |
99 wxID_PLCOPENEDITORFBDTOOLBARITEMS2, wxID_PLCOPENEDITORFBDTOOLBARITEMS3, |
101 wxID_PLCOPENEDITORFBDTOOLBARITEMS2, wxID_PLCOPENEDITORFBDTOOLBARITEMS3, |
100 wxID_PLCOPENEDITORFBDTOOLBARITEMS4, wxID_PLCOPENEDITORFBDTOOLBARITEMS5, |
102 wxID_PLCOPENEDITORFBDTOOLBARITEMS4, wxID_PLCOPENEDITORFBDTOOLBARITEMS5, |
101 ] = [wx.NewId() for _init_coll_FBDToolBar_Items in range(6)] |
103 ] = [wx.NewId() for _init_coll_FBDToolBar_Items in range(5)] |
102 |
104 |
103 [wxID_PLCOPENEDITORLDTOOLBARITEMS0, wxID_PLCOPENEDITORLDTOOLBARITEMS1, |
105 LD_ITEMS = [wxID_PLCOPENEDITORLDTOOLBARITEMS1, |
104 wxID_PLCOPENEDITORLDTOOLBARITEMS2, wxID_PLCOPENEDITORLDTOOLBARITEMS3, |
106 wxID_PLCOPENEDITORLDTOOLBARITEMS2, wxID_PLCOPENEDITORLDTOOLBARITEMS3, |
105 wxID_PLCOPENEDITORLDTOOLBARITEMS4, |
107 wxID_PLCOPENEDITORLDTOOLBARITEMS4, |
106 ] = [wx.NewId() for _init_coll_LDToolBar_Items in range(5)] |
108 ] = [wx.NewId() for _init_coll_LDToolBar_Items in range(4)] |
107 |
109 |
108 [wxID_PLCOPENEDITORFILEMENUITEMS0, wxID_PLCOPENEDITORFILEMENUITEMS1, |
110 [wxID_PLCOPENEDITORFILEMENUITEMS0, wxID_PLCOPENEDITORFILEMENUITEMS1, |
109 wxID_PLCOPENEDITORFILEMENUITEMS2, wxID_PLCOPENEDITORFILEMENUITEMS3, |
111 wxID_PLCOPENEDITORFILEMENUITEMS2, wxID_PLCOPENEDITORFILEMENUITEMS3, |
110 wxID_PLCOPENEDITORFILEMENUITEMS5, wxID_PLCOPENEDITORFILEMENUITEMS6, |
112 wxID_PLCOPENEDITORFILEMENUITEMS5, wxID_PLCOPENEDITORFILEMENUITEMS6, |
111 wxID_PLCOPENEDITORFILEMENUITEMS7, wxID_PLCOPENEDITORFILEMENUITEMS9, |
113 wxID_PLCOPENEDITORFILEMENUITEMS7, wxID_PLCOPENEDITORFILEMENUITEMS9, |
301 def _init_coll_MainGridSizer_Items(self, parent): |
303 def _init_coll_MainGridSizer_Items(self, parent): |
302 # generated method, don't edit |
304 # generated method, don't edit |
303 |
305 |
304 parent.AddWindow(self.splitterWindow1, 0, border=0, flag=wxGROW) |
306 parent.AddWindow(self.splitterWindow1, 0, border=0, flag=wxGROW) |
305 |
307 |
|
308 def _init_coll_EditorGridSizer_Items(self, parent): |
|
309 # generated method, don't edit |
|
310 |
|
311 parent.AddWindow(self.ToolBar, 0, border=0, flag=wxGROW) |
|
312 parent.AddWindow(self.TabsOpened, 0, border=0, flag=wxGROW) |
|
313 |
306 def _init_coll_MainGridSizer_Growables(self, parent): |
314 def _init_coll_MainGridSizer_Growables(self, parent): |
307 # generated method, don't edit |
315 # generated method, don't edit |
308 |
316 |
309 parent.AddGrowableCol(0) |
317 parent.AddGrowableCol(0) |
310 parent.AddGrowableRow(0) |
318 parent.AddGrowableRow(0) |
311 |
319 |
|
320 def _init_coll_EditorGridSizer_Growables(self, parent): |
|
321 # generated method, don't edit |
|
322 |
|
323 parent.AddGrowableCol(0) |
|
324 parent.AddGrowableRow(1) |
|
325 |
312 def _init_sizers(self): |
326 def _init_sizers(self): |
313 # generated method, don't edit |
327 # generated method, don't edit |
314 self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=0) |
328 self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=0) |
|
329 |
|
330 self.EditorGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
315 |
331 |
316 self._init_coll_MainGridSizer_Growables(self.MainGridSizer) |
332 self._init_coll_MainGridSizer_Growables(self.MainGridSizer) |
317 self._init_coll_MainGridSizer_Items(self.MainGridSizer) |
333 self._init_coll_MainGridSizer_Items(self.MainGridSizer) |
318 |
334 self._init_coll_EditorGridSizer_Growables(self.EditorGridSizer) |
|
335 self._init_coll_EditorGridSizer_Items(self.EditorGridSizer) |
|
336 |
319 self.SetSizer(self.MainGridSizer) |
337 self.SetSizer(self.MainGridSizer) |
|
338 self.EditorPanel.SetSizer(self.EditorGridSizer) |
320 |
339 |
321 def _init_ctrls(self, prnt): |
340 def _init_ctrls(self, prnt): |
322 # generated method, don't edit |
341 # generated method, don't edit |
323 wx.Frame.__init__(self, id=wxID_PLCOPENEDITOR, name=u'PLCOpenEditor', |
342 wx.Frame.__init__(self, id=wxID_PLCOPENEDITOR, name=u'PLCOpenEditor', |
324 parent=prnt, pos=wx.Point(235, 287), size=wx.Size(1000, 600), |
343 parent=prnt, pos=wx.Point(235, 287), size=wx.Size(1000, 600), |
339 name='splitterWindow1', parent=self, point=wx.Point(0, 0), |
358 name='splitterWindow1', parent=self, point=wx.Point(0, 0), |
340 size=wx.Size(-1, -1), style=wx.SP_3D) |
359 size=wx.Size(-1, -1), style=wx.SP_3D) |
341 self.splitterWindow1.SetNeedUpdating(True) |
360 self.splitterWindow1.SetNeedUpdating(True) |
342 self.splitterWindow1.SetMinimumPaneSize(1) |
361 self.splitterWindow1.SetMinimumPaneSize(1) |
343 |
362 |
|
363 self.EditorPanel = wx.Panel(id=wxID_PLCOPENEDITOREDITORPANEL, |
|
364 name='TabPanel', parent=self.splitterWindow1, pos=wx.Point(0, 0), |
|
365 size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) |
|
366 |
344 self.TabsOpened = wx.Notebook(id=wxID_PLCOPENEDITORTABSOPENED, |
367 self.TabsOpened = wx.Notebook(id=wxID_PLCOPENEDITORTABSOPENED, |
345 name='TabsOpened', parent=self.splitterWindow1, pos=wx.Point(0, |
368 name='TabsOpened', parent=self.EditorPanel, pos=wx.Point(0, |
346 0), size=wx.Size(-1, -1), style=0) |
369 0), size=wx.Size(-1, -1), style=0) |
347 self.TabsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, |
370 self.TabsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, |
348 self.OnPouSelectedChanged, id=wxID_PLCOPENEDITORTABSOPENED) |
371 self.OnPouSelectedChanged, id=wxID_PLCOPENEDITORTABSOPENED) |
349 |
372 |
|
373 self.ToolBar = wxToolBar(id=wxID_PLCOPENEDITORTOOLBAR, name='ToolBar', |
|
374 parent=self.EditorPanel, pos=wx.Point(0, 0), size=wx.Size(0, 40), |
|
375 style=wxTB_HORIZONTAL | wxNO_BORDER) |
|
376 self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORTOOLBARITEMS0, |
|
377 wxBitmap(os.path.join(CWD, 'Images/select.png')), wxNullBitmap, "Select an object") |
|
378 self.Bind(wx.EVT_TOOL, self.OnSelectionTool, |
|
379 id=wxID_PLCOPENEDITORTOOLBARITEMS0) |
|
380 |
350 self.ProjectTree = wx.TreeCtrl(id=wxID_PLCOPENEDITORPROJECTTREE, |
381 self.ProjectTree = wx.TreeCtrl(id=wxID_PLCOPENEDITORPROJECTTREE, |
351 name='treeCtrl1', parent=self.splitterWindow1, pos=wx.Point(0, 0), |
382 name='treeCtrl1', parent=self.splitterWindow1, pos=wx.Point(0, 0), |
352 size=wx.Size(-1, -1), |
383 size=wx.Size(-1, -1), |
353 style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER) |
384 style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER) |
354 self.ProjectTree.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp) |
385 self.ProjectTree.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp) |
355 self.splitterWindow1.SplitVertically(self.ProjectTree, self.TabsOpened, |
386 self.splitterWindow1.SplitVertically(self.ProjectTree, self.EditorPanel, |
356 200) |
387 200) |
357 |
388 |
358 self._init_sizers() |
389 self._init_sizers() |
359 |
390 |
360 def init_coll_DefaultToolBar_Items(self, parent): |
|
361 parent.AddRadioTool(wxID_PLCOPENEDITORDEFAULTTOOLBARITEMS0, |
|
362 wxBitmap('Images/select.png'), wxNullBitmap, "Select an object") |
|
363 self.Bind(wx.EVT_TOOL, self.OnSelectionTool, |
|
364 id=wxID_PLCOPENEDITORDEFAULTTOOLBARITEMS0) |
|
365 |
|
366 def init_coll_SFCToolBar_Items(self, parent): |
|
367 parent.AddRadioTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS0, |
|
368 wxBitmap('Images/select.png'), wxNullBitmap, "Select an object") |
|
369 parent.AddRadioTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS1, |
|
370 wxBitmap('Images/comment.png'), wxNullBitmap, "Create a new comment") |
|
371 parent.AddRadioTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS2, |
|
372 wxBitmap('Images/initial_step.png'), wxNullBitmap, "Create a new initial step") |
|
373 parent.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS3, |
|
374 wxBitmap('Images/step.png'), "Create a new step") |
|
375 parent.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS4, |
|
376 wxBitmap('Images/action.png'), "Add action block to step") |
|
377 parent.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS5, |
|
378 wxBitmap('Images/divergence.png'), "Create a new divergence") |
|
379 parent.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS6, |
|
380 wxBitmap('Images/jump.png'), "Create a new jump") |
|
381 self.Bind(wx.EVT_TOOL, self.OnSelectionTool, |
|
382 id=wxID_PLCOPENEDITORSFCTOOLBARITEMS0) |
|
383 self.Bind(wx.EVT_TOOL, self.OnCommentTool, |
|
384 id=wxID_PLCOPENEDITORSFCTOOLBARITEMS1) |
|
385 self.Bind(wx.EVT_TOOL, self.OnSFCInitialStepTool, |
|
386 id=wxID_PLCOPENEDITORSFCTOOLBARITEMS2) |
|
387 self.Bind(wx.EVT_TOOL, self.OnSFCStepTool, |
|
388 id=wxID_PLCOPENEDITORSFCTOOLBARITEMS3) |
|
389 self.Bind(wx.EVT_TOOL, self.OnSFCActionBlockTool, |
|
390 id=wxID_PLCOPENEDITORSFCTOOLBARITEMS4) |
|
391 self.Bind(wx.EVT_TOOL, self.OnSFCDivergenceTool, |
|
392 id=wxID_PLCOPENEDITORSFCTOOLBARITEMS5) |
|
393 self.Bind(wx.EVT_TOOL, self.OnSFCJumpTool, |
|
394 id=wxID_PLCOPENEDITORSFCTOOLBARITEMS6) |
|
395 |
|
396 def init_coll_FBDToolBar_Items(self, parent): |
|
397 parent.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS0, |
|
398 wxBitmap('Images/select.png'), wxNullBitmap, "Select an object") |
|
399 parent.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS1, |
|
400 wxBitmap('Images/comment.png'), wxNullBitmap, "Create a new comment") |
|
401 parent.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS2, |
|
402 wxBitmap('Images/variable.png'), wxNullBitmap, "Create a new variable") |
|
403 parent.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS3, |
|
404 wxBitmap('Images/block.png'), wxNullBitmap, "Create a new block") |
|
405 parent.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS4, |
|
406 wxBitmap('Images/connection.png'), wxNullBitmap, "Create a new connection") |
|
407 parent.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS5, |
|
408 wxBitmap('Images/wire.png'), wxNullBitmap, "Create a new wire") |
|
409 self.Bind(wx.EVT_TOOL, self.OnSelectionTool, |
|
410 id=wxID_PLCOPENEDITORFBDTOOLBARITEMS0) |
|
411 self.Bind(wx.EVT_TOOL, self.OnCommentTool, |
|
412 id=wxID_PLCOPENEDITORFBDTOOLBARITEMS1) |
|
413 self.Bind(wx.EVT_TOOL, self.OnFBDVariableTool, |
|
414 id=wxID_PLCOPENEDITORFBDTOOLBARITEMS2) |
|
415 self.Bind(wx.EVT_TOOL, self.OnFBDBlockTool, |
|
416 id=wxID_PLCOPENEDITORFBDTOOLBARITEMS3) |
|
417 self.Bind(wx.EVT_TOOL, self.OnFBDConnectionTool, |
|
418 id=wxID_PLCOPENEDITORFBDTOOLBARITEMS4) |
|
419 self.Bind(wx.EVT_TOOL, self.OnWireTool, |
|
420 id=wxID_PLCOPENEDITORFBDTOOLBARITEMS5) |
|
421 |
|
422 def init_coll_LDToolBar_Items(self, parent): |
|
423 parent.AddRadioTool(wxID_PLCOPENEDITORLDTOOLBARITEMS0, |
|
424 wxBitmap('Images/select.png'), wxNullBitmap, "Select an object") |
|
425 parent.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS1, |
|
426 wxBitmap('Images/coil.png'), "Create a new rung") |
|
427 parent.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS2, |
|
428 wxBitmap('Images/contact.png'), "Create a new contact") |
|
429 parent.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS3, |
|
430 wxBitmap('Images/block.png'), "Create a new block") |
|
431 parent.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS4, |
|
432 wxBitmap('Images/branch.png'), "Create a new branch") |
|
433 self.Bind(wx.EVT_TOOL, self.OnSelectionTool, |
|
434 id=wxID_PLCOPENEDITORLDTOOLBARITEMS0) |
|
435 self.Bind(wx.EVT_TOOL, self.OnLDCoilTool, |
|
436 id=wxID_PLCOPENEDITORLDTOOLBARITEMS1) |
|
437 self.Bind(wx.EVT_TOOL, self.OnLDContactTool, |
|
438 id=wxID_PLCOPENEDITORLDTOOLBARITEMS2) |
|
439 self.Bind(wx.EVT_TOOL, self.OnLDBlockTool, |
|
440 id=wxID_PLCOPENEDITORLDTOOLBARITEMS3) |
|
441 self.Bind(wx.EVT_TOOL, self.OnLDBranchTool, |
|
442 id=wxID_PLCOPENEDITORLDTOOLBARITEMS4) |
|
443 |
|
444 def init_toolbars(self): |
|
445 self.DefaultToolBar = wxToolBar(id=wxID_PLCOPENEDITORDEFAULTTOOLBAR, name='DefaultToolBar', |
|
446 parent=self, pos=wx.Point(0, 27), size=wx.Size(0, 0), |
|
447 style=wxTB_HORIZONTAL | wxNO_BORDER) |
|
448 |
|
449 self.SFCToolBar = wxToolBar(id=wxID_PLCOPENEDITORSFCTOOLBAR, name='SFCToolBar', |
|
450 parent=self, pos=wx.Point(0, 27), size=wx.Size(0, 0), |
|
451 style=wxTB_HORIZONTAL | wxNO_BORDER) |
|
452 |
|
453 self.FBDToolBar = wxToolBar(id=wxID_PLCOPENEDITORFBDTOOLBAR, name='FBDToolBar', |
|
454 parent=self, pos=wx.Point(0, 27), size=wx.Size(0, 0), |
|
455 style=wxTB_HORIZONTAL | wxNO_BORDER) |
|
456 |
|
457 self.LDToolBar = wxToolBar(id=wxID_PLCOPENEDITORLDTOOLBAR, name='LDToolBar', |
|
458 parent=self, pos=wx.Point(0, 27), size=wx.Size(0, 0), |
|
459 style=wxTB_HORIZONTAL | wxNO_BORDER) |
|
460 |
|
461 self.init_coll_DefaultToolBar_Items(self.DefaultToolBar) |
|
462 self.init_coll_SFCToolBar_Items(self.SFCToolBar) |
|
463 self.init_coll_FBDToolBar_Items(self.FBDToolBar) |
|
464 self.init_coll_LDToolBar_Items(self.LDToolBar) |
|
465 |
|
466 def __init__(self, parent): |
391 def __init__(self, parent): |
467 self._init_ctrls(parent) |
392 self._init_ctrls(parent) |
468 self.init_toolbars() |
|
469 |
393 |
470 self.Controler = PLCControler() |
394 self.Controler = PLCControler() |
471 |
395 |
472 if fileOpen: |
396 if fileOpen: |
473 self.Controler.OpenXMLFile(fileOpen) |
397 self.Controler.OpenXMLFile(fileOpen) |
474 self.RefreshProjectTree() |
398 self.RefreshProjectTree() |
|
399 |
|
400 self.CurrentToolBar = [] |
475 |
401 |
476 self.RefreshFileMenu() |
402 self.RefreshFileMenu() |
477 self.RefreshEditMenu() |
403 self.RefreshEditMenu() |
478 self.RefreshToolBar() |
404 self.RefreshToolBar() |
479 |
405 |
623 message.ShowModal() |
549 message.ShowModal() |
624 message.Destroy() |
550 message.Destroy() |
625 dialog.Destroy() |
551 dialog.Destroy() |
626 |
552 |
627 def OnQuitMenu(self, event): |
553 def OnQuitMenu(self, event): |
|
554 self.ToolBar.Reparent(self) |
|
555 self.Controler.Reset() |
628 self.Close() |
556 self.Close() |
629 event.Skip() |
557 event.Skip() |
630 |
558 |
631 def ResetCurrentMode(self): |
559 def ResetCurrentMode(self): |
632 selected = self.TabsOpened.GetSelection() |
560 selected = self.TabsOpened.GetSelection() |
633 if selected != -1: |
561 if selected != -1: |
634 self.TabsOpened.GetPage(selected).SetMode(MODE_SELECTION) |
562 window = self.TabsOpened.GetPage(selected) |
635 language = self.Controler.GetCurrentElementEditingBodyType() |
563 if not isinstance(window, TextViewer): |
636 if language == "SFC": |
564 window.SetMode(MODE_SELECTION) |
637 self.SFCToolBar.ToggleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS0, True) |
565 self.ToolBar.ToggleTool(wxID_PLCOPENEDITORTOOLBARITEMS0, True) |
638 elif language == "FBD": |
566 |
639 self.FBDToolBar.ToggleTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS0, True) |
567 def ResetToolToggle(self, id): |
640 elif language == "LD": |
568 tool = self.ToolBar.FindById(id) |
641 self.LDToolBar.ToggleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS0, True) |
569 tool.SetToggle(False) |
642 else: |
|
643 self.DefaultToolBar.ToggleTool(wxID_PLCOPENEDITORDEFAULTTOOLBARITEMS0, True) |
|
644 |
570 |
645 def OnSelectionTool(self, event): |
571 def OnSelectionTool(self, event): |
646 selected = self.TabsOpened.GetSelection() |
572 selected = self.TabsOpened.GetSelection() |
647 if selected != -1: |
573 if selected != -1: |
648 self.TabsOpened.GetPage(selected).SetMode(MODE_SELECTION) |
574 self.TabsOpened.GetPage(selected).SetMode(MODE_SELECTION) |
649 event.Skip() |
575 event.Skip() |
650 |
576 |
651 def OnCommentTool(self, event): |
577 def OnSFCCommentTool(self, event): |
|
578 self.ResetToolToggle(wxID_PLCOPENEDITORSFCTOOLBARITEMS1) |
652 selected = self.TabsOpened.GetSelection() |
579 selected = self.TabsOpened.GetSelection() |
653 if selected != -1: |
580 if selected != -1: |
654 self.TabsOpened.GetPage(selected).SetMode(MODE_COMMENT) |
581 self.TabsOpened.GetPage(selected).SetMode(MODE_COMMENT) |
655 event.Skip() |
582 event.Skip() |
656 |
|
657 def OnWireTool(self, event): |
|
658 selected = self.TabsOpened.GetSelection() |
|
659 if selected != -1: |
|
660 self.TabsOpened.GetPage(selected).SetMode(MODE_WIRE) |
|
661 event.Skip() |
|
662 |
583 |
663 def OnSFCInitialStepTool(self, event): |
584 def OnSFCInitialStepTool(self, event): |
|
585 self.ResetToolToggle(wxID_PLCOPENEDITORSFCTOOLBARITEMS2) |
664 selected = self.TabsOpened.GetSelection() |
586 selected = self.TabsOpened.GetSelection() |
665 if selected != -1: |
587 if selected != -1: |
666 self.TabsOpened.GetPage(selected).SetMode(MODE_INITIAL_STEP) |
588 self.TabsOpened.GetPage(selected).SetMode(MODE_INITIAL_STEP) |
667 event.Skip() |
589 event.Skip() |
668 |
590 |
748 self.RefreshEditMenu() |
687 self.RefreshEditMenu() |
749 self.RefreshToolBar() |
688 self.RefreshToolBar() |
750 event.Skip() |
689 event.Skip() |
751 |
690 |
752 def OnProjectTreeItemEndEdit(self, event): |
691 def OnProjectTreeItemEndEdit(self, event): |
|
692 message = None |
|
693 abort = False |
753 new_name = event.GetLabel() |
694 new_name = event.GetLabel() |
754 if new_name != "": |
695 if new_name != "": |
755 if TestIdentifier(new_name): |
696 if not TestIdentifier(new_name): |
|
697 message = "\"%s\" is not a valid identifier!"%new_name |
|
698 elif new_name.upper() in IEC_KEYWORDS: |
|
699 message = "\"%s\" is a keyword. It can't be used!"%new_name |
|
700 else: |
756 item = event.GetItem() |
701 item = event.GetItem() |
757 itemtype = self.ProjectTree.GetPyData(item) |
702 itemtype = self.ProjectTree.GetPyData(item) |
758 if itemtype == ITEM_PROJECT: |
703 if itemtype == ITEM_PROJECT: |
759 self.Controler.SetProjectName(new_name) |
704 self.Controler.SetProjectName(new_name) |
760 elif itemtype == ITEM_POU: |
705 elif itemtype == ITEM_POU: |
761 old_name = self.ProjectTree.GetItemText(item) |
706 if new_name.upper() in self.Controler.GetProjectPouNames(): |
762 self.Controler.ChangePouName(old_name, new_name) |
707 message = "\"%s\" pou already exists!"%new_name |
763 self.RefreshTabsOpenedTitles() |
708 abort = True |
|
709 elif new_name.upper() in self.Controler.GetProjectPouVariables(): |
|
710 messageDialog = wxMessageDialog(self, "A variable is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wxYES_NO|wxICON_QUESTION) |
|
711 if messageDialog.ShowModal() == wxID_NO: |
|
712 abort = True |
|
713 messageDialog.Destroy() |
|
714 if not abort: |
|
715 old_name = self.ProjectTree.GetItemText(item) |
|
716 self.Controler.ChangePouName(old_name, new_name) |
|
717 self.RefreshTabsOpenedTitles() |
764 elif itemtype == ITEM_TRANSITION: |
718 elif itemtype == ITEM_TRANSITION: |
765 old_name = self.ProjectTree.GetItemText(item) |
719 category = self.ProjectTree.GetItemParent(item) |
766 parent = self.ProjectTree.GetItemParent(item) |
720 pou = self.ProjectTree.GetItemParent(category) |
767 grandparent = self.ProjectTree.GetItemParent(parent) |
721 pou_name = self.ProjectTree.GetItemText(pou) |
768 grandparent_name = self.ProjectTree.GetItemText(grandparent) |
722 if new_name.upper() in self.Controler.GetProjectPouNames(): |
769 self.Controler.ChangePouTransitionName(grandparent_name, old_name, new_name) |
723 message = "A pou with \"%s\" as name exists!"%new_name |
770 self.RefreshTabsOpenedTitles() |
724 elif new_name.upper() in self.Controler.GetProjectPouVariables(pou_name): |
|
725 message = "A variable with \"%s\" as name already exists in this pou!"%new_name |
|
726 else: |
|
727 old_name = self.ProjectTree.GetItemText(item) |
|
728 self.Controler.ChangePouTransitionName(pou_name, old_name, new_name) |
|
729 self.RefreshTabsOpenedTitles() |
771 elif itemtype == ITEM_ACTION: |
730 elif itemtype == ITEM_ACTION: |
772 old_name = self.ProjectTree.GetItemText(item) |
731 category = self.ProjectTree.GetItemParent(item) |
773 parent = self.ProjectTree.GetItemParent(item) |
732 pou = self.ProjectTree.GetItemParent(category) |
774 grandparent = self.ProjectTree.GetItemParent(parent) |
733 pou_name = self.ProjectTree.GetItemText(pou) |
775 grandparent_name = self.ProjectTree.GetItemText(grandparent) |
734 if new_name.upper() in self.Controler.GetProjectPouNames(): |
776 self.Controler.ChangePouActionName(grandparent_name, old_name, new_name) |
735 message = "A pou with \"%s\" as name exists!"%new_name |
777 self.RefreshTabsOpenedTitles() |
736 elif new_name.upper() in self.Controler.GetProjectPouVariables(pou_name): |
778 wxCallAfter(self.RefreshProjectTree) |
737 message = "A variable with \"%s\" as name already exists in this pou!"%new_name |
779 event.Skip() |
738 else: |
780 else: |
739 old_name = self.ProjectTree.GetItemText(item) |
781 message = wxMessageDialog(self, "\"%s\" is not a valid identifier!"%new_name, "Error", wxOK|wxICON_ERROR) |
740 self.Controler.ChangePouActionName(pou_name, old_name, new_name) |
782 message.ShowModal() |
741 self.RefreshTabsOpenedTitles() |
783 message.Destroy() |
742 elif itemtype == ITEM_VARIABLE: |
|
743 category = self.ProjectTree.GetItemParent(item) |
|
744 if self.ProjectTree.GetItemText(category) != 'Global': |
|
745 category = self.ProjectTree.GetItemParent(category) |
|
746 pou = self.ProjectTree.GetItemParent(category) |
|
747 pou_name = self.ProjectTree.GetItemText(pou) |
|
748 if new_name.upper() in self.Controler.GetProjectPouNames(): |
|
749 message = "A pou with \"%s\" as name exists!"%new_name |
|
750 elif new_name.upper() in self.Controler.GetProjectPouVariables(pou_name): |
|
751 message = "A variable with \"%s\" as name already exists in this pou!"%new_name |
|
752 else: |
|
753 old_name = self.ProjectTree.GetItemText(item) |
|
754 self.Controler.ChangePouVariableName(pou_name, old_name, new_name) |
|
755 self.RefreshTabsOpenedTitles() |
|
756 if message or abort: |
|
757 if message: |
|
758 messageDialog = wxMessageDialog(self, message, "Error", wxOK|wxICON_ERROR) |
|
759 messageDialog.ShowModal() |
|
760 messageDialog.Destroy() |
784 item = event.GetItem() |
761 item = event.GetItem() |
785 wxCallAfter(self.ProjectTree.EditLabel, item) |
762 wxCallAfter(self.ProjectTree.EditLabel, item) |
786 event.Veto() |
763 event.Veto() |
|
764 else: |
|
765 wxCallAfter(self.RefreshProjectTree) |
|
766 event.Skip() |
787 |
767 |
788 def OnProjectTreeItemBeginEdit(self, event): |
768 def OnProjectTreeItemBeginEdit(self, event): |
789 selected = event.GetItem() |
769 selected = event.GetItem() |
790 if self.ProjectTree.GetPyData(selected) == ITEM_UNEDITABLE: |
770 if self.ProjectTree.GetPyData(selected) == ITEM_UNEDITABLE: |
791 event.Veto() |
771 event.Veto() |
1021 to_delete.append(item) |
1005 to_delete.append(item) |
1022 item, root_cookie = self.ProjectTree.GetNextChild(item, root_cookie) |
1006 item, root_cookie = self.ProjectTree.GetNextChild(item, root_cookie) |
1023 for item in to_delete: |
1007 for item in to_delete: |
1024 self.ProjectTree.Delete(item) |
1008 self.ProjectTree.Delete(item) |
1025 |
1009 |
|
1010 def ResetToolBar(self): |
|
1011 for item in self.CurrentToolBar: |
|
1012 self.ToolBar.DeleteTool(item) |
|
1013 |
1026 def RefreshToolBar(self): |
1014 def RefreshToolBar(self): |
1027 language = self.Controler.GetCurrentElementEditingBodyType() |
1015 language = self.Controler.GetCurrentElementEditingBodyType() |
1028 if language == "SFC": |
1016 if language == "SFC": |
1029 self.SFCToolBar.Show() |
1017 if self.CurrentToolBar != SFC_ITEMS: |
1030 self.SetToolBar(self.SFCToolBar) |
1018 self.ResetToolBar() |
1031 self.DefaultToolBar.Hide() |
1019 self.CurrentToolBar = SFC_ITEMS |
1032 self.FBDToolBar.Hide() |
1020 self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS1, |
1033 self.LDToolBar.Hide() |
1021 wxBitmap(os.path.join(CWD, 'Images/comment.png')), wxNullBitmap, "Create a new comment") |
|
1022 self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS2, |
|
1023 wxBitmap(os.path.join(CWD, 'Images/initial_step.png')), wxNullBitmap, "Create a new initial step") |
|
1024 self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS3, |
|
1025 wxBitmap(os.path.join(CWD, 'Images/step.png')), "Create a new step") |
|
1026 self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS4, |
|
1027 wxBitmap(os.path.join(CWD, 'Images/action.png')), "Add action block to step") |
|
1028 self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS5, |
|
1029 wxBitmap(os.path.join(CWD, 'Images/divergence.png')), "Create a new divergence") |
|
1030 self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS6, |
|
1031 wxBitmap(os.path.join(CWD, 'Images/jump.png')), "Create a new jump") |
|
1032 self.Bind(wx.EVT_TOOL, self.OnSFCCommentTool, |
|
1033 id=wxID_PLCOPENEDITORSFCTOOLBARITEMS1) |
|
1034 self.Bind(wx.EVT_TOOL, self.OnSFCInitialStepTool, |
|
1035 id=wxID_PLCOPENEDITORSFCTOOLBARITEMS2) |
|
1036 self.Bind(wx.EVT_TOOL, self.OnSFCStepTool, |
|
1037 id=wxID_PLCOPENEDITORSFCTOOLBARITEMS3) |
|
1038 self.Bind(wx.EVT_TOOL, self.OnSFCActionBlockTool, |
|
1039 id=wxID_PLCOPENEDITORSFCTOOLBARITEMS4) |
|
1040 self.Bind(wx.EVT_TOOL, self.OnSFCDivergenceTool, |
|
1041 id=wxID_PLCOPENEDITORSFCTOOLBARITEMS5) |
|
1042 self.Bind(wx.EVT_TOOL, self.OnSFCJumpTool, |
|
1043 id=wxID_PLCOPENEDITORSFCTOOLBARITEMS6) |
1034 elif language == "FBD": |
1044 elif language == "FBD": |
1035 self.FBDToolBar.Show() |
1045 if self.CurrentToolBar != FBD_ITEMS: |
1036 self.SetToolBar(self.FBDToolBar) |
1046 self.ResetToolBar() |
1037 self.DefaultToolBar.Hide() |
1047 self.CurrentToolBar = FBD_ITEMS |
1038 self.SFCToolBar.Hide() |
1048 self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS1, |
1039 self.LDToolBar.Hide() |
1049 wxBitmap(os.path.join(CWD, 'Images/comment.png')), wxNullBitmap, "Create a new comment") |
|
1050 self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS2, |
|
1051 wxBitmap(os.path.join(CWD, 'Images/variable.png')), wxNullBitmap, "Create a new variable") |
|
1052 self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS3, |
|
1053 wxBitmap(os.path.join(CWD, 'Images/block.png')), wxNullBitmap, "Create a new block") |
|
1054 self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS4, |
|
1055 wxBitmap(os.path.join(CWD, 'Images/connection.png')), wxNullBitmap, "Create a new connection") |
|
1056 self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS5, |
|
1057 wxBitmap(os.path.join(CWD, 'Images/wire.png')), wxNullBitmap, "Create a new wire") |
|
1058 self.Bind(wx.EVT_TOOL, self.OnFBDCommentTool, |
|
1059 id=wxID_PLCOPENEDITORFBDTOOLBARITEMS1) |
|
1060 self.Bind(wx.EVT_TOOL, self.OnFBDVariableTool, |
|
1061 id=wxID_PLCOPENEDITORFBDTOOLBARITEMS2) |
|
1062 self.Bind(wx.EVT_TOOL, self.OnFBDBlockTool, |
|
1063 id=wxID_PLCOPENEDITORFBDTOOLBARITEMS3) |
|
1064 self.Bind(wx.EVT_TOOL, self.OnFBDConnectionTool, |
|
1065 id=wxID_PLCOPENEDITORFBDTOOLBARITEMS4) |
|
1066 self.Bind(wx.EVT_TOOL, self.OnFBDWireTool, |
|
1067 id=wxID_PLCOPENEDITORFBDTOOLBARITEMS5) |
1040 elif language == "LD": |
1068 elif language == "LD": |
1041 self.LDToolBar.Show() |
1069 if self.CurrentToolBar != LD_ITEMS: |
1042 self.SetToolBar(self.LDToolBar) |
1070 self.ResetToolBar() |
1043 self.DefaultToolBar.Hide() |
1071 self.CurrentToolBar = LD_ITEMS |
1044 self.SFCToolBar.Hide() |
1072 self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS1, |
1045 self.FBDToolBar.Hide() |
1073 wxBitmap(os.path.join(CWD, 'Images/coil.png')), "Create a new rung") |
|
1074 self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS2, |
|
1075 wxBitmap(os.path.join(CWD, 'Images/contact.png')), "Create a new contact") |
|
1076 self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS3, |
|
1077 wxBitmap(os.path.join(CWD, 'Images/block.png')), "Create a new block") |
|
1078 self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS4, |
|
1079 wxBitmap(os.path.join(CWD, 'Images/branch.png')), "Create a new branch") |
|
1080 self.Bind(wx.EVT_TOOL, self.OnLDCoilTool, |
|
1081 id=wxID_PLCOPENEDITORLDTOOLBARITEMS1) |
|
1082 self.Bind(wx.EVT_TOOL, self.OnLDContactTool, |
|
1083 id=wxID_PLCOPENEDITORLDTOOLBARITEMS2) |
|
1084 self.Bind(wx.EVT_TOOL, self.OnLDBlockTool, |
|
1085 id=wxID_PLCOPENEDITORLDTOOLBARITEMS3) |
|
1086 self.Bind(wx.EVT_TOOL, self.OnLDBranchTool, |
|
1087 id=wxID_PLCOPENEDITORLDTOOLBARITEMS4) |
1046 else: |
1088 else: |
1047 self.DefaultToolBar.Show() |
1089 if len(self.CurrentToolBar) > 0: |
1048 self.SetToolBar(self.DefaultToolBar) |
1090 self.ResetToolBar() |
1049 self.SFCToolBar.Hide() |
1091 self.CurrentToolBar = [] |
1050 self.FBDToolBar.Hide() |
|
1051 self.LDToolBar.Hide() |
|
1052 self.ResetCurrentMode() |
1092 self.ResetCurrentMode() |
1053 |
1093 |
1054 def RefreshTabsOpenedTitles(self): |
1094 def RefreshTabsOpenedTitles(self): |
1055 pous = self.Controler.GetElementsOpenedNames() |
1095 pous = self.Controler.GetElementsOpenedNames() |
1056 for i, pou in enumerate(pous): |
1096 for i, pou in enumerate(pous): |