Viewer.py
changeset 391 07447ee3538e
parent 388 7ea1f5094df3
child 400 12b55d82d363
equal deleted inserted replaced
390:020420ad8914 391:07447ee3538e
   206         scaling = self.ParentWindow.Scaling
   206         scaling = self.ParentWindow.Scaling
   207         message = None
   207         message = None
   208         try:
   208         try:
   209             values = eval(data)
   209             values = eval(data)
   210         except:
   210         except:
   211             message = "Invalid value \"%s\" for viewer block"%data
   211             message = _("Invalid value \"%s\" for viewer block")%data
   212             values = None
   212             values = None
   213         if not isinstance(values, TupleType):
   213         if not isinstance(values, TupleType):
   214             message = "Invalid value \"%s\" for viewer block"%data
   214             message = _("Invalid value \"%s\" for viewer block")%data
   215             values = None
   215             values = None
   216         if values is not None:
   216         if values is not None:
   217             if values[1] == "debug":
   217             if values[1] == "debug":
   218                 pass
   218                 pass
   219             elif values[1] == "program":
   219             elif values[1] == "program":
   220                 message = "Programs can't be used by other POUs!"
   220                 message = _("Programs can't be used by other POUs!")
   221             elif values[1] in ["function", "functionBlock", "program"]:
   221             elif values[1] in ["function", "functionBlock", "program"]:
   222                 name, type = self.ParentWindow.Controler.GetEditedElementType(self.ParentWindow.GetTagName(), self.ParentWindow.Debug)
   222                 name, type = self.ParentWindow.Controler.GetEditedElementType(self.ParentWindow.GetTagName(), self.ParentWindow.Debug)
   223                 words = self.ParentWindow.TagName.split("::")
   223                 words = self.ParentWindow.TagName.split("::")
   224                 if name == values[0]:
   224                 if name == values[0]:
   225                     message = "\"%s\" can't use itself!"%name
   225                     message = _("\"%s\" can't use itself!")%name
   226                 elif type == "function" and values[1] != "function":
   226                 elif type == "function" and values[1] != "function":
   227                     message = "Function Blocks can't be used in Functions!"
   227                     message = _("Function Blocks can't be used in Functions!")
   228                 elif words[0] == "T" and values[1] != "function":
   228                 elif words[0] == "T" and values[1] != "function":
   229                     message = "Function Blocks can't be used in Transitions!"
   229                     message = _("Function Blocks can't be used in Transitions!")
   230                 elif self.ParentWindow.Controler.PouIsUsedBy(name, values[0], self.ParentWindow.Debug):
   230                 elif self.ParentWindow.Controler.PouIsUsedBy(name, values[0], self.ParentWindow.Debug):
   231                     message = "\"%s\" is already used by \"%s\"!"%(name, values[0])
   231                     message = _("\"%s\" is already used by \"%s\"!")%(name, values[0])
   232                 else:
   232                 else:
   233                     blockname = values[2]
   233                     blockname = values[2]
   234                     if len(values) > 3:
   234                     if len(values) > 3:
   235                         blockinputs = values[3]
   235                         blockinputs = values[3]
   236                     else:
   236                     else:
   241                             blockname = dialog.GetValue()
   241                             blockname = dialog.GetValue()
   242                         else:
   242                         else:
   243                             return
   243                             return
   244                         dialog.Destroy()
   244                         dialog.Destroy()
   245                     if blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
   245                     if blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
   246                         message = "\"%s\" pou already exists!"%blockname
   246                         message = _("\"%s\" pou already exists!")%blockname
   247                     elif blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(self.ParentWindow.GetTagName(), self.ParentWindow.Debug)]:
   247                     elif blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(self.ParentWindow.GetTagName(), self.ParentWindow.Debug)]:
   248                         message = "\"%s\" element for this pou already exists!"%blockname
   248                         message = _("\"%s\" element for this pou already exists!")%blockname
   249                     else:
   249                     else:
   250                         id = self.ParentWindow.GetNewId()
   250                         id = self.ParentWindow.GetNewId()
   251                         block = FBD_Block(self.ParentWindow, values[0], blockname, id, inputs = blockinputs)
   251                         block = FBD_Block(self.ParentWindow, values[0], blockname, id, inputs = blockinputs)
   252                         width, height = block.GetMinSize()
   252                         width, height = block.GetMinSize()
   253                         if scaling is not None:
   253                         if scaling is not None:
   281                             self.GenerateTreeMenu(x, y, scaling, menu, "", var_class, [(values[0], values[2], tree)])
   281                             self.GenerateTreeMenu(x, y, scaling, menu, "", var_class, [(values[0], values[2], tree)])
   282                             self.ParentWindow.PopupMenuXY(menu)
   282                             self.ParentWindow.PopupMenuXY(menu)
   283                         else:
   283                         else:
   284                             self.AddParentVariableBlock(x, y, scaling, var_class, values[0], values[2])
   284                             self.AddParentVariableBlock(x, y, scaling, var_class, values[0], values[2])
   285                     else:
   285                     else:
   286                         message = "Unknown variable \"%s\" this POU!" % values[0]
   286                         message = _("Unknown variable \"%s\" for this POU!") % values[0]
   287                 else:
   287                 else:
   288                     message = "Variable don't belong to this POU!"
   288                     message = _("Variable don't belong to this POU!")
   289         if message is not None:
   289         if message is not None:
   290             wx.CallAfter(self.ShowMessage, message)
   290             wx.CallAfter(self.ShowMessage, message)
   291 
   291 
   292     def GenerateTreeMenu(self, x, y, scaling, menu, base_path, var_class, tree):
   292     def GenerateTreeMenu(self, x, y, scaling, menu, base_path, var_class, tree):
   293         for child_name, child_type, (child_tree, child_dimensions) in tree:
   293         for child_name, child_type, (child_tree, child_dimensions) in tree:
   330         self.ParentWindow.RefreshScrollBars()
   330         self.ParentWindow.RefreshScrollBars()
   331         self.ParentWindow.RefreshVisibleElements()
   331         self.ParentWindow.RefreshVisibleElements()
   332         self.ParentWindow.Refresh(False)
   332         self.ParentWindow.Refresh(False)
   333     
   333     
   334     def ShowMessage(self, message):
   334     def ShowMessage(self, message):
   335         message = wx.MessageDialog(self.ParentWindow, message, "Error", wx.OK|wx.ICON_ERROR)
   335         message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
   336         message.ShowModal()
   336         message.ShowModal()
   337         message.Destroy()
   337         message.Destroy()
   338 
   338 
   339 
   339 
   340 """
   340 """
   353     
   353     
   354     # Create Alignment Menu items
   354     # Create Alignment Menu items
   355     def _init_coll_AlignmentMenu_Items(self, parent):
   355     def _init_coll_AlignmentMenu_Items(self, parent):
   356         # Create menu items
   356         # Create menu items
   357         AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS0,
   357         AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS0,
   358               kind=wx.ITEM_NORMAL, text=u'Left')
   358               kind=wx.ITEM_NORMAL, text=_(u'Left'))
   359         AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS1,
   359         AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS1,
   360               kind=wx.ITEM_NORMAL, text=u'Center')
   360               kind=wx.ITEM_NORMAL, text=_(u'Center'))
   361         AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS2,
   361         AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS2,
   362               kind=wx.ITEM_NORMAL, text=u'Right')
   362               kind=wx.ITEM_NORMAL, text=_(u'Right'))
   363         parent.AppendSeparator()
   363         parent.AppendSeparator()
   364         AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS4,
   364         AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS4,
   365               kind=wx.ITEM_NORMAL, text=u'Top')
   365               kind=wx.ITEM_NORMAL, text=_(u'Top'))
   366         AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS5,
   366         AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS5,
   367               kind=wx.ITEM_NORMAL, text=u'Middle')
   367               kind=wx.ITEM_NORMAL, text=_(u'Middle'))
   368         AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS6,
   368         AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS6,
   369               kind=wx.ITEM_NORMAL, text=u'Bottom')
   369               kind=wx.ITEM_NORMAL, text=_(u'Bottom'))
   370         # Link menu event to corresponding called functions
   370         # Link menu event to corresponding called functions
   371         self.Bind(wx.EVT_MENU, self.OnAlignLeftMenu,
   371         self.Bind(wx.EVT_MENU, self.OnAlignLeftMenu,
   372               id=ID_VIEWERALIGNMENTMENUITEMS0)
   372               id=ID_VIEWERALIGNMENTMENUITEMS0)
   373         self.Bind(wx.EVT_MENU, self.OnAlignCenterMenu,
   373         self.Bind(wx.EVT_MENU, self.OnAlignCenterMenu,
   374               id=ID_VIEWERALIGNMENTMENUITEMS1)
   374               id=ID_VIEWERALIGNMENTMENUITEMS1)
   383     
   383     
   384     # Create Contextual Menu items
   384     # Create Contextual Menu items
   385     def _init_coll_ContextualMenu_Items(self, parent):
   385     def _init_coll_ContextualMenu_Items(self, parent):
   386         # Create menu items
   386         # Create menu items
   387         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS0,
   387         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS0,
   388               kind=wx.ITEM_RADIO, text=u'No Modifier')
   388               kind=wx.ITEM_RADIO, text=_(u'No Modifier'))
   389         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS1,
   389         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS1,
   390               kind=wx.ITEM_RADIO, text=u'Negated')
   390               kind=wx.ITEM_RADIO, text=_(u'Negated'))
   391         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS2,
   391         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS2,
   392               kind=wx.ITEM_RADIO, text=u'Rising Edge')
   392               kind=wx.ITEM_RADIO, text=_(u'Rising Edge'))
   393         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS3,
   393         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS3,
   394               kind=wx.ITEM_RADIO, text=u'Falling Edge')
   394               kind=wx.ITEM_RADIO, text=_(u'Falling Edge'))
   395         parent.AppendSeparator()
   395         parent.AppendSeparator()
   396         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS5,
   396         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS5,
   397               kind=wx.ITEM_NORMAL, text=u'Add Wire Segment')
   397               kind=wx.ITEM_NORMAL, text=_(u'Add Wire Segment'))
   398         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS6,
   398         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS6,
   399               kind=wx.ITEM_NORMAL, text=u'Delete Wire Segment')
   399               kind=wx.ITEM_NORMAL, text=_(u'Delete Wire Segment'))
   400         parent.AppendSeparator()
   400         parent.AppendSeparator()
   401         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS8,
   401         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS8,
   402               kind=wx.ITEM_NORMAL, text=u'Add Divergence Branch')
   402               kind=wx.ITEM_NORMAL, text=_(u'Add Divergence Branch'))
   403         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS9,
   403         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS9,
   404               kind=wx.ITEM_NORMAL, text=u'Delete Divergence Branch')
   404               kind=wx.ITEM_NORMAL, text=_(u'Delete Divergence Branch'))
   405         parent.AppendSeparator()
   405         parent.AppendSeparator()
   406         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS11,
   406         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS11,
   407               kind=wx.ITEM_NORMAL, text=u'Clear Execution Order')
   407               kind=wx.ITEM_NORMAL, text=_(u'Clear Execution Order'))
   408         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS12,
   408         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS12,
   409               kind=wx.ITEM_NORMAL, text=u'Reset Execution Order')
   409               kind=wx.ITEM_NORMAL, text=_(u'Reset Execution Order'))
   410         parent.AppendSeparator()
   410         parent.AppendSeparator()
   411         parent.AppendMenu(ID_VIEWERCONTEXTUALMENUITEMS14, "Alignment", self.AlignmentMenu)
   411         parent.AppendMenu(ID_VIEWERCONTEXTUALMENUITEMS14, _("Alignment"), self.AlignmentMenu)
   412         parent.AppendSeparator()
   412         parent.AppendSeparator()
   413         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS16,
   413         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS16,
   414               kind=wx.ITEM_NORMAL, text=u'Edit Block')
   414               kind=wx.ITEM_NORMAL, text=_(u'Edit Block'))
   415         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS17,
   415         AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS17,
   416               kind=wx.ITEM_NORMAL, text=u'Delete')
   416               kind=wx.ITEM_NORMAL, text=_(u'Delete'))
   417         # Link menu event to corresponding called functions
   417         # Link menu event to corresponding called functions
   418         self.Bind(wx.EVT_MENU, self.OnNoModifierMenu,
   418         self.Bind(wx.EVT_MENU, self.OnNoModifierMenu,
   419               id=ID_VIEWERCONTEXTUALMENUITEMS0)
   419               id=ID_VIEWERCONTEXTUALMENUITEMS0)
   420         self.Bind(wx.EVT_MENU, self.OnNegatedMenu,
   420         self.Bind(wx.EVT_MENU, self.OnNegatedMenu,
   421               id=ID_VIEWERCONTEXTUALMENUITEMS1)
   421               id=ID_VIEWERCONTEXTUALMENUITEMS1)
  1791             connection.Refresh()
  1791             connection.Refresh()
  1792         dialog.Destroy()
  1792         dialog.Destroy()
  1793 
  1793 
  1794     def AddNewComment(self, bbox):
  1794     def AddNewComment(self, bbox):
  1795         if wx.VERSION >= (2, 5, 0):
  1795         if wx.VERSION >= (2, 5, 0):
  1796             dialog = wx.TextEntryDialog(self.ParentWindow, "Edit comment", "Please enter comment text", "", wx.OK|wx.CANCEL|wx.TE_MULTILINE)
  1796             dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), "", wx.OK|wx.CANCEL|wx.TE_MULTILINE)
  1797         else:
  1797         else:
  1798             dialog = wx.TextEntryDialog(self.ParentWindow, "Edit comment", "Please enter comment text", "", wx.OK|wx.CANCEL)
  1798             dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), "", wx.OK|wx.CANCEL)
  1799         if dialog.ShowModal() == wx.ID_OK:
  1799         if dialog.ShowModal() == wx.ID_OK:
  1800             value = dialog.GetValue()
  1800             value = dialog.GetValue()
  1801             id = self.GetNewId()
  1801             id = self.GetNewId()
  1802             comment = Comment(self, value, id)
  1802             comment = Comment(self, value, id)
  1803             comment.SetPosition(bbox.x, bbox.y)
  1803             comment.SetPosition(bbox.x, bbox.y)
  1966     def AddNewJump(self, bbox):
  1966     def AddNewJump(self, bbox):
  1967         choices = []
  1967         choices = []
  1968         for block in self.Blocks.itervalues():
  1968         for block in self.Blocks.itervalues():
  1969             if isinstance(block, SFC_Step):
  1969             if isinstance(block, SFC_Step):
  1970                 choices.append(block.GetName())
  1970                 choices.append(block.GetName())
  1971         dialog = wx.SingleChoiceDialog(self.ParentWindow, "Add a new jump", "Please choose a target", choices, wx.OK|wx.CANCEL)
  1971         dialog = wx.SingleChoiceDialog(self.ParentWindow, _("Add a new jump"), _("Please choose a target"), choices, wx.OK|wx.CANCEL)
  1972         if dialog.ShowModal() == wx.ID_OK:
  1972         if dialog.ShowModal() == wx.ID_OK:
  1973             id = self.GetNewId()
  1973             id = self.GetNewId()
  1974             value = dialog.GetStringSelection()
  1974             value = dialog.GetStringSelection()
  1975             jump = SFC_Jump(self, value, id)
  1975             jump = SFC_Jump(self, value, id)
  1976             jump.SetPosition(bbox.x, bbox.y)
  1976             jump.SetPosition(bbox.x, bbox.y)
  2205         dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
  2205         dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
  2206         dialog.SetStepNames([block.GetName() for block in self.Blocks.itervalues() if isinstance(block, SFC_Step) and block.GetName() != step.GetName()])
  2206         dialog.SetStepNames([block.GetName() for block in self.Blocks.itervalues() if isinstance(block, SFC_Step) and block.GetName() != step.GetName()])
  2207         dialog.SetMinStepSize(step.GetSize())
  2207         dialog.SetMinStepSize(step.GetSize())
  2208         values = {"name" : step.GetName()}
  2208         values = {"name" : step.GetName()}
  2209         connectors = step.GetConnectors()
  2209         connectors = step.GetConnectors()
  2210         values["input"] = connectors["input"] != None
  2210         values["input"] = len(connectors["inputs"]) > 0
  2211         values["output"] = connectors["output"] != None
  2211         values["output"] = len(connectors["outputs"]) > 0
  2212         values["action"] = connectors["action"] != None
  2212         values["action"] = step.GetActionConnector() != None
  2213         dialog.SetValues(values)
  2213         dialog.SetValues(values)
  2214         if dialog.ShowModal() == wx.ID_OK:
  2214         if dialog.ShowModal() == wx.ID_OK:
  2215             values = dialog.GetValues()
  2215             values = dialog.GetValues()
  2216             rect = step.GetRedrawRect(1, 1)
  2216             rect = step.GetRedrawRect(1, 1)
  2217             step.SetName(values["name"])
  2217             step.SetName(values["name"])
  2257     def EditJumpContent(self, jump):
  2257     def EditJumpContent(self, jump):
  2258         choices = []
  2258         choices = []
  2259         for block in self.Blocks.itervalues():
  2259         for block in self.Blocks.itervalues():
  2260             if isinstance(block, SFC_Step):
  2260             if isinstance(block, SFC_Step):
  2261                 choices.append(block.GetName())
  2261                 choices.append(block.GetName())
  2262         dialog = wx.SingleChoiceDialog(self.ParentWindow, "Edit jump target", "Please choose a target", choices, wx.OK|wx.CANCEL)
  2262         dialog = wx.SingleChoiceDialog(self.ParentWindow, _("Edit jump target"), _("Please choose a target"), choices, wx.OK|wx.CANCEL)
  2263         dialog.SetSelection(choices.index(jump.GetTarget()))
  2263         dialog.SetSelection(choices.index(jump.GetTarget()))
  2264         if dialog.ShowModal() == wx.ID_OK:
  2264         if dialog.ShowModal() == wx.ID_OK:
  2265             value = dialog.GetStringSelection()
  2265             value = dialog.GetStringSelection()
  2266             rect = jump.GetRedrawRect(1, 1)
  2266             rect = jump.GetRedrawRect(1, 1)
  2267             jump.SetTarget(value)
  2267             jump.SetTarget(value)
  2292             actionblock.Refresh(rect)
  2292             actionblock.Refresh(rect)
  2293         dialog.Destroy()
  2293         dialog.Destroy()
  2294 
  2294 
  2295     def EditCommentContent(self, comment):
  2295     def EditCommentContent(self, comment):
  2296         if wx.VERSION >= (2, 5, 0):
  2296         if wx.VERSION >= (2, 5, 0):
  2297             dialog = wx.TextEntryDialog(self.ParentWindow, "Edit comment", "Please enter comment text", comment.GetContent(), wx.OK|wx.CANCEL|wx.TE_MULTILINE)
  2297             dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), comment.GetContent(), wx.OK|wx.CANCEL|wx.TE_MULTILINE)
  2298         else:
  2298         else:
  2299             dialog = wx.TextEntryDialog(self.ParentWindow, "Edit comment", "Please enter comment text", comment.GetContent(), wx.OK|wx.CANCEL)
  2299             dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), comment.GetContent(), wx.OK|wx.CANCEL)
  2300         if dialog.ShowModal() == wx.ID_OK:
  2300         if dialog.ShowModal() == wx.ID_OK:
  2301             value = dialog.GetValue()
  2301             value = dialog.GetValue()
  2302             rect = comment.GetRedrawRect(1, 1)
  2302             rect = comment.GetRedrawRect(1, 1)
  2303             comment.SetContent(value)
  2303             comment.SetContent(value)
  2304             comment.SetSize(*self.GetScaledSize(*comment.GetSize()))
  2304             comment.SetSize(*self.GetScaledSize(*comment.GetSize()))