1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| def home(self)
self.nbcom = QtGui.QLineEdit(self)
self.validator = QtGui.QIntValidator()
self.nbcom.setValidator(self.validator)
self.nbcom.setMaxLength(5)
#self.nbcom.setReadOnly(True)
self.nblines = QtGui.QLineEdit(self)
self.nbcom.setValidator(self.validator)
self.nblines.setMaxLength(5)
def change_state(self):
print(self.nbcom.text())
print(self.nblines.text())
def File_Open(self):
self.numl = 0
self.commentCount = 0;
self.name = QtGui.QFileDialog.getOpenFileName(self, 'Open File')
self.home()
with open(self.name, 'r') as file:
print("file name :", self.name)
for eachLine in file: # loops the lines in the file object ans sets the pointer to the end of the file
if eachLine.strip(): # check if the line is a blank line
self.numl += 1
if eachLine.find('#') != -1: # looks to find the comment tag
self.commentCount += 1
print("number of comments %i" % self.commentCount)
print("num lines %i: "% self.numl)
self.nbcom.setText(str(self.commentCount))
self.nblines.setText(str(self.numl)) |
Partager