Salome HOME
f16ced47c5392ba54e0ea0b5d806cd032f369dd8
[modules/adao.git] / src / daSalome / daGUI / daUtils / adaoEficasEvent.py
1 # -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2010 EDF R&D
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 __author__="AndrĂ© Ribes - EDF R&D"
22
23 class DevelException(Exception):
24     def __init__(self, message):
25         """Canonical constructor"""
26         Exception.__init__(self,message)
27
28 #
29 # ==============================================================================
30 # Interface of an eficas observer (for implementing the subject/observer pattern)
31 # ==============================================================================
32 #
33 from daGuiImpl.enumerate import Enumerate
34
35 class EficasObserver:
36     """
37     This class specifies the interface of an eficas observer. See example at the
38     bottom of this file.
39     """
40     def processEficasEvent(self, eficasWrapper, eficasEvent):
41         """
42         This function should be implemented in the concrete Observer.
43         @param eficasWrapper the instance of the source EficasWrapper
44         @param eficasEvent the emitted event (instance of EficasEvent)
45         """
46         raise DevelException("processEficasEvent not implemented yet")
47
48 class EficasEvent:
49     EVENT_TYPES=Enumerate([
50         'CLOSE',
51         'SAVE',
52         'DESTROY',
53         'OPEN',
54         'REOPEN',
55         'NEW',
56         'TABCHANGED'
57     ])
58
59     def __init__(self,eventType,callbackId=None):
60         """
61         Creates an eficas event to be used by an EficasWrapper to notify an
62         EficasObserver.
63
64         The eventType depends of the context of creation. It specify the nature
65         of the event inside EficasWrapper that triggers the creation of this instance.
66
67         The callbackId is an object used by the EficasObserver to map the
68         notification (this received event) with the initial event (callback)
69         This object can be anything and has to be defined through a convention
70         that both the EficasWrapper and the EficasObserver can understand.
71         Typically, the eficas observer set the callback id to the eficas wrapper
72         before running the asynchronous show. Then, when an event is raised by
73         the eficas wrapper toward its observer, it embeds the callback id so that
74         the observer can match the received event to the initial trigger context.
75
76         @param the eventType to be choosen in the EVENT_TYPES
77         @param callbackId an arbitrary data object
78         """
79         if not self.EVENT_TYPES.isValid(eventType):
80             raise DevelException("The event type "+str(eventType)+" is not defined")
81
82         self.eventType = eventType
83         self.callbackId = callbackId