source: trunk/src/testing/dim/eventHandler.py @ 4

Revision 4, 3.6 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
1############################################################################
2#
3# DIM - A Direct Interaction Manager for SAGE
4# Copyright (C) 2007 Electronic Visualization Laboratory,
5# University of Illinois at Chicago
6#
7# All rights reserved.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions are met:
11#
12#  * Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14#  * Redistributions in binary form must reproduce the above
15#    copyright notice, this list of conditions and the following disclaimer
16#    in the documentation and/or other materials provided with the distribution.
17#  * Neither the name of the University of Illinois at Chicago nor
18#    the names of its contributors may be used to endorse or promote
19#    products derived from this software without specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32#
33# Direct questions, comments etc about SAGE UI to www.evl.uic.edu/cavern/forum
34#
35# Author: Ratko Jagodic
36#       
37############################################################################
38
39
40
41from globals import *
42
43
44
45class EventHandler:
46    """ The base class for any objects wanting to receive device events.
47        Make sure the bounds member is up to date since it's used
48        in deciding whether an event should be delivered to it or not.
49        Also, make sure you update the z value (if applicable)
50
51        Example of registering for events:
52        ----------------------------------------
53        self.registerForEvent(EVT_CLICK, self.onClick)
54        def onClick(self, event):
55            # do something with the click event...
56    """
57
58    def __init__(self):
59        self.evtMgr = getEvtMgr()  # for registering for events
60        self.captured = False
61        self.bounds = Bounds()     # the bounds for detecting the events
62        self.displayId = 0         # the bounds will depend on this...
63        self.z = TOP_Z   # always on top
64        self.__callbacks = {}  # key eventId, value=callback
65
66 ##        # kind of a hack to make sure that enter and
67##         # leave events get delivered properly
68##         self.registerForEvent(EVT_MOVE, self.dummyOnMove)
69
70
71##     def dummyOnMove(self, event):
72##         # kind of a hack to make sure that enter and
73##         # leave events get delivered properly
74##         pass
75       
76
77    def registerForEvent(self, eventId, callback):
78        self.__callbacks[eventId] = callback
79        self.evtMgr.register(eventId, callback)
80
81
82    def getCallback(self, eventId):
83        if eventId in self.__callbacks:
84            return self.__callbacks[eventId]
85
86
87    def destroy(self):
88        """ may be overridden but you need to call this base class' method """
89        self.evtMgr.unregister(self.__callbacks)
90       
91       
Note: See TracBrowser for help on using the repository browser.