graphics/GraphicCommons.py
changeset 4007 76dede1e3403
parent 3975 2ef76b61bf1e
equal deleted inserted replaced
4006:e16c8443e877 4007:76dede1e3403
   347     def SetBestSize(self, scaling, x_factor=0.5, y_factor=0.5):
   347     def SetBestSize(self, scaling, x_factor=0.5, y_factor=0.5):
   348         width, height = self.GetSize()
   348         width, height = self.GetSize()
   349         posx, posy = self.GetPosition()
   349         posx, posy = self.GetPosition()
   350         min_width, min_height = self.GetMinSize()
   350         min_width, min_height = self.GetMinSize()
   351         if width < min_width:
   351         if width < min_width:
   352             self.Pos.x = max(0, self.Pos.x - (width - min_width) * x_factor)
   352             self.Pos.x = max(0, round(self.Pos.x - (width - min_width) * x_factor))
   353             width = min_width
   353             width = min_width
   354         if height < min_height:
   354         if height < min_height:
   355             self.Pos.y = max(0, self.Pos.y - (height - min_height) * y_factor)
   355             self.Pos.y = max(0, round(self.Pos.y - (height - min_height) * y_factor))
   356             height = min_height
   356             height = min_height
   357         if scaling is not None:
   357         if scaling is not None:
   358             self.Pos.x = round_scaling(self.Pos.x, scaling[0])
   358             self.Pos.x = round_scaling(self.Pos.x, scaling[0])
   359             self.Pos.y = round_scaling(self.Pos.y, scaling[1])
   359             self.Pos.y = round_scaling(self.Pos.y, scaling[1])
   360             width = round_scaling(width, scaling[0], 1)
   360             width = round_scaling(width, scaling[0], 1)
  1024     """
  1024     """
  1025     Class that implements a connector for any type of block
  1025     Class that implements a connector for any type of block
  1026     """
  1026     """
  1027 
  1027 
  1028     # Create a new connector
  1028     # Create a new connector
  1029     def __init__(self, parent, name, type, position, direction, negated=False, edge="none", onlyone=False):
  1029     def __init__(self, parent, name, Type, position, direction, negated=False, edge="none", onlyone=False):
  1030         DebugDataConsumer.__init__(self)
  1030         DebugDataConsumer.__init__(self)
  1031         ToolTipProducer.__init__(self, parent.Parent)
  1031         ToolTipProducer.__init__(self, parent.Parent)
  1032         self.ParentBlock = parent
  1032         self.ParentBlock = parent
  1033         self.Name = name
  1033         self.Name = name
  1034         self.Type = type
  1034         self.Type = Type
  1035         self.Pos = position
  1035         self.Pos = position
  1036         self.Direction = direction
  1036         self.Direction = direction
  1037         self.Wires = []
  1037         self.Wires = []
  1038         if self.ParentBlock.IsOfType("BOOL", type):
  1038         if self.ParentBlock.IsOfType("BOOL", Type):
  1039             self.Negated = negated
  1039             self.Negated = negated
  1040             self.Edge = edge
  1040             self.Edge = edge
  1041         else:
  1041         else:
  1042             self.Negated = False
  1042             self.Negated = False
  1043             self.Edge = "none"
  1043             self.Edge = "none"
  1139     def IsCompatible(self, type):
  1139     def IsCompatible(self, type):
  1140         reference = self.GetType()
  1140         reference = self.GetType()
  1141         return self.ParentBlock.IsOfType(type, reference) or self.ParentBlock.IsOfType(reference, type)
  1141         return self.ParentBlock.IsOfType(type, reference) or self.ParentBlock.IsOfType(reference, type)
  1142 
  1142 
  1143     # Changes the connector name
  1143     # Changes the connector name
  1144     def SetType(self, type):
  1144     def SetType(self, Type):
  1145         self.Type = type
  1145         self.Type = Type
  1146         for wire, _handle in self.Wires:
  1146         for wire, _handle in self.Wires:
  1147             wire.SetValid(wire.IsConnectedCompatible())
  1147             wire.SetValid(wire.IsConnectedCompatible())
  1148 
  1148 
  1149     # Returns the connector name
  1149     # Returns the connector name
  1150     def GetName(self):
  1150     def GetName(self):