mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-08-16 15:00:33 +03:00
windows gui code
This commit is contained in:
parent
39858ce1ff
commit
ec55ef5fe2
3
.gitignore
vendored
3
.gitignore
vendored
@ -76,3 +76,6 @@ mert/sentence-bleu
|
||||
build/
|
||||
nbproject/
|
||||
|
||||
mingw/MosesGUI/MosesGUI.e4p
|
||||
mingw/MosesGUI/_eric4project/
|
||||
|
||||
|
133
mingw/MosesGUI/Ui_addMTModel.py
Normal file
133
mingw/MosesGUI/Ui_addMTModel.py
Normal file
@ -0,0 +1,133 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'C:\work\eric4workspace\MosesGUI\addMTModel.ui'
|
||||
#
|
||||
# Created: Thu Jul 11 13:38:49 2013
|
||||
# by: PyQt4 UI code generator 4.10.2
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
try:
|
||||
_fromUtf8 = QtCore.QString.fromUtf8
|
||||
except AttributeError:
|
||||
def _fromUtf8(s):
|
||||
return s
|
||||
|
||||
try:
|
||||
_encoding = QtGui.QApplication.UnicodeUTF8
|
||||
def _translate(context, text, disambig):
|
||||
return QtGui.QApplication.translate(context, text, disambig, _encoding)
|
||||
except AttributeError:
|
||||
def _translate(context, text, disambig):
|
||||
return QtGui.QApplication.translate(context, text, disambig)
|
||||
|
||||
class Ui_Dialog(object):
|
||||
def setupUi(self, Dialog):
|
||||
Dialog.setObjectName(_fromUtf8("Dialog"))
|
||||
Dialog.resize(494, 342)
|
||||
Dialog.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedKingdom))
|
||||
Dialog.setWindowFilePath(_fromUtf8(""))
|
||||
self.verticalLayout = QtGui.QVBoxLayout(Dialog)
|
||||
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
|
||||
self.groupBox_3 = QtGui.QGroupBox(Dialog)
|
||||
self.groupBox_3.setObjectName(_fromUtf8("groupBox_3"))
|
||||
self.gridLayout = QtGui.QGridLayout(self.groupBox_3)
|
||||
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
|
||||
self.label = QtGui.QLabel(self.groupBox_3)
|
||||
self.label.setObjectName(_fromUtf8("label"))
|
||||
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
|
||||
self.editName = QtGui.QLineEdit(self.groupBox_3)
|
||||
self.editName.setObjectName(_fromUtf8("editName"))
|
||||
self.gridLayout.addWidget(self.editName, 0, 1, 1, 3)
|
||||
self.verticalLayout.addWidget(self.groupBox_3)
|
||||
self.groupBox = QtGui.QGroupBox(Dialog)
|
||||
self.groupBox.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedKingdom))
|
||||
self.groupBox.setObjectName(_fromUtf8("groupBox"))
|
||||
self.verticalLayout_2 = QtGui.QVBoxLayout(self.groupBox)
|
||||
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
|
||||
self.grpBoxInternet = QtGui.QGroupBox(self.groupBox)
|
||||
self.grpBoxInternet.setCheckable(True)
|
||||
self.grpBoxInternet.setObjectName(_fromUtf8("grpBoxInternet"))
|
||||
self.verticalLayout_3 = QtGui.QVBoxLayout(self.grpBoxInternet)
|
||||
self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3"))
|
||||
self.editInternet = QtGui.QLineEdit(self.grpBoxInternet)
|
||||
self.editInternet.setObjectName(_fromUtf8("editInternet"))
|
||||
self.verticalLayout_3.addWidget(self.editInternet)
|
||||
self.verticalLayout_2.addWidget(self.grpBoxInternet)
|
||||
self.grpBoxLocal = QtGui.QGroupBox(self.groupBox)
|
||||
self.grpBoxLocal.setFlat(False)
|
||||
self.grpBoxLocal.setCheckable(True)
|
||||
self.grpBoxLocal.setChecked(False)
|
||||
self.grpBoxLocal.setObjectName(_fromUtf8("grpBoxLocal"))
|
||||
self.horizontalLayout = QtGui.QHBoxLayout(self.grpBoxLocal)
|
||||
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
|
||||
self.editLocal = QtGui.QLineEdit(self.grpBoxLocal)
|
||||
self.editLocal.setText(_fromUtf8(""))
|
||||
self.editLocal.setObjectName(_fromUtf8("editLocal"))
|
||||
self.horizontalLayout.addWidget(self.editLocal)
|
||||
self.btnLocal = QtGui.QPushButton(self.grpBoxLocal)
|
||||
self.btnLocal.setObjectName(_fromUtf8("btnLocal"))
|
||||
self.horizontalLayout.addWidget(self.btnLocal)
|
||||
self.horizontalLayout.setStretch(0, 9)
|
||||
self.horizontalLayout.setStretch(1, 1)
|
||||
self.verticalLayout_2.addWidget(self.grpBoxLocal)
|
||||
self.verticalLayout.addWidget(self.groupBox)
|
||||
self.groupBox_2 = QtGui.QGroupBox(Dialog)
|
||||
self.groupBox_2.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedKingdom))
|
||||
self.groupBox_2.setObjectName(_fromUtf8("groupBox_2"))
|
||||
self.horizontalLayout_2 = QtGui.QHBoxLayout(self.groupBox_2)
|
||||
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
|
||||
self.editPath = QtGui.QLineEdit(self.groupBox_2)
|
||||
self.editPath.setObjectName(_fromUtf8("editPath"))
|
||||
self.horizontalLayout_2.addWidget(self.editPath)
|
||||
self.btnPath = QtGui.QPushButton(self.groupBox_2)
|
||||
self.btnPath.setObjectName(_fromUtf8("btnPath"))
|
||||
self.horizontalLayout_2.addWidget(self.btnPath)
|
||||
self.horizontalLayout_2.setStretch(0, 9)
|
||||
self.horizontalLayout_2.setStretch(1, 1)
|
||||
self.verticalLayout.addWidget(self.groupBox_2)
|
||||
self.buttonBox = QtGui.QDialogButtonBox(Dialog)
|
||||
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
|
||||
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
|
||||
self.verticalLayout.addWidget(self.buttonBox)
|
||||
self.verticalLayout.setStretch(1, 2)
|
||||
self.verticalLayout.setStretch(2, 1)
|
||||
self.verticalLayout.setStretch(3, 1)
|
||||
|
||||
self.retranslateUi(Dialog)
|
||||
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.reject)
|
||||
QtCore.QMetaObject.connectSlotsByName(Dialog)
|
||||
Dialog.setTabOrder(self.editName, self.grpBoxInternet)
|
||||
Dialog.setTabOrder(self.grpBoxInternet, self.editInternet)
|
||||
Dialog.setTabOrder(self.editInternet, self.grpBoxLocal)
|
||||
Dialog.setTabOrder(self.grpBoxLocal, self.editLocal)
|
||||
Dialog.setTabOrder(self.editLocal, self.btnLocal)
|
||||
Dialog.setTabOrder(self.btnLocal, self.editPath)
|
||||
Dialog.setTabOrder(self.editPath, self.btnPath)
|
||||
Dialog.setTabOrder(self.btnPath, self.buttonBox)
|
||||
|
||||
def retranslateUi(self, Dialog):
|
||||
Dialog.setWindowTitle(_translate("Dialog", "Install MT Model", None))
|
||||
self.groupBox_3.setTitle(_translate("Dialog", "MT Model Details", None))
|
||||
self.label.setText(_translate("Dialog", "Model Name:", None))
|
||||
self.editName.setText(_translate("Dialog", "SampleModel", None))
|
||||
self.groupBox.setTitle(_translate("Dialog", "Install From ...", None))
|
||||
self.grpBoxInternet.setTitle(_translate("Dialog", "From Internet ...", None))
|
||||
self.editInternet.setText(_translate("Dialog", "http://www.statmt.org/~jie/models/EnFr4MosesGUI.zip", None))
|
||||
self.grpBoxLocal.setTitle(_translate("Dialog", "From Local File", None))
|
||||
self.btnLocal.setText(_translate("Dialog", "...", None))
|
||||
self.groupBox_2.setTitle(_translate("Dialog", "Install To ...", None))
|
||||
self.btnPath.setText(_translate("Dialog", "...", None))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
app = QtGui.QApplication(sys.argv)
|
||||
Dialog = QtGui.QDialog()
|
||||
ui = Ui_Dialog()
|
||||
ui.setupUi(Dialog)
|
||||
Dialog.show()
|
||||
sys.exit(app.exec_())
|
||||
|
73
mingw/MosesGUI/Ui_chooseMTModel.py
Normal file
73
mingw/MosesGUI/Ui_chooseMTModel.py
Normal file
@ -0,0 +1,73 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'C:\work\eric4workspace\MosesGUI\chooseMTModel.ui'
|
||||
#
|
||||
# Created: Wed Jul 10 16:00:02 2013
|
||||
# by: PyQt4 UI code generator 4.10.2
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
try:
|
||||
_fromUtf8 = QtCore.QString.fromUtf8
|
||||
except AttributeError:
|
||||
def _fromUtf8(s):
|
||||
return s
|
||||
|
||||
try:
|
||||
_encoding = QtGui.QApplication.UnicodeUTF8
|
||||
def _translate(context, text, disambig):
|
||||
return QtGui.QApplication.translate(context, text, disambig, _encoding)
|
||||
except AttributeError:
|
||||
def _translate(context, text, disambig):
|
||||
return QtGui.QApplication.translate(context, text, disambig)
|
||||
|
||||
class Ui_Dialog(object):
|
||||
def setupUi(self, Dialog):
|
||||
Dialog.setObjectName(_fromUtf8("Dialog"))
|
||||
Dialog.resize(400, 300)
|
||||
self.verticalLayout = QtGui.QVBoxLayout(Dialog)
|
||||
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
|
||||
self.groupBox = QtGui.QGroupBox(Dialog)
|
||||
self.groupBox.setObjectName(_fromUtf8("groupBox"))
|
||||
self.verticalLayout_2 = QtGui.QVBoxLayout(self.groupBox)
|
||||
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
|
||||
self.selTableView = QtGui.QTableView(self.groupBox)
|
||||
self.selTableView.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
|
||||
self.selTableView.setProperty("showDropIndicator", False)
|
||||
self.selTableView.setDragDropOverwriteMode(False)
|
||||
self.selTableView.setAlternatingRowColors(False)
|
||||
self.selTableView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
|
||||
self.selTableView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
|
||||
self.selTableView.setGridStyle(QtCore.Qt.DashLine)
|
||||
self.selTableView.setSortingEnabled(True)
|
||||
self.selTableView.setObjectName(_fromUtf8("selTableView"))
|
||||
self.selTableView.verticalHeader().setVisible(False)
|
||||
self.verticalLayout_2.addWidget(self.selTableView)
|
||||
self.verticalLayout.addWidget(self.groupBox)
|
||||
self.buttonBox = QtGui.QDialogButtonBox(Dialog)
|
||||
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
|
||||
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
|
||||
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
|
||||
self.verticalLayout.addWidget(self.buttonBox)
|
||||
|
||||
self.retranslateUi(Dialog)
|
||||
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), Dialog.accept)
|
||||
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.reject)
|
||||
QtCore.QMetaObject.connectSlotsByName(Dialog)
|
||||
|
||||
def retranslateUi(self, Dialog):
|
||||
Dialog.setWindowTitle(_translate("Dialog", "Please choose an MT model to load...", None))
|
||||
self.groupBox.setTitle(_translate("Dialog", "Avaialble MT Models", None))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
app = QtGui.QApplication(sys.argv)
|
||||
Dialog = QtGui.QDialog()
|
||||
ui = Ui_Dialog()
|
||||
ui.setupUi(Dialog)
|
||||
Dialog.show()
|
||||
sys.exit(app.exec_())
|
||||
|
65
mingw/MosesGUI/Ui_credits.py
Normal file
65
mingw/MosesGUI/Ui_credits.py
Normal file
@ -0,0 +1,65 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'C:\work\eric4workspace\MosesGUI\credits.ui'
|
||||
#
|
||||
# Created: Wed Jul 10 16:52:58 2013
|
||||
# by: PyQt4 UI code generator 4.10.2
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
try:
|
||||
_fromUtf8 = QtCore.QString.fromUtf8
|
||||
except AttributeError:
|
||||
def _fromUtf8(s):
|
||||
return s
|
||||
|
||||
try:
|
||||
_encoding = QtGui.QApplication.UnicodeUTF8
|
||||
def _translate(context, text, disambig):
|
||||
return QtGui.QApplication.translate(context, text, disambig, _encoding)
|
||||
except AttributeError:
|
||||
def _translate(context, text, disambig):
|
||||
return QtGui.QApplication.translate(context, text, disambig)
|
||||
|
||||
class Ui_Dialog(object):
|
||||
def setupUi(self, Dialog):
|
||||
Dialog.setObjectName(_fromUtf8("Dialog"))
|
||||
Dialog.resize(359, 271)
|
||||
self.label = QtGui.QLabel(Dialog)
|
||||
self.label.setGeometry(QtCore.QRect(10, 10, 341, 211))
|
||||
self.label.setAlignment(QtCore.Qt.AlignJustify|QtCore.Qt.AlignVCenter)
|
||||
self.label.setWordWrap(True)
|
||||
self.label.setObjectName(_fromUtf8("label"))
|
||||
self.pushButton = QtGui.QPushButton(Dialog)
|
||||
self.pushButton.setGeometry(QtCore.QRect(150, 240, 75, 23))
|
||||
self.pushButton.setObjectName(_fromUtf8("pushButton"))
|
||||
|
||||
self.retranslateUi(Dialog)
|
||||
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), Dialog.accept)
|
||||
QtCore.QMetaObject.connectSlotsByName(Dialog)
|
||||
|
||||
def retranslateUi(self, Dialog):
|
||||
Dialog.setWindowTitle(_translate("Dialog", "Credits and Support", None))
|
||||
self.label.setText(_translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
|
||||
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
|
||||
"p, li { white-space: pre-wrap; }\n"
|
||||
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8pt; font-weight:400; font-style:normal;\">\n"
|
||||
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:10pt;\">This software is provided by </span><a href=\"http://www.capitatranslationinterpreting.com/\"><span style=\" font-size:10pt; text-decoration: underline; color:#0000ff;\">Capita Translation and Interpreting</span></a><span style=\" font-size:10pt;\"> for the </span><a href=\"http://www.statmt.org/moses/\"><span style=\" font-size:10pt; text-decoration: underline; color:#0000ff;\">Moses</span></a><span style=\" font-size:10pt;\"> Statistical Machine Translation decoder as part of the </span><a href=\"http://www.statmt.org/mosescore/\"><span style=\" font-size:10pt; text-decoration: underline; color:#0000ff;\">Moses Core Project</span></a><a href=\"http://www.statmt.org/mosescore/\"><span style=\" font-size:10pt; text-decoration: underline; color:#000000;\">.</span></a></p>\n"
|
||||
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt; color:#000000;\"><br /></p>\n"
|
||||
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:10pt; color:#000000;\">For support, please email mail.jie.jiang@gmail.com or submit a post on </span><a href=\"http://www.statmt.org/moses/?n=Moses.MailingLists\"><span style=\" font-size:10pt; text-decoration: underline; color:#0000ff;\">Moses Support List</span></a><span style=\" font-size:10pt; text-decoration: underline; color:#000000;\">.</span></p>\n"
|
||||
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt; color:#000000;\"><br /></p>\n"
|
||||
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:10pt; color:#000000;\">More models are coming soon, please check </span><a href=\"http://www.statmt.org/moses/?n=Moses.Packages\"><span style=\" font-size:10pt; text-decoration: underline; color:#0000ff;\">Moses Packages</span></a><span style=\" font-size:10pt; text-decoration: underline; color:#000000;\">.</span></p></body></html>", None))
|
||||
self.pushButton.setText(_translate("Dialog", "OK", None))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
app = QtGui.QApplication(sys.argv)
|
||||
Dialog = QtGui.QDialog()
|
||||
ui = Ui_Dialog()
|
||||
ui.setupUi(Dialog)
|
||||
Dialog.show()
|
||||
sys.exit(app.exec_())
|
||||
|
188
mingw/MosesGUI/Ui_mainWindow.py
Normal file
188
mingw/MosesGUI/Ui_mainWindow.py
Normal file
@ -0,0 +1,188 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'C:\work\eric4workspace\MosesGUI\mainWindow.ui'
|
||||
#
|
||||
# Created: Thu Jul 11 13:38:46 2013
|
||||
# by: PyQt4 UI code generator 4.10.2
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
try:
|
||||
_fromUtf8 = QtCore.QString.fromUtf8
|
||||
except AttributeError:
|
||||
def _fromUtf8(s):
|
||||
return s
|
||||
|
||||
try:
|
||||
_encoding = QtGui.QApplication.UnicodeUTF8
|
||||
def _translate(context, text, disambig):
|
||||
return QtGui.QApplication.translate(context, text, disambig, _encoding)
|
||||
except AttributeError:
|
||||
def _translate(context, text, disambig):
|
||||
return QtGui.QApplication.translate(context, text, disambig)
|
||||
|
||||
class Ui_MainWindow(object):
|
||||
def setupUi(self, MainWindow):
|
||||
MainWindow.setObjectName(_fromUtf8("MainWindow"))
|
||||
MainWindow.resize(705, 491)
|
||||
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
|
||||
MainWindow.setSizePolicy(sizePolicy)
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon/moses.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
MainWindow.setWindowIcon(icon)
|
||||
MainWindow.setLayoutDirection(QtCore.Qt.LeftToRight)
|
||||
MainWindow.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedKingdom))
|
||||
self.centralWidget = QtGui.QWidget(MainWindow)
|
||||
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(self.centralWidget.sizePolicy().hasHeightForWidth())
|
||||
self.centralWidget.setSizePolicy(sizePolicy)
|
||||
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
|
||||
self.verticalLayout_3 = QtGui.QVBoxLayout(self.centralWidget)
|
||||
self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3"))
|
||||
self.tabWidget = QtGui.QTabWidget(self.centralWidget)
|
||||
self.tabWidget.setAutoFillBackground(True)
|
||||
self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
|
||||
self.tab = QtGui.QWidget()
|
||||
self.tab.setAutoFillBackground(True)
|
||||
self.tab.setObjectName(_fromUtf8("tab"))
|
||||
self.verticalLayout_2 = QtGui.QVBoxLayout(self.tab)
|
||||
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
|
||||
self.groupBox = QtGui.QGroupBox(self.tab)
|
||||
self.groupBox.setObjectName(_fromUtf8("groupBox"))
|
||||
self.gridLayout = QtGui.QGridLayout(self.groupBox)
|
||||
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
|
||||
self.label = QtGui.QLabel(self.groupBox)
|
||||
self.label.setObjectName(_fromUtf8("label"))
|
||||
self.gridLayout.addWidget(self.label, 2, 0, 1, 1)
|
||||
self.editSrcLang = QtGui.QLineEdit(self.groupBox)
|
||||
self.editSrcLang.setReadOnly(True)
|
||||
self.editSrcLang.setObjectName(_fromUtf8("editSrcLang"))
|
||||
self.gridLayout.addWidget(self.editSrcLang, 2, 1, 1, 1)
|
||||
self.editTrgLang = QtGui.QLineEdit(self.groupBox)
|
||||
self.editTrgLang.setReadOnly(True)
|
||||
self.editTrgLang.setObjectName(_fromUtf8("editTrgLang"))
|
||||
self.gridLayout.addWidget(self.editTrgLang, 2, 4, 1, 1)
|
||||
self.label_3 = QtGui.QLabel(self.groupBox)
|
||||
self.label_3.setObjectName(_fromUtf8("label_3"))
|
||||
self.gridLayout.addWidget(self.label_3, 2, 3, 1, 1)
|
||||
self.btnTranslate = QtGui.QPushButton(self.groupBox)
|
||||
self.btnTranslate.setEnabled(True)
|
||||
self.btnTranslate.setMinimumSize(QtCore.QSize(120, 30))
|
||||
self.btnTranslate.setFlat(False)
|
||||
self.btnTranslate.setObjectName(_fromUtf8("btnTranslate"))
|
||||
self.gridLayout.addWidget(self.btnTranslate, 3, 2, 1, 1)
|
||||
self.editModelName = QtGui.QLineEdit(self.groupBox)
|
||||
self.editModelName.setReadOnly(True)
|
||||
self.editModelName.setObjectName(_fromUtf8("editModelName"))
|
||||
self.gridLayout.addWidget(self.editModelName, 1, 2, 1, 1)
|
||||
self.label_2 = QtGui.QLabel(self.groupBox)
|
||||
self.label_2.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
|
||||
self.label_2.setObjectName(_fromUtf8("label_2"))
|
||||
self.gridLayout.addWidget(self.label_2, 1, 1, 1, 1)
|
||||
self.verticalLayout_2.addWidget(self.groupBox)
|
||||
self.splitter = QtGui.QSplitter(self.tab)
|
||||
self.splitter.setOrientation(QtCore.Qt.Horizontal)
|
||||
self.splitter.setObjectName(_fromUtf8("splitter"))
|
||||
self.editSrc = QtGui.QTextEdit(self.splitter)
|
||||
self.editSrc.setObjectName(_fromUtf8("editSrc"))
|
||||
self.editTrg = QtGui.QTextEdit(self.splitter)
|
||||
self.editTrg.setReadOnly(True)
|
||||
self.editTrg.setObjectName(_fromUtf8("editTrg"))
|
||||
self.verticalLayout_2.addWidget(self.splitter)
|
||||
self.verticalLayout_2.setStretch(0, 2)
|
||||
self.verticalLayout_2.setStretch(1, 8)
|
||||
self.tabWidget.addTab(self.tab, _fromUtf8(""))
|
||||
self.tab_2 = QtGui.QWidget()
|
||||
self.tab_2.setAutoFillBackground(True)
|
||||
self.tab_2.setObjectName(_fromUtf8("tab_2"))
|
||||
self.verticalLayout = QtGui.QVBoxLayout(self.tab_2)
|
||||
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
|
||||
self.label_5 = QtGui.QLabel(self.tab_2)
|
||||
self.label_5.setAutoFillBackground(True)
|
||||
self.label_5.setObjectName(_fromUtf8("label_5"))
|
||||
self.verticalLayout.addWidget(self.label_5)
|
||||
self.splitter_4 = QtGui.QSplitter(self.tab_2)
|
||||
self.splitter_4.setOrientation(QtCore.Qt.Horizontal)
|
||||
self.splitter_4.setObjectName(_fromUtf8("splitter_4"))
|
||||
self.groupBox_3 = QtGui.QGroupBox(self.splitter_4)
|
||||
self.groupBox_3.setMinimumSize(QtCore.QSize(200, 0))
|
||||
self.groupBox_3.setMaximumSize(QtCore.QSize(200, 16777215))
|
||||
self.groupBox_3.setAutoFillBackground(True)
|
||||
self.groupBox_3.setObjectName(_fromUtf8("groupBox_3"))
|
||||
self.formLayout = QtGui.QFormLayout(self.groupBox_3)
|
||||
self.formLayout.setObjectName(_fromUtf8("formLayout"))
|
||||
self.newModelBtn = QtGui.QPushButton(self.groupBox_3)
|
||||
self.newModelBtn.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedKingdom))
|
||||
self.newModelBtn.setObjectName(_fromUtf8("newModelBtn"))
|
||||
self.formLayout.setWidget(0, QtGui.QFormLayout.SpanningRole, self.newModelBtn)
|
||||
self.delModelBtn = QtGui.QPushButton(self.groupBox_3)
|
||||
self.delModelBtn.setObjectName(_fromUtf8("delModelBtn"))
|
||||
self.formLayout.setWidget(1, QtGui.QFormLayout.SpanningRole, self.delModelBtn)
|
||||
self.tableView = QtGui.QTableView(self.splitter_4)
|
||||
font = QtGui.QFont()
|
||||
font.setPointSize(7)
|
||||
self.tableView.setFont(font)
|
||||
self.tableView.setMouseTracking(False)
|
||||
self.tableView.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
|
||||
self.tableView.setAutoFillBackground(True)
|
||||
self.tableView.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedKingdom))
|
||||
self.tableView.setFrameShape(QtGui.QFrame.StyledPanel)
|
||||
self.tableView.setFrameShadow(QtGui.QFrame.Plain)
|
||||
self.tableView.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
|
||||
self.tableView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
|
||||
self.tableView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
|
||||
self.tableView.setGridStyle(QtCore.Qt.DashLine)
|
||||
self.tableView.setSortingEnabled(True)
|
||||
self.tableView.setWordWrap(False)
|
||||
self.tableView.setCornerButtonEnabled(False)
|
||||
self.tableView.setObjectName(_fromUtf8("tableView"))
|
||||
self.tableView.verticalHeader().setVisible(False)
|
||||
self.tableView.verticalHeader().setSortIndicatorShown(True)
|
||||
self.verticalLayout.addWidget(self.splitter_4)
|
||||
self.verticalLayout.setStretch(1, 1000)
|
||||
self.tabWidget.addTab(self.tab_2, _fromUtf8(""))
|
||||
self.verticalLayout_3.addWidget(self.tabWidget)
|
||||
self.labelInfo = QtGui.QLabel(self.centralWidget)
|
||||
self.labelInfo.setTextFormat(QtCore.Qt.AutoText)
|
||||
self.labelInfo.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
|
||||
self.labelInfo.setObjectName(_fromUtf8("labelInfo"))
|
||||
self.verticalLayout_3.addWidget(self.labelInfo)
|
||||
MainWindow.setCentralWidget(self.centralWidget)
|
||||
|
||||
self.retranslateUi(MainWindow)
|
||||
self.tabWidget.setCurrentIndex(0)
|
||||
QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
||||
|
||||
def retranslateUi(self, MainWindow):
|
||||
MainWindow.setWindowTitle(_translate("MainWindow", "Moses Machine Translation System", None))
|
||||
self.groupBox.setTitle(_translate("MainWindow", "Current MT Model", None))
|
||||
self.label.setText(_translate("MainWindow", "Translate From:", None))
|
||||
self.label_3.setText(_translate("MainWindow", "Translate Into:", None))
|
||||
self.btnTranslate.setText(_translate("MainWindow", "Translate", None))
|
||||
self.label_2.setText(_translate("MainWindow", "Model Name:", None))
|
||||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "Machine Translation", None))
|
||||
self.label_5.setText(_translate("MainWindow", "TextLabel", None))
|
||||
self.groupBox_3.setTitle(_translate("MainWindow", "Management", None))
|
||||
self.newModelBtn.setText(_translate("MainWindow", "Install New Model ...", None))
|
||||
self.delModelBtn.setText(_translate("MainWindow", "Uninstall Selected Model ...", None))
|
||||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "Model Management", None))
|
||||
self.labelInfo.setText(_translate("MainWindow", "<qt><a href=\"www\">Credits and Support</a></qt>", None))
|
||||
|
||||
import icons_rc
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
app = QtGui.QApplication(sys.argv)
|
||||
MainWindow = QtGui.QMainWindow()
|
||||
ui = Ui_MainWindow()
|
||||
ui.setupUi(MainWindow)
|
||||
MainWindow.show()
|
||||
sys.exit(app.exec_())
|
||||
|
0
mingw/MosesGUI/__init__.py
Normal file
0
mingw/MosesGUI/__init__.py
Normal file
114
mingw/MosesGUI/addMTModel.py
Normal file
114
mingw/MosesGUI/addMTModel.py
Normal file
@ -0,0 +1,114 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Module implementing Dialog.
|
||||
"""
|
||||
|
||||
from PyQt4.QtGui import *
|
||||
from PyQt4.QtCore import *
|
||||
|
||||
import os, datetime
|
||||
|
||||
from Ui_addMTModel import Ui_Dialog
|
||||
from util import *
|
||||
|
||||
class AddMTModelDialog(QDialog, Ui_Dialog):
|
||||
"""
|
||||
Class documentation goes here.
|
||||
"""
|
||||
def __init__(self, parent = None, workdir=None):
|
||||
"""
|
||||
Constructor
|
||||
"""
|
||||
QDialog.__init__(self, parent)
|
||||
self.setupUi(self)
|
||||
self.timestr = None
|
||||
self.workdir = workdir
|
||||
todir, timestr = self.findEmptyDirWithTime(self.workdir)
|
||||
self.editPath.setText(todir)
|
||||
self.editName.setText("SampleModel_" + timestr)
|
||||
|
||||
def findEmptyDirWithTime(self, workdir):
|
||||
if not self.timestr:
|
||||
self.timestr = datetime.datetime.now().strftime('%Y-%m-%d_%H%M%S')
|
||||
while True:
|
||||
todir = os.path.join(workdir, "Model_%s" % self.timestr)
|
||||
if not os.path.exists(todir):
|
||||
break
|
||||
self.timestr = datetime.datetime.now().strftime('%Y-%m-%d_%H%M%S')
|
||||
return todir, self.timestr
|
||||
|
||||
@pyqtSignature("")
|
||||
def on_btnLocal_clicked(self):
|
||||
"""
|
||||
Slot documentation goes here.
|
||||
"""
|
||||
dialog = QFileDialog(self)
|
||||
dialog.setFileMode(QFileDialog.ExistingFile)
|
||||
dialog.setNameFilter("Zipped model files (*.zip)")
|
||||
dialog.setViewMode(QFileDialog.Detail)
|
||||
if dialog.exec_():
|
||||
self.editLocal.setText(dialog.selectedFiles()[0])
|
||||
|
||||
@pyqtSignature("")
|
||||
def on_btnPath_clicked(self):
|
||||
"""
|
||||
Slot documentation goes here.
|
||||
"""
|
||||
dialog = QFileDialog(self, directory=self.workdir)
|
||||
dialog.setFileMode(QFileDialog.Directory)
|
||||
dialog.setViewMode(QFileDialog.Detail)
|
||||
dialog.setOptions(QFileDialog.ShowDirsOnly)
|
||||
if dialog.exec_():
|
||||
root = str(dialog.selectedFiles()[0])
|
||||
todir, _ = self.findEmptyDirWithTime(root)
|
||||
self.editPath.setText(todir)
|
||||
|
||||
@pyqtSignature("bool")
|
||||
def on_grpBoxInternet_toggled(self, p0):
|
||||
"""
|
||||
Slot documentation goes here.
|
||||
"""
|
||||
self.grpBoxLocal.setChecked(not p0)
|
||||
|
||||
@pyqtSignature("bool")
|
||||
def on_grpBoxLocal_toggled(self, p0):
|
||||
"""
|
||||
Slot documentation goes here.
|
||||
"""
|
||||
self.grpBoxInternet.setChecked(not p0)
|
||||
|
||||
@pyqtSignature("")
|
||||
def on_buttonBox_accepted(self):
|
||||
"""
|
||||
Slot documentation goes here.
|
||||
"""
|
||||
def checkEmpty(mystr):
|
||||
return len(str(mystr).strip()) <= 0
|
||||
|
||||
#check everything
|
||||
self.modelName = self.editName.text()
|
||||
if checkEmpty(self.modelName):
|
||||
doAlert("Please provide non-empty Model Name")
|
||||
return
|
||||
if self.grpBoxInternet.isChecked():
|
||||
self.source = self.editInternet.text()
|
||||
self.sourceMode = "Internet"
|
||||
elif self.grpBoxLocal.isChecked():
|
||||
self.source = self.editLocal.text()
|
||||
self.sourceMode = "Local"
|
||||
if not os.path.exists(str(self.source)):
|
||||
doAlert("Please provide valid local file as source")
|
||||
return
|
||||
else:
|
||||
doAlert("Please provide Install Source")
|
||||
return
|
||||
if checkEmpty(self.source):
|
||||
doAlert("Please provide non-empty Install Source")
|
||||
return
|
||||
self.dest = self.editPath.text()
|
||||
if checkEmpty(self.dest):
|
||||
doAlert("Please provide non-empty Install Destination Folder")
|
||||
return
|
||||
self.accept()
|
||||
|
170
mingw/MosesGUI/addMTModel.ui
Normal file
170
mingw/MosesGUI/addMTModel.ui
Normal file
@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>494</width>
|
||||
<height>342</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Install MT Model</string>
|
||||
</property>
|
||||
<property name="locale">
|
||||
<locale language="English" country="UnitedKingdom"/>
|
||||
</property>
|
||||
<property name="windowFilePath">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,2,1,1">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>MT Model Details</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Model Name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="3">
|
||||
<widget class="QLineEdit" name="editName">
|
||||
<property name="text">
|
||||
<string>SampleModel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="locale">
|
||||
<locale language="English" country="UnitedKingdom"/>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Install From ...</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="grpBoxInternet">
|
||||
<property name="title">
|
||||
<string>From Internet ...</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editInternet">
|
||||
<property name="text">
|
||||
<string>http://www.statmt.org/~jie/models/EnFr4MosesGUI.zip</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="grpBoxLocal">
|
||||
<property name="title">
|
||||
<string>From Local File</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="9,1">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editLocal">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnLocal">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="locale">
|
||||
<locale language="English" country="UnitedKingdom"/>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Install To ...</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="9,1">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editPath"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnPath">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>editName</tabstop>
|
||||
<tabstop>grpBoxInternet</tabstop>
|
||||
<tabstop>editInternet</tabstop>
|
||||
<tabstop>grpBoxLocal</tabstop>
|
||||
<tabstop>editLocal</tabstop>
|
||||
<tabstop>btnLocal</tabstop>
|
||||
<tabstop>editPath</tabstop>
|
||||
<tabstop>btnPath</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>442</x>
|
||||
<y>326</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>474</x>
|
||||
<y>339</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
71
mingw/MosesGUI/chooseMTModel.py
Normal file
71
mingw/MosesGUI/chooseMTModel.py
Normal file
@ -0,0 +1,71 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Module implementing ChooseMTModelDialog.
|
||||
"""
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
from PyQt4.QtSql import *
|
||||
|
||||
from Ui_chooseMTModel import Ui_Dialog
|
||||
|
||||
class ChooseMTModelDialog(QDialog, Ui_Dialog):
|
||||
"""
|
||||
Class documentation goes here.
|
||||
"""
|
||||
def __init__(self, parent = None, datamodel = None):
|
||||
"""
|
||||
Constructor
|
||||
"""
|
||||
QDialog.__init__(self, parent)
|
||||
self.setupUi(self)
|
||||
self.model = QSqlQueryModel()
|
||||
self.selTableView.setModel(self.model)
|
||||
self.database = datamodel.getQSqlDatabase()
|
||||
self.updateModel()
|
||||
self.selTableView.hideColumn(0)
|
||||
self.selTableView.hideColumn(5)
|
||||
self.selTableView.hideColumn(6)
|
||||
#change status and keep the column
|
||||
QObject.connect(datamodel, SIGNAL("modelInstalled()"), self.on_datamodel_modelInstalled)
|
||||
|
||||
def updateModel(self):
|
||||
self.model.setQuery('SELECT ID, name, srclang, trglang, status, path, mosesini FROM models WHERE status = "READY" AND deleted != "True"', self.database)
|
||||
|
||||
def on_datamodel_recordUpdated(self, bRecord):
|
||||
#deal with the selection changed problem
|
||||
try:
|
||||
if bRecord:
|
||||
current = self.selTableView.currentIndex()
|
||||
if current and current.row() <> -1:
|
||||
self.curSelection = current.row()
|
||||
else:
|
||||
self.curSelection = None
|
||||
else:
|
||||
if not self.curSelection is None:
|
||||
self.selTableView.selectRow(self.curSelection)
|
||||
except Exception, e:
|
||||
print >> sys.stderr, str(e)
|
||||
|
||||
def on_datamodel_modelInstalled(self):
|
||||
self.updateModel()
|
||||
|
||||
@pyqtSignature("")
|
||||
def on_buttonBox_accepted(self):
|
||||
"""
|
||||
Slot documentation goes here.
|
||||
"""
|
||||
current = self.selTableView.currentIndex()
|
||||
if not current:
|
||||
doAlert("Please choose a model to start.")
|
||||
return
|
||||
record = self.model.record(current.row())
|
||||
self.ID = record.value("ID").toString()
|
||||
self.modelName = record.value("name").toString()
|
||||
self.srcLang = record.value('srclang').toString()
|
||||
self.trgLang = record.value('trglang').toString()
|
||||
self.path = record.value("path").toString()
|
||||
self.mosesini = record.value("mosesini").toString()
|
||||
self.accept()
|
||||
|
104
mingw/MosesGUI/chooseMTModel.ui
Normal file
104
mingw/MosesGUI/chooseMTModel.ui
Normal file
@ -0,0 +1,104 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Please choose an MT model to load...</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Avaialble MT Models</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QTableView" name="selTableView">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="showDropIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="dragDropOverwriteMode">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="gridStyle">
|
||||
<enum>Qt::DashLine</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
29
mingw/MosesGUI/credits.py
Normal file
29
mingw/MosesGUI/credits.py
Normal file
@ -0,0 +1,29 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Module implementing DlgCredits.
|
||||
"""
|
||||
|
||||
from PyQt4.QtGui import QDialog, QDesktopServices
|
||||
from PyQt4.QtCore import pyqtSignature, QUrl
|
||||
|
||||
from Ui_credits import Ui_Dialog
|
||||
|
||||
class DlgCredits(QDialog, Ui_Dialog):
|
||||
"""
|
||||
Class documentation goes here.
|
||||
"""
|
||||
def __init__(self, parent = None):
|
||||
"""
|
||||
Constructor
|
||||
"""
|
||||
QDialog.__init__(self, parent)
|
||||
self.setupUi(self)
|
||||
|
||||
|
||||
@pyqtSignature("QString")
|
||||
def on_label_linkActivated(self, link):
|
||||
"""
|
||||
Slot documentation goes here.
|
||||
"""
|
||||
QDesktopServices().openUrl(QUrl(link))
|
76
mingw/MosesGUI/credits.ui
Normal file
76
mingw/MosesGUI/credits.ui
Normal file
@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>359</width>
|
||||
<height>271</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Credits and Support</string>
|
||||
</property>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>341</width>
|
||||
<height>211</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">This software is provided by </span><a href="http://www.capitatranslationinterpreting.com/"><span style=" font-size:10pt; text-decoration: underline; color:#0000ff;">Capita Translation and Interpreting</span></a><span style=" font-size:10pt;"> for the </span><a href="http://www.statmt.org/moses/"><span style=" font-size:10pt; text-decoration: underline; color:#0000ff;">Moses</span></a><span style=" font-size:10pt;"> Statistical Machine Translation decoder as part of the </span><a href="http://www.statmt.org/mosescore/"><span style=" font-size:10pt; text-decoration: underline; color:#0000ff;">Moses Core Project</span></a><a href="http://www.statmt.org/mosescore/"><span style=" font-size:10pt; text-decoration: underline; color:#000000;">.</span></a></p>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt; color:#000000;"><br /></p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt; color:#000000;">For support, please email mail.jie.jiang@gmail.com or submit a post on </span><a href="http://www.statmt.org/moses/?n=Moses.MailingLists"><span style=" font-size:10pt; text-decoration: underline; color:#0000ff;">Moses Support List</span></a><span style=" font-size:10pt; text-decoration: underline; color:#000000;">.</span></p>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt; color:#000000;"><br /></p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt; color:#000000;">More models are coming soon, please check </span><a href="http://www.statmt.org/moses/?n=Moses.Packages"><span style=" font-size:10pt; text-decoration: underline; color:#0000ff;">Moses Packages</span></a><span style=" font-size:10pt; text-decoration: underline; color:#000000;">.</span></p></body></html></string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignJustify|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>150</x>
|
||||
<y>240</y>
|
||||
<width>75</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>OK</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>pushButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>151</x>
|
||||
<y>98</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>186</x>
|
||||
<y>118</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
325
mingw/MosesGUI/datamodel.py
Normal file
325
mingw/MosesGUI/datamodel.py
Normal file
@ -0,0 +1,325 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtSql import *
|
||||
|
||||
import sys, os, threading, time, urllib2, zipfile, shutil, ConfigParser
|
||||
from util import *
|
||||
|
||||
class DataModel(QSqlTableModel):
|
||||
import os
|
||||
defaultDbFile = os.path.join(os.path.split(os.path.realpath(__file__))[0], "models.sqlite")
|
||||
|
||||
def __init__(self, parent=None, filename=None):
|
||||
self.installThreads = {}
|
||||
self.processes = set()
|
||||
if filename is None:
|
||||
filename = DataModel.defaultDbFile
|
||||
self.db = QSqlDatabase.addDatabase('QSQLITE')
|
||||
print >> sys.stderr, "Open database at %s" % filename
|
||||
self.db.setDatabaseName(filename)
|
||||
self.db.open()
|
||||
query = QSqlQuery('SELECT COUNT(*) FROM sqlite_master WHERE type="table" AND tbl_name="models"', self.db)
|
||||
if not query.next() or query.value(0).toInt()[0] < 1:
|
||||
#create new table
|
||||
print >> sys.stderr, "Table not find, create the table"
|
||||
query = QSqlQuery('CREATE TABLE models (ID INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, status TEXT, srclang TEXT, trglang TEXT, date DATE, path TEXT, mosesini TEXT, origin TEXT, originMode TEXT, deleted TEXT)', self.db)
|
||||
if query.next():
|
||||
print >> sys.stderr, query.value(0).toString()
|
||||
#TODO: shoudn't design the deletion checking like this
|
||||
#change all deleted models into not deleted in case it failed last time
|
||||
query = QSqlQuery('UPDATE models SET deleted="False" WHERE deleted="True"', self.db)
|
||||
query = QSqlQuery('UPDATE models SET status="READY" WHERE status="ON"', self.db)
|
||||
super(DataModel, self).__init__(parent, self.db)
|
||||
self.setTable("models")
|
||||
self.select()
|
||||
self.setEditStrategy(QSqlTableModel.OnFieldChange)
|
||||
|
||||
def destroy(self):
|
||||
bExit = False
|
||||
for i in self.installThreads:
|
||||
t, flag = self.installThreads[i]
|
||||
if t.isAlive() and flag:
|
||||
if not bExit:
|
||||
if not doQuestion("Installing process is running in the background, do you want to terminate them and exit?"):
|
||||
return False
|
||||
else:
|
||||
bExit = True
|
||||
self.installThreads[i][1] = False
|
||||
t.join()
|
||||
if self.db:
|
||||
self.db.close()
|
||||
self.db = None
|
||||
return True
|
||||
|
||||
def getQSqlDatabase(self):
|
||||
return self.db
|
||||
|
||||
def getRowID(self, row):
|
||||
record = self.record(row)
|
||||
return record.value('ID')
|
||||
|
||||
def delModel(self, row):
|
||||
record = self.record(row)
|
||||
if str(record.value('deleted').toString()) == 'True':
|
||||
self.emit(SIGNAL("messageBox(QString)"), "The model is deleting, please be patient!")
|
||||
return
|
||||
#hint to decide what to delete
|
||||
text = '''You are going to delete the selected model entry.
|
||||
Do you also want to delete all the model files on the disk?
|
||||
Click "Yes" to delete model entry and model files.
|
||||
Click "No" to delete model entry but keep model files.
|
||||
Click "Cancel" to do nothing.'''
|
||||
reply = QMessageBox.question(None, 'Message', text, QMessageBox.Yes, QMessageBox.No, QMessageBox.Cancel)
|
||||
|
||||
if reply == QMessageBox.Cancel:
|
||||
return
|
||||
else:
|
||||
record.setValue('deleted', 'True')
|
||||
self.changeRecord(row, record)
|
||||
def delModelThread():
|
||||
irowid, _ = record.value("ID").toInt()
|
||||
if irowid in self.installThreads:
|
||||
t, flag = self.installThreads[irowid]
|
||||
if t.isAlive() and flag:
|
||||
self.installThreads[irowid][1] = False
|
||||
t.join()
|
||||
if reply == QMessageBox.Yes:
|
||||
destDir = str(record.value("path").toString())
|
||||
try:
|
||||
shutil.rmtree(destDir)
|
||||
except Exception, e:
|
||||
self.emit(SIGNAL("messageBox(QString)"), "Failed to remove dir: " + destDir)
|
||||
print >> sys.stderr, str(e)
|
||||
self.removeRow(row)
|
||||
#end of Model deleting thread
|
||||
|
||||
t = threading.Thread(target=delModelThread)
|
||||
t.start()
|
||||
|
||||
def newEntry(self):
|
||||
import random
|
||||
rec = self.record()
|
||||
for i in xrange(1, 10):
|
||||
rec.setValue(i, QVariant(str(random.random())))
|
||||
self.insertRecord(-1, rec)
|
||||
doAlert(self.query().lastInsertId().toString())
|
||||
|
||||
def changeRecord(self, curRow, record):
|
||||
#self.emit(SIGNAL("recordUpdated(bool)"), True) #record selection
|
||||
self.setRecord(curRow, record)
|
||||
#self.emit(SIGNAL("recordUpdated(bool)"), False) #restore selection
|
||||
|
||||
def installModel(self, installParam):
|
||||
dest = installParam['dest']
|
||||
#make dir
|
||||
if not os.path.exists(dest):
|
||||
try:
|
||||
os.makedirs(str(dest))
|
||||
except:
|
||||
doAlert("Failed to create install directory: %s" % dest)
|
||||
return
|
||||
#create entry in db
|
||||
rec = self.record()
|
||||
rec.setValue('name', installParam['modelName'])
|
||||
rec.setValue('status', 'Fetching Source...')
|
||||
rec.setValue('path', dest)
|
||||
rec.setValue('origin', installParam['source'])
|
||||
rec.setValue('originMode', installParam['sourceMode'])
|
||||
rec.setValue('date', QDateTime.currentDateTime())
|
||||
rec.setValue('deleted', 'False')
|
||||
self.insertRecord(-1, rec)
|
||||
rowid = self.query().lastInsertId()
|
||||
|
||||
#start thread
|
||||
def installThread(irowid):
|
||||
|
||||
#find the current row in model
|
||||
def updateRecord(keyvalues):
|
||||
curRow = None
|
||||
for i in xrange(0, self.rowCount()): # TODO: use binary search instead of linear
|
||||
if self.record(i).value("ID") == rowid:
|
||||
curRow = i
|
||||
break
|
||||
if not curRow is None:
|
||||
record = self.record(curRow)
|
||||
for key in keyvalues:
|
||||
record.setValue(key, keyvalues[key])
|
||||
self.changeRecord(curRow, record)
|
||||
return curRow
|
||||
|
||||
def checkExit():
|
||||
if not irowid in self.installThreads or not self.installThreads[irowid][1]: #check thread is ok to run
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def markExit():
|
||||
if irowid in self.installThreads: #set thread to dead
|
||||
self.installThreads[irowid][1] = False
|
||||
|
||||
def statusMessageLogMarkExit(status=None, message=None, exception=None):
|
||||
if not status is None:
|
||||
updateRecord({'status':status})
|
||||
if not message is None:
|
||||
self.emit(SIGNAL("messageBox(QString)"), message)
|
||||
print >> sys.stderr, message
|
||||
if not exception is None:
|
||||
print >> sys.stderr, str(exception)
|
||||
markExit()
|
||||
|
||||
#1. download or copy from local
|
||||
destFile = os.path.join(str(dest), "model.zip") #where the downloaded/copied zip file is
|
||||
destDir = os.path.join(str(dest), "model") #where the unzipped contents are
|
||||
|
||||
if installParam['sourceMode'] == 'Local':
|
||||
fin = fout = None
|
||||
try:
|
||||
inFile = str(installParam['source'])
|
||||
total_size = os.path.getsize(inFile)
|
||||
fin = open(inFile, 'rb')
|
||||
chunk_size = 52428800 #50MB as chunk size
|
||||
fout = open(destFile, 'wb')
|
||||
content = fin.read(chunk_size)
|
||||
download_size = content_size = len(content)
|
||||
lastMsg = ""
|
||||
while content_size > 0:
|
||||
if checkExit(): #check if thread is notified as exit
|
||||
return statusMessageLogMarkExit()
|
||||
fout.write(content)
|
||||
if total_size > 0:
|
||||
msg = 'COPY %.0f%%' % (download_size * 100.0 / total_size)
|
||||
else:
|
||||
msg = 'COPY %d MB' % (download_size/1048576)
|
||||
if msg <> lastMsg:
|
||||
updateRecord({'status' : msg})
|
||||
lastMsg = msg
|
||||
content = fin.read(chunk_size)
|
||||
content_size = len(content)
|
||||
download_size += content_size
|
||||
except Exception, e:
|
||||
return statusMessageLogMarkExit(status='Failed copying from: %s' % installParam['source'],
|
||||
message="Failed copy model: %s" % installParam['modelName'], exception=e)
|
||||
finally:
|
||||
if fin:
|
||||
fin.close()
|
||||
if fout:
|
||||
fout.close()
|
||||
|
||||
elif installParam['sourceMode'] == 'Internet':
|
||||
conn = fout = None
|
||||
try:
|
||||
conn = urllib2.urlopen(str(installParam['source']))
|
||||
total_size = int(conn.headers['Content-Length'])
|
||||
chunk_size = 1048576 #1MB as chunk size
|
||||
fout = open(destFile, 'wb')
|
||||
content = conn.read(chunk_size)
|
||||
download_size = content_size = len(content)
|
||||
lastMsg = ""
|
||||
while content_size > 0:
|
||||
if checkExit(): #check if thread is notified as exit
|
||||
return statusMessageLogMarkExit()
|
||||
fout.write(content)
|
||||
if total_size > 0:
|
||||
msg = 'DOWNLOAD %.0f%%' % (download_size * 100.0 / total_size)
|
||||
else:
|
||||
msg = 'DOWNLOAD %d MB' % (download_size/1048576)
|
||||
if msg <> lastMsg:
|
||||
updateRecord({'status' : msg})
|
||||
lastMsg = msg
|
||||
content = conn.read(chunk_size)
|
||||
content_size = len(content)
|
||||
download_size += content_size
|
||||
except Exception, e:
|
||||
return statusMessageLogMarkExit(status='Failed downloading from: %s' % installParam['source'],
|
||||
message="Failed download model: %s" % installParam['modelName'], exception=e)
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
if fout:
|
||||
fout.close()
|
||||
else:
|
||||
return statusMessageLogMarkExit(status='Unsupported source mode: %s' % installParam['sourceMode'])
|
||||
|
||||
#2. unzip
|
||||
zfile = fout = None
|
||||
try:
|
||||
zfile = zipfile.ZipFile(destFile)
|
||||
#check property files
|
||||
if not "model.ini" in zfile.namelist():
|
||||
return statusMessageLogMarkExit(status='Missing model.ini in model file: %s' % installParam['sourceMode'],
|
||||
message="Invalid modle file format because model.ini is missing in the zipped model file, exit installation for model %s" % installParam['modelName'])
|
||||
chunk_size = 52428800 #50MB as chunk size
|
||||
#get file size uncompressed
|
||||
total_size = 0
|
||||
for name in zfile.namelist():
|
||||
total_size += zfile.getinfo(name).file_size
|
||||
download_size = 0
|
||||
lastMsg = ""
|
||||
for i, name in enumerate(zfile.namelist()):
|
||||
(dirname, filename) = os.path.split(name)
|
||||
outDir = os.path.join(destDir, dirname)
|
||||
if not os.path.exists(outDir):
|
||||
os.makedirs(outDir)
|
||||
if filename:
|
||||
fin = zfile.open(name, 'r')
|
||||
outFile = os.path.join(destDir, name)
|
||||
fout = open(outFile, 'wb')
|
||||
content = fin.read(chunk_size)
|
||||
content_size = len(content)
|
||||
download_size += content_size
|
||||
while content_size > 0:
|
||||
if checkExit(): #check if thread is notified as exit
|
||||
return statusMessageLogMarkExit()
|
||||
fout.write(content)
|
||||
if total_size > 0:
|
||||
msg = 'UNZIP %.0f%%' % (download_size * 100.0 / total_size)
|
||||
else:
|
||||
msg = 'UNZIP %d MB' % (download_size/1048576)
|
||||
if msg <> lastMsg:
|
||||
updateRecord({'status' : msg})
|
||||
lastMsg = msg
|
||||
content = fin.read(chunk_size)
|
||||
content_size = len(content)
|
||||
download_size += content_size
|
||||
fin.close()
|
||||
fout.close()
|
||||
except Exception, e:
|
||||
return statusMessageLogMarkExit(status='Failed unzipping from: %s' % installParam['source'],
|
||||
message="Failed unzip model: %s" % installParam['modelName'], exception=e)
|
||||
finally:
|
||||
if zfile:
|
||||
zfile.close()
|
||||
if fin:
|
||||
fin.close()
|
||||
if fout:
|
||||
fout.close()
|
||||
|
||||
#3 post process and check data validity
|
||||
try:
|
||||
modelini = os.path.join(destDir, "model.ini")
|
||||
cp = ConfigParser.RawConfigParser()
|
||||
cp.read(modelini)
|
||||
mosesini = os.path.join(destDir, 'moses.ini')
|
||||
if not os.path.exists(mosesini):
|
||||
raise Exception, "Moses ini doesn't exist"
|
||||
updateRecord({'srclang':cp.get("Language", 'Source Language').upper(), 'trglang':cp.get("Language", 'Target Language').upper(), 'mosesini':mosesini})
|
||||
except Exception, e:
|
||||
return statusMessageLogMarkExit(status='ERROR model format %s' % installParam['source'],
|
||||
message="Unspported model format: %s" % installParam['modelName'], exception=e)
|
||||
|
||||
statusMessageLogMarkExit(status='READY', message="Model %s Installed!" % installParam['modelName'])
|
||||
#send new model signal
|
||||
self.emit(SIGNAL("modelInstalled()")) #record selection
|
||||
return
|
||||
#end of thread func
|
||||
|
||||
#start the thread
|
||||
irowid, _ = rowid.toInt()
|
||||
t = threading.Thread(target=installThread, args=(irowid, ))
|
||||
if irowid in self.installThreads: #if old thread is there
|
||||
print >> sys.stderr, "table rowid %d already has a thread running, stop it" % irowid
|
||||
self.installThreads[irowid][1] = False
|
||||
self.installThreads[irowid] = [t, True]
|
||||
t.start()
|
||||
|
89
mingw/MosesGUI/engine.py
Normal file
89
mingw/MosesGUI/engine.py
Normal file
@ -0,0 +1,89 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
|
||||
import os, subprocess, sys, signal, ConfigParser
|
||||
|
||||
from moses import Moses
|
||||
from util import *
|
||||
|
||||
class Engine(QObject):
|
||||
def __init__(self, model, moses):
|
||||
super(Engine, self).__init__()
|
||||
self.model = model
|
||||
self.moses = moses
|
||||
self.check(self.model)
|
||||
#determine how many steps by num of modules in the model directory (moses + tok/detok + ...) + 1
|
||||
modelini = model['path'] + os.sep + 'model' + os.sep + 'model.ini'
|
||||
if not os.path.exists(modelini):
|
||||
raise Exception, "Model ini file doesn't exist, please check model dir %s" % modelini
|
||||
cp = ConfigParser.RawConfigParser()
|
||||
cp.readfp(open(modelini))
|
||||
#true model
|
||||
truemodel = None
|
||||
try:
|
||||
truemodel = cp.get("Preprocess", 'Truemodel')
|
||||
if not os.path.exists(model['path'] + os.sep + 'model' + os.sep + truemodel):
|
||||
doAlert("Truemodel doesn't exist, ignore %s" % truemodel)
|
||||
truemodel = None
|
||||
except:
|
||||
#doAlert("Truemodel not configured")
|
||||
truemodel = None
|
||||
self.cmds = []
|
||||
#tok
|
||||
self.cmds.append('"%s" -q -l %s -noxml' % (self.moses.getTokenizer(), str(model['srclang']).lower()))
|
||||
if not truemodel is None:
|
||||
self.cmds.append('"%s" -model "%s"' % (self.moses.getTruecase(), truemodel) )
|
||||
self.cmds.append('"%s" -f moses.ini' % self.moses.getMosesCmd())
|
||||
self.cmds.append('"%s"' % self.moses.getDetruecase())
|
||||
self.cmds.append('"%s" -q -noxml -l %s' % (self.moses.getDetokenizer(), str(model['trglang']).lower()))
|
||||
self.process = []
|
||||
#doAlert('\n'.join(self.cmds))
|
||||
|
||||
def check(self, model):
|
||||
if not os.path.exists(model['path']) or not os.path.exists(model['mosesini']):
|
||||
raise Exception, "Model file doesn't exist, please check model dir %s" % self.model['path']
|
||||
|
||||
def countSteps(self):
|
||||
return len(self.cmds) + 1
|
||||
|
||||
def start(self):
|
||||
#print >> sys.stderr, self.cmds
|
||||
try:
|
||||
self.emit(SIGNAL("stepFinished(int)"), 0)
|
||||
for i, cmd in enumerate(self.cmds):
|
||||
proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=os.path.join(str(self.model['path']), 'model'))
|
||||
self.process.append(proc)
|
||||
if not proc.poll() is None:
|
||||
raise Exception, "Failed to start engine!"
|
||||
proc.stdin.write("dummy\n")
|
||||
proc.stdin.flush()
|
||||
if len(proc.stdout.readline().strip()) <= 0:
|
||||
raise Exception, "Engine process exited: [%s] in folder [%s]" % (cmd, os.path.join(str(self.model['path']), 'model'))
|
||||
self.emit(SIGNAL("stepFinished(int)"), i+1)
|
||||
self.emit(SIGNAL("loaded(bool, QString)"), True, "Model Loaded")
|
||||
except Exception, e:
|
||||
self.emit(SIGNAL("loaded(bool, QString)"), False, "Failed to load Model: %s" % str(e))
|
||||
|
||||
def stop(self):
|
||||
for process in self.process:
|
||||
#doAlert(str(process.pid))
|
||||
#print >> sys.stderr, str(process)
|
||||
process.terminate()
|
||||
process.wait()
|
||||
self.process = []
|
||||
|
||||
def translate(self, input):
|
||||
lastInput = input
|
||||
try:
|
||||
for i, proc in enumerate(self.process):
|
||||
if not proc.poll() is None:
|
||||
raise Exception, "Failed to start engine!"
|
||||
proc.stdin.write("%s\n" % lastInput)
|
||||
proc.stdin.flush()
|
||||
output = proc.stdout.readline().strip()
|
||||
lastInput = output
|
||||
return output
|
||||
except Exception, e:
|
||||
print >> sys.stderr, "Translate error: %s" % str(e)
|
||||
return lastInput
|
BIN
mingw/MosesGUI/icon/moses.gif
Normal file
BIN
mingw/MosesGUI/icon/moses.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
BIN
mingw/MosesGUI/icon/moses.ico
Normal file
BIN
mingw/MosesGUI/icon/moses.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
5
mingw/MosesGUI/icons.qrc
Normal file
5
mingw/MosesGUI/icons.qrc
Normal file
@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>icon/moses.ico</file>
|
||||
</qresource>
|
||||
</RCC>
|
1021
mingw/MosesGUI/icons_rc.py
Normal file
1021
mingw/MosesGUI/icons_rc.py
Normal file
File diff suppressed because it is too large
Load Diff
25
mingw/MosesGUI/main.py
Normal file
25
mingw/MosesGUI/main.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
|
||||
import sys, os
|
||||
|
||||
from mainWindow import MainWindow
|
||||
from datamodel import DataModel
|
||||
from moses import Moses
|
||||
from util import *
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
workdir = os.path.join(os.path.join(os.path.expanduser('~'), 'mosesgui'))
|
||||
if not os.path.exists(workdir):
|
||||
os.makedirs(workdir)
|
||||
dm = DataModel(filename=os.path.join(workdir, "models.sqlite"))
|
||||
moses = Moses()
|
||||
if not moses.detect():
|
||||
sys.exit(1)
|
||||
MainWindow = MainWindow(dm=dm, moses=moses, workdir=workdir)
|
||||
MainWindow.setupUi(MainWindow)
|
||||
MainWindow.show()
|
||||
sys.exit(app.exec_())
|
227
mingw/MosesGUI/mainWindow.py
Normal file
227
mingw/MosesGUI/mainWindow.py
Normal file
@ -0,0 +1,227 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Module implementing MainWindow.
|
||||
"""
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
from PyQt4.QtSql import *
|
||||
|
||||
import time, threading
|
||||
|
||||
from Ui_mainWindow import Ui_MainWindow
|
||||
from datamodel import DataModel
|
||||
from addMTModel import AddMTModelDialog
|
||||
from chooseMTModel import ChooseMTModelDialog
|
||||
from engine import Engine
|
||||
from credits import DlgCredits
|
||||
from util import *
|
||||
|
||||
class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
"""
|
||||
Class documentation goes here.
|
||||
"""
|
||||
def setupUi(self, mainWindow):
|
||||
super(MainWindow, self).setupUi(mainWindow)
|
||||
self.tableView.setModel(self.datamodel)
|
||||
self.tableView.hideColumn(0)
|
||||
#change status and keep the column
|
||||
QObject.connect(self.datamodel, SIGNAL("recordUpdated(bool)"), self.on_datamodel_recordUpdated)
|
||||
QObject.connect(self.datamodel, SIGNAL("messageBox(QString)"), self.on_datamodel_messageBox)
|
||||
#the response to change model
|
||||
for obj in (self.editModelName, self.editSrcLang, self.editTrgLang):
|
||||
obj.installEventFilter(self)
|
||||
|
||||
def __init__(self, parent = None, dm=None, moses=None, workdir=None):
|
||||
"""
|
||||
Constructor
|
||||
"""
|
||||
QMainWindow.__init__(self, parent)
|
||||
self.moses = moses
|
||||
self.datamodel = dm
|
||||
self.engine = None
|
||||
self.progress = None
|
||||
self.workdir = workdir
|
||||
|
||||
@pyqtSignature("")
|
||||
def on_delModelBtn_clicked(self):
|
||||
"""
|
||||
Slot documentation goes here.
|
||||
"""
|
||||
current = self.tableView.currentIndex()
|
||||
if current and current.row() >= 0:
|
||||
if self.engine and self.datamodel.getRowID(current.row()) == self.engine.model['ID']:
|
||||
text = '''The model is still in use, do you want to stop and delete it?
|
||||
It might take a while...'''
|
||||
reply = QMessageBox.question(None, 'Message', text, QMessageBox.Yes, QMessageBox.No)
|
||||
if reply == QMessageBox.No:
|
||||
return
|
||||
t = self.stopEngine(self.engine)
|
||||
t.join()
|
||||
self.engine = None
|
||||
self.clearPanel()
|
||||
self.datamodel.delModel(current.row())
|
||||
|
||||
@pyqtSignature("")
|
||||
def on_newModelBtn_clicked(self):
|
||||
"""
|
||||
Slot documentation goes here.
|
||||
"""
|
||||
dialog = AddMTModelDialog(self, self.workdir)
|
||||
if dialog.exec_():
|
||||
installParam = {'modelName': dialog.modelName, 'source':dialog.source, 'sourceMode':dialog.sourceMode, 'dest': dialog.dest}
|
||||
self.datamodel.installModel(installParam)
|
||||
self.tableView.selectRow(self.tableView.model().rowCount()-1)
|
||||
#self.datamodel.newEntry()
|
||||
|
||||
def on_datamodel_recordUpdated(self, bRecord):
|
||||
#deal with the selection changed problem
|
||||
try:
|
||||
if bRecord:
|
||||
current = self.tableView.currentIndex()
|
||||
if current and current.row() <> -1:
|
||||
self.curSelection = current.row()
|
||||
else:
|
||||
self.curSelection = None
|
||||
else:
|
||||
if not self.curSelection is None:
|
||||
self.tableView.selectRow(self.curSelection)
|
||||
except Exception, e:
|
||||
print >> sys.stderr, str(e)
|
||||
|
||||
def on_datamodel_messageBox(self, str):
|
||||
doAlert(str)
|
||||
|
||||
def closeEvent(self, event):
|
||||
#clear up
|
||||
if self.datamodel.destroy():
|
||||
event.accept()
|
||||
else:
|
||||
event.reject()
|
||||
|
||||
def eventFilter(self, obj, event):
|
||||
for obj in (self.editModelName, self.editSrcLang, self.editTrgLang):
|
||||
if self.gridLayout.indexOf(obj) <> -1:
|
||||
if event.type() == event.MouseButtonPress:
|
||||
dialog = ChooseMTModelDialog(self, self.datamodel)
|
||||
if dialog.exec_():
|
||||
#get the model
|
||||
model = {'ID':dialog.ID, 'name':dialog.modelName, 'srclang':dialog.srcLang, 'trglang':dialog.trgLang,
|
||||
'path':dialog.path, 'mosesini':dialog.mosesini}
|
||||
self.startEngine(model)
|
||||
return True #we handle it here
|
||||
return super(MainWindow, self).eventFilter(obj, event)
|
||||
|
||||
def stopEngine(self, engine):
|
||||
#stop the engine with another thread
|
||||
def stopEngineThread():
|
||||
engine.stop()
|
||||
t = threading.Thread(target=stopEngineThread)
|
||||
t.start()
|
||||
return t
|
||||
|
||||
def startEngine(self, model):
|
||||
self.editModelName.setText(model['name'])
|
||||
self.editSrcLang.setText(model['srclang'])
|
||||
self.editTrgLang.setText(model['trglang'])
|
||||
self.editSrc.setText("")
|
||||
self.editTrg.setText("")
|
||||
try:
|
||||
if self.engine:
|
||||
self.stopEngine(self.engine)
|
||||
self.engine = None
|
||||
#create engine
|
||||
self.engine = Engine(model, self.moses)
|
||||
|
||||
#create progress bar dialog
|
||||
if self.progress:
|
||||
self.progress.close()
|
||||
self.progress = None
|
||||
self.progress = QProgressDialog("Model: %s" % model['name'], "Cancel", 0, self.engine.countSteps(), self)
|
||||
self.progress.setAutoReset(True)
|
||||
self.progress.setAutoClose(True)
|
||||
self.progress.setWindowModality(Qt.WindowModal)
|
||||
self.progress.setWindowTitle('Loading Model...')
|
||||
QObject.connect(self.progress, SIGNAL("canceled()"), self.progressCancelled)
|
||||
self.progress.show()
|
||||
|
||||
#connect engine signal
|
||||
QObject.connect(self.engine, SIGNAL("stepFinished(int)"), self.engineStepFinished)
|
||||
QObject.connect(self.engine, SIGNAL("loaded(bool, QString)"), self.engineLoaded)
|
||||
|
||||
def startEngineThread():
|
||||
self.engine.start()
|
||||
t = threading.Thread(target=startEngineThread)
|
||||
t.start()
|
||||
except Exception, e:
|
||||
if self.engine:
|
||||
self.stopEngine(self.engine)
|
||||
self.engine = None
|
||||
self.clearPanel()
|
||||
doAlert("Error start MT engine: " + str(e))
|
||||
|
||||
def clearPanel(self):
|
||||
if self.engine:
|
||||
self.stopEngine(self.engine)
|
||||
self.engine = None
|
||||
self.editModelName.setText("")
|
||||
self.editSrcLang.setText("")
|
||||
self.editTrgLang.setText("")
|
||||
self.editSrc.setText("")
|
||||
self.editTrg.setText("")
|
||||
|
||||
def progressCancelled(self):
|
||||
self.clearPanel()
|
||||
if self.engine:
|
||||
self.stopEngine(self.engine)
|
||||
self.engine = None
|
||||
if self.progress:
|
||||
self.progress = None
|
||||
|
||||
def engineStepFinished(self, nStep):
|
||||
if self.progress:
|
||||
self.progress.setValue(nStep)
|
||||
|
||||
def engineLoaded(self, success, message):
|
||||
if not success:
|
||||
self.clearPanel()
|
||||
if message:
|
||||
doAlert(message)
|
||||
else:
|
||||
if self.progress:
|
||||
self.progress.setValue(self.progress.maximum())
|
||||
self.progress = None
|
||||
|
||||
@pyqtSignature("")
|
||||
def on_btnTranslate_clicked(self):
|
||||
"""
|
||||
Slot documentation goes here.
|
||||
"""
|
||||
if self.engine is None:
|
||||
doAlert("Please load MT model first.")
|
||||
return
|
||||
self.btnTranslate.setEnabled(False)
|
||||
self.editTrg.setText("")
|
||||
try:
|
||||
texts = str(self.editSrc.toPlainText().toUtf8()).split('\n')
|
||||
trans = []
|
||||
for text in texts:
|
||||
if text.strip() == "":
|
||||
trans.append(text)
|
||||
else:
|
||||
trans.append(self.engine.translate(text.replace('\r', ' ').strip()).decode('utf8'))
|
||||
self.editTrg.setText('\n'.join(trans))
|
||||
except Exception, e:
|
||||
print >> sys.stderr, str(e)
|
||||
doAlert("Translation failed!")
|
||||
self.btnTranslate.setEnabled(True)
|
||||
self.btnTranslate.setFocus()
|
||||
|
||||
@pyqtSignature("QString")
|
||||
def on_labelInfo_linkActivated(self, link):
|
||||
"""
|
||||
Slot documentation goes here.
|
||||
"""
|
||||
dialog = DlgCredits(self)
|
||||
dialog.exec_()
|
284
mingw/MosesGUI/mainWindow.ui
Normal file
284
mingw/MosesGUI/mainWindow.ui
Normal file
@ -0,0 +1,284 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>705</width>
|
||||
<height>491</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Moses Machine Translation System</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="icons.qrc">
|
||||
<normaloff>:/icon/moses.ico</normaloff>:/icon/moses.ico</iconset>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="locale">
|
||||
<locale language="English" country="UnitedKingdom"/>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="title">
|
||||
<string>Machine Translation</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="2,8">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Current MT Model</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Translate From:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="editSrcLang">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="4">
|
||||
<widget class="QLineEdit" name="editTrgLang">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Translate Into:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QPushButton" name="btnTranslate">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Translate</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLineEdit" name="editModelName">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Model Name:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QTextEdit" name="editSrc"/>
|
||||
<widget class="QTextEdit" name="editTrg">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="title">
|
||||
<string>Model Management</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1000">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Management</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="newModelBtn">
|
||||
<property name="locale">
|
||||
<locale language="English" country="UnitedKingdom"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Install New Model ...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="delModelBtn">
|
||||
<property name="text">
|
||||
<string>Uninstall Selected Model ...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QTableView" name="tableView">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>7</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::DefaultContextMenu</enum>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="locale">
|
||||
<locale language="English" country="UnitedKingdom"/>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="gridStyle">
|
||||
<enum>Qt::DashLine</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="cornerButtonEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderShowSortIndicator" stdset="0">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelInfo">
|
||||
<property name="text">
|
||||
<string><qt><a href="www">Credits and Support</a></qt></string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::AutoText</enum>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="icons.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
79
mingw/MosesGUI/moses.py
Normal file
79
mingw/MosesGUI/moses.py
Normal file
@ -0,0 +1,79 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys, os, platform
|
||||
from PyQt4.QtGui import QFileDialog
|
||||
from util import *
|
||||
|
||||
class Moses():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def findRegistryPath(self):
|
||||
import _winreg
|
||||
key = None
|
||||
path = None
|
||||
try:
|
||||
reg = _winreg.ConnectRegistry(None, _winreg.HKEY_CURRENT_USER)
|
||||
key = _winreg.OpenKey(reg, r'Software\Moses Core Team\MosesDecoder')
|
||||
value, type = _winreg.QueryValueEx(key, 'Path')
|
||||
path = value
|
||||
except Exception, e:
|
||||
print >> sys.stderr, str(e)
|
||||
return None
|
||||
finally:
|
||||
if key:
|
||||
_winreg.CloseKey(key)
|
||||
return path
|
||||
|
||||
def checkMosesInstall(self):
|
||||
for func in (self.getMosesCmd, self.getTokenizer, self.getDetokenizer, self.getTruecase, self.getDetruecase):
|
||||
if not os.path.exists(func()):
|
||||
doAlert("Missing executables in Moses installation path [%s], exit." % self.mosesPath)
|
||||
return False
|
||||
return True
|
||||
|
||||
def detect(self):
|
||||
pf = platform.system()
|
||||
if pf == 'Windows':
|
||||
self.mosesPath = self.findRegistryPath()
|
||||
if self.mosesPath:
|
||||
return self.checkMosesInstall()
|
||||
else:
|
||||
if not doQuestion('Cannot find Moses installation, click "Yes" to manually set the Moses path, click "No" to exit.'):
|
||||
return False
|
||||
#if not find, use a dialog
|
||||
startdir = 'C:\\'
|
||||
if "ProgramFiles(x86)" in os.environ:
|
||||
startdir = os.environ["ProgramFiles(x86)"]
|
||||
elif "ProgramFiles" in os.environ:
|
||||
startdir = os.environ["ProgramFiles"]
|
||||
else:
|
||||
pass
|
||||
dialog = QFileDialog(None, directory=startdir)
|
||||
dialog.setFileMode(QFileDialog.Directory)
|
||||
dialog.setViewMode(QFileDialog.Detail)
|
||||
dialog.setOptions(QFileDialog.ShowDirsOnly)
|
||||
if dialog.exec_():
|
||||
self.mosesPath = str(dialog.selectedFiles()[0])
|
||||
return self.checkMosesInstall()
|
||||
else:
|
||||
doAlert("Failed to find Moses Installation path, exit.")
|
||||
return False
|
||||
else:
|
||||
doAlert("Platform %s not supported yet" % pf)
|
||||
return False
|
||||
|
||||
def getMosesCmd(self):
|
||||
return os.path.join(self.mosesPath, 'moses-cmd.exe')
|
||||
|
||||
def getTokenizer(self):
|
||||
return os.path.join(self.mosesPath, 'tokenizer.exe')
|
||||
|
||||
def getDetokenizer(self):
|
||||
return os.path.join(self.mosesPath, 'detokenizer.exe')
|
||||
|
||||
def getTruecase(self):
|
||||
return os.path.join(self.mosesPath, 'truecase.exe')
|
||||
|
||||
def getDetruecase(self):
|
||||
return os.path.join(self.mosesPath, 'detruecase.exe')
|
23
mingw/MosesGUI/util.py
Normal file
23
mingw/MosesGUI/util.py
Normal file
@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PyQt4.QtGui import *
|
||||
import sys
|
||||
|
||||
def doAlert(text):
|
||||
msgBox = QMessageBox()
|
||||
msgBox.setText(text)
|
||||
msgBox.setWindowTitle("Message")
|
||||
msgBox.setIcon(QMessageBox.Warning)
|
||||
msgBox.exec_()
|
||||
|
||||
def doQuestion(text):
|
||||
reply = QMessageBox.question(None, 'Message', text, QMessageBox.Yes, QMessageBox.No)
|
||||
if reply == QMessageBox.Yes:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication(sys.argv)
|
||||
doAlert("doAlert")
|
||||
print doQuestion("doQuestion")
|
Loading…
Reference in New Issue
Block a user