# Used to store actions, menus, toolbars, etc...
################################################
+# data model
+__data_model__ = None
+
class GUIcontext:
# constructor
def __init__( self ):
+ global __data_model__
# Load File action
sgPyQt.createAction(dict_actions["loadfile"], "Load text File", "Load text file")
# Save File action
sgPyQt.createMenu( dict_actions["eraseLine"], menuPyLight, 10 );
# Create DataModel
- self.DM = PYLIGHT_DataModel.PYLIGHT_DataModel()
-
+ if __data_model__ is None:
+ __data_model__ = PYLIGHT_DataModel.PYLIGHT_DataModel()
+ pass
+
pass # def __init__( self )
pass # class GUIcontext
# Global variables and functions
################################################
-###
-# get active study ID
-###
-def _getStudyId():
- return sgPyQt.getStudyId()
-
# verbosity level
__verbose__ = None
pass
return __verbose__
-# study-to-context map
-__study2context__ = {}
-# current context
-__current_context__ = None
-
-###
-# get current GUI context
-###
-def _getContext():
- global __current_context__
- return __current_context__
-
-###
-# set and return current GUI context
-# study ID is passed as parameter
-###
-def _setContext( studyID ):
- global __study2context__, __current_context__
- if studyID not in __study2context__:
- __study2context__[studyID] = GUIcontext()
- pass
- __current_context__ = __study2context__[studyID]
- return __current_context__
-
################################################
# Create actions and menus
# called when module is activated
# returns True if activating is successfull and False otherwise
def activate():
- if verbose() : print("PYLIGHTGUI.activate() : study : %d" % _getStudyId())
- ctx = _setContext( _getStudyId() )
+ if verbose() : print("PYLIGHTGUI.activate()")
+ GUIcontext()
return True
# called when module is deactivated
def deactivate():
- if verbose() : print("PYLIGHTGUI.deactivate() : study : %d" % _getStudyId())
- pass
-
-# called when active study is changed
-# active study ID is passed as parameter
-def activeStudyChanged( studyID ):
- if verbose() : print("PYLIGHTGUI.activeStudyChanged(): study : %d" % studyID)
- ctx = _setContext( _getStudyId() )
+ if verbose() : print("PYLIGHTGUI.deactivate()")
pass
# Process GUI action
# Customize popup menu
def createPopupMenu(popup, context):
+ global __data_model__
if verbose() : print("PYLIGHTGUI.createPopupMenu(): context = %s" % context)
if context != 'ObjectBrowser':
return
- studyId = _getStudyId()
- ctx = _setContext( studyId )
selcount = sg.SelectedCount()
if selcount == 1:
entry = sg.getSelected( 0 )
- obj = ctx.DM.getObject(entry)
+ obj = __data_model__.getObject(entry)
if obj is not None:
if obj.getText() != "\n":
# Line is selected
# For saving data in the study
def saveFiles(prefix):
+ global __data_model__
if verbose(): print("PYLIGHTGUI::saveFile()")
- ctx = _setContext( _getStudyId() )
postfix = "PYLIGHT.txt"
filename = prefix+postfix
- ctx.DM.saveFile(filename)
+ __data_model__.saveFile(filename)
return postfix
# For restore data from the study
def openFiles(filelist):
+ global __data_model__
if verbose(): print("PYLIGHTGUI::openFile()")
- ctx = _setContext( _getStudyId() )
filename = filelist[0]
filename.append(filelist[1])
- ctx.DM.loadFile(filename)
+ __data_model__.loadFile(filename)
return True
# Loading a text file
def loadfile():
- ctx = _setContext( _getStudyId() )
+ global __data_model__
aFilter = "Text files (*.txt)"
filename = QFileDialog.getOpenFileName(sgPyQt.getDesktop(), "Open text file", "", aFilter, "Choose a text file to open")
return
if os.access(str(filename),os.R_OK):
- ctx.DM.loadFile(filename)
+ __data_model__.loadFile(filename)
else:
QMessageBox.warning(sgPyQt.getDesktop(),
"Error!",
"Can not read file:\n%s"%(filename))
pass
- sg.updateObjBrowser(True)
+ sg.updateObjBrowser()
pass
# Saving a text file
def savefile():
- ctx = _setContext( _getStudyId() )
+ global __data_model__
aFilter = "Text files (*.txt)"
filename = QFileDialog.getSaveFileName(sgPyQt.getDesktop(),"Save text file", "", aFilter, "Choose a text file to save")
fn = filename
# Get directory name and check access
if os.access(str(fn[:fn.rindex(os.path.sep)]), os.W_OK):
- ctx.DM.saveFile(filename)
+ __data_model__.saveFile(filename)
else:
QMessageBox.warning(sgPyQt.getDesktop(),
"Error!",
'''
Insert new line in the selected paragraph.
'''
- ctx = _setContext( _getStudyId() )
+ global __data_model__
#Get result
res = QInputDialog.getText(sgPyQt.getDesktop(),
"Add new line",
# Nb selected objects
selcount = sg.SelectedCount()
# Nb object in the Data Model
- paragrCount = len(ctx.DM.getParagraphs())
+ paragrCount = len(__data_model__.getParagraphs())
# Create first paragraph
if paragrCount == 0:
- ctx.DM.createObject()
+ __data_model__.createObject()
# If line not empty create first line
if text != "\n":
- ctx.DM.createObject(text,ctx.DM.getParagraphs()[0])
- sg.updateObjBrowser(True)
+ __data_model__.createObject(text,__data_model__.getParagraphs()[0])
+ sg.updateObjBrowser()
return
# Create paragraph
if text == "\n":
- ctx.DM.createObject()
- sg.updateObjBrowser(True)
+ __data_model__.createObject()
+ sg.updateObjBrowser()
return
else:
if selcount == 0:
return
if selcount == 1:
entry = sg.getSelected( 0 )
- obj = ctx.DM.getObject(entry)
+ obj = __data_model__.getObject(entry)
if obj is not None:
# Create line
if(obj.getText() == "\n"):
- ctx.DM.createObject(text,entry)
- sg.updateObjBrowser(True);
+ __data_model__.createObject(text,entry)
+ sg.updateObjBrowser();
return
else:
QMessageBox.warning(sgPyQt.getDesktop(),
# Edit selected line
def editLine():
- ctx = _setContext( _getStudyId() )
+ global __data_model__
if sg.SelectedCount() == 1:
entry = sg.getSelected( 0 )
- obj = ctx.DM.getObject(entry)
+ obj = __data_model__.getObject(entry)
if(obj is not None and obj.getText() != "\n"):
#Get text line
res = QInputDialog.getText(sgPyQt.getDesktop(),
QMessageBox.information(sgPyQt.getDesktop(),
'Info',
'Please, select one line!')
- sg.updateObjBrowser(True);
+ sg.updateObjBrowser();
pass
# Remove selected lines
def removeLine():
- ctx = _setContext( _getStudyId() )
+ global __data_model__
selcount = sg.SelectedCount()
onlyLines = True
lines = []
while selcount != 0:
entry = sg.getSelected( selcount - 1)
#Check what only lines selected
- obj = ctx.DM.getObject(entry)
+ obj = __data_model__.getObject(entry)
if obj is None:
continue
if obj.getText() == "\n":
renderer.RemoveActor(actor)
pass
pass
- ctx.DM.removeObjects(lines)
- sg.updateObjBrowser(True)
+ __data_model__.removeObjects(lines)
+ sg.updateObjBrowser()
pass
pass
# Remove all lines from all paragraphs
def clearAll():
- ctx = _setContext( _getStudyId() )
- paragraphs = ctx.DM.getParagraphs()
+ global __data_model__
+ paragraphs = __data_model__.getParagraphs()
for paragr in paragraphs:
lines = sgPyQt.getChildren(paragr)
- ctx.DM.removeObjects(lines)
+ __data_model__.removeObjects(lines)
renderer=libSalomePy.getRenderer()
for l in lines:
actor = getActor(l)
renderer.RemoveActor(actor)
pass
pass
- sg.updateObjBrowser(True)
+ sg.updateObjBrowser()
pass
# Display the selected line
def displayLine():
- ctx = _setContext( _getStudyId() )
+ global __data_model__
if sg.SelectedCount() != 1:
return
entry = sg.getSelected(0)
# Clear remove all lines under selected paragraph
def clearParagraph():
- ctx = _setContext( _getStudyId() )
+ global __data_model__
lines = sgPyQt.getChildren(sg.getSelected(0))
- ctx.DM.removeObjects(lines)
- sg.updateObjBrowser(True)
+ __data_model__.removeObjects(lines)
+ sg.updateObjBrowser()
pass
# Erase the selected line
def eraseLine():
- ctx = _setContext( _getStudyId() )
+ global __data_model__
if sg.SelectedCount() != 1:
return
entry = sg.getSelected(0)
- obj = ctx.DM.getObject(entry)
+ obj = __data_model__.getObject(entry)
if obj is None:
QMessageBox.information(sgPyQt.getDesktop(),
'Info',