controls/DebugVariablePanel.py
changeset 936 364d178df2d3
parent 935 fc1515f27e1f
child 937 bd6fdbb61784
equal deleted inserted replaced
935:fc1515f27e1f 936:364d178df2d3
   696             self.ContextualButtonsItem = None
   696             self.ContextualButtonsItem = None
   697             
   697             
   698             for size in [SIZE_MINI, SIZE_MIDDLE]:
   698             for size in [SIZE_MINI, SIZE_MIDDLE]:
   699                 self.Buttons.append(GraphButton(0, 0, *self.SizeButtonsParams[size]))
   699                 self.Buttons.append(GraphButton(0, 0, *self.SizeButtonsParams[size]))
   700             self.Buttons.append(
   700             self.Buttons.append(
       
   701                 GraphButton(0, 0, GetBitmap("export_graph_mini"), self.OnExportGraphButton))
       
   702             self.Buttons.append(
   701                 GraphButton(0, 0, GetBitmap("delete_graph"), self.OnCloseButton))
   703                 GraphButton(0, 0, GetBitmap("delete_graph"), self.OnCloseButton))
   702             
   704             
   703             self.ShowButtons(False)
   705             self.ShowButtons(False)
   704             
   706             
   705         def SetHighlight(self, highlight):
   707         def SetHighlight(self, highlight):
   790                     self.ContextualButtons.append(
   792                     self.ContextualButtons.append(
   791                         GraphButton(0, 0, GetBitmap("release"), self.OnReleaseButton))
   793                         GraphButton(0, 0, GetBitmap("release"), self.OnReleaseButton))
   792                 else:
   794                 else:
   793                     self.ContextualButtons.append(
   795                     self.ContextualButtons.append(
   794                         GraphButton(0, 0, GetBitmap("force"), self.OnForceButton))
   796                         GraphButton(0, 0, GetBitmap("force"), self.OnForceButton))
       
   797                 self.ContextualButtons.append(
       
   798                     GraphButton(0, 0, GetBitmap("export_graph_mini"), self.OnExportItemGraphButton))
   795                 self.ContextualButtons.append(
   799                 self.ContextualButtons.append(
   796                     GraphButton(0, 0, GetBitmap("delete_graph"), self.OnRemoveItemButton))
   800                     GraphButton(0, 0, GetBitmap("delete_graph"), self.OnRemoveItemButton))
   797                 
   801                 
   798                 offset = 0
   802                 offset = 0
   799                 buttons = self.ContextualButtons[:]
   803                 buttons = self.ContextualButtons[:]
   872                 for button, (bitmap, callback) in zip(self.Buttons, params):
   876                 for button, (bitmap, callback) in zip(self.Buttons, params):
   873                     button.SetBitmap(bitmap)
   877                     button.SetBitmap(bitmap)
   874                     button.SetCallback(callback)
   878                     button.SetCallback(callback)
   875             return OnChangeSizeButton
   879             return OnChangeSizeButton
   876         
   880         
       
   881         def OnExportGraphButton(self):
       
   882             self.Parent.ExportGraph()
       
   883         
   877         def OnCloseButton(self):
   884         def OnCloseButton(self):
   878             self.ParentWindow.DeleteValue(self.Parent)
   885             self.ParentWindow.DeleteValue(self.Parent)
   879         
   886         
   880         def OnForceButton(self):
   887         def OnForceButton(self):
   881             wx.CallAfter(self.Parent.ForceValue, 
   888             wx.CallAfter(self.Parent.ForceValue, 
   884             
   891             
   885         def OnReleaseButton(self):
   892         def OnReleaseButton(self):
   886             wx.CallAfter(self.Parent.ReleaseValue, 
   893             wx.CallAfter(self.Parent.ReleaseValue, 
   887                          self.ContextualButtonsItem)
   894                          self.ContextualButtonsItem)
   888             self.DismissContextualButtons()
   895             self.DismissContextualButtons()
       
   896         
       
   897         def OnExportItemGraphButton(self):
       
   898             wx.CallAfter(self.Parent.ExportGraph, 
       
   899                          self.ContextualButtonsItem)
       
   900             self.DismissContextualButtons()
   889             
   901             
   890         def OnRemoveItemButton(self):            
   902         def OnRemoveItemButton(self):            
   891             wx.CallAfter(self.ParentWindow.DeleteValue, self.Parent, 
   903             wx.CallAfter(self.ParentWindow.DeleteValue, self.Parent, 
   892                          self.ContextualButtonsItem)
   904                          self.ContextualButtonsItem)
   893             self.DismissContextualButtons()
   905             self.DismissContextualButtons()
   894             
   906         
   895         def OnResizeWindow(self, event):
   907         def OnResizeWindow(self, event):
   896             width, height = self.GetSize()
   908             width, height = self.GetSize()
   897             offset = 0
   909             offset = 0
   898             buttons = self.Buttons[:]
   910             buttons = self.Buttons[:]
   899             buttons.reverse()
   911             buttons.reverse()
   910         
   922         
   911             self.GraphType = graph_type
   923             self.GraphType = graph_type
   912             self.CursorTick = None
   924             self.CursorTick = None
   913             self.MouseStartPos = None
   925             self.MouseStartPos = None
   914             self.StartCursorTick = None
   926             self.StartCursorTick = None
   915             self.ItemButtons = None
       
   916             
   927             
   917             main_sizer = wx.BoxSizer(wx.VERTICAL)
   928             main_sizer = wx.BoxSizer(wx.VERTICAL)
   918             
   929             
   919             self.Figure = matplotlib.figure.Figure(facecolor='w')
   930             self.Figure = matplotlib.figure.Figure(facecolor='w')
   920             self.Figure.subplotpars.update(top=0.95, left=0.1, bottom=0.1, right=0.95)
   931             self.Figure.subplotpars.update(top=0.95, left=0.1, bottom=0.1, right=0.95)
   921             
   932             
   922             self.Canvas = DraggingFigureCanvas(self, self.ParentWindow, -1, self.Figure)
   933             self.Canvas = DraggingFigureCanvas(self, self.ParentWindow, -1, self.Figure)
   923             self.Canvas.SetMinSize(wx.Size(200, 200))
   934             self.Canvas.SetMinSize(wx.Size(200, 200))
   924             self.Canvas.SetDropTarget(DebugVariableDropTarget(self.ParentWindow, self))
   935             self.Canvas.SetDropTarget(DebugVariableDropTarget(self.ParentWindow, self))
   925             self.Canvas.Bind(wx.EVT_MOUSEWHEEL, self.OnCanvasMouseWheel)
       
   926             self.Canvas.mpl_connect('button_press_event', self.OnCanvasButtonPressed)
   936             self.Canvas.mpl_connect('button_press_event', self.OnCanvasButtonPressed)
   927             self.Canvas.mpl_connect('motion_notify_event', self.OnCanvasMotion)
   937             self.Canvas.mpl_connect('motion_notify_event', self.OnCanvasMotion)
   928             self.Canvas.mpl_connect('button_release_event', self.OnCanvasButtonReleased)
   938             self.Canvas.mpl_connect('button_release_event', self.OnCanvasButtonReleased)
   929             self.Canvas.mpl_connect('scroll_event', self.OnCanvasScroll)
   939             self.Canvas.mpl_connect('scroll_event', self.OnCanvasScroll)
   930             
   940             
  1044                     start_tick, end_tick = self.ParentWindow.GetRange()
  1054                     start_tick, end_tick = self.ParentWindow.GetRange()
  1045                     rect = self.GetAxesBoundingBox()
  1055                     rect = self.GetAxesBoundingBox()
  1046                     self.ParentWindow.SetCanvasPosition(
  1056                     self.ParentWindow.SetCanvasPosition(
  1047                         self.StartCursorTick + (self.MouseStartPos.x - event.x) *
  1057                         self.StartCursorTick + (self.MouseStartPos.x - event.x) *
  1048                         (end_tick - start_tick) / rect.width)
  1058                         (end_tick - start_tick) / rect.width)
  1049                 elif event.button is None:
  1059                 elif event.button in [None, "up", "down"]:
  1050                     if self.GraphType == GRAPH_PARALLEL:
  1060                     if self.GraphType == GRAPH_PARALLEL:
  1051                         orientation = [wx.RIGHT] * len(self.AxesLabels) + [wx.LEFT] * len(self.Labels)
  1061                         orientation = [wx.RIGHT] * len(self.AxesLabels) + [wx.LEFT] * len(self.Labels)
  1052                     elif len(self.AxesLabels) > 0:
  1062                     elif len(self.AxesLabels) > 0:
  1053                         orientation = [wx.RIGHT, wx.TOP, wx.LEFT, wx.BOTTOM]
  1063                         orientation = [wx.RIGHT, wx.TOP, wx.LEFT, wx.BOTTOM]
  1054                     item_idx = None
  1064                     item_idx = None
  1096                     start_tick, end_tick = self.ParentWindow.GetRange()
  1106                     start_tick, end_tick = self.ParentWindow.GetRange()
  1097                     tick = (start_tick + end_tick) / 2.
  1107                     tick = (start_tick + end_tick) / 2.
  1098                 else:
  1108                 else:
  1099                     tick = event.xdata
  1109                     tick = event.xdata
  1100                 self.ParentWindow.ChangeRange(int(-event.step) / 3, tick)
  1110                 self.ParentWindow.ChangeRange(int(-event.step) / 3, tick)
  1101         
       
  1102         def OnCanvasMouseWheel(self, event):
       
  1103             if self.ItemButtons is not None:
       
  1104                 event.Skip()
       
  1105         
  1111         
  1106         def HighlightCanvas(self, highlight):
  1112         def HighlightCanvas(self, highlight):
  1107             self.Canvas.SetHighlight(highlight)
  1113             self.Canvas.SetHighlight(highlight)
  1108         
  1114         
  1109         def HandleCursorMove(self, event):
  1115         def HandleCursorMove(self, event):
  1345                 label.set_text(value)
  1351                 label.set_text(value)
  1346                 label.set_style(style)
  1352                 label.set_style(style)
  1347             
  1353             
  1348             self.Canvas.draw()
  1354             self.Canvas.draw()
  1349     
  1355     
       
  1356         def ExportGraph(self, item=None):
       
  1357             if item is not None:
       
  1358                 variables = [(item, [entry for entry in item.GetData()])]
       
  1359             else:
       
  1360                 variables = [(item, [entry for entry in item.GetData()])
       
  1361                              for item in self.Items]
       
  1362             self.ParentWindow.CopyDataToClipboard(variables)
       
  1363     
  1350 class DebugVariablePanel(wx.Panel, DebugViewer):
  1364 class DebugVariablePanel(wx.Panel, DebugViewer):
  1351     
  1365     
  1352     def __init__(self, parent, producer, window):
  1366     def __init__(self, parent, producer, window):
  1353         wx.Panel.__init__(self, parent, style=wx.SP_3D|wx.TAB_TRAVERSAL)
  1367         wx.Panel.__init__(self, parent, style=wx.SP_3D|wx.TAB_TRAVERSAL)
  1354         self.SetBackgroundColour(wx.WHITE)
  1368         self.SetBackgroundColour(wx.WHITE)
  1621             panel.HighlightCanvas(HIGHLIGHT_NONE)
  1635             panel.HighlightCanvas(HIGHLIGHT_NONE)
  1622             xw, yw = panel.GetPosition()
  1636             xw, yw = panel.GetPosition()
  1623             width, height = panel.Canvas.GetSize()
  1637             width, height = panel.Canvas.GetSize()
  1624             bbox = wx.Rect(xw, yw, width, height)
  1638             bbox = wx.Rect(xw, yw, width, height)
  1625             if bbox.InsideXY(x_mouse, y_mouse):
  1639             if bbox.InsideXY(x_mouse, y_mouse):
       
  1640                 panel.Canvas.ShowButtons(True)
  1626                 merge_type = GRAPH_PARALLEL
  1641                 merge_type = GRAPH_PARALLEL
  1627                 if panel.Is3DCanvas():
  1642                 if panel.Is3DCanvas():
  1628                     if y_mouse > yw + height / 2:
  1643                     if y_mouse > yw + height / 2:
  1629                         idx += 1
  1644                         idx += 1
  1630                     wx.CallAfter(self.MoveGraph, variable, idx)
  1645                     wx.CallAfter(self.MoveGraph, variable, idx)
  2073                     if source_panel.IsEmpty():
  2088                     if source_panel.IsEmpty():
  2074                         if source_panel.Canvas.HasCapture():
  2089                         if source_panel.Canvas.HasCapture():
  2075                             source_panel.Canvas.ReleaseMouse()
  2090                             source_panel.Canvas.ReleaseMouse()
  2076                         self.GraphicPanels.remove(source_panel)
  2091                         self.GraphicPanels.remove(source_panel)
  2077                         source_panel.Destroy()
  2092                         source_panel.Destroy()
  2078                         
  2093             elif (merge_type != graph_type and len(target_panel.Items) == 2):
       
  2094                 target_panel.RemoveItem(source_item)
       
  2095             else:
       
  2096                 target_panel = None
       
  2097                 
       
  2098             if target_panel is not None:
  2079                 target_panel.AddItem(source_item)
  2099                 target_panel.AddItem(source_item)
  2080                 target_panel.GraphType = merge_type
  2100                 target_panel.GraphType = merge_type
  2081                 target_panel.ResetGraphics()
  2101                 target_panel.ResetGraphics()
  2082                 
  2102                 
  2083                 self.ResetVariableNameMask()
  2103                 self.ResetVariableNameMask()