controls/DebugVariablePanel/GraphButton.py
changeset 1730 64d8f52bc8c8
parent 1571 486f94a8032c
child 1736 7e61baa047f0
equal deleted inserted replaced
1726:d51af006fa6b 1730:64d8f52bc8c8
    33 """
    33 """
    34 Class that implements a custom button for graphic Viewer
    34 Class that implements a custom button for graphic Viewer
    35 """
    35 """
    36 
    36 
    37 class GraphButton():
    37 class GraphButton():
    38     
    38 
    39     def __init__(self, x, y, bitmap, callback):
    39     def __init__(self, x, y, bitmap, callback):
    40         """
    40         """
    41         Constructor
    41         Constructor
    42         @param x: X coordinate of Button in Graphic Viewer
    42         @param x: X coordinate of Button in Graphic Viewer
    43         @param y: Y coordinate of Button in Graphic Viewer
    43         @param y: Y coordinate of Button in Graphic Viewer
    46         """
    46         """
    47         # Save button position
    47         # Save button position
    48         self.SetPosition(x, y)
    48         self.SetPosition(x, y)
    49         # Set button bitmap
    49         # Set button bitmap
    50         self.SetBitmap(bitmap)
    50         self.SetBitmap(bitmap)
    51         
    51 
    52         # By default button is hide and enabled
    52         # By default button is hide and enabled
    53         self.Shown = False
    53         self.Shown = False
    54         self.Enabled = True
    54         self.Enabled = True
    55         
    55 
    56         # Save reference to callback function
    56         # Save reference to callback function
    57         self.Callback = callback
    57         self.Callback = callback
    58     
    58 
    59     def __del__(self):
    59     def __del__(self):
    60         """
    60         """
    61         Destructor
    61         Destructor
    62         """
    62         """
    63         # Remove reference to callback function
    63         # Remove reference to callback function
    64         self.callback = None
    64         self.callback = None
    65     
    65 
    66     def SetBitmap(self, bitmap):
    66     def SetBitmap(self, bitmap):
    67         """
    67         """
    68         Set bitmap to use for button
    68         Set bitmap to use for button
    69         @param bitmap: Name of bitmap to use for button
    69         @param bitmap: Name of bitmap to use for button
    70         """
    70         """
    71         # Get wx.Bitmap object corresponding to bitmap
    71         # Get wx.Bitmap object corresponding to bitmap
    72         self.Bitmap = GetBitmap(bitmap)
    72         self.Bitmap = GetBitmap(bitmap)
    73     
    73 
    74     def GetSize(self):
    74     def GetSize(self):
    75         """
    75         """
    76         Return size of button
    76         Return size of button
    77         @return: wx.Size object containing button size
    77         @return: wx.Size object containing button size
    78         """
    78         """
    79         # Button size is size of bitmap
    79         # Button size is size of bitmap
    80         return self.Bitmap.GetSize()
    80         return self.Bitmap.GetSize()
    81     
    81 
    82     def SetPosition(self, x, y):
    82     def SetPosition(self, x, y):
    83         """
    83         """
    84         Set button position
    84         Set button position
    85         @param x: X coordinate of Button in Graphic Viewer
    85         @param x: X coordinate of Button in Graphic Viewer
    86         @param y: Y coordinate of Button in Graphic Viewer
    86         @param y: Y coordinate of Button in Graphic Viewer
    87         """
    87         """
    88         self.Position = wx.Point(x, y)
    88         self.Position = wx.Point(x, y)
    89     
    89 
    90     def Show(self, show=True):
    90     def Show(self, show=True):
    91         """
    91         """
    92         Mark if button to be displayed in Graphic Viewer
    92         Mark if button to be displayed in Graphic Viewer
    93         @param show: True if button to be displayed in Graphic Viewer
    93         @param show: True if button to be displayed in Graphic Viewer
    94         (default True)
    94         (default True)
    95         """
    95         """
    96         self.Shown = show
    96         self.Shown = show
    97         
    97 
    98     def Hide(self):
    98     def Hide(self):
    99         """
    99         """
   100         Hide button from Graphic Viewer
   100         Hide button from Graphic Viewer
   101         """
   101         """
   102         self.Show(False)
   102         self.Show(False)
   103     
   103 
   104     def IsShown(self):
   104     def IsShown(self):
   105         """
   105         """
   106         Return if button is displayed in Graphic Viewer
   106         Return if button is displayed in Graphic Viewer
   107         @return: True if button is displayed in Graphic Viewer
   107         @return: True if button is displayed in Graphic Viewer
   108         """
   108         """
   109         return self.Shown
   109         return self.Shown
   110     
   110 
   111     def Enable(self, enable=True):
   111     def Enable(self, enable=True):
   112         """
   112         """
   113         Mark if button is active in Graphic Viewer
   113         Mark if button is active in Graphic Viewer
   114         @param enable: True if button is active in Graphic Viewer
   114         @param enable: True if button is active in Graphic Viewer
   115         (default True)
   115         (default True)
   116         """
   116         """
   117         self.Enabled = enable
   117         self.Enabled = enable
   118     
   118 
   119     def Disable(self):
   119     def Disable(self):
   120         """
   120         """
   121         Deactivate button in Graphic Viewer
   121         Deactivate button in Graphic Viewer
   122         """
   122         """
   123         self.Enabled = False
   123         self.Enabled = False
   124     
   124 
   125     def IsEnabled(self):
   125     def IsEnabled(self):
   126         """
   126         """
   127         Return if button is active in Graphic Viewer
   127         Return if button is active in Graphic Viewer
   128         @return: True if button is active in Graphic Viewer
   128         @return: True if button is active in Graphic Viewer
   129         """
   129         """
   130         return self.Enabled
   130         return self.Enabled
   131     
   131 
   132     def HitTest(self, x, y):
   132     def HitTest(self, x, y):
   133         """
   133         """
   134         Test if point is inside button
   134         Test if point is inside button
   135         @param x: X coordinate of point
   135         @param x: X coordinate of point
   136         @param y: Y coordinate of point
   136         @param y: Y coordinate of point
   137         @return: True if button is active and displayed and point is inside
   137         @return: True if button is active and displayed and point is inside
   138         button 
   138         button
   139         """
   139         """
   140         # Return immediately if button is hidden or inactive
   140         # Return immediately if button is hidden or inactive
   141         if not (self.IsShown() and self.IsEnabled()):
   141         if not (self.IsShown() and self.IsEnabled()):
   142             return False
   142             return False
   143         
   143 
   144         # Test if point is inside button
   144         # Test if point is inside button
   145         w, h = self.Bitmap.GetSize()
   145         w, h = self.Bitmap.GetSize()
   146         rect = wx.Rect(self.Position.x, self.Position.y, w, h)
   146         rect = wx.Rect(self.Position.x, self.Position.y, w, h)
   147         return rect.InsideXY(x, y)
   147         return rect.InsideXY(x, y)
   148     
   148 
   149     def ProcessCallback(self):
   149     def ProcessCallback(self):
   150         """
   150         """
   151         Call callback function if defined
   151         Call callback function if defined
   152         """
   152         """
   153         if self.Callback is not None:
   153         if self.Callback is not None:
   154             self.Callback()
   154             self.Callback()
   155     
   155 
   156     def Draw(self, dc):
   156     def Draw(self, dc):
   157         """
   157         """
   158         Draw button in Graphic Viewer
   158         Draw button in Graphic Viewer
   159         @param dc: wx.DC object corresponding to Graphic Viewer device context
   159         @param dc: wx.DC object corresponding to Graphic Viewer device context
   160         """
   160         """