controls/CustomToolTip.py
changeset 1221 d18ccec78117
parent 1172 dff0a4e40808
child 1571 486f94a8032c
equal deleted inserted replaced
1220:16c283246241 1221:d18ccec78117
    48         @param restricted: Tool tip must follow size restriction in line and 
    48         @param restricted: Tool tip must follow size restriction in line and 
    49             characters number defined (default True)
    49             characters number defined (default True)
    50         """
    50         """
    51         wx.PopupWindow.__init__(self, parent)
    51         wx.PopupWindow.__init__(self, parent)
    52         
    52         
    53         self.CurrentPosition = wx.Point(0, 0)
       
    54         self.Restricted = restricted
    53         self.Restricted = restricted
    55         
    54         
    56         self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
    55         self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
    57         self.SetTip(tip)
    56         self.SetTip(tip)
    58         
    57         
   124         # Get screen size to prevent tool tip to go out of the screen
   123         # Get screen size to prevent tool tip to go out of the screen
   125         screen_width, screen_height = wx.GetDisplaySize()
   124         screen_width, screen_height = wx.GetDisplaySize()
   126         
   125         
   127         # Calculate position of tool tip to stay in screen limits
   126         # Calculate position of tool tip to stay in screen limits
   128         tip_width, tip_height = self.GetToolTipSize()
   127         tip_width, tip_height = self.GetToolTipSize()
   129         self.CurrentPosition = wx.Point(
   128         self.SetPosition(wx.Point(
   130             max(0, min(pos.x, screen_width - tip_width)),
   129             max(0, min(pos.x, screen_width - tip_width)),
   131             max(0, min(pos.y, screen_height - tip_height))) 
   130             max(0, min(pos.y, screen_height - tip_height))))
   132         
       
   133         self.SetPosition(pos)
       
   134     
   131     
   135     def GetToolTipSize(self):
   132     def GetToolTipSize(self):
   136         """
   133         """
   137         Get tool tip size according to tip text and restriction
   134         Get tool tip size according to tip text and restriction
   138         @return: wx.Size(tool_tip_width, tool_tip_height)
   135         @return: wx.Size(tool_tip_width, tool_tip_height)
   156         Refresh tip on screen
   153         Refresh tip on screen
   157         """
   154         """
   158         # Prevent to call this function if tool tip destroyed
   155         # Prevent to call this function if tool tip destroyed
   159         if self:
   156         if self:
   160             # Refresh tool tip size and position
   157             # Refresh tool tip size and position
   161             self.SetSize(self.GetToolTipSize())
   158             self.SetClientSize(self.GetToolTipSize())
   162             self.SetPosition(self.CurrentPosition)
       
   163             
   159             
   164             # Redraw tool tip
   160             # Redraw tool tip
   165             self.Refresh()
   161             self.Refresh()
   166     
   162     
   167     def OnPaint(self, event):
   163     def OnPaint(self, event):