2
# This file is part of GNU Enterprise.
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.
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.
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.
19
# Copyright 2000-2005 Free Software Foundation
30
# Basic event passed between items
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
38
An Event is the actual event object passed back and forth between the event
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
47
>>> myEvent = Event('myEventName', color='Blue', x=1, y=2)
56
def __init__(self, event, data=None, **parms):
58
@param event: The name of the event. GNUe event listeners
59
register the names of the events they wish to
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
67
- vals={'name':'Bob', 'title':'Mr'}
69
self.__dict__.update(parms)
71
# TODO: Get rid of data=
74
self.__event__ = event
75
self.__result__ = None
78
self.__errortext__ = ""
83
Returns the result value stored in the event by the L{setResult} function.
84
@return: The result value of the event.
87
return self.__result__
89
def setResult(self, value):
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.
96
@param value: The result value to assign to the event. It can
97
be anything that is concidered valid python.
99
self.__result__ = value
103
Returns the name of the event.
104
@return: The name of the event
107
return self.__event__
111
When called the event will be dropped. No additional
112
event listeners will receive the event.
116
def setError(self, text = ""):
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.
122
@param text: Text describing the error.
126
self.__errortext__ = text
128
def dispatchAfter(self, *args, **parms):
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.
136
>>> from gnue.common.events.Event import *
137
>>> myEvent = Event('myEventName', color='Blue', x=1, y=2)
138
>>> myEvent.dispatchAfter('theNextEvent',name='FSF')
140
self.__after__.append((args, parms))