485 return _("Debug: %s") % self.Parent.InstancePath |
485 return _("Debug: %s") % self.Parent.InstancePath |
486 |
486 |
487 def GetRedrawRect(self): |
487 def GetRedrawRect(self): |
488 x, y = self.Parent.CalcUnscrolledPosition(self.x_offset, self.y_offset) |
488 x, y = self.Parent.CalcUnscrolledPosition(self.x_offset, self.y_offset) |
489 dc = self.Parent.GetLogicalDC() |
489 dc = self.Parent.GetLogicalDC() |
490 ipw, iph = dc.GetTextExtent(self.GetInstanceName()) |
490 ipw, _iph = dc.GetTextExtent(self.GetInstanceName()) |
491 vw, vh = 0, 0 |
491 vw, vh = 0, 0 |
492 for value in self.VALUE_TRANSLATION.itervalues(): |
492 for value in self.VALUE_TRANSLATION.itervalues(): |
493 w, h = dc.GetTextExtent(" (%s)" % value) |
493 w, h = dc.GetTextExtent(" (%s)" % value) |
494 vw = max(vw, w) |
494 vw = max(vw, w) |
495 vh = max(vh, h) |
495 vh = max(vh, h) |
503 text = self.GetInstanceName() |
503 text = self.GetInstanceName() |
504 if self.ActionState is not None: |
504 if self.ActionState is not None: |
505 text += " (" |
505 text += " (" |
506 |
506 |
507 dc.DrawText(text, x, y) |
507 dc.DrawText(text, x, y) |
508 tw, th = dc.GetTextExtent(text) |
508 tw, _th = dc.GetTextExtent(text) |
509 if self.ActionState is not None: |
509 if self.ActionState is not None: |
510 |
510 |
511 text = self.VALUE_TRANSLATION[self.ActionState] |
511 text = self.VALUE_TRANSLATION[self.ActionState] |
512 if self.ActionState: |
512 if self.ActionState: |
513 dc.SetTextForeground(wx.GREEN) |
513 dc.SetTextForeground(wx.GREEN) |
546 self.Bind(wx.EVT_MENU, callback, id=id) |
546 self.Bind(wx.EVT_MENU, callback, id=id) |
547 |
547 |
548 # Add Block Pin Menu items to the given menu |
548 # Add Block Pin Menu items to the given menu |
549 def AddBlockPinMenuItems(self, menu, connector): |
549 def AddBlockPinMenuItems(self, menu, connector): |
550 [ID_NO_MODIFIER, ID_NEGATED, ID_RISING_EDGE, |
550 [ID_NO_MODIFIER, ID_NEGATED, ID_RISING_EDGE, |
551 ID_FALLING_EDGE] = [wx.NewId() for i in xrange(4)] |
551 ID_FALLING_EDGE] = [wx.NewId() for dummy in xrange(4)] |
552 |
552 |
553 # Create menu items |
553 # Create menu items |
554 self.AddMenuItems(menu, [ |
554 self.AddMenuItems(menu, [ |
555 (ID_NO_MODIFIER, wx.ITEM_RADIO, _(u'No Modifier'), '', self.OnNoModifierMenu), |
555 (ID_NO_MODIFIER, wx.ITEM_RADIO, _(u'No Modifier'), '', self.OnNoModifierMenu), |
556 (ID_NEGATED, wx.ITEM_RADIO, _(u'Negated'), '', self.OnNegatedMenu), |
556 (ID_NEGATED, wx.ITEM_RADIO, _(u'Negated'), '', self.OnNegatedMenu), |
573 # Add Alignment Menu items to the given menu |
573 # Add Alignment Menu items to the given menu |
574 def AddAlignmentMenuItems(self, menu): |
574 def AddAlignmentMenuItems(self, menu): |
575 [ |
575 [ |
576 ID_ALIGN_LEFT, ID_ALIGN_CENTER, ID_ALIGN_RIGHT, |
576 ID_ALIGN_LEFT, ID_ALIGN_CENTER, ID_ALIGN_RIGHT, |
577 ID_ALIGN_TOP, ID_ALIGN_MIDDLE, ID_ALIGN_BOTTOM, |
577 ID_ALIGN_TOP, ID_ALIGN_MIDDLE, ID_ALIGN_BOTTOM, |
578 ] = [wx.NewId() for i in xrange(6)] |
578 ] = [wx.NewId() for dummy in xrange(6)] |
579 |
579 |
580 # Create menu items |
580 # Create menu items |
581 self.AddMenuItems(menu, [ |
581 self.AddMenuItems(menu, [ |
582 (ID_ALIGN_LEFT, wx.ITEM_NORMAL, _(u'Left'), '', self.OnAlignLeftMenu), |
582 (ID_ALIGN_LEFT, wx.ITEM_NORMAL, _(u'Left'), '', self.OnAlignLeftMenu), |
583 (ID_ALIGN_CENTER, wx.ITEM_NORMAL, _(u'Center'), '', self.OnAlignCenterMenu), |
583 (ID_ALIGN_CENTER, wx.ITEM_NORMAL, _(u'Center'), '', self.OnAlignCenterMenu), |
588 (ID_ALIGN_BOTTOM, wx.ITEM_NORMAL, _(u'Bottom'), '', self.OnAlignBottomMenu)]) |
588 (ID_ALIGN_BOTTOM, wx.ITEM_NORMAL, _(u'Bottom'), '', self.OnAlignBottomMenu)]) |
589 |
589 |
590 # Add Wire Menu items to the given menu |
590 # Add Wire Menu items to the given menu |
591 def AddWireMenuItems(self, menu, delete=False, replace=False): |
591 def AddWireMenuItems(self, menu, delete=False, replace=False): |
592 [ID_ADD_SEGMENT, ID_DELETE_SEGMENT, ID_REPLACE_WIRE, |
592 [ID_ADD_SEGMENT, ID_DELETE_SEGMENT, ID_REPLACE_WIRE, |
593 ] = [wx.NewId() for i in xrange(3)] |
593 ] = [wx.NewId() for dummy in xrange(3)] |
594 |
594 |
595 # Create menu items |
595 # Create menu items |
596 self.AddMenuItems(menu, [ |
596 self.AddMenuItems(menu, [ |
597 (ID_ADD_SEGMENT, wx.ITEM_NORMAL, _(u'Add Wire Segment'), '', self.OnAddSegmentMenu), |
597 (ID_ADD_SEGMENT, wx.ITEM_NORMAL, _(u'Add Wire Segment'), '', self.OnAddSegmentMenu), |
598 (ID_DELETE_SEGMENT, wx.ITEM_NORMAL, _(u'Delete Wire Segment'), '', self.OnDeleteSegmentMenu), |
598 (ID_DELETE_SEGMENT, wx.ITEM_NORMAL, _(u'Delete Wire Segment'), '', self.OnDeleteSegmentMenu), |
601 menu.Enable(ID_DELETE_SEGMENT, delete) |
601 menu.Enable(ID_DELETE_SEGMENT, delete) |
602 menu.Enable(ID_REPLACE_WIRE, replace) |
602 menu.Enable(ID_REPLACE_WIRE, replace) |
603 |
603 |
604 # Add Divergence Menu items to the given menu |
604 # Add Divergence Menu items to the given menu |
605 def AddDivergenceMenuItems(self, menu, delete=False): |
605 def AddDivergenceMenuItems(self, menu, delete=False): |
606 [ID_ADD_BRANCH, ID_DELETE_BRANCH] = [wx.NewId() for i in xrange(2)] |
606 [ID_ADD_BRANCH, ID_DELETE_BRANCH] = [wx.NewId() for dummy in xrange(2)] |
607 |
607 |
608 # Create menu items |
608 # Create menu items |
609 self.AddMenuItems(menu, [ |
609 self.AddMenuItems(menu, [ |
610 (ID_ADD_BRANCH, wx.ITEM_NORMAL, _(u'Add Divergence Branch'), '', self.OnAddBranchMenu), |
610 (ID_ADD_BRANCH, wx.ITEM_NORMAL, _(u'Add Divergence Branch'), '', self.OnAddBranchMenu), |
611 (ID_DELETE_BRANCH, wx.ITEM_NORMAL, _(u'Delete Divergence Branch'), '', self.OnDeleteBranchMenu)]) |
611 (ID_DELETE_BRANCH, wx.ITEM_NORMAL, _(u'Delete Divergence Branch'), '', self.OnDeleteBranchMenu)]) |
613 menu.Enable(ID_DELETE_BRANCH, delete) |
613 menu.Enable(ID_DELETE_BRANCH, delete) |
614 |
614 |
615 # Add Add Menu items to the given menu |
615 # Add Add Menu items to the given menu |
616 def AddAddMenuItems(self, menu): |
616 def AddAddMenuItems(self, menu): |
617 [ID_ADD_BLOCK, ID_ADD_VARIABLE, ID_ADD_CONNECTION, |
617 [ID_ADD_BLOCK, ID_ADD_VARIABLE, ID_ADD_CONNECTION, |
618 ID_ADD_COMMENT] = [wx.NewId() for i in xrange(4)] |
618 ID_ADD_COMMENT] = [wx.NewId() for dummy in xrange(4)] |
619 |
619 |
620 # Create menu items |
620 # Create menu items |
621 self.AddMenuItems(menu, [ |
621 self.AddMenuItems(menu, [ |
622 (ID_ADD_BLOCK, wx.ITEM_NORMAL, _(u'Block'), '', self.GetAddMenuCallBack(self.AddNewBlock)), |
622 (ID_ADD_BLOCK, wx.ITEM_NORMAL, _(u'Block'), '', self.GetAddMenuCallBack(self.AddNewBlock)), |
623 (ID_ADD_VARIABLE, wx.ITEM_NORMAL, _(u'Variable'), '', self.GetAddMenuCallBack(self.AddNewVariable)), |
623 (ID_ADD_VARIABLE, wx.ITEM_NORMAL, _(u'Variable'), '', self.GetAddMenuCallBack(self.AddNewVariable)), |
625 None]) |
625 None]) |
626 |
626 |
627 if self.CurrentLanguage != "FBD": |
627 if self.CurrentLanguage != "FBD": |
628 [ |
628 [ |
629 ID_ADD_POWER_RAIL, ID_ADD_CONTACT, ID_ADD_COIL, |
629 ID_ADD_POWER_RAIL, ID_ADD_CONTACT, ID_ADD_COIL, |
630 ] = [wx.NewId() for i in xrange(3)] |
630 ] = [wx.NewId() for dummy in xrange(3)] |
631 |
631 |
632 # Create menu items |
632 # Create menu items |
633 self.AddMenuItems(menu, [ |
633 self.AddMenuItems(menu, [ |
634 (ID_ADD_POWER_RAIL, wx.ITEM_NORMAL, _(u'Power Rail'), '', self.GetAddMenuCallBack(self.AddNewPowerRail)), |
634 (ID_ADD_POWER_RAIL, wx.ITEM_NORMAL, _(u'Power Rail'), '', self.GetAddMenuCallBack(self.AddNewPowerRail)), |
635 (ID_ADD_CONTACT, wx.ITEM_NORMAL, _(u'Contact'), '', self.GetAddMenuCallBack(self.AddNewContact))]) |
635 (ID_ADD_CONTACT, wx.ITEM_NORMAL, _(u'Contact'), '', self.GetAddMenuCallBack(self.AddNewContact))]) |
642 |
642 |
643 if self.CurrentLanguage == "SFC": |
643 if self.CurrentLanguage == "SFC": |
644 [ |
644 [ |
645 ID_ADD_INITIAL_STEP, ID_ADD_STEP, ID_ADD_TRANSITION, |
645 ID_ADD_INITIAL_STEP, ID_ADD_STEP, ID_ADD_TRANSITION, |
646 ID_ADD_ACTION_BLOCK, ID_ADD_DIVERGENCE, ID_ADD_JUMP, |
646 ID_ADD_ACTION_BLOCK, ID_ADD_DIVERGENCE, ID_ADD_JUMP, |
647 ] = [wx.NewId() for i in xrange(6)] |
647 ] = [wx.NewId() for dummy in xrange(6)] |
648 |
648 |
649 # Create menu items |
649 # Create menu items |
650 self.AddMenuItems(menu, [ |
650 self.AddMenuItems(menu, [ |
651 (ID_ADD_INITIAL_STEP, wx.ITEM_NORMAL, _(u'Initial Step'), '', self.GetAddMenuCallBack(self.AddNewStep, True)), |
651 (ID_ADD_INITIAL_STEP, wx.ITEM_NORMAL, _(u'Initial Step'), '', self.GetAddMenuCallBack(self.AddNewStep, True)), |
652 (ID_ADD_STEP, wx.ITEM_NORMAL, _(u'Step'), '', self.GetAddMenuCallBack(self.AddNewStep)), |
652 (ID_ADD_STEP, wx.ITEM_NORMAL, _(u'Step'), '', self.GetAddMenuCallBack(self.AddNewStep)), |
660 (ID_ADD_COMMENT, wx.ITEM_NORMAL, _(u'Comment'), '', self.GetAddMenuCallBack(self.AddNewComment))]) |
660 (ID_ADD_COMMENT, wx.ITEM_NORMAL, _(u'Comment'), '', self.GetAddMenuCallBack(self.AddNewComment))]) |
661 |
661 |
662 # Add Default Menu items to the given menu |
662 # Add Default Menu items to the given menu |
663 def AddDefaultMenuItems(self, menu, edit=False, block=False): |
663 def AddDefaultMenuItems(self, menu, edit=False, block=False): |
664 if block: |
664 if block: |
665 [ID_EDIT_BLOCK, ID_DELETE, ID_ADJUST_BLOCK_SIZE] = [wx.NewId() for i in xrange(3)] |
665 [ID_EDIT_BLOCK, ID_DELETE, ID_ADJUST_BLOCK_SIZE] = [wx.NewId() for dummy in xrange(3)] |
666 |
666 |
667 # Create menu items |
667 # Create menu items |
668 self.AddMenuItems(menu, [ |
668 self.AddMenuItems(menu, [ |
669 (ID_EDIT_BLOCK, wx.ITEM_NORMAL, _(u'Edit Block'), '', self.OnEditBlockMenu), |
669 (ID_EDIT_BLOCK, wx.ITEM_NORMAL, _(u'Edit Block'), '', self.OnEditBlockMenu), |
670 (ID_ADJUST_BLOCK_SIZE, wx.ITEM_NORMAL, _(u'Adjust Block Size'), '', self.OnAdjustBlockSizeMenu), |
670 (ID_ADJUST_BLOCK_SIZE, wx.ITEM_NORMAL, _(u'Adjust Block Size'), '', self.OnAdjustBlockSizeMenu), |
671 (ID_DELETE, wx.ITEM_NORMAL, _(u'Delete'), '', self.OnDeleteMenu)]) |
671 (ID_DELETE, wx.ITEM_NORMAL, _(u'Delete'), '', self.OnDeleteMenu)]) |
672 |
672 |
673 menu.Enable(ID_EDIT_BLOCK, edit) |
673 menu.Enable(ID_EDIT_BLOCK, edit) |
674 |
674 |
675 else: |
675 else: |
676 [ID_CLEAR_EXEC_ORDER, ID_RESET_EXEC_ORDER] = [wx.NewId() for i in xrange(2)] |
676 [ID_CLEAR_EXEC_ORDER, ID_RESET_EXEC_ORDER] = [wx.NewId() for dummy in xrange(2)] |
677 |
677 |
678 # Create menu items |
678 # Create menu items |
679 if self.CurrentLanguage == 'FBD': |
679 if self.CurrentLanguage == 'FBD': |
680 self.AddMenuItems(menu, [ |
680 self.AddMenuItems(menu, [ |
681 (ID_CLEAR_EXEC_ORDER, wx.ITEM_NORMAL, _(u'Clear Execution Order'), '', self.OnClearExecutionOrderMenu), |
681 (ID_CLEAR_EXEC_ORDER, wx.ITEM_NORMAL, _(u'Clear Execution Order'), '', self.OnClearExecutionOrderMenu), |
686 self.AddAddMenuItems(add_menu) |
686 self.AddAddMenuItems(add_menu) |
687 menu.AppendMenu(-1, _(u'Add'), add_menu) |
687 menu.AppendMenu(-1, _(u'Add'), add_menu) |
688 |
688 |
689 menu.AppendSeparator() |
689 menu.AppendSeparator() |
690 |
690 |
691 [ID_CUT, ID_COPY, ID_PASTE] = [wx.NewId() for i in xrange(3)] |
691 [ID_CUT, ID_COPY, ID_PASTE] = [wx.NewId() for dummy in xrange(3)] |
692 |
692 |
693 # Create menu items |
693 # Create menu items |
694 self.AddMenuItems(menu, [ |
694 self.AddMenuItems(menu, [ |
695 (ID_CUT, wx.ITEM_NORMAL, _(u'Cut'), '', self.GetClipboardCallBack(self.Cut)), |
695 (ID_CUT, wx.ITEM_NORMAL, _(u'Cut'), '', self.GetClipboardCallBack(self.Cut)), |
696 (ID_COPY, wx.ITEM_NORMAL, _(u'Copy'), '', self.GetClipboardCallBack(self.Copy)), |
696 (ID_COPY, wx.ITEM_NORMAL, _(u'Copy'), '', self.GetClipboardCallBack(self.Copy)), |
762 self.ElementRefreshList_lock = Lock() |
762 self.ElementRefreshList_lock = Lock() |
763 |
763 |
764 dc = wx.ClientDC(self.Editor) |
764 dc = wx.ClientDC(self.Editor) |
765 font = wx.Font(faces["size"], wx.SWISS, wx.NORMAL, wx.NORMAL, faceName=faces["mono"]) |
765 font = wx.Font(faces["size"], wx.SWISS, wx.NORMAL, wx.NORMAL, faceName=faces["mono"]) |
766 dc.SetFont(font) |
766 dc.SetFont(font) |
767 width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ") |
767 width, _height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ") |
768 while width > 260: |
768 while width > 260: |
769 faces["size"] -= 1 |
769 faces["size"] -= 1 |
770 font = wx.Font(faces["size"], wx.SWISS, wx.NORMAL, wx.NORMAL, faceName=faces["mono"]) |
770 font = wx.Font(faces["size"], wx.SWISS, wx.NORMAL, wx.NORMAL, faceName=faces["mono"]) |
771 dc.SetFont(font) |
771 dc.SetFont(font) |
772 width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ") |
772 width, _height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ") |
773 self.SetFont(font) |
773 self.SetFont(font) |
774 self.MiniTextDC = wx.MemoryDC() |
774 self.MiniTextDC = wx.MemoryDC() |
775 self.MiniTextDC.SetFont(wx.Font(faces["size"] * 0.75, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName=faces["helv"])) |
775 self.MiniTextDC.SetFont(wx.Font(faces["size"] * 0.75, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName=faces["helv"])) |
776 |
776 |
777 self.CurrentScale = None |
777 self.CurrentScale = None |
1293 self.Editor.Refresh(False) |
1293 self.Editor.Refresh(False) |
1294 |
1294 |
1295 def GetPreviousSteps(self, connectors): |
1295 def GetPreviousSteps(self, connectors): |
1296 steps = [] |
1296 steps = [] |
1297 for connector in connectors: |
1297 for connector in connectors: |
1298 for wire, handle in connector.GetWires(): |
1298 for wire, _handle in connector.GetWires(): |
1299 previous = wire.GetOtherConnected(connector).GetParentBlock() |
1299 previous = wire.GetOtherConnected(connector).GetParentBlock() |
1300 if isinstance(previous, SFC_Step): |
1300 if isinstance(previous, SFC_Step): |
1301 steps.append(previous.GetName()) |
1301 steps.append(previous.GetName()) |
1302 elif isinstance(previous, SFC_Divergence) and previous.GetType() in [SIMULTANEOUS_CONVERGENCE, SELECTION_DIVERGENCE]: |
1302 elif isinstance(previous, SFC_Divergence) and previous.GetType() in [SIMULTANEOUS_CONVERGENCE, SELECTION_DIVERGENCE]: |
1303 connectors = previous.GetConnectors() |
1303 connectors = previous.GetConnectors() |
1305 return steps |
1305 return steps |
1306 |
1306 |
1307 def GetNextSteps(self, connectors): |
1307 def GetNextSteps(self, connectors): |
1308 steps = [] |
1308 steps = [] |
1309 for connector in connectors: |
1309 for connector in connectors: |
1310 for wire, handle in connector.GetWires(): |
1310 for wire, _handle in connector.GetWires(): |
1311 next = wire.GetOtherConnected(connector).GetParentBlock() |
1311 next = wire.GetOtherConnected(connector).GetParentBlock() |
1312 if isinstance(next, SFC_Step): |
1312 if isinstance(next, SFC_Step): |
1313 steps.append(next.GetName()) |
1313 steps.append(next.GetName()) |
1314 elif isinstance(next, SFC_Jump): |
1314 elif isinstance(next, SFC_Jump): |
1315 steps.append(next.GetTarget()) |
1315 steps.append(next.GetTarget()) |
1557 if element.HitTest(pos, connectors) or element.TestHandle(event) != (0, 0): |
1557 if element.HitTest(pos, connectors) or element.TestHandle(event) != (0, 0): |
1558 return element |
1558 return element |
1559 return None |
1559 return None |
1560 |
1560 |
1561 def FindBlockConnector(self, pos, direction=None, exclude=None): |
1561 def FindBlockConnector(self, pos, direction=None, exclude=None): |
1562 result, error = self.FindBlockConnectorWithError(pos, direction, exclude) |
1562 result, _error = self.FindBlockConnectorWithError(pos, direction, exclude) |
1563 return result |
1563 return result |
1564 |
1564 |
1565 def FindBlockConnectorWithError(self, pos, direction=None, exclude=None): |
1565 def FindBlockConnectorWithError(self, pos, direction=None, exclude=None): |
1566 error = False |
1566 error = False |
1567 startblock = None |
1567 startblock = None |
3563 self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT) |
3563 self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT) |
3564 |
3564 |
3565 self.SearchParams = search_params |
3565 self.SearchParams = search_params |
3566 self.SearchResults = [] |
3566 self.SearchResults = [] |
3567 blocks = [] |
3567 blocks = [] |
3568 for infos, start, end, text in self.Controler.SearchInPou(self.TagName, search_params, self.Debug): |
3568 for infos, start, end, _text in self.Controler.SearchInPou(self.TagName, search_params, self.Debug): |
3569 if (infos[0] == self.TagName or self.TagName.split("::")[0] in ['A', 'T']) and infos[1] is not 'name': |
3569 if (infos[0] == self.TagName or self.TagName.split("::")[0] in ['A', 'T']) and infos[1] is not 'name': |
3570 if infos[1] in ["var_local", "var_input", "var_output", "var_inout"]: |
3570 if infos[1] in ["var_local", "var_input", "var_output", "var_inout"]: |
3571 self.SearchResults.append((infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT)) |
3571 self.SearchResults.append((infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT)) |
3572 else: |
3572 else: |
3573 block = self.Blocks.get(infos[2]) |
3573 block = self.Blocks.get(infos[2]) |