]> SALOME platform Git repositories - samples/pylight.git/blobdiff - src/PYLIGHTGUI/PYLIGHTGUI.py
Salome HOME
Porting to Python 3 (1st draft)
[samples/pylight.git] / src / PYLIGHTGUI / PYLIGHTGUI.py
index 511281c327c85e974237d2538bcfe9967941e6a7..3fabc1d504fa53bf2c3926b3de273467c0ba924f 100644 (file)
@@ -138,7 +138,7 @@ def _getContext():
 ###
 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]
@@ -148,43 +148,43 @@ def _setContext( 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
@@ -219,7 +219,7 @@ def createPopupMenu(popup, context):
 
 # 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
@@ -228,7 +228,7 @@ def saveFiles(prefix):
 
 # 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])
@@ -244,8 +244,6 @@ def loadfile():
     if isinstance(filename,tuple) and len(filename) >=2:
        filename = filename[0]
 
-    filename = unicode(filename)
-
     if len(filename) == 0:
         return
     
@@ -268,8 +266,6 @@ def savefile():
     if isinstance(filename,tuple) and len(filename) >=2:
         filename = filename[0]
 
-    filename = unicode(filename)
-
     if filename.endswith(".txt") == 0:
         filename+=".txt"
         pass
@@ -349,7 +345,7 @@ def editLine():
     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",
@@ -381,7 +377,10 @@ def removeLine():
     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)
@@ -425,7 +424,13 @@ def displayLine():
     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()
@@ -440,7 +445,7 @@ def displayLine():
     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
@@ -459,7 +464,13 @@ def eraseLine():
     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()
@@ -472,7 +483,7 @@ def eraseLine():
 # 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