###
def _setContext( studyID ):
global __study2context__, __current_context__
- if not __study2context__.has_key(studyID):
+ if studyID not in __study2context__:
__study2context__[studyID] = GUIcontext()
pass
__current_context__ = __study2context__[studyID]
# Create actions and menus
def initialize():
- if verbose(): print "PYLIGHTGUI::initialize()"
+ if verbose(): print("PYLIGHTGUI::initialize()")
return
# called when module is activated
# returns True if activating is successfull and False otherwise
def activate():
- if verbose() : print "PYLIGHTGUI.activate() : study : %d" % _getStudyId()
+ if verbose() : print("PYLIGHTGUI.activate() : study : %d" % _getStudyId())
ctx = _setContext( _getStudyId() )
return True
# called when module is deactivated
def deactivate():
- if verbose() : print "PYLIGHTGUI.deactivate() : study : %d" % _getStudyId()
+ 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
+ if verbose() : print("PYLIGHTGUI.activeStudyChanged(): study : %d" % studyID)
ctx = _setContext( _getStudyId() )
pass
# Process GUI action
def OnGUIEvent(commandID):
- if verbose() : print "PYLIGHTGUI::OnGUIEvent : commandID = %d" % commandID
- if dict_command.has_key( commandID ):
+ if verbose() : print("PYLIGHTGUI::OnGUIEvent : commandID = %d" % commandID)
+ if commandID in dict_command:
try:
dict_command[commandID]()
except:
traceback.print_exc()
else:
- if verbose() : print "The command is not implemented: %d" % commandID
+ if verbose() : print("The command is not implemented: %d" % commandID)
pass
# Customize popup menu
def createPopupMenu(popup, context):
- if verbose() : print "PYLIGHTGUI.createPopupMenu(): context = %s" % context
+ if verbose() : print("PYLIGHTGUI.createPopupMenu(): context = %s" % context)
if context != 'ObjectBrowser':
return
# For saving data in the study
def saveFiles(prefix):
- if verbose(): print "PYLIGHTGUI::saveFile()"
+ if verbose(): print("PYLIGHTGUI::saveFile()")
ctx = _setContext( _getStudyId() )
postfix = "PYLIGHT.txt"
filename = prefix+postfix
# For restore data from the study
def openFiles(filelist):
- if verbose(): print "PYLIGHTGUI::openFile()"
+ if verbose(): print("PYLIGHTGUI::openFile()")
ctx = _setContext( _getStudyId() )
filename = filelist[0]
filename.append(filelist[1])
if isinstance(filename,tuple) and len(filename) >=2:
filename = filename[0]
- filename = unicode(filename)
-
if len(filename) == 0:
return
if isinstance(filename,tuple) and len(filename) >=2:
filename = filename[0]
- filename = unicode(filename)
-
if filename.endswith(".txt") == 0:
filename+=".txt"
pass
if sg.SelectedCount() == 1:
entry = sg.getSelected( 0 )
obj = ctx.DM.getObject(entry)
- if(obj.getText() != "\n"):
+ if(obj is not None and obj.getText() != "\n"):
#Get text line
res = QInputDialog.getText(sgPyQt.getDesktop(),
"Edit line",
while selcount != 0:
entry = sg.getSelected( selcount - 1)
#Check what only lines selected
- if ctx.DM.getObject(entry).getText() == "\n":
+ obj = ctx.DM.getObject(entry)
+ if obj is None:
+ continue
+ if obj.getText() == "\n":
onlyLines = False
break
lines.append(entry)
if sg.SelectedCount() != 1:
return
entry = sg.getSelected(0)
- text = ctx.DM.getObject(entry).getText()
+ obj = ctx.DM.getObject(entry)
+ if obj is None:
+ QMessageBox.information(sgPyQt.getDesktop(),
+ 'Info',
+ 'Please, select line!')
+ return
+ text = obj.getText()
if text == "\n":
return
renderer=libSalomePy.getRenderer()
txtPr = vtk.vtkTextProperty()
txtPr.SetFontSize(30)
actor.SetTextProperty(txtPr)
- for act in dict_actors.values():
+ for act in list(dict_actors.values()):
renderer.RemoveActor(act)
renderer.AddActor(actor)
pass
if sg.SelectedCount() != 1:
return
entry = sg.getSelected(0)
- text = ctx.DM.getObject(entry).getText()
+ obj = ctx.DM.getObject(entry)
+ if obj is None:
+ QMessageBox.information(sgPyQt.getDesktop(),
+ 'Info',
+ 'Please, select line!')
+ return
+ text = obj.getText()
if text == "\n":
return
renderer=libSalomePy.getRenderer()
# Return vtkActor by entry
def getActor(entry):
entry = str(entry)
- if dict_actors.has_key(entry):
+ if entry in dict_actors:
return dict_actors[entry]
return None
'''
Read text file and publish it.
'''
- aFile = open(str(filename),"r")
- lines = aFile.readlines()
- if(lines[0] != "\n"):
- paragr = self.createObject()
- for line in lines:
- if line == "\n":
+ with open(str(filename), "r") as aFile:
+ lines = aFile.readlines()
+ if(lines[0] != "\n"):
paragr = self.createObject()
+ for line in lines:
+ if line == "\n":
+ paragr = self.createObject()
- else:
- self.createObject(processText(line), paragr)
+ else:
+ self.createObject(processText(line), paragr)
+ pass
pass
pass
- aFile.close()
pass
def saveFile(self, filename):
- aFile = open(str(filename),"w")
- paragrs = self.getParagraphs()
- for paragr in paragrs:
- aFile.write("\n")
- lines = sgPyQt.getChildren(paragr)
- for line in lines:
- aFile.write(str(sgPyQt.getName(line))+"\n")
+ with open(str(filename), "w") as aFile:
+ paragrs = self.getParagraphs()
+ for paragr in paragrs:
+ aFile.write("\n")
+ lines = sgPyQt.getChildren(paragr)
+ for line in lines:
+ aFile.write(str(sgPyQt.getName(line)) + "\n")
+ pass
pass
pass
- aFile.close()
pass
pass