-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
73 lines (57 loc) · 2.39 KB
/
main.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
from PyQt5.QtWidgets import QMainWindow, QApplication, QTextEdit, QPushButton, QComboBox, QMessageBox
from PyQt5 import uic
import googletrans
import textblob
import sys
class TranslatorApp(QMainWindow):
def __init__(self):
super(TranslatorApp, self).__init__()
uic.loadUi("app.ui", self)
Window_Width = 692
Window_Height = 303
self.setFixedSize(Window_Width, Window_Height)
self.from_text = self.findChild(QTextEdit, "from_text")
self.to_text = self.findChild(QTextEdit, "to_text")
self.translate_btn = self.findChild(QPushButton, "translate_btn")
self.clear_btn = self.findChild(QPushButton, "clear_btn")
self.paste_btn = self.findChild(QPushButton, "paste_btn")
self.copy_btn = self.findChild(QPushButton, "copy_btn")
self.from_comb = self.findChild(QComboBox, "comboBox")
self.to_comb = self.findChild(QComboBox, "comboBox_2")
self.languages = googletrans.LANGUAGES
# print(self.languages)
self.language_list = list(self.languages.values())
# print(self.language_list)
# print(len(self.language_list))
self.from_comb.addItems(self.language_list)
self.to_comb.addItems(self.language_list)
self.from_comb.setCurrentText("english")
self.to_comb.setCurrentText("amharic")
self.translate_btn.clicked.connect(self.translate)
self.clear_btn.clicked.connect(self.clear)
self.paste_btn.clicked.connect(self.paste)
self.copy_btn.clicked.connect(self.copy)
self.show()
def translate(self):
try:
for key, value in self.languages.items():
if (value == self.from_comb.currentText()):
from_lang_key = key
for key, value in self.languages.items():
if (value == self.to_comb.currentText()):
to_lang_key = key
words = textblob.TextBlob(self.from_text.toPlainText())
words = words.translate(from_lang=from_lang_key, to=to_lang_key)
self.to_text.setText(str(words))
except Exception as e:
QMessageBox.critical(self, "Translator", str(e))
def clear(self):
self.from_text.setText("")
self.to_text.setText("")
def copy(self):
pass
def paste(self):
pass
app = QApplication(sys.argv)
window = TranslatorApp()
app.exec_()