Salome HOME
Copyright update 2021
[tools/yacsgen.git] / Examples / pygui1 / components.py
1 # Copyright (C) 2009-2021  EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 import os
21
22 #import context from ..
23 exec(compile(open("../context.py").read(), "../context.py", 'exec'))
24
25 from module_generator import *
26
27 defs="""
28 """
29
30 body="""
31       c=a+b
32       d=a-b
33 """
34
35 idldefs="""
36 #include "myinterface.idl"
37 """
38
39 compodefs=r"""
40 import SALOME_DriverPy
41 import traceback
42
43 class A(SALOME_DriverPy.SALOME_DriverPy_i):
44     def __init__(self):
45       SALOME_DriverPy.SALOME_DriverPy_i.__init__(self,"pycompos")
46       return
47
48     def createObject( self, study, name ):
49       "Create object.  "
50       try:
51         print (study,name)
52         builder = study.NewBuilder()
53         father = study.FindComponent( "pycompos" )
54         if father is None:
55             father = builder.NewComponent( "pycompos" )
56             attr = builder.FindOrCreateAttribute( father, "AttributeName" )
57             attr.SetValue( "pycompos" )
58
59         object  = builder.NewObject( father )
60         attr    = builder.FindOrCreateAttribute( object, "AttributeName" )
61         attr.SetValue( name )
62       except:
63         traceback.print_exc()
64
65     def DumpPython( self, study, isPublished ):
66        abuffer = []
67        abuffer.append( "def RebuildData( theStudy ):" )
68        names = []
69        father = study.FindComponent( "pycompos" )
70        if father:
71            iter = study.NewChildIterator( father )
72            while iter.More():
73                name = iter.Value().GetName()
74                if name: names.append( name )
75                iter.Next()
76                pass
77            pass
78        if names:
79            abuffer += [ "  from salome import lcc" ]
80            abuffer += [ "  import pycompos_ORB" ]
81            abuffer += [ "  " ]
82            abuffer += [ "  compo = lcc.FindOrLoadComponent( 'FactoryServerPy', 'pycompos' )" ]
83            abuffer += [ "  " ]
84            abuffer += [ "  compo.createObject( theStudy, '%s' )" % name for name in names ]
85            pass
86        abuffer += [ "  " ]
87
88        return ("\n".join( abuffer ), 1)
89
90 """
91
92 c1=PYComponent("pycompos",services=[
93           Service("s1",inport=[("a","double"),("b","double")],
94                        outport=[("c","double"),("d","double")],
95                        defs=defs,body=body,
96                  ),
97          ],
98               idls=["*.idl"],
99               interfacedefs=idldefs,
100               inheritedinterface="Idl_A",
101               compodefs=compodefs,
102               inheritedclass="A",
103          )
104
105 modul=Module("pycompos",components=[c1],prefix="./install",
106               doc=["*.rst","*.png"],
107               gui=["pycomposGUI.py","demo.ui","*.png"],
108             )
109
110 g=Generator(modul,context)
111 g.generate()
112 g.configure()
113 g.make()
114 g.install()
115 g.make_appli("appli", restrict=["KERNEL"], altmodules={"GUI":GUI_ROOT_DIR, "YACS":YACS_ROOT_DIR})
116
117