# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'tts1.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog import tltk class Ui_TTSDialog(object): def setupUi(self, TTSDialog): TTSDialog.setObjectName("TTSDialog") TTSDialog.resize(691, 435) self.scrollArea = QtWidgets.QScrollArea(TTSDialog) self.scrollArea.setGeometry(QtCore.QRect(0, 0, 681, 371)) self.scrollArea.setWidgetResizable(True) self.scrollArea.setObjectName("scrollArea") self.scrollAreaWidgetContents = QtWidgets.QWidget() self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 679, 369)) self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents") self.OuttextEdit = QtWidgets.QPlainTextEdit(self.scrollAreaWidgetContents) self.OuttextEdit.setGeometry(QtCore.QRect(0, 70, 681, 291)) font = QtGui.QFont() font.setFamily("TH Sarabun Chula") font.setPointSize(18) self.OuttextEdit.setFont(font) self.OuttextEdit.setObjectName("OuttextEdit") self.textEdit = QtWidgets.QTextEdit(self.scrollAreaWidgetContents) self.textEdit.setGeometry(QtCore.QRect(0, 28, 681, 41)) font = QtGui.QFont() font.setFamily("TH Sarabun New") font.setPointSize(18) self.textEdit.setFont(font) self.textEdit.setObjectName("textEdit") self.label = QtWidgets.QLabel(self.scrollAreaWidgetContents) self.label.setGeometry(QtCore.QRect(10, 0, 351, 31)) self.label.setObjectName("label") self.scrollArea.setWidget(self.scrollAreaWidgetContents) self.label_2 = QtWidgets.QLabel(TTSDialog) self.label_2.setGeometry(QtCore.QRect(20, 410, 421, 16)) self.label_2.setObjectName("label_2") self.SavepushButton = QtWidgets.QPushButton(TTSDialog) self.SavepushButton.setGeometry(QtCore.QRect(590, 370, 71, 32)) self.SavepushButton.setObjectName("SavepushButton") self.ExitpushButton = QtWidgets.QPushButton(TTSDialog) self.ExitpushButton.setGeometry(QtCore.QRect(590, 410, 71, 32)) self.ExitpushButton.setObjectName("ExitpushButton") self.progressBar = QtWidgets.QProgressBar(TTSDialog) self.progressBar.setGeometry(QtCore.QRect(20, 380, 421, 30)) self.progressBar.setBaseSize(QtCore.QSize(0, 0)) self.progressBar.setProperty("value", 0) self.progressBar.setObjectName("progressBar") self.radioButton = QtWidgets.QRadioButton(TTSDialog) self.radioButton.setGeometry(QtCore.QRect(480, 380, 100, 20)) self.radioButton.setObjectName("radioButton") self.radioButton_2 = QtWidgets.QRadioButton(TTSDialog) self.radioButton_2.setGeometry(QtCore.QRect(480, 410, 100, 20)) self.radioButton_2.setObjectName("radioButton_2") self.checkAll = QtWidgets.QCheckBox(TTSDialog) self.checkAll.setGeometry(QtCore.QRect(540, 380, 87, 20)) self.checkAll.setObjectName("checkAll") self.retranslateUi(TTSDialog) QtCore.QMetaObject.connectSlotsByName(TTSDialog) def retranslateUi(self, TTSDialog): _translate = QtCore.QCoreApplication.translate TTSDialog.setWindowTitle(_translate("TTSDialog", "Thai transcription 1.1")) self.label.setText(_translate("TTSDialog", "Input Thai texts below:")) self.label_2.setText(_translate("TTSDialog", "Department of Linguistics, Facyulty of Arts, Chulalongkorn University")) self.SavepushButton.setText(_translate("TTSDialog", "Copy")) self.ExitpushButton.setText(_translate("TTSDialog", "Exit")) self.radioButton.setText(_translate("TTSDialog", "IPA")) self.radioButton_2.setText(_translate("TTSDialog", "Roman")) self.checkAll.setText(_translate("TTSDialog", "all")) ### add this after generate py code from .ui to set action from button click events ################ self.SavepushButton.clicked.connect(copyText) self.ExitpushButton.clicked.connect(exitProg) self.radioButton.clicked.connect(ipa) self.radioButton_2.clicked.connect(roman) self.checkAll.clicked.connect(Transl) self.textEdit.textChanged.connect(Transl) def Transl(): if ui.radioButton.isChecked(): ui.radioButton.setChecked(True) if ui.checkAll.isChecked() == True: ipa_all() else: ipa() else: ui.radioButton_2.setChecked(True) roman() def roman(): ui.OuttextEdit.clear() txt = ui.textEdit.toPlainText() # lines = txt.split("\n") # fileLength = len(''.join(lines)) out = '' # for line in lines: # line = line.rstrip() out = tltk.nlp.th2roman(txt) ui.OuttextEdit.appendPlainText(out) return(1) def ipa(): ui.OuttextEdit.clear() txt = ui.textEdit.toPlainText() completed = 0 # lines = txt.split("\n") # fileLength = len(''.join(lines)) out = '' # for line in lines: # line = line.rstrip() out = tltk.nlp.th2ipa(txt) ui.OuttextEdit.appendPlainText(out) return(1) def ipa_all(): ui.OuttextEdit.clear() txt = ui.textEdit.toPlainText() completed = 0 # lines = txt.split("\n") # fileLength = len(''.join(lines)) out = '' # for line in lines: # line = line.rstrip() out = tltk.nlp.g2p_all(txt) no=1 for (th,tran) in out: ui.OuttextEdit.appendPlainText(str(no)+') '+th+' : '+tran) no+=1 return(1) def exitProg(): sys.exit() def copyText(): ui.OuttextEdit.selectAll() ui.OuttextEdit.copy() return() if __name__ == "__main__": global ui import sys app = QtWidgets.QApplication(sys.argv) TTSDialog = QtWidgets.QDialog() ui = Ui_TTSDialog() ui.setupUi(TTSDialog) TTSDialog.show() sys.exit(app.exec_())