~ubuntu-branches/ubuntu/hardy/gnue-common/hardy

« back to all changes in this revision

Viewing changes to src/events/Event.py

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2005-03-09 11:06:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050309110631-8gvvn39q7tjz1kj6
Tags: upstream-0.5.14
ImportĀ upstreamĀ versionĀ 0.5.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# This file is part of GNU Enterprise.
 
3
#
 
4
# GNU Enterprise is free software; you can redistribute it
 
5
# and/or modify it under the terms of the GNU General Public
 
6
# License as published by the Free Software Foundation; either
 
7
# version 2, or (at your option) any later version.
 
8
#
 
9
# GNU Enterprise is distributed in the hope that it will be
 
10
# useful, but WITHOUT ANY WARRANTY; without even the implied
 
11
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 
12
# PURPOSE. See the GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public
 
15
# License along with program; see the file COPYING. If not,
 
16
# write to the Free Software Foundation, Inc., 59 Temple Place
 
17
# - Suite 330, Boston, MA 02111-1307, USA.
 
18
#
 
19
# Copyright 2000-2005 Free Software Foundation
 
20
#
 
21
# FILE:
 
22
# Event.py
 
23
#
 
24
# DESCRIPTION:
 
25
#
 
26
# NOTES:
 
27
#
 
28
 
 
29
#
 
30
# Basic event passed between items
 
31
#
 
32
# If event = Event('MYEVENT',x=1, y=2, object=MyObject), then
 
33
#   event.event == 'MYEVENT', event.x = 1,
 
34
#   event.y == 2, and event.object == MyObject
 
35
#
 
36
class Event:
 
37
  """
 
38
  An Event is the actual event object passed back and forth between the event
 
39
  listeners.
 
40
 
 
41
  Any parameters passed to the Event's __init__ are added as attributes of the
 
42
  event. The first attribute, however, should always be the case-sensitive
 
43
  event name.
 
44
 
 
45
  Creating an Event:
 
46
 
 
47
  >>> myEvent = Event('myEventName', color='Blue', x=1, y=2)
 
48
  >>> myEvent.color
 
49
  'Blue'
 
50
  >>> myEvent.x
 
51
  1
 
52
  >>> myEvent.y
 
53
  2
 
54
  """
 
55
 
 
56
  def __init__(self, event, data=None, **parms):
 
57
    """
 
58
    @param event: The name of the event.  GNUe event listeners
 
59
                  register the names of the events they wish to 
 
60
                  receive.
 
61
    @type event: string
 
62
    @param data: B{OBSOLETE: Do not use}
 
63
    @param parms: Allows the event to accept any argument names you like.
 
64
                  Examples would be things like
 
65
                     - caller=self
 
66
                     - x=15
 
67
                     - vals={'name':'Bob', 'title':'Mr'}
 
68
    """
 
69
    self.__dict__.update(parms)
 
70
 
 
71
    # TODO: Get rid of data=
 
72
    self.data  = data
 
73
 
 
74
    self.__event__ = event
 
75
    self.__result__ = None
 
76
    self.__dropped__ = 0
 
77
    self.__error__ = 0
 
78
    self.__errortext__ = ""
 
79
    self.__after__ = []
 
80
 
 
81
  def getResult(self):
 
82
    """
 
83
    Returns the result value stored in the event by the L{setResult} function.
 
84
    @return: The result value of the event.
 
85
    @rtype: Any
 
86
    """
 
87
    return self.__result__
 
88
 
 
89
  def setResult(self, value):
 
90
    """
 
91
    Can be used by an event listener to assign a return value to an event.
 
92
    The result will be returned by the event controller's
 
93
    L{dispatchEvent<gnue.common.events.EventController.EventController>} function.
 
94
    It can also be obtained by the L{getResult} function.
 
95
 
 
96
    @param value: The result value to assign to the event.  It can 
 
97
                  be anything that is concidered valid python.
 
98
    """
 
99
    self.__result__ = value
 
100
 
 
101
  def getEvent(self):
 
102
    """
 
103
    Returns the name of the event.
 
104
    @return: The name of the event
 
105
    @rtype: string
 
106
    """
 
107
    return self.__event__
 
108
 
 
109
  def drop(self):
 
110
    """
 
111
    When called the event will be dropped.  No additional
 
112
    event listeners will receive the event.
 
113
    """
 
114
    self.__dropped__ = 1
 
115
 
 
116
  def setError(self, text = ""):
 
117
    """
 
118
    Sets the event error flag.  Setting the error
 
119
    also causes the event to be dropped in the
 
120
    same mannor as the L{drop} function.
 
121
 
 
122
    @param text: Text describing the error.
 
123
    @type text: string
 
124
    """
 
125
    self.__error__ = 1
 
126
    self.__errortext__ = text
 
127
 
 
128
  def dispatchAfter(self, *args, **parms):
 
129
    """
 
130
    Adds an event to the event queue that will be 
 
131
    dispatched upon this events completion.  The arguments
 
132
    to this function match those used in creating an event.
 
133
 
 
134
    Sample Usage:
 
135
 
 
136
    >>> from gnue.common.events.Event import *
 
137
    >>> myEvent = Event('myEventName', color='Blue', x=1, y=2)
 
138
    >>> myEvent.dispatchAfter('theNextEvent',name='FSF')
 
139
    """    
 
140
    self.__after__.append((args, parms))