-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.py
39 lines (35 loc) · 1.24 KB
/
controller.py
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
34
35
36
37
38
39
import sys
from view import *
from PyQt5.QtWidgets import*
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class MyMainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent = None):
super(MyMainWindow, self).__init__(parent)
self.setupUi(self)
self.textEdit.textChanged.connect(self.calculate)
def calculate(self):
string = self.textEdit.toPlainText()
length = len(string)
flag = False
charNum = 0
wordNum = 0
engNum = 0
for i in range(0, length):
if((not flag) and string[i:i+1] != " "):
flag = True
wordNum += 1
elif(flag and string[i:i+1] == " "):
flag = False
if(flag):
charNum += 1
if string[i:i+1] >="A" and string[i:i+1] <="Z" or string[i:i+1] >="a" and string[i:i+1]<="z":
engNum += 1;
self.wordNumberLabel.setText(str(wordNum))
self.characterNumberLabel.setText(str(charNum))
self.engNumberLabel.setText(str(engNum))
if __name__=="__main__" :
app = QApplication(sys.argv)
myWin = MyMainWindow()
myWin.show()
sys.exit(app.exec_())