1 # Copyright (C) 2009-2021 EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 from PyQt5.QtCore import *
23 from PyQt5.QtWidgets import *
24 from PyQt5 import QtCore, uic, QtWidgets
25 from PyQt5.QtWebKitWidgets import QWebView
30 # Get SALOME PyQt interface
32 sgPyQt = SalomePyQt.SalomePyQt()
34 # Get SALOME Swig interface
36 sg = libSALOME_Swig.SALOMEGUI_Swig()
45 return sgPyQt.getStudyId()
51 studyId = _getStudyId()
52 study = salome.myStudyManager.GetStudyByID( studyId )
55 # called when module is initialized
56 # return map of popup windows to be used by the module
59 wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
60 wm[SalomePyQt.WT_PyConsole] = Qt.BottomDockWidgetArea
63 # called when module is initialized
64 # return list of 2d/3d views to be used ny the module
68 # called when module is activated
69 # returns True if activating is successfull and False otherwise
71 # create top-level menu
72 mid = sgPyQt.createMenu( "pycompos", -1, 90, sgPyQt.defaultMenuGroup() )
74 tid = sgPyQt.createTool( "pycompos" )
75 # create actions and fill menu and toolbar with actions
76 a = sgPyQt.createAction( 941, "Hello", "Hello", "Show hello dialog box" ,"exec.png")
77 sgPyQt.createMenu( a, mid )
78 sgPyQt.createTool( a, tid )
79 a = sgPyQt.createAction( 942, "Hello2", "Hello2", "Show hello2 dialog box" ,"exec.png")
80 sgPyQt.createMenu( a, mid )
81 sgPyQt.createTool( a, tid )
82 a = sgPyQt.createAction( 943, "Create object", "Create object", "Create object","exec.png" )
83 sgPyQt.createMenu( a, mid )
84 sgPyQt.createTool( a, tid )
88 # called when module is deactivated
96 _engine= salome.lcc.FindOrLoadComponent( "FactoryServerPy", "pycompos" )
104 default_name = str( sgPyQt.stringSetting( "pycompos", "def_obj_name", "Object" ).lstrip().rstrip() )
105 # generate object name
106 __objectid__ = __objectid__ + 1
107 name = "%s_%d" % ( default_name, __objectid__ )
109 getEngine().createObject( _getStudy(), name )
110 print(getEngine().s1(4,5))
111 print(getEngine().ComponentDataType())
112 sg.updateObjBrowser( True )
114 class DemoImpl(QtWidgets.QDialog):
115 def __init__(self, *args):
116 super(DemoImpl, self).__init__(*args)
118 uic.loadUi(os.path.join(os.environ["pycompos_ROOT_DIR"],"share","salome","resources","pycompos","demo.ui"), self)
121 def on_button1_clicked(self):
122 for s in "This is a demo".split(" "):
125 # called when GUI action is activated
126 # action ID is passed as parameter
127 def OnGUIEvent( commandID ):
128 print("pycompos.OnGUIEvent(): command = %d" % commandID)
130 widget=QMainWindow(sgPyQt.getDesktop())
131 web = QWebView(widget)
132 page=os.path.join(os.environ["pycompos_ROOT_DIR"],"share","doc","salome","gui","pycompos","index.html")
134 widget.setCentralWidget(web)
138 widget = DemoImpl(sgPyQt.getDesktop())