This commit is contained in:
Tan, Kian-ting 2016-04-01 23:22:25 +08:00
parent 47662c1094
commit c5dc669b5e
3 changed files with 79 additions and 31 deletions

View file

@ -87,16 +87,35 @@ class MainWindow(QtGui.QMainWindow, ui.Ui_MainWindow):
self.lineEdit.returnPressed.connect(self.input_characters)
self.pushButton.clicked.connect(self.input_characters)
def show_result(self,char_code):
result = ""
header = '<table style=\"vertical-align:top;\">'
result = header + result
for (char,code) in char_code:
result = result + '<tr><td style="font-size:x-large;' + \
'vertical-align:top;">' + \
char + '</td><td>'
for i in range(len(code)):
if (i < len(code) - 1):
result = result + code[i] + '<br/>'
else:
result = result + code[i] + '</td></tr>'
result = result + '</table>'
self.label_2.setText(result)
def input_characters(self):
import re
characters = self.lineEdit.text()
chinese_char_pattern = re.compile("^[\u4e00-\u9fa5]+$")
chinese_char_pattern = re.compile("^[\u2f00-\u2fd5\u4e00-\u9fcc\u3400-\u4db5\u20000-\u2a6d6\u2a700-\u2b734\u2b740-\u2b81d\u2b820-\u2cea1]+$")
is_chinese_chars = chinese_char_pattern.match(characters)
if is_chinese_chars:
char_code_list = [(ch,find_code(ch,self.c)) for ch in characters]
print(char_code_list)
self.show_result(char_code_list)
else:
print("error")

18
ui.py
View file

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'ui.ui'
#
# Created: Wed Mar 23 23:22:07 2016
# Created: Fri Apr 1 23:13:43 2016
# by: PyQt4 UI code generator 4.10.4
#
# WARNING! All changes made in this file will be lost!
@ -76,7 +76,15 @@ class Ui_MainWindow(object):
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.horizontalLayout_2.addWidget(self.pushButton_2)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.label_2 = QtGui.QLabel(self.centralwidget)
self.scrollArea = QtGui.QScrollArea(self.centralwidget)
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName(_fromUtf8("scrollArea"))
self.scrollAreaWidgetContents = QtGui.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 365, 219))
self.scrollAreaWidgetContents.setObjectName(_fromUtf8("scrollAreaWidgetContents"))
self.horizontalLayout_4 = QtGui.QHBoxLayout(self.scrollAreaWidgetContents)
self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4"))
self.label_2 = QtGui.QLabel(self.scrollAreaWidgetContents)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
@ -88,11 +96,13 @@ class Ui_MainWindow(object):
self.label_2.setIndent(5)
self.label_2.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByKeyboard|QtCore.Qt.LinksAccessibleByMouse|QtCore.Qt.TextBrowserInteraction|QtCore.Qt.TextSelectableByKeyboard|QtCore.Qt.TextSelectableByMouse)
self.label_2.setObjectName(_fromUtf8("label_2"))
self.verticalLayout.addWidget(self.label_2)
self.horizontalLayout_4.addWidget(self.label_2)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.verticalLayout.addWidget(self.scrollArea)
self.horizontalLayout_3.addLayout(self.verticalLayout)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 387, 22))
self.menubar.setGeometry(QtCore.QRect(0, 0, 387, 23))
self.menubar.setObjectName(_fromUtf8("menubar"))
self.menu_Help = QtGui.QMenu(self.menubar)
self.menu_Help.setObjectName(_fromUtf8("menu_Help"))

21
ui.ui
View file

@ -96,6 +96,21 @@
</item>
</layout>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>365</width>
<height>219</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
@ -136,6 +151,10 @@
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
@ -145,7 +164,7 @@
<x>0</x>
<y>0</y>
<width>387</width>
<height>22</height>
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="menu_Help">