Laurent@814: #!/usr/bin/env python
Laurent@814: # -*- coding: utf-8 -*-
Laurent@814: 
andrej@1571: # This file is part of Beremiz, a Integrated Development Environment for
andrej@1571: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
Laurent@814: #
andrej@1571: # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
Laurent@814: #
andrej@1571: # See COPYING file for copyrights details.
Laurent@814: #
andrej@1571: # This program is free software; you can redistribute it and/or
andrej@1571: # modify it under the terms of the GNU General Public License
andrej@1571: # as published by the Free Software Foundation; either version 2
andrej@1571: # of the License, or (at your option) any later version.
Laurent@814: #
andrej@1571: # This program is distributed in the hope that it will be useful,
andrej@1571: # but WITHOUT ANY WARRANTY; without even the implied warranty of
andrej@1571: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
andrej@1571: # GNU General Public License for more details.
Laurent@814: #
andrej@1571: # You should have received a copy of the GNU General Public License
andrej@1571: # along with this program; if not, write to the Free Software
andrej@1571: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
Laurent@814: 
andrej@1881: 
kinsamanka@3750: 
Laurent@814: import wx
Laurent@814: 
Laurent@1169: from controls.CustomToolTip import CustomToolTip, TOOLTIP_WAIT_PERIOD
andrej@1730: 
andrej@1782: 
andrej@1782: # -------------------------------------------------------------------------------
Laurent@1170: #                           Tool Tip Producer class
andrej@1782: # -------------------------------------------------------------------------------
Laurent@814: 
Laurent@814: 
andrej@1831: class ToolTipProducer(object):
andrej@1736:     """
andrej@1736:     Class that implements an element that generate Tool Tip
andrej@1736:     """
andrej@1730: 
Laurent@1170:     def __init__(self, parent):
Laurent@1170:         """
Laurent@1170:         Constructor
Laurent@1170:         @param parent: Parent Viewer
Laurent@1170:         """
Laurent@1170:         self.Parent = parent
andrej@1730: 
Laurent@1170:         self.ToolTip = None
Laurent@1170:         self.ToolTipPos = None
andrej@1730: 
Laurent@1170:         # Timer for firing Tool tip display
Laurent@1170:         self.ToolTipTimer = wx.Timer(self.Parent, -1)
andrej@1730:         self.Parent.Bind(wx.EVT_TIMER,
andrej@1768:                          self.OnToolTipTimer,
andrej@1768:                          self.ToolTipTimer)
andrej@1730: 
Laurent@1170:     def OnToolTipTimer(self, event):
Laurent@1170:         """
Laurent@1170:         Callback for Tool Tip firing timer Event
Laurent@1170:         @param event: Tool tip text
Laurent@1170:         """
Laurent@1170:         # Get Tool Tip text
Laurent@1170:         value = self.GetToolTipValue()
andrej@1730: 
Laurent@1170:         if value is not None and self.ToolTipPos is not None:
Laurent@1170:             # Create Tool Tip
Laurent@1170:             self.ToolTip = CustomToolTip(self.Parent, value)
Laurent@1170:             self.ToolTip.SetToolTipPosition(self.ToolTipPos)
Laurent@1170:             self.ToolTip.Show()
andrej@1730: 
Laurent@1170:     def GetToolTipValue(self):
Laurent@1170:         """
Laurent@1177:         Return tool tip text
andrej@1730:         Have to be overridden by inherited classes
andrej@1730:         @return: Tool tip text (None if not overridden)
Laurent@1170:         """
Laurent@814:         return None
andrej@1730: 
Laurent@1170:     def DisplayToolTip(self, pos):
Laurent@1170:         """
Laurent@1170:         Display Tool tip
Laurent@1170:         @param pos: Tool tip position
Laurent@1170:         """
Laurent@1170:         # Destroy current displayed Tool tip
Laurent@1170:         self.DestroyToolTip()
andrej@1730: 
Laurent@1170:         # Save Tool Tip position
Laurent@1170:         self.ToolTipPos = pos
Laurent@1170:         # Start Tool tip firing timer
Laurent@1170:         self.ToolTipTimer.Start(
andrej@1730:             int(TOOLTIP_WAIT_PERIOD * 1000),
Laurent@1170:             oneShot=True)
andrej@1730: 
Laurent@1170:     def SetToolTipText(self, text):
Laurent@1170:         """
Laurent@1170:         Set current Tool tip text
Laurent@1170:         @param text: Tool tip Text
Laurent@1170:         """
Laurent@1170:         if self.ToolTip is not None:
Laurent@1170:             self.ToolTip.SetTip(text)
andrej@1730: 
Laurent@1170:     def DestroyToolTip(self):
Laurent@1170:         """
Laurent@1170:         Destroy current displayed Tool Tip
Laurent@1170:         """
Laurent@1170:         # Stop Tool tip firing timer
Laurent@814:         self.ToolTipTimer.Stop()
Laurent@814:         self.ToolTipPos = None
andrej@1730: 
Laurent@1170:         # Destroy Tool Tip
Laurent@814:         if self.ToolTip is not None:
Laurent@814:             self.ToolTip.Destroy()
Laurent@814:             self.ToolTip = None