37 """ |
37 """ |
38 Class that implements a custom drop target class for Debug Variable Text Viewer |
38 Class that implements a custom drop target class for Debug Variable Text Viewer |
39 """ |
39 """ |
40 |
40 |
41 class DebugVariableTextDropTarget(wx.TextDropTarget): |
41 class DebugVariableTextDropTarget(wx.TextDropTarget): |
42 |
42 |
43 def __init__(self, parent, window): |
43 def __init__(self, parent, window): |
44 """ |
44 """ |
45 Constructor |
45 Constructor |
46 @param parent: Reference to Debug Variable Text Viewer |
46 @param parent: Reference to Debug Variable Text Viewer |
47 @param window: Reference to the Debug Variable Panel |
47 @param window: Reference to the Debug Variable Panel |
48 """ |
48 """ |
49 wx.TextDropTarget.__init__(self) |
49 wx.TextDropTarget.__init__(self) |
50 self.ParentControl = parent |
50 self.ParentControl = parent |
51 self.ParentWindow = window |
51 self.ParentWindow = window |
52 |
52 |
53 def __del__(self): |
53 def __del__(self): |
54 """ |
54 """ |
55 Destructor |
55 Destructor |
56 """ |
56 """ |
57 # Remove reference to Debug Variable Text Viewer and Debug Variable |
57 # Remove reference to Debug Variable Text Viewer and Debug Variable |
58 # Panel |
58 # Panel |
59 self.ParentControl = None |
59 self.ParentControl = None |
60 self.ParentWindow = None |
60 self.ParentWindow = None |
61 |
61 |
62 def OnDragOver(self, x, y, d): |
62 def OnDragOver(self, x, y, d): |
63 """ |
63 """ |
64 Function called when mouse is dragged over Drop Target |
64 Function called when mouse is dragged over Drop Target |
65 @param x: X coordinate of mouse pointer |
65 @param x: X coordinate of mouse pointer |
66 @param y: Y coordinate of mouse pointer |
66 @param y: Y coordinate of mouse pointer |
67 @param d: Suggested default for return value |
67 @param d: Suggested default for return value |
68 """ |
68 """ |
69 # Signal parent that mouse is dragged over |
69 # Signal parent that mouse is dragged over |
70 self.ParentControl.OnMouseDragging(x, y) |
70 self.ParentControl.OnMouseDragging(x, y) |
71 |
71 |
72 return wx.TextDropTarget.OnDragOver(self, x, y, d) |
72 return wx.TextDropTarget.OnDragOver(self, x, y, d) |
73 |
73 |
74 def OnDropText(self, x, y, data): |
74 def OnDropText(self, x, y, data): |
75 """ |
75 """ |
76 Function called when mouse is released in Drop Target |
76 Function called when mouse is released in Drop Target |
77 @param x: X coordinate of mouse pointer |
77 @param x: X coordinate of mouse pointer |
78 @param y: Y coordinate of mouse pointer |
78 @param y: Y coordinate of mouse pointer |
79 @param data: Text associated to drag'n drop |
79 @param data: Text associated to drag'n drop |
80 """ |
80 """ |
81 # Signal Debug Variable Panel to reset highlight |
81 # Signal Debug Variable Panel to reset highlight |
82 self.ParentWindow.ResetHighlight() |
82 self.ParentWindow.ResetHighlight() |
83 |
83 |
84 message = None |
84 message = None |
85 |
85 |
86 # Check that data is valid regarding DebugVariablePanel |
86 # Check that data is valid regarding DebugVariablePanel |
87 try: |
87 try: |
88 values = eval(data) |
88 values = eval(data) |
89 if not isinstance(values, TupleType): |
89 if not isinstance(values, TupleType): |
90 raise ValueError |
90 raise ValueError |
91 except: |
91 except: |
92 message = _("Invalid value \"%s\" for debug variable") % data |
92 message = _("Invalid value \"%s\" for debug variable") % data |
93 values = None |
93 values = None |
94 |
94 |
95 # Display message if data is invalid |
95 # Display message if data is invalid |
96 if message is not None: |
96 if message is not None: |
97 wx.CallAfter(self.ShowMessage, message) |
97 wx.CallAfter(self.ShowMessage, message) |
98 |
98 |
99 # Data contain a reference to a variable to debug |
99 # Data contain a reference to a variable to debug |
100 elif values[1] == "debug": |
100 elif values[1] == "debug": |
101 |
101 |
102 # Get Before which Viewer the variable has to be moved or added |
102 # Get Before which Viewer the variable has to be moved or added |
103 # according to the position of mouse in Viewer. |
103 # according to the position of mouse in Viewer. |
104 width, height = self.ParentControl.GetSize() |
104 width, height = self.ParentControl.GetSize() |
105 target_idx = self.ParentControl.GetIndex() |
105 target_idx = self.ParentControl.GetIndex() |
106 if y > height / 2: |
106 if y > height / 2: |
107 target_idx += 1 |
107 target_idx += 1 |
108 |
108 |
109 # Drag'n Drop is an internal is an internal move inside Debug |
109 # Drag'n Drop is an internal is an internal move inside Debug |
110 # Variable Panel |
110 # Variable Panel |
111 if len(values) > 2 and values[2] == "move": |
111 if len(values) > 2 and values[2] == "move": |
112 self.ParentWindow.MoveValue(values[0], |
112 self.ParentWindow.MoveValue(values[0], |
113 target_idx) |
113 target_idx) |
114 |
114 |
115 # Drag'n Drop was initiated by another control of Beremiz |
115 # Drag'n Drop was initiated by another control of Beremiz |
116 else: |
116 else: |
117 self.ParentWindow.InsertValue(values[0], |
117 self.ParentWindow.InsertValue(values[0], |
118 target_idx, |
118 target_idx, |
119 force=True) |
119 force=True) |
120 |
120 |
121 def OnLeave(self): |
121 def OnLeave(self): |
122 """ |
122 """ |
123 Function called when mouse is leave Drop Target |
123 Function called when mouse is leave Drop Target |
124 """ |
124 """ |
125 # Signal Debug Variable Panel to reset highlight |
125 # Signal Debug Variable Panel to reset highlight |
126 self.ParentWindow.ResetHighlight() |
126 self.ParentWindow.ResetHighlight() |
127 |
127 |
128 return wx.TextDropTarget.OnLeave(self) |
128 return wx.TextDropTarget.OnLeave(self) |
129 |
129 |
130 def ShowMessage(self, message): |
130 def ShowMessage(self, message): |
131 """ |
131 """ |
132 Show error message in Error Dialog |
132 Show error message in Error Dialog |
133 @param message: Error message to display |
133 @param message: Error message to display |
134 """ |
134 """ |
135 dialog = wx.MessageDialog(self.ParentWindow, |
135 dialog = wx.MessageDialog(self.ParentWindow, |
136 message, |
136 message, |
137 _("Error"), |
137 _("Error"), |
138 wx.OK|wx.ICON_ERROR) |
138 wx.OK|wx.ICON_ERROR) |
139 dialog.ShowModal() |
139 dialog.ShowModal() |
140 dialog.Destroy() |
140 dialog.Destroy() |
141 |
141 |
142 |
142 |
147 """ |
147 """ |
148 Class that implements a Viewer that display variable values as a text |
148 Class that implements a Viewer that display variable values as a text |
149 """ |
149 """ |
150 |
150 |
151 class DebugVariableTextViewer(DebugVariableViewer, wx.Panel): |
151 class DebugVariableTextViewer(DebugVariableViewer, wx.Panel): |
152 |
152 |
153 def __init__(self, parent, window, items=[]): |
153 def __init__(self, parent, window, items=[]): |
154 """ |
154 """ |
155 Constructor |
155 Constructor |
156 @param parent: Parent wx.Window of DebugVariableText |
156 @param parent: Parent wx.Window of DebugVariableText |
157 @param window: Reference to the Debug Variable Panel |
157 @param window: Reference to the Debug Variable Panel |
158 @param items: List of DebugVariableItem displayed by Viewer |
158 @param items: List of DebugVariableItem displayed by Viewer |
159 """ |
159 """ |
160 DebugVariableViewer.__init__(self, window, items) |
160 DebugVariableViewer.__init__(self, window, items) |
161 |
161 |
162 wx.Panel.__init__(self, parent) |
162 wx.Panel.__init__(self, parent) |
163 # Set panel background colour |
163 # Set panel background colour |
164 self.SetBackgroundColour(wx.WHITE) |
164 self.SetBackgroundColour(wx.WHITE) |
165 # Define panel drop target |
165 # Define panel drop target |
166 self.SetDropTarget(DebugVariableTextDropTarget(self, window)) |
166 self.SetDropTarget(DebugVariableTextDropTarget(self, window)) |
167 |
167 |
168 # Bind events |
168 # Bind events |
169 self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) |
169 self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) |
170 self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) |
170 self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) |
171 self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick) |
171 self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick) |
172 self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter) |
172 self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter) |
173 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) |
173 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) |
174 self.Bind(wx.EVT_SIZE, self.OnResize) |
174 self.Bind(wx.EVT_SIZE, self.OnResize) |
175 self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) |
175 self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) |
176 self.Bind(wx.EVT_PAINT, self.OnPaint) |
176 self.Bind(wx.EVT_PAINT, self.OnPaint) |
177 |
177 |
178 # Define panel min size for parent sizer layout |
178 # Define panel min size for parent sizer layout |
179 self.SetMinSize(wx.Size(0, 25)) |
179 self.SetMinSize(wx.Size(0, 25)) |
180 |
180 |
181 # Add buttons to Viewer |
181 # Add buttons to Viewer |
182 for bitmap, callback in [("force", self.OnForceButton), |
182 for bitmap, callback in [("force", self.OnForceButton), |
183 ("release", self.OnReleaseButton), |
183 ("release", self.OnReleaseButton), |
184 ("delete_graph", self.OnCloseButton)]: |
184 ("delete_graph", self.OnCloseButton)]: |
185 self.Buttons.append(GraphButton(0, 0, bitmap, callback)) |
185 self.Buttons.append(GraphButton(0, 0, bitmap, callback)) |
186 |
186 |
187 def RefreshViewer(self): |
187 def RefreshViewer(self): |
188 """ |
188 """ |
189 Method that refresh the content displayed by Viewer |
189 Method that refresh the content displayed by Viewer |
190 """ |
190 """ |
191 # Create buffered DC for drawing in panel |
191 # Create buffered DC for drawing in panel |
192 width, height = self.GetSize() |
192 width, height = self.GetSize() |
193 bitmap = wx.EmptyBitmap(width, height) |
193 bitmap = wx.EmptyBitmap(width, height) |
194 dc = wx.BufferedDC(wx.ClientDC(self), bitmap) |
194 dc = wx.BufferedDC(wx.ClientDC(self), bitmap) |
195 dc.Clear() |
195 dc.Clear() |
196 |
196 |
197 # Get Graphics Context for DC, for anti-aliased and transparent |
197 # Get Graphics Context for DC, for anti-aliased and transparent |
198 # rendering |
198 # rendering |
199 gc = wx.GCDC(dc) |
199 gc = wx.GCDC(dc) |
200 |
200 |
201 gc.BeginDrawing() |
201 gc.BeginDrawing() |
202 |
202 |
203 # Get first item |
203 # Get first item |
204 item = self.ItemsDict.values()[0] |
204 item = self.ItemsDict.values()[0] |
205 |
205 |
206 # Get item variable path masked according Debug Variable Panel mask |
206 # Get item variable path masked according Debug Variable Panel mask |
207 item_path = item.GetVariable( |
207 item_path = item.GetVariable( |
208 self.ParentWindow.GetVariableNameMask()) |
208 self.ParentWindow.GetVariableNameMask()) |
209 |
209 |
210 # Draw item variable path at Viewer left side |
210 # Draw item variable path at Viewer left side |
211 w, h = gc.GetTextExtent(item_path) |
211 w, h = gc.GetTextExtent(item_path) |
212 gc.DrawText(item_path, 20, (height - h) / 2) |
212 gc.DrawText(item_path, 20, (height - h) / 2) |
213 |
213 |
214 # Update 'Release' button state and text color according to item forced |
214 # Update 'Release' button state and text color according to item forced |
215 # flag value |
215 # flag value |
216 item_forced = item.IsForced() |
216 item_forced = item.IsForced() |
217 self.Buttons[1].Enable(item_forced) |
217 self.Buttons[1].Enable(item_forced) |
218 self.RefreshButtonsPosition() |
218 self.RefreshButtonsPosition() |
219 if item_forced: |
219 if item_forced: |
220 gc.SetTextForeground(wx.BLUE) |
220 gc.SetTextForeground(wx.BLUE) |
221 |
221 |
222 # Draw item current value at right side of Viewer |
222 # Draw item current value at right side of Viewer |
223 item_value = item.GetValue() |
223 item_value = item.GetValue() |
224 w, h = gc.GetTextExtent(item_value) |
224 w, h = gc.GetTextExtent(item_value) |
225 gc.DrawText(item_value, width - 40 - w, (height - h) / 2) |
225 gc.DrawText(item_value, width - 40 - w, (height - h) / 2) |
226 |
226 |
227 # Draw other Viewer common elements |
227 # Draw other Viewer common elements |
228 self.DrawCommonElements(gc) |
228 self.DrawCommonElements(gc) |
229 |
229 |
230 gc.EndDrawing() |
230 gc.EndDrawing() |
231 |
231 |
232 def OnLeftDown(self, event): |
232 def OnLeftDown(self, event): |
233 """ |
233 """ |
234 Function called when mouse left button is pressed |
234 Function called when mouse left button is pressed |
235 @param event: wx.MouseEvent |
235 @param event: wx.MouseEvent |
236 """ |
236 """ |
237 # Get first item |
237 # Get first item |
238 item = self.ItemsDict.values()[0] |
238 item = self.ItemsDict.values()[0] |
239 |
239 |
240 # Calculate item path bounding box |
240 # Calculate item path bounding box |
241 width, height = self.GetSize() |
241 width, height = self.GetSize() |
242 item_path = item.GetVariable( |
242 item_path = item.GetVariable( |
243 self.ParentWindow.GetVariableNameMask()) |
243 self.ParentWindow.GetVariableNameMask()) |
244 w, h = self.GetTextExtent(item_path) |
244 w, h = self.GetTextExtent(item_path) |
245 |
245 |
246 # Test if mouse has been pressed in this bounding box. In that case |
246 # Test if mouse has been pressed in this bounding box. In that case |
247 # start a move drag'n drop of item variable |
247 # start a move drag'n drop of item variable |
248 x, y = event.GetPosition() |
248 x, y = event.GetPosition() |
249 item_path_bbox = wx.Rect(20, (height - h) / 2, w, h) |
249 item_path_bbox = wx.Rect(20, (height - h) / 2, w, h) |
250 if item_path_bbox.InsideXY(x, y): |
250 if item_path_bbox.InsideXY(x, y): |
251 self.ShowButtons(False) |
251 self.ShowButtons(False) |
252 data = wx.TextDataObject(str((item.GetVariable(), "debug", "move"))) |
252 data = wx.TextDataObject(str((item.GetVariable(), "debug", "move"))) |
253 dragSource = wx.DropSource(self) |
253 dragSource = wx.DropSource(self) |
254 dragSource.SetData(data) |
254 dragSource.SetData(data) |
255 dragSource.DoDragDrop() |
255 dragSource.DoDragDrop() |
256 |
256 |
257 # In other case handle event normally |
257 # In other case handle event normally |
258 else: |
258 else: |
259 event.Skip() |
259 event.Skip() |
260 |
260 |
261 def OnLeftUp(self, event): |
261 def OnLeftUp(self, event): |
262 """ |
262 """ |
263 Function called when mouse left button is released |
263 Function called when mouse left button is released |
264 @param event: wx.MouseEvent |
264 @param event: wx.MouseEvent |
265 """ |
265 """ |
266 # Execute callback on button under mouse pointer if it exists |
266 # Execute callback on button under mouse pointer if it exists |
267 x, y = event.GetPosition() |
267 x, y = event.GetPosition() |
268 wx.CallAfter(self.HandleButton, x, y) |
268 wx.CallAfter(self.HandleButton, x, y) |
269 event.Skip() |
269 event.Skip() |
270 |
270 |
271 def OnLeftDClick(self, event): |
271 def OnLeftDClick(self, event): |
272 """ |
272 """ |
273 Function called when mouse left button is double clicked |
273 Function called when mouse left button is double clicked |
274 @param event: wx.MouseEvent |
274 @param event: wx.MouseEvent |
275 """ |
275 """ |
276 # Only numeric variables can be toggled to graph canvas |
276 # Only numeric variables can be toggled to graph canvas |
277 if self.ItemsDict.values()[0].IsNumVariable(): |
277 if self.ItemsDict.values()[0].IsNumVariable(): |
278 self.ParentWindow.ToggleViewerType(self) |
278 self.ParentWindow.ToggleViewerType(self) |
279 |
279 |
280 def OnPaint(self, event): |
280 def OnPaint(self, event): |
281 """ |
281 """ |
282 Function called when redrawing Viewer content is needed |
282 Function called when redrawing Viewer content is needed |
283 @param event: wx.PaintEvent |
283 @param event: wx.PaintEvent |
284 """ |
284 """ |