graphics/ToolTipProducer.py
changeset 1170 074e46cdedbc
parent 1169 53e4a2b775a7
child 1177 4cbbc58b91b4
equal deleted inserted replaced
1169:53e4a2b775a7 1170:074e46cdedbc
       
     1 #!/usr/bin/env python
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
       
     5 #based on the plcopen standard. 
       
     6 #
       
     7 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
       
     8 #
       
     9 #See COPYING file for copyrights details.
       
    10 #
       
    11 #This library is free software; you can redistribute it and/or
       
    12 #modify it under the terms of the GNU General Public
       
    13 #License as published by the Free Software Foundation; either
       
    14 #version 2.1 of the License, or (at your option) any later version.
       
    15 #
       
    16 #This library is distributed in the hope that it will be useful,
       
    17 #but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    19 #General Public License for more details.
       
    20 #
       
    21 #You should have received a copy of the GNU General Public
       
    22 #License along with this library; if not, write to the Free Software
       
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    24 
       
    25 import wx
       
    26 
       
    27 from controls.CustomToolTip import CustomToolTip, TOOLTIP_WAIT_PERIOD
       
    28     
       
    29 #-------------------------------------------------------------------------------
       
    30 #                           Tool Tip Producer class
       
    31 #-------------------------------------------------------------------------------
       
    32 
       
    33 """
       
    34 Class that implements an element that generate Tool Tip
       
    35 """
       
    36 
       
    37 class ToolTipProducer:
       
    38     
       
    39     def __init__(self, parent):
       
    40         """
       
    41         Constructor
       
    42         @param parent: Parent Viewer
       
    43         """
       
    44         self.Parent = parent
       
    45         
       
    46         self.ToolTip = None
       
    47         self.ToolTipPos = None
       
    48         
       
    49         # Timer for firing Tool tip display
       
    50         self.ToolTipTimer = wx.Timer(self.Parent, -1)
       
    51         self.Parent.Bind(wx.EVT_TIMER, 
       
    52             self.OnToolTipTimer, 
       
    53             self.ToolTipTimer)
       
    54     
       
    55     def __del__(self):
       
    56         """
       
    57         Destructor
       
    58         """
       
    59         self.DestroyToolTip()
       
    60     
       
    61     def OnToolTipTimer(self, event):
       
    62         """
       
    63         Callback for Tool Tip firing timer Event
       
    64         @param event: Tool tip text
       
    65         """
       
    66         # Get Tool Tip text
       
    67         value = self.GetToolTipValue()
       
    68         
       
    69         if value is not None and self.ToolTipPos is not None:
       
    70             # Create Tool Tip
       
    71             self.ToolTip = CustomToolTip(self.Parent, value)
       
    72             self.ToolTip.SetToolTipPosition(self.ToolTipPos)
       
    73             self.ToolTip.Show()
       
    74     
       
    75     def GetToolTipValue(self):
       
    76         """
       
    77         Generic method that have to be overridden by derived classes 
       
    78         @return: Tool tip text (None if not overridden) 
       
    79         """
       
    80         return None
       
    81     
       
    82     def DisplayToolTip(self, pos):
       
    83         """
       
    84         Display Tool tip
       
    85         @param pos: Tool tip position
       
    86         """
       
    87         # Destroy current displayed Tool tip
       
    88         self.DestroyToolTip()
       
    89         
       
    90         # Save Tool Tip position
       
    91         self.ToolTipPos = pos
       
    92         # Start Tool tip firing timer
       
    93         self.ToolTipTimer.Start(
       
    94             int(TOOLTIP_WAIT_PERIOD * 1000), 
       
    95             oneShot=True)
       
    96     
       
    97     def SetToolTipText(self, text):
       
    98         """
       
    99         Set current Tool tip text
       
   100         @param text: Tool tip Text
       
   101         """
       
   102         if self.ToolTip is not None:
       
   103             self.ToolTip.SetTip(text)
       
   104     
       
   105     def DestroyToolTip(self):
       
   106         """
       
   107         Destroy current displayed Tool Tip
       
   108         """
       
   109         # Stop Tool tip firing timer
       
   110         self.ToolTipTimer.Stop()
       
   111         self.ToolTipPos = None
       
   112         
       
   113         # Destroy Tool Tip
       
   114         if self.ToolTip is not None:
       
   115             self.ToolTip.Destroy()
       
   116             self.ToolTip = None