Salome HOME
merge from branch BR_V5_DEV
[modules/kernel.git] / src / KERNEL_PY / salome_notebook.py
1 #  Copyright (C) 2008  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
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 #
22 #  File   : salome_notebook.py
23 #  Author : Roman NIKOLAEV, Open CASCADE S.A.S.
24 #  Module : SALOME
25 #  $Header:
26 """
27 Module salome_notebook gives access to Salome Notebook.
28 """
29
30 import salome
31
32 class NoteBook:
33     
34     def __init__(self, Study):
35         self.myStudy = Study
36     
37     def set(self, variableName, variable):
38         """
39         Create (or modify) variable with name "variableName" 
40         and value equal "theValue".
41         """
42         if type(variable) == float:
43             self.myStudy.SetReal(variableName, variable)
44             
45         elif type(variable) == int:
46             self.myStudy.SetInteger(variableName, variable)
47             
48         elif type(variable) == bool:
49             self.myStudy.SetBoolean(variableName, variable)
50             
51     def get(self, variableName):
52         """
53         Return value of the variable with name "variableName".
54         """
55         aResult = None
56         if self.myStudy.IsVariable(variableName):
57             
58             if self.myStudy.IsReal(variableName):
59                 aResult = self.myStudy.GetReal(variableName)
60
61             elif self.myStudy.IsInteger(variableName):
62                 aResult = self.myStudy.GetInteger(variableName)
63
64             elif self.myStudy.IsBoolean(variableName):
65                 aResult = self.myStudy.GetBoolean(variableName)
66                 
67         return aResult
68     
69     def isVariable(self, variableName): 
70         """
71         Return true if variable with name "variableName" 
72         exists in the study, otherwise return false.
73         """
74         return self.myStudy.IsVariable(variableName)
75                 
76 notebook = NoteBook(salome.myStudy)