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