diff -r d51af006fa6b -r 64d8f52bc8c8 controls/DebugVariablePanel/DebugVariableTextViewer.py --- a/controls/DebugVariablePanel/DebugVariableTextViewer.py Fri Aug 11 15:18:19 2017 +0300 +++ b/controls/DebugVariablePanel/DebugVariableTextViewer.py Mon Aug 14 19:13:01 2017 +0300 @@ -39,7 +39,7 @@ """ class DebugVariableTextDropTarget(wx.TextDropTarget): - + def __init__(self, parent, window): """ Constructor @@ -49,7 +49,7 @@ wx.TextDropTarget.__init__(self) self.ParentControl = parent self.ParentWindow = window - + def __del__(self): """ Destructor @@ -58,7 +58,7 @@ # Panel self.ParentControl = None self.ParentWindow = None - + def OnDragOver(self, x, y, d): """ Function called when mouse is dragged over Drop Target @@ -68,9 +68,9 @@ """ # Signal parent that mouse is dragged over self.ParentControl.OnMouseDragging(x, y) - + return wx.TextDropTarget.OnDragOver(self, x, y, d) - + def OnDropText(self, x, y, data): """ Function called when mouse is released in Drop Target @@ -80,9 +80,9 @@ """ # Signal Debug Variable Panel to reset highlight self.ParentWindow.ResetHighlight() - + message = None - + # Check that data is valid regarding DebugVariablePanel try: values = eval(data) @@ -91,50 +91,50 @@ except: message = _("Invalid value \"%s\" for debug variable") % data values = None - + # Display message if data is invalid if message is not None: wx.CallAfter(self.ShowMessage, message) - + # Data contain a reference to a variable to debug elif values[1] == "debug": - + # Get Before which Viewer the variable has to be moved or added # according to the position of mouse in Viewer. width, height = self.ParentControl.GetSize() target_idx = self.ParentControl.GetIndex() if y > height / 2: target_idx += 1 - + # Drag'n Drop is an internal is an internal move inside Debug - # Variable Panel + # Variable Panel if len(values) > 2 and values[2] == "move": - self.ParentWindow.MoveValue(values[0], + self.ParentWindow.MoveValue(values[0], target_idx) - + # Drag'n Drop was initiated by another control of Beremiz else: - self.ParentWindow.InsertValue(values[0], - target_idx, + self.ParentWindow.InsertValue(values[0], + target_idx, force=True) - + def OnLeave(self): """ Function called when mouse is leave Drop Target """ # Signal Debug Variable Panel to reset highlight self.ParentWindow.ResetHighlight() - + return wx.TextDropTarget.OnLeave(self) - + def ShowMessage(self, message): """ Show error message in Error Dialog @param message: Error message to display """ - dialog = wx.MessageDialog(self.ParentWindow, - message, - _("Error"), + dialog = wx.MessageDialog(self.ParentWindow, + message, + _("Error"), wx.OK|wx.ICON_ERROR) dialog.ShowModal() dialog.Destroy() @@ -149,7 +149,7 @@ """ class DebugVariableTextViewer(DebugVariableViewer, wx.Panel): - + def __init__(self, parent, window, items=[]): """ Constructor @@ -158,13 +158,13 @@ @param items: List of DebugVariableItem displayed by Viewer """ DebugVariableViewer.__init__(self, window, items) - + wx.Panel.__init__(self, parent) # Set panel background colour self.SetBackgroundColour(wx.WHITE) # Define panel drop target self.SetDropTarget(DebugVariableTextDropTarget(self, window)) - + # Bind events self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) @@ -174,16 +174,16 @@ self.Bind(wx.EVT_SIZE, self.OnResize) self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) self.Bind(wx.EVT_PAINT, self.OnPaint) - + # Define panel min size for parent sizer layout self.SetMinSize(wx.Size(0, 25)) - + # Add buttons to Viewer for bitmap, callback in [("force", self.OnForceButton), ("release", self.OnReleaseButton), ("delete_graph", self.OnCloseButton)]: self.Buttons.append(GraphButton(0, 0, bitmap, callback)) - + def RefreshViewer(self): """ Method that refresh the content displayed by Viewer @@ -193,24 +193,24 @@ bitmap = wx.EmptyBitmap(width, height) dc = wx.BufferedDC(wx.ClientDC(self), bitmap) dc.Clear() - + # Get Graphics Context for DC, for anti-aliased and transparent # rendering gc = wx.GCDC(dc) - + gc.BeginDrawing() - + # Get first item item = self.ItemsDict.values()[0] - + # Get item variable path masked according Debug Variable Panel mask item_path = item.GetVariable( self.ParentWindow.GetVariableNameMask()) - + # Draw item variable path at Viewer left side w, h = gc.GetTextExtent(item_path) gc.DrawText(item_path, 20, (height - h) / 2) - + # Update 'Release' button state and text color according to item forced # flag value item_forced = item.IsForced() @@ -218,17 +218,17 @@ self.RefreshButtonsPosition() if item_forced: gc.SetTextForeground(wx.BLUE) - + # Draw item current value at right side of Viewer item_value = item.GetValue() w, h = gc.GetTextExtent(item_value) gc.DrawText(item_value, width - 40 - w, (height - h) / 2) - + # Draw other Viewer common elements self.DrawCommonElements(gc) - + gc.EndDrawing() - + def OnLeftDown(self, event): """ Function called when mouse left button is pressed @@ -236,15 +236,15 @@ """ # Get first item item = self.ItemsDict.values()[0] - + # Calculate item path bounding box width, height = self.GetSize() item_path = item.GetVariable( self.ParentWindow.GetVariableNameMask()) w, h = self.GetTextExtent(item_path) - + # Test if mouse has been pressed in this bounding box. In that case - # start a move drag'n drop of item variable + # start a move drag'n drop of item variable x, y = event.GetPosition() item_path_bbox = wx.Rect(20, (height - h) / 2, w, h) if item_path_bbox.InsideXY(x, y): @@ -253,11 +253,11 @@ dragSource = wx.DropSource(self) dragSource.SetData(data) dragSource.DoDragDrop() - + # In other case handle event normally else: event.Skip() - + def OnLeftUp(self, event): """ Function called when mouse left button is released @@ -267,7 +267,7 @@ x, y = event.GetPosition() wx.CallAfter(self.HandleButton, x, y) event.Skip() - + def OnLeftDClick(self, event): """ Function called when mouse left button is double clicked @@ -276,7 +276,7 @@ # Only numeric variables can be toggled to graph canvas if self.ItemsDict.values()[0].IsNumVariable(): self.ParentWindow.ToggleViewerType(self) - + def OnPaint(self, event): """ Function called when redrawing Viewer content is needed