1 # Copyright (C) 2009-2020 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 qtsalome import *
26 # Get SALOME PyQt interface
27 sgPyQt=SalomePyQt.SalomePyQt()
29 def processText(text):
31 Remove "\n" sumbol from end of line
34 if processed[len(processed)-1:] == "\n":
35 processed = processed[:len(processed)-1]
39 class PYLIGHT_DataModel:
41 Data model of PYLIGHT module
45 Constructor of PYLIGHT_DataModel class.
50 def getParagraphs(self):
52 Return the list of all paragraph entries.
54 return sgPyQt.getChildren()
56 def getObject(self,entry):
58 Return PYLIGHT_DataObject by its entry.
60 for obj in self.myObjects:
61 if obj.getEntry() == entry:
65 def createObject(self, text="\n", parent=None):
67 Create PYLIGHT_DataObject (Paragraph or Line).
69 obj = PYLIGHT_DataObject(text,parent)
70 self.myObjects.append(obj)
74 def removeObjects(self,lines):
76 Remove objects by its entries
79 sgPyQt.removeObject(ln)
80 self.myObjects.remove(self.getObject(ln))
84 def loadFile(self,filename):
86 Read text file and publish it.
88 with open(str(filename), "r") as aFile:
89 lines = aFile.readlines()
91 paragr = self.createObject()
94 paragr = self.createObject()
97 self.createObject(processText(line), paragr)
103 def saveFile(self, filename):
104 with open(str(filename), "w") as aFile:
105 paragrs = self.getParagraphs()
106 for paragr in paragrs:
108 lines = sgPyQt.getChildren(paragr)
110 aFile.write(str(sgPyQt.getName(line)) + "\n")
117 class PYLIGHT_DataObject:
119 Data Object of PYLIGHT module
121 def __init__(self,text,parent):
123 Constructor of PYLIGHT_DataObject class
126 entry = sgPyQt.createObject("Paragraph",
129 sgPyQt.setIcon(entry,"PYLIGHT_PARAGR_ICON")
131 entry = sgPyQt.createObject(processText(text),
142 Return entry of object
147 def setText(self,text):
153 sgPyQt.setName(self.entry,text)