Laurent@814: #!/usr/bin/env python Laurent@814: # -*- coding: utf-8 -*- Laurent@814: Laurent@814: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor Laurent@814: #based on the plcopen standard. Laurent@814: # Laurent@814: #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD Laurent@814: # Laurent@814: #See COPYING file for copyrights details. Laurent@814: # Laurent@814: #This library is free software; you can redistribute it and/or Laurent@814: #modify it under the terms of the GNU General Public Laurent@814: #License as published by the Free Software Foundation; either Laurent@814: #version 2.1 of the License, or (at your option) any later version. Laurent@814: # Laurent@814: #This library is distributed in the hope that it will be useful, Laurent@814: #but WITHOUT ANY WARRANTY; without even the implied warranty of Laurent@814: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Laurent@814: #General Public License for more details. Laurent@814: # Laurent@814: #You should have received a copy of the GNU General Public Laurent@814: #License along with this library; if not, write to the Free Software Laurent@814: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Laurent@814: Laurent@814: import wx Laurent@814: Laurent@1169: from controls.CustomToolTip import CustomToolTip, TOOLTIP_WAIT_PERIOD Laurent@1170: Laurent@814: #------------------------------------------------------------------------------- Laurent@1170: # Tool Tip Producer class Laurent@814: #------------------------------------------------------------------------------- Laurent@814: Laurent@814: """ Laurent@1170: Class that implements an element that generate Tool Tip Laurent@814: """ Laurent@814: Laurent@1170: class ToolTipProducer: Laurent@814: Laurent@1170: def __init__(self, parent): Laurent@1170: """ Laurent@1170: Constructor Laurent@1170: @param parent: Parent Viewer Laurent@1170: """ Laurent@1170: self.Parent = parent Laurent@1170: Laurent@1170: self.ToolTip = None Laurent@1170: self.ToolTipPos = None Laurent@1170: Laurent@1170: # Timer for firing Tool tip display Laurent@1170: self.ToolTipTimer = wx.Timer(self.Parent, -1) Laurent@1170: self.Parent.Bind(wx.EVT_TIMER, Laurent@1170: self.OnToolTipTimer, Laurent@1170: self.ToolTipTimer) Laurent@814: Laurent@1170: def __del__(self): Laurent@1170: """ Laurent@1170: Destructor Laurent@1170: """ Laurent@1170: self.DestroyToolTip() Laurent@814: 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() Laurent@1170: 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() Laurent@814: Laurent@1170: def GetToolTipValue(self): Laurent@1170: """ Laurent@1177: Return tool tip text Laurent@1177: Have to be overridden by inherited classes Laurent@1170: @return: Tool tip text (None if not overridden) Laurent@1170: """ Laurent@814: return None Laurent@814: 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() Laurent@1170: Laurent@1170: # Save Tool Tip position Laurent@1170: self.ToolTipPos = pos Laurent@1170: # Start Tool tip firing timer Laurent@1170: self.ToolTipTimer.Start( Laurent@1170: int(TOOLTIP_WAIT_PERIOD * 1000), Laurent@1170: oneShot=True) Laurent@887: 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) Laurent@814: 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 Laurent@1170: Laurent@1170: # Destroy Tool Tip Laurent@814: if self.ToolTip is not None: Laurent@814: self.ToolTip.Destroy() Laurent@814: self.ToolTip = None