1 # Copyright (C) 2009-2016 OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author : Roman NIKOLAEV Open CASCADE S.A.S. (roman.nikolaev@opencascade.com)
24 from PyQt4.QtCore import *
26 # Get SALOME PyQt interface
27 sgPyQt=SalomePyQt.SalomePyQt()
29 def processText(text):
31 Remove "\n" sumbol from end of line
34 if isinstance(text,QString):
35 processed = text.toLatin1().data()
36 if processed[len(processed)-1:] == "\n":
37 processed = processed[:len(processed)-1]
41 class PYLIGHT_DataModel:
43 Data model of PYLIGHT module
47 Constructor of PYLIGHT_DataModel class.
52 def getParagraphs(self):
54 Return the list of all paragraph entries.
56 return sgPyQt.getChildren()
58 def getObject(self,entry):
60 Return PYLIGHT_DataObject by its entry.
62 for obj in self.myObjects:
63 if obj.getEntry() == entry:
67 def createObject(self, text="\n", parent=None):
69 Create PYLIGHT_DataObject (Paragraph or Line).
71 obj = PYLIGHT_DataObject(text,parent)
72 self.myObjects.append(obj)
76 def removeObjects(self,lines):
78 Remove objects by its entries
81 sgPyQt.removeObject(ln)
82 self.myObjects.remove(self.getObject(ln))
86 def loadFile(self,filename):
88 Read text file and publish it.
90 aFile = open(str(filename),"r")
91 lines = aFile.readlines()
93 paragr = self.createObject()
96 paragr = self.createObject()
99 self.createObject(processText(line), paragr)
105 def saveFile(self, filename):
106 aFile = open(str(filename),"w")
107 paragrs = self.getParagraphs()
108 for paragr in paragrs:
110 lines = sgPyQt.getChildren(paragr)
112 aFile.write(str(sgPyQt.getName(line))+"\n")
119 class PYLIGHT_DataObject:
121 Data Object of PYLIGHT module
123 def __init__(self,text,parent):
125 Constructor of PYLIGHT_DataObject class
128 entry = sgPyQt.createObject("Paragraph",
131 sgPyQt.setIcon(entry,"PYLIGHT_PARAGR_ICON")
133 entry = sgPyQt.createObject(processText(text),
144 Return entry of object
149 def setText(self,text):
155 sgPyQt.setName(self.entry,text)