1512 |
1512 |
1513 """ |
1513 """ |
1514 Class that implements a connector for any type of block |
1514 Class that implements a connector for any type of block |
1515 """ |
1515 """ |
1516 |
1516 |
1517 class Connector: |
1517 class Connector(DebugDataConsumer): |
1518 |
1518 |
1519 # Create a new connector |
1519 # Create a new connector |
1520 def __init__(self, parent, name, type, position, direction, negated = False, edge = "none", onlyone = False): |
1520 def __init__(self, parent, name, type, position, direction, negated = False, edge = "none", onlyone = False): |
|
1521 DebugDataConsumer.__init__(self) |
1521 self.ParentBlock = parent |
1522 self.ParentBlock = parent |
1522 self.Name = name |
1523 self.Name = name |
1523 self.Type = type |
1524 self.Type = type |
1524 self.Pos = position |
1525 self.Pos = position |
1525 self.Direction = direction |
1526 self.Direction = direction |
1555 width = CONNECTOR_SIZE |
1558 width = CONNECTOR_SIZE |
1556 if self.Direction[1] == 0: |
1559 if self.Direction[1] == 0: |
1557 height = 5 |
1560 height = 5 |
1558 else: |
1561 else: |
1559 height = CONNECTOR_SIZE |
1562 height = CONNECTOR_SIZE |
1560 return wx.Rect(x - abs(movex), y - abs(movey), width + 2 * abs(movex), height + 2 * abs(movey)) |
1563 rect = wx.Rect(x - abs(movex), y - abs(movey), width + 2 * abs(movex), height + 2 * abs(movey)) |
|
1564 if self.ValueSize is None and isinstance(self.ComputedValue, (StringType, UnicodeType)): |
|
1565 self.ValueSize = self.ParentBlock.Parent.GetMiniTextExtent(self.ComputedValue) |
|
1566 if self.ValueSize is not None: |
|
1567 width, height = self.ValueSize |
|
1568 rect = rect.Union(wx.Rect( |
|
1569 parent_pos[0] + self.Pos.x + CONNECTOR_SIZE * self.Direction[0] + \ |
|
1570 width * (self.Direction[0] - 1) / 2, |
|
1571 parent_pos[1] + self.Pos.y + CONNECTOR_SIZE * self.Direction[1] + \ |
|
1572 height * (self.Direction[1] - 1), |
|
1573 width, height)) |
|
1574 return rect |
1561 |
1575 |
1562 # Change the connector selection |
1576 # Change the connector selection |
1563 def SetSelected(self, selected): |
1577 def SetSelected(self, selected): |
1564 self.Selected = selected |
1578 self.Selected = selected |
1565 |
1579 |
1619 # Changes the connector name |
1633 # Changes the connector name |
1620 def SetName(self, name): |
1634 def SetName(self, name): |
1621 self.Name = name |
1635 self.Name = name |
1622 self.RefreshNameSize() |
1636 self.RefreshNameSize() |
1623 |
1637 |
|
1638 def SetForced(self, forced): |
|
1639 if self.Forced != forced: |
|
1640 self.Forced = forced |
|
1641 if self.Visible: |
|
1642 self.Parent.ElementNeedRefresh(self) |
|
1643 |
|
1644 def SetValue(self, value): |
|
1645 if self.Value != value: |
|
1646 self.Value = value |
|
1647 if value is not None and not isinstance(value, BooleanType): |
|
1648 connector_type = self.GetType() |
|
1649 if connector_type == "STRING": |
|
1650 self.ComputedValue = "'%s'"%value |
|
1651 elif connector_type == "WSTRING": |
|
1652 self.ComputedValue = "\"%s\""%value |
|
1653 else: |
|
1654 self.ComputedValue = str(value) |
|
1655 #if self.ToolTip is not None: |
|
1656 # self.ToolTip.SetTip(self.ComputedValue) |
|
1657 if len(self.ComputedValue) > 4: |
|
1658 self.ComputedValue = self.ComputedValue[:4] + "..." |
|
1659 self.ValueSize = None |
|
1660 if self.ParentBlock.Visible: |
|
1661 self.ParentBlock.Parent.ElementNeedRefresh(self) |
|
1662 |
1624 def RefreshForced(self): |
1663 def RefreshForced(self): |
1625 self.Forced = False |
1664 self.Forced = False |
1626 for wire, handle in self.Wires: |
1665 for wire, handle in self.Wires: |
1627 self.Forced |= wire.IsForced() |
1666 self.Forced |= wire.IsForced() |
1628 |
1667 |
1957 ytext = parent_pos[1] + self.Pos.y - (name_size[1] + 5) |
1996 ytext = parent_pos[1] + self.Pos.y - (name_size[1] + 5) |
1958 # Draw the text |
1997 # Draw the text |
1959 dc.DrawText(self.Name, xtext, ytext) |
1998 dc.DrawText(self.Name, xtext, ytext) |
1960 if not getattr(dc, "printing", False): |
1999 if not getattr(dc, "printing", False): |
1961 DrawHighlightedText(dc, self.Name, self.Highlights, xtext, ytext) |
2000 DrawHighlightedText(dc, self.Name, self.Highlights, xtext, ytext) |
|
2001 |
|
2002 if self.Value is not None and not isinstance(self.Value, BooleanType) and self.Value != "undefined": |
|
2003 dc.SetFont(self.ParentBlock.Parent.GetMiniFont()) |
|
2004 dc.SetTextForeground(wx.NamedColour("purple")) |
|
2005 if self.ValueSize is None and isinstance(self.ComputedValue, (StringType, UnicodeType)): |
|
2006 self.ValueSize = self.ParentBlock.Parent.GetMiniTextExtent(self.ComputedValue) |
|
2007 if self.ValueSize is not None: |
|
2008 width, height = self.ValueSize |
|
2009 dc.DrawText(self.ComputedValue, |
|
2010 parent_pos[0] + self.Pos.x + CONNECTOR_SIZE * self.Direction[0] + \ |
|
2011 width * (self.Direction[0] - 1) / 2, |
|
2012 parent_pos[1] + self.Pos.y + CONNECTOR_SIZE * self.Direction[1] + \ |
|
2013 height * (self.Direction[1] - 1)) |
|
2014 dc.SetFont(self.ParentBlock.Parent.GetFont()) |
|
2015 dc.SetTextForeground(wx.BLACK) |
1962 |
2016 |
1963 #------------------------------------------------------------------------------- |
2017 #------------------------------------------------------------------------------- |
1964 # Common Wire Element |
2018 # Common Wire Element |
1965 #------------------------------------------------------------------------------- |
2019 #------------------------------------------------------------------------------- |
1966 |
2020 |