-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
31 lines (26 loc) · 973 Bytes
/
app.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
import sys
import requests
import json
from PyQt5 import QtWidgets, uic
url = 'https://translate.mentality.rip/translate'
cu = requests.get(url)
class Ui(QtWidgets.QMainWindow):
def __init__(self):
super(Ui, self).__init__()
uic.loadUi('main.ui', self)
self.button = self.findChild(QtWidgets.QPushButton, 'actionButton')
self.button.clicked.connect(self.translationAction)
self.show()
if cu:
self.serverStat.setText('OK!')
else:
self.serverStat.setText('NOT OK!')
def translationAction(self, text):
req = requests.post(url, data = json.dumps({"q": self.InputField.toPlainText(), "source": "en", "target": "ru"}), headers={"Content-Type": "application/json"})
sts = req.status_code
data = req.json()
self.OutputField.setText(data["translatedText"])
app = QtWidgets.QApplication([])
application = Ui()
application.show()
sys.exit(app.exec())