Salome HOME
Merge branch 'V7_dev'
[samples/pylight.git] / src / PYLIGHTGUI / PYLIGHTGUI.py
index b96f7896604fdcd4eb32e1d1c45f46df48237ea3..dc2ec8c940d8211df374e5d7431928120be4100c 100644 (file)
@@ -1,9 +1,9 @@
-# Copyright (C) 2009-2012  OPEN CASCADE
+# Copyright (C) 2009-2016  OPEN CASCADE
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 # License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# version 2.1 of the License, or (at your option) any later version.
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -23,8 +23,7 @@
 import traceback
 from SalomePyQt import *
 import PYLIGHT_DataModel
-from PyQt4.QtGui import *
-from PyQt4.QtCore import *
+from qtsalome import *
 import libSALOME_Swig
 
 import os
@@ -57,6 +56,8 @@ class GUIcontext:
         sgPyQt.createAction(dict_actions["editLine"], "Edit Line", "Edit selected line")
         # Remove selected line action
         sgPyQt.createAction(dict_actions["removeLine"], "Remove Lines", "Remove selected lines")
+        # Clear paragraph
+        sgPyQt.createAction(dict_actions["clearParagraph"], "Clear Paragraph", "Clear selected paragraph")
         # Clear all paragraphs
         sgPyQt.createAction(dict_actions["clearAll"], "Clear All", "Clear all paragraphs")
         # Display line
@@ -222,7 +223,7 @@ def saveFiles(prefix):
     ctx = _setContext( _getStudyId() )
     postfix = "PYLIGHT.txt"
     filename = prefix+postfix
-    ctx.DM.saveFile(QString(filename))
+    ctx.DM.saveFile(filename)
     return postfix
 
 # For restore data from the study
@@ -239,7 +240,14 @@ def loadfile():
     ctx = _setContext( _getStudyId() )
     aFilter = "Text files (*.txt)"
     filename = QFileDialog.getOpenFileName(sgPyQt.getDesktop(), "Open text file", "", aFilter, "Choose a text file to open")
-    if filename.isEmpty():
+
+    print filename
+    if isinstance(filename,tuple) and len(filename) >=2:
+       filename = filename[0]
+
+    filename = unicode(filename)
+
+    if len(filename) == 0:
         return
     
     if os.access(str(filename),os.R_OK):
@@ -247,7 +255,7 @@ def loadfile():
     else:
         QMessageBox.warning(sgPyQt.getDesktop(),
                             "Error!",
-                            QString("Can not read file:\n%1").arg(filename))
+                            "Can not read file:\n%s"%(filename))
         pass
     sg.updateObjBrowser(True)
     pass
@@ -257,17 +265,25 @@ def savefile():
     ctx = _setContext( _getStudyId() )
     aFilter = "Text files (*.txt)"
     filename = QFileDialog.getSaveFileName(sgPyQt.getDesktop(),"Save text file", "", aFilter, "Choose a text file to save")
-    if filename.contains(".txt") == 0:
-        filename.append(".txt")
+
+    print filename
+    if isinstance(filename,tuple) and len(filename) >=2:
+        filename = filename[0]
+
+    filename = unicode(filename)
+
+    if filename.endswith(".txt") == 0:
+        filename+=".txt"
         pass
+
     fn = filename
     # Get directory name and check access
-    if os.access(str(fn.left(fn.lastIndexOf("/"))), os.W_OK):
+    if os.access(str(fn[:fn.rindex(os.path.sep)]), os.W_OK):
         ctx.DM.saveFile(filename)
     else:
         QMessageBox.warning(sgPyQt.getDesktop(),
                             "Error!",
-                            QString("Can not save file:\n%1").arg(filename))
+                            "Can not save file:\n%s"%(filename))
         pass
     pass
 
@@ -285,6 +301,7 @@ def insertLine():
         return
     
     text = res[0]
+    print "RNV: !", res
     # Nb selected objects
     selcount = sg.SelectedCount()
     # Nb object in the Data Model
@@ -457,8 +474,7 @@ def eraseLine():
 
 # Return vtkActor by entry
 def getActor(entry):
-    if isinstance(entry,QString):
-        entry = entry.toLatin1().data()
+    entry = str(entry)
     if dict_actors.has_key(entry):
         return dict_actors[entry]
     return None