1 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # Author : Roman NIKOLAEV Open CASCADE S.A.S. (roman.nikolaev@opencascade.com)
26 from PyQt4.QtCore import *
28 # Get SALOME PyQt interface
29 sgPyQt=SalomePyQt.SalomePyQt()
31 def processText(text):
33 Remove "\n" sumbol from end of line
36 if isinstance(text,QString):
37 processed = text.toLatin1().data()
38 if processed[len(processed)-1:] == "\n":
39 processed = processed[:len(processed)-1]
43 class PYLIGHT_DataModel:
45 Data model of PYLIGHT module
49 Constructor of PYLIGHT_DataModel class.
54 def getParagraphs(self):
56 Return the list of all paragraph entries.
58 return sgPyQt.getChildren()
60 def getObject(self,entry):
62 Return PYLIGHT_DataObject by its entry.
64 for obj in self.myObjects:
65 if obj.getEntry() == entry:
69 def createObject(self, text="\n", parent=None):
71 Create PYLIGHT_DataObject (Paragraph or Line).
73 obj = PYLIGHT_DataObject(text,parent)
74 self.myObjects.append(obj)
78 def removeObjects(self,lines):
80 Remove objects by its entries
83 sgPyQt.removeObject(ln)
84 self.myObjects.remove(self.getObject(ln))
88 def loadFile(self,filename):
90 Read text file and publish it.
92 aFile = open(str(filename),"r")
93 lines = aFile.readlines()
95 paragr = self.createObject()
98 paragr = self.createObject()
101 self.createObject(processText(line), paragr)
107 def saveFile(self, filename):
108 aFile = open(str(filename),"w")
109 paragrs = self.getParagraphs()
110 for paragr in paragrs:
112 lines = sgPyQt.getChildren(paragr)
114 aFile.write(str(sgPyQt.getName(line))+"\n")
121 class PYLIGHT_DataObject:
123 Data Object of PYLIGHT module
125 def __init__(self,text,parent):
127 Constructor of PYLIGHT_DataObject class
130 entry = sgPyQt.createObject("Paragraph",
133 sgPyQt.setIcon(entry,"PYLIGHT_PARAGR_ICON")
135 entry = sgPyQt.createObject(processText(text),
146 Return entry of object
151 def setText(self,text):
157 sgPyQt.setName(self.entry,text)