graphics/SFC_Objects.py
branchpython3
changeset 3750 f62625418bff
parent 3303 0ffb41625592
child 3752 9f6f46dbe3ae
equal deleted inserted replaced
3749:fda6c1a37662 3750:f62625418bff
    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 from future.builtins import round
    28 from future.builtins import round
    29 
    29 
    30 import wx
    30 import wx
    31 from six.moves import xrange
    31 from six.moves import xrange
    32 
    32 
   974     # Removes all the highlights of one particular type from the block
   974     # Removes all the highlights of one particular type from the block
   975     def ClearHighlight(self, highlight_type=None):
   975     def ClearHighlight(self, highlight_type=None):
   976         if highlight_type is None:
   976         if highlight_type is None:
   977             self.Highlights = {}
   977             self.Highlights = {}
   978         else:
   978         else:
   979             highlight_items = self.Highlights.items()
   979             highlight_items = list(self.Highlights.items())
   980             for name, highlights in highlight_items:
   980             for name, highlights in highlight_items:
   981                 highlights = ClearHighlights(highlights, highlight_type)
   981                 highlights = ClearHighlights(highlights, highlight_type)
   982                 if len(highlights) == 0:
   982                 if len(highlights) == 0:
   983                     self.Highlights.pop(name)
   983                     self.Highlights.pop(name)
   984 
   984 
  1035         self.Output.Draw(dc)
  1035         self.Output.Draw(dc)
  1036         if self.Type == "connection":
  1036         if self.Type == "connection":
  1037             self.Condition.Draw(dc)
  1037             self.Condition.Draw(dc)
  1038 
  1038 
  1039         if not getattr(dc, "printing", False):
  1039         if not getattr(dc, "printing", False):
  1040             for name, highlights in self.Highlights.iteritems():
  1040             for name, highlights in self.Highlights.items():
  1041                 if name == "priority":
  1041                 if name == "priority":
  1042                     DrawHighlightedText(dc, str(self.Priority), highlights, priority_pos[0], priority_pos[1])
  1042                     DrawHighlightedText(dc, str(self.Priority), highlights, priority_pos[0], priority_pos[1])
  1043                 else:
  1043                 else:
  1044                     DrawHighlightedText(dc, condition, highlights, condition_pos[0], condition_pos[1])
  1044                     DrawHighlightedText(dc, condition, highlights, condition_pos[0], condition_pos[1])
  1045 
  1045 
  1065         self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, self.GetMinSize()[1])
  1065         self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, self.GetMinSize()[1])
  1066         # Create an input and output connector
  1066         # Create an input and output connector
  1067         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
  1067         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
  1068             self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] // 2, 0), NORTH, onlyone=True)]
  1068             self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] // 2, 0), NORTH, onlyone=True)]
  1069             self.Outputs = []
  1069             self.Outputs = []
  1070             for i in xrange(number):
  1070             for i in range(number):
  1071                 self.Outputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone=True))
  1071                 self.Outputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone=True))
  1072         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
  1072         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
  1073             self.Inputs = []
  1073             self.Inputs = []
  1074             for i in xrange(number):
  1074             for i in range(number):
  1075                 self.Inputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone=True))
  1075                 self.Inputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone=True))
  1076             self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] // 2, self.Size[1]), SOUTH, onlyone=True)]
  1076             self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] // 2, self.Size[1]), SOUTH, onlyone=True)]
  1077         self.Value = None
  1077         self.Value = None
  1078         self.PreviousValue = None
  1078         self.PreviousValue = None
  1079 
  1079 
  1122         divergence.Inputs = [input.Clone(divergence) for input in self.Inputs]
  1122         divergence.Inputs = [input.Clone(divergence) for input in self.Inputs]
  1123         divergence.Outputs = [output.Clone(divergence) for output in self.Outputs]
  1123         divergence.Outputs = [output.Clone(divergence) for output in self.Outputs]
  1124         return divergence
  1124         return divergence
  1125 
  1125 
  1126     def GetConnectorTranslation(self, element):
  1126     def GetConnectorTranslation(self, element):
  1127         return dict(zip(self.Inputs + self.Outputs, element.Inputs + element.Outputs))
  1127         return dict(list(zip(self.Inputs + self.Outputs, element.Inputs + element.Outputs)))
  1128 
  1128 
  1129     # Returns the RedrawRect
  1129     # Returns the RedrawRect
  1130     def GetRedrawRect(self, movex=0, movey=0):
  1130     def GetRedrawRect(self, movex=0, movey=0):
  1131         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
  1131         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
  1132         if movex != 0 or movey != 0:
  1132         if movex != 0 or movey != 0:
  2002     # Removes all the highlights of one particular type from the block
  2002     # Removes all the highlights of one particular type from the block
  2003     def ClearHighlight(self, highlight_type=None):
  2003     def ClearHighlight(self, highlight_type=None):
  2004         if highlight_type is None:
  2004         if highlight_type is None:
  2005             self.Highlights = {}
  2005             self.Highlights = {}
  2006         else:
  2006         else:
  2007             highlight_items = self.Highlights.items()
  2007             highlight_items = list(self.Highlights.items())
  2008             for number, action_highlights in highlight_items:
  2008             for number, action_highlights in highlight_items:
  2009                 action_highlight_items = action_highlights.items()
  2009                 action_highlight_items = list(action_highlights.items())
  2010                 for name, attribute_highlights in action_highlight_items:
  2010                 for name, attribute_highlights in action_highlight_items:
  2011                     attribute_highlights = ClearHighlights(attribute_highlights, highlight_type)
  2011                     attribute_highlights = ClearHighlights(attribute_highlights, highlight_type)
  2012                     if len(attribute_highlights) == 0:
  2012                     if len(attribute_highlights) == 0:
  2013                         action_highlights.pop(name)
  2013                         action_highlights.pop(name)
  2014                 if len(action_highlights) == 0:
  2014                 if len(action_highlights) == 0:
  2056                                  self.Pos.y + i * line_size + (line_size - indicator_size[1]) // 2)
  2056                                  self.Pos.y + i * line_size + (line_size - indicator_size[1]) // 2)
  2057                 dc.DrawText(action.indicator, indicator_pos[0], indicator_pos[1])
  2057                 dc.DrawText(action.indicator, indicator_pos[0], indicator_pos[1])
  2058 
  2058 
  2059             if not getattr(dc, "printing", False):
  2059             if not getattr(dc, "printing", False):
  2060                 action_highlights = self.Highlights.get(i, {})
  2060                 action_highlights = self.Highlights.get(i, {})
  2061                 for name, attribute_highlights in action_highlights.iteritems():
  2061                 for name, attribute_highlights in action_highlights.items():
  2062                     if name == "qualifier":
  2062                     if name == "qualifier":
  2063                         DrawHighlightedText(dc, action.qualifier, attribute_highlights, qualifier_pos[0], qualifier_pos[1])
  2063                         DrawHighlightedText(dc, action.qualifier, attribute_highlights, qualifier_pos[0], qualifier_pos[1])
  2064                     elif name == "duration":
  2064                     elif name == "duration":
  2065                         DrawHighlightedText(dc, action.duration, attribute_highlights, duration_pos[0], duration_pos[1])
  2065                         DrawHighlightedText(dc, action.duration, attribute_highlights, duration_pos[0], duration_pos[1])
  2066                     elif name in ["reference", "inline"]:
  2066                     elif name in ["reference", "inline"]: