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