\code
def createPreferences():
- if verbose() : print "PYHELLOGUI.createPreferences()"
- gid = sgPyQt.addPreference( "General" )
- gid = sgPyQt.addPreference( "Object creation", gid )
- pid = sgPyQt.addPreference( "Default name", gid, SalomePyQt.PT_String, "PYHELLO", "def_obj_name" )
- pid = sgPyQt.addPreference( "Default creation mode", gid, SalomePyQt.PT_Selector, "PYHELLO", "creation_mode" )
- strings = QStringList()
- strings.append( "Default name" )
- strings.append( "Generate name" )
- strings.append( "Ask name" )
- indexes = []
- indexes.append( QVariant(0) )
- indexes.append( QVariant(1) )
- indexes.append( QVariant(2) )
- sgPyQt.setPreferenceProperty( pid, "strings", QVariant( strings ) )
- sgPyQt.setPreferenceProperty( pid, "indexes", QVariant( indexes ) )
+ if verbose():
- print("PYHELLOGUI.createPreferences() : study : %d" % _getStudyId())
++ print("PYHELLOGUI.createPreferences()")
+ gid = sgPyQt.addPreference("General")
+ gid = sgPyQt.addPreference("Object creation", gid)
+ sgPyQt.addPreference("Default name", gid, SalomePyQt.PT_String, "PYHELLO", "def_obj_name")
+ pid = sgPyQt.addPreference("Default creation mode", gid, SalomePyQt.PT_Selector, "PYHELLO", "creation_mode")
+ strings = ["Default name", "Generate name", "Ask name"]
+ indexes = [0, 1, 2]
+ sgPyQt.setPreferenceProperty(pid, "strings", strings)
+ sgPyQt.setPreferenceProperty(pid, "indexes", indexes)
+ pid = sgPyQt.addPreference("Password", gid, SalomePyQt.PT_String, "PYHELLO", "Password")
+ sgPyQt.setPreferenceProperty(pid, "echo", 2)
pass
\endcode
\code
def windows():
- if verbose() : print "PYHELLOGUI.windows()"
- if verbose() : print("PYHELLOGUI.windows() : study : %d" % _getStudyId())
++ if verbose() : print("PYHELLOGUI.windows()")
wm = {}
wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
wm[SalomePyQt.WT_PyConsole] = Qt.BottomDockWidgetArea
"""
Dump module data to the Python script.
"""
- def DumpPython( self, study, isPublished, isMultiFile ):
+ def DumpPython( self, isPublished, isMultiFile ):
abuffer = []
names = []
+ study = getStudy()
father = study.FindComponent( moduleName() )
if father:
- iter = study.NewChildIterator( father )
- while iter.More():
- name = iter.Value().GetName()
+ iterator = study.NewChildIterator(father)
+ while iterator.More():
+ name = iterator.Value().GetName()
if name: names.append( name )
- iter.Next()
+ iterator.Next()
pass
pass
if names:
- abuffer += [ "from salome import lcc" ]
+ abuffer += [ "import salome" ]
abuffer += [ "import PYHELLO_ORB" ]
abuffer += [ "" ]
- abuffer += [ "pyhello = lcc.FindOrLoadComponent('FactoryServerPy', '%s')" % moduleName() ]
+ abuffer += [ "pyhello = salome.lcc.FindOrLoadComponent( 'FactoryServerPy', '%s' )" % moduleName() ]
abuffer += [ "" ]
- abuffer += [ "pyhello.createObject( '%s' )" % name for name in names ]
- abuffer += [ "pyhello.createObject(theStudy, '%s')" % name for name in names ]
++ abuffer += [ "pyhello.createObject( '%s')" % name for name in names ]
abuffer += [ "" ]
pass
if isMultiFile:
- abuffer = [ " " + s for s in abuffer ]
- abuffer[0:0] = [ "def RebuildData():" ]
- abuffer += [ " pass" ]
+ abuffer = [ " " + s for s in abuffer ]
- abuffer[0:0] = [ "def RebuildData( theStudy ):" ]
++ abuffer[0:0] = [ "def RebuildData():" ]
+ abuffer += [ " pass" ]
abuffer += [ "\0" ]
return ("\n".join( abuffer ), 1)
# ---
#
import traceback
- import os
- from qtsalome import *
- from PYHELLO_utils import *
+ from PYHELLO_utils import (moduleName, getStudyManager, getObjectID, verbose,
+ moduleID, objectID, getEngineIOR, getEngine)
+ from SalomePyQt import (SalomePyQt, WT_ObjectBrowser, WT_PyConsole, PT_Selector, # @UnresolvedImport
+ PT_String) # @UnresolvedImport
+ from qtsalome import (QDialog, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, # @UnresolvedImport
+ QPushButton, QMessageBox, QInputDialog, Qt) # @UnresolvedImport
+ from salome.kernel import termcolor
+ from salome.kernel.logger import Logger
+ import libSALOME_Swig
+
+
+ logger = Logger(moduleName(), color=termcolor.RED_FG)
+import salome
+
################################################
# GUI context class
# Used to store actions, menus, toolbars, etc...
# called when module is initialized
# perform initialization actions
def initialize():
- if verbose() : print "PYHELLOGUI.initialize()"
- if verbose() : print("PYHELLOGUI.initialize() : study : %d" % _getStudyId())
++ if verbose() : print("PYHELLOGUI.initialize()")
# set default preferences values
if not sgPyQt.hasSetting( "PYHELLO", "def_obj_name"):
sgPyQt.addSetting( "PYHELLO", "def_obj_name", GUIcontext.DEFAULT_NAME )
# called when module is initialized
# return map of popup windows to be used by the module
def windows():
- if verbose() : print "PYHELLOGUI.windows()"
- if verbose() : print("PYHELLOGUI.windows() : study : %d" % _getStudyId())
++ if verbose() : print("PYHELLOGUI.windows()")
wm = {}
- wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
- wm[SalomePyQt.WT_PyConsole] = Qt.BottomDockWidgetArea
+ wm[WT_ObjectBrowser] = Qt.LeftDockWidgetArea
+ wm[WT_PyConsole] = Qt.BottomDockWidgetArea
return wm
# called when module is initialized
# return list of 2d/3d views to be used ny the module
def views():
- if verbose() : print "PYHELLOGUI.views()"
- if verbose() : print("PYHELLOGUI.views() : study : %d" % _getStudyId())
++ if verbose() : print("PYHELLOGUI.views()")
return []
# called when module is initialized
# export module's preferences
def createPreferences():
- if verbose() : print "PYHELLOGUI.createPreferences()"
- gid = sgPyQt.addPreference( "General" )
- gid = sgPyQt.addPreference( "Object creation", gid )
- pid = sgPyQt.addPreference( "Default name", gid, SalomePyQt.PT_String, "PYHELLO", "def_obj_name" )
- pid = sgPyQt.addPreference( "Default creation mode", gid, SalomePyQt.PT_Selector, "PYHELLO", "creation_mode" )
- strings = QStringList()
- strings.append( "Default name" )
- strings.append( "Generate name" )
- strings.append( "Ask name" )
- indexes = []
- indexes.append( QVariant(0) )
- indexes.append( QVariant(1) )
- indexes.append( QVariant(2) )
- sgPyQt.setPreferenceProperty( pid, "strings", QVariant( strings ) )
- sgPyQt.setPreferenceProperty( pid, "indexes", QVariant( indexes ) )
- pid = sgPyQt.addPreference( "Password", gid, SalomePyQt.PT_String, "PYHELLO", "Password" )
- sgPyQt.setPreferenceProperty( pid, "echo", QVariant( 2 ) )
+ if verbose():
- print("PYHELLOGUI.createPreferences() : study : %d" % _getStudyId())
++ print("PYHELLOGUI.createPreferences()")
+ gid = sgPyQt.addPreference("General")
+ gid = sgPyQt.addPreference("Object creation", gid)
+ sgPyQt.addPreference("Default name", gid, PT_String, "PYHELLO", "def_obj_name")
+ pid = sgPyQt.addPreference("Default creation mode", gid, PT_Selector, "PYHELLO", "creation_mode")
+ strings = ["Default name", "Generate name", "Ask name"]
+ indexes = [0, 1, 2]
+ sgPyQt.setPreferenceProperty(pid, "strings", strings)
+ sgPyQt.setPreferenceProperty(pid, "indexes", indexes)
+ pid = sgPyQt.addPreference("Password", gid, PT_String, "PYHELLO", "Password")
+ sgPyQt.setPreferenceProperty(pid, "echo", 2)
pass
# called when module is activated
# returns True if activating is successfull and False otherwise
def activate():
- if verbose() : print "PYHELLOGUI.activate()"
- if verbose() : print("PYHELLOGUI.activate() : study : %d" % _getStudyId())
- ctx = _setContext( _getStudyId() )
++ if verbose() : print("PYHELLOGUI.activate()")
+ GUIcontext()
return True
# called when module is deactivated
def deactivate():
- if verbose() : print "PYHELLOGUI.deactivate()"
- if verbose() : print("PYHELLOGUI.deactivate() : study : %d" % _getStudyId())
- pass
-
-# called when active study is changed
-# active study ID is passed as parameter
-def activeStudyChanged( studyID ):
- if verbose() : print("PYHELLOGUI.activeStudyChanged(): study : %d" % studyID)
- ctx = _setContext( _getStudyId() )
++ if verbose() : print("PYHELLOGUI.deactivate()")
pass
# called when popup menu is invoked
# popup menu and menu context are passed as parameters
def createPopupMenu( popup, context ):
- if verbose() : print "PYHELLOGUI.createPopupMenu(): context = %s" % context
+ if verbose() : print("PYHELLOGUI.createPopupMenu(): context = %s" % context)
- ctx = _setContext( _getStudyId() )
- study = _getStudy()
selcount, selected = _getSelection()
- if verbose() : print selcount, selected
+ if verbose() : print(selcount, selected)
if selcount == 1:
# one object is selected
if moduleID() in selected:
name = default_name
pass
pass
- except:
+ except Exception as e:
+ logger.debug(e)
# generate object name
- __objectid__ = __objectid__ + 1
- name = "%s %d" % ( default_name, __objectid__ )
+ __objectid__ = __objectid__ + 1
+ name = "%s %d" % (default_name, __objectid__)
pass
- if not name: return
- getEngine().createObject( name )
+ if not name:
+ return
- getEngine().createObject(_getStudy(), name)
- sg.updateObjBrowser(True)
++ getEngine().createObject( name)
+ sg.updateObjBrowser()
pass
###