1 # Copyright (C) 2009-2022 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
29 # Get SALOME PyQt interface
31 sgPyQt = SalomePyQt.SalomePyQt()
33 # Get SALOME Swig interface
35 sg = libSALOME_Swig.SALOMEGUI_Swig()
44 return sgPyQt.getStudyId()
50 studyId = _getStudyId()
51 study = salome.myStudyManager.GetStudyByID( studyId )
54 # called when module is initialized
55 # return map of popup windows to be used by the module
58 wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
59 wm[SalomePyQt.WT_PyConsole] = Qt.BottomDockWidgetArea
62 # called when module is initialized
63 # return list of 2d/3d views to be used ny the module
67 # called when module is activated
68 # returns True if activating is successfull and False otherwise
70 # create top-level menu
71 mid = sgPyQt.createMenu( "pycompos", -1, 90, sgPyQt.defaultMenuGroup() )
73 tid = sgPyQt.createTool( "pycompos" )
74 # create actions and fill menu and toolbar with actions
75 a = sgPyQt.createAction( 941, "Hello", "Hello", "Show hello dialog box" ,"exec.png")
76 sgPyQt.createMenu( a, mid )
77 sgPyQt.createTool( a, tid )
78 a = sgPyQt.createAction( 942, "Hello2", "Hello2", "Show hello2 dialog box" ,"exec.png")
79 sgPyQt.createMenu( a, mid )
80 sgPyQt.createTool( a, tid )
81 a = sgPyQt.createAction( 943, "Create object", "Create object", "Create object","exec.png" )
82 sgPyQt.createMenu( a, mid )
83 sgPyQt.createTool( a, tid )
87 # called when module is deactivated
95 _engine= salome.lcc.FindOrLoadComponent( "FactoryServerPy", "pycompos" )
103 default_name = str( sgPyQt.stringSetting( "pycompos", "def_obj_name", "Object" ).lstrip().rstrip() )
104 # generate object name
105 __objectid__ = __objectid__ + 1
106 name = "%s_%d" % ( default_name, __objectid__ )
108 getEngine().createObject( _getStudy(), name )
109 print(getEngine().s1(4,5))
110 print(getEngine().ComponentDataType())
111 sg.updateObjBrowser( True )
113 class DemoImpl(QtWidgets.QDialog):
114 def __init__(self, *args):
115 super(DemoImpl, self).__init__(*args)
117 uic.loadUi(os.path.join(os.environ["pycompos_ROOT_DIR"],"share","salome","resources","pycompos","demo.ui"), self)
120 def on_button1_clicked(self):
121 for s in "This is a demo".split(" "):
124 # called when GUI action is activated
125 # action ID is passed as parameter
126 def OnGUIEvent( commandID ):
127 print("pycompos.OnGUIEvent(): command = %d" % commandID)
129 widget=QMainWindow(sgPyQt.getDesktop())
130 mywidget = QLabel("Hello world!", widget)
131 widget.setCentralWidget(mywidget)
135 widget = DemoImpl(sgPyQt.getDesktop())