controls/DebugVariablePanel/DebugVariableGraphicPanel.py
changeset 1199 fc0e7d80494f
parent 1198 8b4e6bd0aa92
child 1200 501cb0bb4c05
equal deleted inserted replaced
1198:8b4e6bd0aa92 1199:fc0e7d80494f
    39 from mpl_toolkits.mplot3d import Axes3D
    39 from mpl_toolkits.mplot3d import Axes3D
    40 color_cycle = ['r', 'b', 'g', 'm', 'y', 'k']
    40 color_cycle = ['r', 'b', 'g', 'm', 'y', 'k']
    41 cursor_color = '#800080'
    41 cursor_color = '#800080'
    42 
    42 
    43 from editors.DebugViewer import DebugViewer, REFRESH_PERIOD
    43 from editors.DebugViewer import DebugViewer, REFRESH_PERIOD
    44 from controls.DebugVariablePanel.DebugVariableItem import DebugVariableItem
       
    45 from dialogs.ForceVariableDialog import ForceVariableDialog
    44 from dialogs.ForceVariableDialog import ForceVariableDialog
    46 from util.BitmapLibrary import GetBitmap
    45 from util.BitmapLibrary import GetBitmap
       
    46 
       
    47 from DebugVariableItem import DebugVariableItem
       
    48 from GraphButton import GraphButton
    47 
    49 
    48 class DebugVariableDropTarget(wx.TextDropTarget):
    50 class DebugVariableDropTarget(wx.TextDropTarget):
    49     
    51     
    50     def __init__(self, parent, control=None):
    52     def __init__(self, parent, control=None):
    51         wx.TextDropTarget.__init__(self)
    53         wx.TextDropTarget.__init__(self)
   193     else:
   195     else:
   194         center = 0.5
   196         center = 0.5
   195         range = 1.0
   197         range = 1.0
   196     return data, center - range * 0.55, center + range * 0.55
   198     return data, center - range * 0.55, center + range * 0.55
   197 
   199 
   198 class GraphButton():
       
   199     
       
   200     def __init__(self, x, y, bitmap, callback):
       
   201         self.Position = wx.Point(x, y)
       
   202         self.Bitmap = bitmap
       
   203         self.Shown = True
       
   204         self.Enabled = True
       
   205         self.Callback = callback
       
   206     
       
   207     def __del__(self):
       
   208         self.callback = None
       
   209     
       
   210     def GetSize(self):
       
   211         return self.Bitmap.GetSize()
       
   212     
       
   213     def SetPosition(self, x, y):
       
   214         self.Position = wx.Point(x, y)
       
   215     
       
   216     def Show(self):
       
   217         self.Shown = True
       
   218         
       
   219     def Hide(self):
       
   220         self.Shown = False
       
   221     
       
   222     def IsShown(self):
       
   223         return self.Shown
       
   224     
       
   225     def Enable(self):
       
   226         self.Enabled = True
       
   227     
       
   228     def Disable(self):
       
   229         self.Enabled = False
       
   230     
       
   231     def IsEnabled(self):
       
   232         return self.Enabled
       
   233     
       
   234     def HitTest(self, x, y):
       
   235         if self.Shown and self.Enabled:
       
   236             w, h = self.Bitmap.GetSize()
       
   237             rect = wx.Rect(self.Position.x, self.Position.y, w, h)
       
   238             if rect.InsideXY(x, y):
       
   239                 return True
       
   240         return False
       
   241     
       
   242     def ProcessCallback(self):
       
   243         if self.Callback is not None:
       
   244             wx.CallAfter(self.Callback)
       
   245             
       
   246     def Draw(self, dc):
       
   247         if self.Shown and self.Enabled:
       
   248             dc.DrawBitmap(self.Bitmap, self.Position.x, self.Position.y, True)
       
   249 
       
   250 class DebugVariableViewer:
   200 class DebugVariableViewer:
   251     
   201     
   252     def __init__(self, window, items=[]):
   202     def __init__(self, window, items=[]):
   253         self.ParentWindow = window
   203         self.ParentWindow = window
   254         self.Items = items
   204         self.Items = items
   348             if refresh_positions:
   298             if refresh_positions:
   349                 offset = 0
   299                 offset = 0
   350                 buttons = self.Buttons[:]
   300                 buttons = self.Buttons[:]
   351                 buttons.reverse()
   301                 buttons.reverse()
   352                 for button in buttons:
   302                 for button in buttons:
   353                     w, h = button.GetSize()
   303                     if button.IsEnabled():
   354                     button.SetPosition(width - 5 - w - offset, 5)
   304                         w, h = button.GetSize()
   355                     offset += w + 2
   305                         button.SetPosition(width - 5 - w - offset, 5)
       
   306                         offset += w + 2
   356                 self.ParentWindow.ForceRefresh()
   307                 self.ParentWindow.ForceRefresh()
   357     
   308     
   358     def DrawCommonElements(self, dc, buttons=None):
   309     def DrawCommonElements(self, dc, buttons=None):
   359         width, height = self.GetSize()
   310         width, height = self.GetSize()
   360         
   311         
   471         self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
   422         self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
   472         self.Bind(wx.EVT_PAINT, self.OnPaint)
   423         self.Bind(wx.EVT_PAINT, self.OnPaint)
   473         
   424         
   474         self.SetMinSize(wx.Size(0, 25))
   425         self.SetMinSize(wx.Size(0, 25))
   475         
   426         
   476         self.Buttons.append(
   427         for bitmap, callback in [("force", self.OnForceButton),
   477             GraphButton(0, 0, GetBitmap("force"), self.OnForceButton))
   428                                  ("release", self.OnReleaseButton),
   478         self.Buttons.append(
   429                                  ("delete_graph", self.OnCloseButton)]:
   479             GraphButton(0, 0, GetBitmap("release"), self.OnReleaseButton))
   430             self.Buttons.append(GraphButton(0, 0, bitmap, callback))
   480         self.Buttons.append(
       
   481             GraphButton(0, 0, GetBitmap("delete_graph"), self.OnCloseButton))
       
   482         
   431         
   483         self.ShowButtons(False)
   432         self.ShowButtons(False)
   484         
   433         
   485     def RefreshViewer(self):
   434     def RefreshViewer(self):
   486         width, height = self.GetSize()
   435         width, height = self.GetSize()
   570         self.mpl_connect('button_release_event', self.OnCanvasButtonReleased)
   519         self.mpl_connect('button_release_event', self.OnCanvasButtonReleased)
   571         self.mpl_connect('scroll_event', self.OnCanvasScroll)
   520         self.mpl_connect('scroll_event', self.OnCanvasScroll)
   572         
   521         
   573         for size, bitmap in zip([SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI],
   522         for size, bitmap in zip([SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI],
   574                                 ["minimize_graph", "middle_graph", "maximize_graph"]):
   523                                 ["minimize_graph", "middle_graph", "maximize_graph"]):
   575             self.Buttons.append(GraphButton(0, 0, GetBitmap(bitmap), self.GetOnChangeSizeButton(size)))
   524             self.Buttons.append(GraphButton(0, 0, bitmap, self.GetOnChangeSizeButton(size)))
   576         self.Buttons.append(
   525         for bitmap, callback in [("export_graph_mini", self.OnExportGraphButton),
   577             GraphButton(0, 0, GetBitmap("export_graph_mini"), self.OnExportGraphButton))
   526                                  ("delete_graph", self.OnCloseButton)]:
   578         self.Buttons.append(
   527             self.Buttons.append(GraphButton(0, 0, bitmap, callback))
   579             GraphButton(0, 0, GetBitmap("delete_graph"), self.OnCloseButton))
       
   580         
   528         
   581         self.ResetGraphics()
   529         self.ResetGraphics()
   582         self.RefreshLabelsPosition(canvas_size.height)
   530         self.RefreshLabelsPosition(canvas_size.height)
   583         self.ShowButtons(False)
   531         self.ShowButtons(False)
   584     
   532     
   627         if self.ContextualButtonsItem is None:
   575         if self.ContextualButtonsItem is None:
   628             self.ContextualButtonsItem = item
   576             self.ContextualButtonsItem = item
   629             
   577             
   630             if self.ContextualButtonsItem.IsForced():
   578             if self.ContextualButtonsItem.IsForced():
   631                 self.ContextualButtons.append(
   579                 self.ContextualButtons.append(
   632                     GraphButton(0, 0, GetBitmap("release"), self.OnReleaseButton))
   580                     GraphButton(0, 0, "release", self.OnReleaseButton))
   633             self.ContextualButtons.append(
   581             for bitmap, callback in [("force", self.OnForceButton),
   634                 GraphButton(0, 0, GetBitmap("force"), self.OnForceButton))
   582                                      ("export_graph_mini", self.OnExportItemGraphButton),
   635             self.ContextualButtons.append(
   583                                      ("delete_graph", self.OnRemoveItemButton)]:
   636                 GraphButton(0, 0, GetBitmap("export_graph_mini"), self.OnExportItemGraphButton))
   584                 self.ContextualButtons.append(GraphButton(0, 0, bitmap, callback))
   637             self.ContextualButtons.append(
       
   638                 GraphButton(0, 0, GetBitmap("delete_graph"), self.OnRemoveItemButton))
       
   639             
   585             
   640             offset = 0
   586             offset = 0
   641             buttons = self.ContextualButtons[:]
   587             buttons = self.ContextualButtons[:]
   642             if style in [wx.TOP, wx.LEFT]:
   588             if style in [wx.TOP, wx.LEFT]:
   643                  buttons.reverse()
   589                  buttons.reverse()