From ae6d93bbdfd77025f72ef353dcca7db715b8ba80 Mon Sep 17 00:00:00 2001 From: rnv Date: Tue, 26 Jan 2016 18:01:30 +0300 Subject: [PATCH] PyQt5/PyQt4 support --- src/PYLIGHTGUI/PYLIGHTGUI.py | 36 ++++++++++++++++++++--------- src/PYLIGHTGUI/PYLIGHT_DataModel.py | 6 ++--- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/PYLIGHTGUI/PYLIGHTGUI.py b/src/PYLIGHTGUI/PYLIGHTGUI.py index b4148ba..e1de088 100644 --- a/src/PYLIGHTGUI/PYLIGHTGUI.py +++ b/src/PYLIGHTGUI/PYLIGHTGUI.py @@ -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 @@ -224,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 @@ -241,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): @@ -249,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 @@ -259,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 @@ -287,6 +301,7 @@ def insertLine(): return text = res[0] + print "RNV: !", res # Nb selected objects selcount = sg.SelectedCount() # Nb object in the Data Model @@ -459,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 diff --git a/src/PYLIGHTGUI/PYLIGHT_DataModel.py b/src/PYLIGHTGUI/PYLIGHT_DataModel.py index 154a5ce..adb4a54 100644 --- a/src/PYLIGHTGUI/PYLIGHT_DataModel.py +++ b/src/PYLIGHTGUI/PYLIGHT_DataModel.py @@ -21,7 +21,7 @@ # Date : 13/04/2009 # import SalomePyQt -from PyQt4.QtCore import * +from qtsalome import * # Get SALOME PyQt interface sgPyQt=SalomePyQt.SalomePyQt() @@ -30,9 +30,7 @@ def processText(text): ''' Remove "\n" sumbol from end of line ''' - processed = text - if isinstance(text,QString): - processed = text.toLatin1().data() + processed = str(text) if processed[len(processed)-1:] == "\n": processed = processed[:len(processed)-1] -- 2.39.2