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