74 'other': 'new century schoolbook', |
74 'other': 'new century schoolbook', |
75 'size' : 12, |
75 'size' : 12, |
76 } |
76 } |
77 |
77 |
78 ZOOM_FACTORS = [math.sqrt(2) ** x for x in xrange(-6, 7)] |
78 ZOOM_FACTORS = [math.sqrt(2) ** x for x in xrange(-6, 7)] |
79 |
|
80 |
79 |
81 def GetVariableCreationFunction(variable_type): |
80 def GetVariableCreationFunction(variable_type): |
82 def variableCreationFunction(viewer, id, specific_values): |
81 def variableCreationFunction(viewer, id, specific_values): |
83 return FBD_Variable(viewer, variable_type, |
82 return FBD_Variable(viewer, variable_type, |
84 specific_values["name"], |
83 specific_values["name"], |
504 self.SetFont(font) |
503 self.SetFont(font) |
505 self.MiniTextDC = wx.MemoryDC() |
504 self.MiniTextDC = wx.MemoryDC() |
506 self.MiniTextDC.SetFont(wx.Font(faces["size"] * 0.75, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["helv"])) |
505 self.MiniTextDC.SetFont(wx.Font(faces["size"] * 0.75, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["helv"])) |
507 |
506 |
508 self.SetScale(len(ZOOM_FACTORS) / 2) |
507 self.SetScale(len(ZOOM_FACTORS) / 2) |
|
508 |
|
509 self.RefreshHighlightsTimer = wx.Timer(self, -1) |
|
510 self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
509 |
511 |
510 self.ResetView() |
512 self.ResetView() |
511 |
513 |
512 # Link Viewer event to corresponding methods |
514 # Link Viewer event to corresponding methods |
513 self.Bind(wx.EVT_PAINT, self.OnPaint) |
515 self.Bind(wx.EVT_PAINT, self.OnPaint) |
523 self.Bind(wx.EVT_CHAR, self.OnChar) |
525 self.Bind(wx.EVT_CHAR, self.OnChar) |
524 self.Bind(wx.EVT_SCROLLWIN, self.OnScrollWindow) |
526 self.Bind(wx.EVT_SCROLLWIN, self.OnScrollWindow) |
525 self.Bind(wx.EVT_SCROLLWIN_THUMBRELEASE, self.OnScrollStop) |
527 self.Bind(wx.EVT_SCROLLWIN_THUMBRELEASE, self.OnScrollStop) |
526 self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheelWindow) |
528 self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheelWindow) |
527 self.Bind(wx.EVT_SIZE, self.OnMoveWindow) |
529 self.Bind(wx.EVT_SIZE, self.OnMoveWindow) |
|
530 |
|
531 def __del__(self): |
|
532 DebugViewer.__del__(self) |
|
533 self.RefreshHighlightsTimer.Stop() |
528 |
534 |
529 def SetCurrentCursor(self, cursor): |
535 def SetCurrentCursor(self, cursor): |
530 global CURSORS |
536 global CURSORS |
531 if self.CurrentCursor != cursor: |
537 if self.CurrentCursor != cursor: |
532 self.CurrentCursor = cursor |
538 self.CurrentCursor = cursor |
837 if iec_path is not None: |
843 if iec_path is not None: |
838 self.AddDataConsumer(iec_path.upper(), block) |
844 self.AddDataConsumer(iec_path.upper(), block) |
839 |
845 |
840 self.Inhibit(False) |
846 self.Inhibit(False) |
841 self.RefreshVisibleElements() |
847 self.RefreshVisibleElements() |
842 self.ShowErrors() |
848 self.ShowHighlights() |
843 self.Refresh(False) |
849 self.Refresh(False) |
844 |
850 |
845 def GetPreviousSteps(self, connectors): |
851 def GetPreviousSteps(self, connectors): |
846 steps = [] |
852 steps = [] |
847 for connector in connectors: |
853 for connector in connectors: |
1846 def AddNewComment(self, bbox): |
1852 def AddNewComment(self, bbox): |
1847 if wx.VERSION >= (2, 5, 0): |
1853 if wx.VERSION >= (2, 5, 0): |
1848 dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), "", wx.OK|wx.CANCEL|wx.TE_MULTILINE) |
1854 dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), "", wx.OK|wx.CANCEL|wx.TE_MULTILINE) |
1849 else: |
1855 else: |
1850 dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), "", wx.OK|wx.CANCEL) |
1856 dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), "", wx.OK|wx.CANCEL) |
|
1857 dialog.SetClientSize(wx.Size(400, 200)) |
1851 if dialog.ShowModal() == wx.ID_OK: |
1858 if dialog.ShowModal() == wx.ID_OK: |
1852 value = dialog.GetValue() |
1859 value = dialog.GetValue() |
1853 id = self.GetNewId() |
1860 id = self.GetNewId() |
1854 comment = Comment(self, value, id) |
1861 comment = Comment(self, value, id) |
1855 comment.SetPosition(bbox.x, bbox.y) |
1862 comment.SetPosition(bbox.x, bbox.y) |
2347 def EditCommentContent(self, comment): |
2354 def EditCommentContent(self, comment): |
2348 if wx.VERSION >= (2, 5, 0): |
2355 if wx.VERSION >= (2, 5, 0): |
2349 dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), comment.GetContent(), wx.OK|wx.CANCEL|wx.TE_MULTILINE) |
2356 dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), comment.GetContent(), wx.OK|wx.CANCEL|wx.TE_MULTILINE) |
2350 else: |
2357 else: |
2351 dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), comment.GetContent(), wx.OK|wx.CANCEL) |
2358 dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), comment.GetContent(), wx.OK|wx.CANCEL) |
|
2359 dialog.SetClientSize(wx.Size(400, 200)) |
2352 if dialog.ShowModal() == wx.ID_OK: |
2360 if dialog.ShowModal() == wx.ID_OK: |
2353 value = dialog.GetValue() |
2361 value = dialog.GetValue() |
2354 rect = comment.GetRedrawRect(1, 1) |
2362 rect = comment.GetRedrawRect(1, 1) |
2355 comment.SetContent(value) |
2363 comment.SetContent(value) |
2356 comment.SetSize(*self.GetScaledSize(*comment.GetSize())) |
2364 comment.SetSize(*self.GetScaledSize(*comment.GetSize())) |
2745 self.Controler.AddEditedElementActionBlock(self.TagName, block.GetId()) |
2753 self.Controler.AddEditedElementActionBlock(self.TagName, block.GetId()) |
2746 self.RefreshActionBlockModel(block) |
2754 self.RefreshActionBlockModel(block) |
2747 |
2755 |
2748 |
2756 |
2749 #------------------------------------------------------------------------------- |
2757 #------------------------------------------------------------------------------- |
2750 # Errors showing functions |
2758 # Highlights showing functions |
2751 #------------------------------------------------------------------------------- |
2759 #------------------------------------------------------------------------------- |
2752 |
2760 |
2753 def ClearErrors(self): |
2761 def OnRefreshHighlightsTimer(self, event): |
2754 self.Errors = [] |
|
2755 self.RefreshView() |
2762 self.RefreshView() |
2756 |
2763 event.Skip() |
2757 def AddShownError(self, infos, start, end): |
2764 |
2758 self.Errors.append((infos, start, end)) |
2765 def ClearHighlights(self, highlight_type=None): |
2759 |
2766 if highlight_type is None: |
2760 def ShowErrors(self): |
2767 self.Highlights = [] |
2761 for infos, start, end in self.Errors: |
2768 else: |
2762 if infos[0] in ["io_variable", "block", "coil", "contact", "transition", "step", "action_block"]: |
2769 self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type] |
|
2770 self.RefreshView() |
|
2771 |
|
2772 def AddHighlight(self, infos, start, end, highlight_type): |
|
2773 self.Highlights.append((infos, start, end, highlight_type)) |
|
2774 self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
2775 |
|
2776 def ShowHighlights(self): |
|
2777 for infos, start, end, highlight_type in self.Highlights: |
|
2778 if infos[0] in ["comment", "io_variable", "block", "connector", "coil", "contact", "step", "transition", "jump", "action_block"]: |
2763 block = self.FindElementById(infos[1]) |
2779 block = self.FindElementById(infos[1]) |
2764 if block is not None: |
2780 if block is not None: |
2765 block.AddError(infos[2:], start, end) |
2781 block.AddHighlight(infos[2:], start, end, highlight_type) |
2766 |
2782 |
2767 #------------------------------------------------------------------------------- |
2783 #------------------------------------------------------------------------------- |
2768 # Drawing functions |
2784 # Drawing functions |
2769 #------------------------------------------------------------------------------- |
2785 #------------------------------------------------------------------------------- |
2770 |
2786 |