-
Notifications
You must be signed in to change notification settings - Fork 1
/
PyQt5_dictionary.py
176 lines (156 loc) · 6.99 KB
/
PyQt5_dictionary.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QFont
import sys
import json
class MyDictionary(QMainWindow):
count = 0
uzbek_angliz =[]
uzbList = []
angList = []
def __init__(self):
super().__init__()
self.mainWindow()
self.openJson()
self.changeLanguage()
self.wordTranslation('')
self.showWords(self.uzbList)
def openJson(self):
with open("uzb_ang.json") as file:
data1 = json.load(file)
for item in data1:
self.uzbek_angliz.append(item)
for value in item.values():
self.angList.append(value)
for key in item.keys():
self.uzbList.append(key)
self.angList.sort()
self.uzbList.sort()
def mainWindow(self):
self.setFixedSize(500,600)
self.setStyleSheet("background-color:purple;")
self.radio1 = QRadioButton(self)
self.radio1.move(115,50)
self.radio1.clicked.connect(self.checkRadioButton)
self.btnInRadio1 = QLabel("add 📝",self)
self.btnInRadio1.setGeometry(20,50,90,30)
self.btnInRadio1.setStyleSheet("background-color:green;")
self.btnInRadio1.setFont(QFont('Arial',14))
self.btnOnAdd = QPushButton("Add the new world",self)
self.btnOnAdd.setGeometry(175,230,160,55)
self.btnOnAdd.setFont(QFont('Arial',14))
self.btnOnAdd.setStyleSheet("background-color:green;")
self.btnOnAdd.setEnabled(False)
self.btnOnAdd.clicked.connect(self.addNewWord)
self.radio2 = QRadioButton(self)
self.radio2.move(360,50)
self.radio2.clicked.connect(self.checkRadioButton)
self.bntInRadio2 = QLabel("🔍search",self)
self.bntInRadio2.setGeometry(380,50,90,30)
self.bntInRadio2.setFont(QFont('Arial',14))
self.bntInRadio2.setStyleSheet("background-color:blue;")
self.input1 = QLineEdit(self)
self.input1.setGeometry(20,140,150,60)
self.input1.setFont(QFont('Arial',14))
self.input1.setStyleSheet("background-color:white;")
self.input1.textChanged.connect(self.findWords)
self.buttonChange = QPushButton("⏪⏩",self)
self.buttonChange.setGeometry(200,135,100,75)
self.buttonChange.setFont(QFont('Arial',24))
self.buttonChange.clicked.connect(self.changeLanguage)
self.input2 = QLineEdit(self)
self.input2.setGeometry(330,140,150,60)
self.input2.setFont(QFont('Arial',14))
self.input2.setStyleSheet("background-color:white;")
self.ListVue = QListWidget(self)
self.ListVue.setGeometry(20,300,150,290)
self.ListVue.setFont(QFont('Arial',14))
self.ListVue.setStyleSheet("background-color:white;")
self.ListVue.itemClicked.connect(self.setMainText)
self.ListVue.itemClicked.connect(self.wordTranslation)
def showWords(self,uzb_ang):
self.ListVue.clear()
for item in uzb_ang:
self.ListVue.addItem(item)
def changeLanguage(self):
self.input1.clear()
self.input2.clear()
if self.count%2==0:
self.input1.setPlaceholderText('Uzbek')
self.input2.setPlaceholderText('English')
self.showWords(self.uzbList)
else:
self.input2.setPlaceholderText('Uzbek')
self.input1.setPlaceholderText('English')
self.showWords(self.angList)
self.count+=1
def checkRadioButton(self):
if self.radio1.isChecked():
self.btnOnAdd.setEnabled(True)
elif self.radio2.isChecked():
self.btnOnAdd.setEnabled(False)
def findWords(self):
newListWords = []
if self.count%2==0:
for item in self.angList:
if self.input1.text().lower() in item.lower():
newListWords.append(item)
else:
for item in self.uzbList:
if self.input1.text().lower() in item.lower():
newListWords.append(item)
self.showWords(newListWords)
def setMainText(self):
word =""
word = self.ListVue.currentItem().text()
self.input1.setText(self.ListVue.currentItem().text())
self.wordTranslation(word)
def wordTranslation(self,word):
for item in self.uzbek_angliz:
if self.count%2!=0:
for key in item.keys():
if key==word:
self.input2.setText(item[key])
else:
for key,value in item.items():
if word == value:
self.input2.setText(key)
def addNewWord(self):
if len(self.input1.text())!=0 and len(self.input2.text())!=0:
if self.count%2!=0:
if {self.input1.text():self.input2.text()} not in self.uzbek_angliz:
self.uzbek_angliz.append({self.input1.text():self.input2.text()})
self.input1.clear()
self.input2.clear()
else:
thereWordMsg = QMessageBox()
thereWordMsg.setIcon(QMessageBox.Information)
thereWordMsg.setText('Error')
thereWordMsg.setInformativeText("There is such a word\nin the dictionary")
thereWordMsg.setFont(QFont('Arial',10))
thereWordMsg.exec_()
else:
if {self.input2.text():self.input1.text()} not in self.uzbek_angliz:
self.uzbek_angliz.append({self.input2.text():self.input1.text()})
else:
thereWordMsg = QMessageBox()
thereWordMsg.setIcon(QMessageBox.Information)
thereWordMsg.setText('Error')
thereWordMsg.setInformativeText("There is such a word\nin the dictionary")
thereWordMsg.setFont(QFont('Arial',10))
thereWordMsg.exec_()
self.input1.clear()
self.input2.clear()
with open("uzb_ang.json","w") as file:
json.dump(self.uzbek_angliz,file,indent='\t')
self.input1.clear()
self.input2.clear()
else:
lenMsg = QMessageBox()
lenMsg.setIcon(QMessageBox.Critical)
lenMsg.setInformativeText("Please enter \na word to input")
lenMsg.setFont(QFont('Arial',10))
lenMsg.exec_()
app = QApplication(sys.argv)
word = MyDictionary()
word.show()
sys.exit(app.exec_())