equal
deleted
inserted
replaced
21 # You should have received a copy of the GNU General Public License |
21 # You should have received a copy of the GNU General Public License |
22 # along with this program; if not, write to the Free Software |
22 # along with this program; if not, write to the Free Software |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
24 |
25 |
25 |
26 from __future__ import absolute_import |
26 |
27 from __future__ import division |
27 |
28 import wx |
28 import wx |
29 from future.builtins import round |
29 from future.builtins import round |
30 from six.moves import xrange |
30 from six.moves import xrange |
31 |
31 |
32 from graphics.GraphicCommons import * |
32 from graphics.GraphicCommons import * |
71 for connector in self.Connectors: |
71 for connector in self.Connectors: |
72 powerrail.Connectors.append(connector.Clone(powerrail)) |
72 powerrail.Connectors.append(connector.Clone(powerrail)) |
73 return powerrail |
73 return powerrail |
74 |
74 |
75 def GetConnectorTranslation(self, element): |
75 def GetConnectorTranslation(self, element): |
76 return dict(zip([connector for connector in self.Connectors], |
76 return dict(list(zip([connector for connector in self.Connectors], |
77 [connector for connector in element.Connectors])) |
77 [connector for connector in element.Connectors]))) |
78 |
78 |
79 # Returns the RedrawRect |
79 # Returns the RedrawRect |
80 def GetRedrawRect(self, movex=0, movey=0): |
80 def GetRedrawRect(self, movex=0, movey=0): |
81 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
81 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
82 for connector in self.Connectors: |
82 for connector in self.Connectors: |
236 # Create a connector or a blank according to 'connectors' and add it in |
236 # Create a connector or a blank according to 'connectors' and add it in |
237 # the connectors list |
237 # the connectors list |
238 self.Type = type |
238 self.Type = type |
239 self.Clean() |
239 self.Clean() |
240 self.Connectors = [] |
240 self.Connectors = [] |
241 for dummy in xrange(connectors): |
241 for dummy in range(connectors): |
242 self.AddConnector() |
242 self.AddConnector() |
243 self.RefreshSize() |
243 self.RefreshSize() |
244 |
244 |
245 # Returns the power rail type |
245 # Returns the power rail type |
246 def GetType(self): |
246 def GetType(self): |
253 if height > 0: |
253 if height > 0: |
254 for connector in self.Connectors: |
254 for connector in self.Connectors: |
255 position = connector.GetRelPosition() |
255 position = connector.GetRelPosition() |
256 self.RealConnectors.append(max(0., min((position.y - self.Extensions[0]) / height, 1.))) |
256 self.RealConnectors.append(max(0., min((position.y - self.Extensions[0]) / height, 1.))) |
257 elif len(self.Connectors) > 1: |
257 elif len(self.Connectors) > 1: |
258 self.RealConnectors = map(lambda x: x * 1 / (len(self.Connectors) - 1), xrange(len(self.Connectors))) |
258 self.RealConnectors = [x * 1 / (len(self.Connectors) - 1) for x in range(len(self.Connectors))] |
259 else: |
259 else: |
260 self.RealConnectors = [0.5] |
260 self.RealConnectors = [0.5] |
261 Graphic_Element.OnLeftDown(self, event, dc, scaling) |
261 Graphic_Element.OnLeftDown(self, event, dc, scaling) |
262 |
262 |
263 # Method called when a LeftUp event have been generated |
263 # Method called when a LeftUp event have been generated |
624 # Removes all the highlights of one particular type from the connection |
624 # Removes all the highlights of one particular type from the connection |
625 def ClearHighlight(self, highlight_type=None): |
625 def ClearHighlight(self, highlight_type=None): |
626 if highlight_type is None: |
626 if highlight_type is None: |
627 self.Highlights = {} |
627 self.Highlights = {} |
628 else: |
628 else: |
629 highlight_items = self.Highlights.items() |
629 highlight_items = list(self.Highlights.items()) |
630 for name, highlights in highlight_items: |
630 for name, highlights in highlight_items: |
631 highlights = ClearHighlights(highlights, highlight_type) |
631 highlights = ClearHighlights(highlights, highlight_type) |
632 if len(highlights) == 0: |
632 if len(highlights) == 0: |
633 self.Highlights.pop(name) |
633 self.Highlights.pop(name) |
634 |
634 |
685 # Draw input and output connectors |
685 # Draw input and output connectors |
686 self.Input.Draw(dc) |
686 self.Input.Draw(dc) |
687 self.Output.Draw(dc) |
687 self.Output.Draw(dc) |
688 |
688 |
689 if not getattr(dc, "printing", False): |
689 if not getattr(dc, "printing", False): |
690 for name, highlights in self.Highlights.iteritems(): |
690 for name, highlights in self.Highlights.items(): |
691 if name == "reference": |
691 if name == "reference": |
692 DrawHighlightedText(dc, self.Name, highlights, name_pos[0], name_pos[1]) |
692 DrawHighlightedText(dc, self.Name, highlights, name_pos[0], name_pos[1]) |
693 elif typetext != "": |
693 elif typetext != "": |
694 DrawHighlightedText(dc, typetext, highlights, type_pos[0], type_pos[1]) |
694 DrawHighlightedText(dc, typetext, highlights, type_pos[0], type_pos[1]) |
695 |
695 |
946 # Removes all the highlights of one particular type from the connection |
946 # Removes all the highlights of one particular type from the connection |
947 def ClearHighlight(self, highlight_type=None): |
947 def ClearHighlight(self, highlight_type=None): |
948 if highlight_type is None: |
948 if highlight_type is None: |
949 self.Highlights = {} |
949 self.Highlights = {} |
950 else: |
950 else: |
951 highlight_items = self.Highlights.items() |
951 highlight_items = list(self.Highlights.items()) |
952 for name, highlights in highlight_items: |
952 for name, highlights in highlight_items: |
953 highlights = ClearHighlights(highlights, highlight_type) |
953 highlights = ClearHighlights(highlights, highlight_type) |
954 if len(highlights) == 0: |
954 if len(highlights) == 0: |
955 self.Highlights.pop(name) |
955 self.Highlights.pop(name) |
956 |
956 |
1014 # Draw input and output connectors |
1014 # Draw input and output connectors |
1015 self.Input.Draw(dc) |
1015 self.Input.Draw(dc) |
1016 self.Output.Draw(dc) |
1016 self.Output.Draw(dc) |
1017 |
1017 |
1018 if not getattr(dc, "printing", False): |
1018 if not getattr(dc, "printing", False): |
1019 for name, highlights in self.Highlights.iteritems(): |
1019 for name, highlights in self.Highlights.items(): |
1020 if name == "reference": |
1020 if name == "reference": |
1021 DrawHighlightedText(dc, self.Name, highlights, name_pos[0], name_pos[1]) |
1021 DrawHighlightedText(dc, self.Name, highlights, name_pos[0], name_pos[1]) |
1022 elif typetext != "": |
1022 elif typetext != "": |
1023 DrawHighlightedText(dc, typetext, highlights, type_pos[0], type_pos[1]) |
1023 DrawHighlightedText(dc, typetext, highlights, type_pos[0], type_pos[1]) |