This commit is contained in:
Tan, Kian-ting 2016-04-02 18:31:49 +08:00
parent c5dc669b5e
commit f9e3422898
5 changed files with 28 additions and 34 deletions

View file

@ -86,10 +86,22 @@ class MainWindow(QtGui.QMainWindow, ui.Ui_MainWindow):
self.setupUi(self)
self.lineEdit.returnPressed.connect(self.input_characters)
self.pushButton.clicked.connect(self.input_characters)
self.pushButton_2.clicked.connect(self.clear_input)
self.action_About.triggered.connect(self.show_about)
def clear_input(self):
self.label_2.setText("")
self.lineEdit.clear()
def show_about(self):
about_dialog = QtGui.QWidget()
about_dialog_ui = ui2.Ui_Dialog()
about_dialog_ui.setupUi(about_dialog)
about_dialog.show()
def show_result(self,char_code):
result = ""
header = '<table style=\"vertical-align:top;\">'
header = "<table style=\"vertical-align:top;\"><tr><td colspan=2>查碼結果:</td></tr>"
result = header + result
for (char,code) in char_code:
@ -108,9 +120,13 @@ class MainWindow(QtGui.QMainWindow, ui.Ui_MainWindow):
def input_characters(self):
import re
characters = self.lineEdit.text()
chinese_char_pattern = re.compile("^[\u2f00-\u2fd5\u4e00-\u9fcc\u3400-\u4db5\u20000-\u2a6d6\u2a700-\u2b734\u2b740-\u2b81d\u2b820-\u2cea1]+$")
#some CJK ext B,C,etc arerepensented in utf16 in pyqt qlineedit.
#convert it to utf8
#characters = characters.encode(encoding='utf-16',errors='surrogatepass').decode('utf-8')
#print('\\u'+"\\u".join("{:x}".format(ord(c)) for c in characters))
chinese_char_pattern = re.compile("^[一-鿌㐀-䶵𠀷𠂁𠁍]+$",re.UNICODE)
is_chinese_chars = chinese_char_pattern.match(characters)
if is_chinese_chars:
@ -121,8 +137,8 @@ class MainWindow(QtGui.QMainWindow, ui.Ui_MainWindow):
def main():
app = QtGui.QApplication(sys.argv)
form = MainWindow()
form.show()
main_window = MainWindow()
main_window.show()
app.exec_()

Binary file not shown.

Binary file not shown.

19
ui.py
View file

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'ui.ui'
#
# Created: Fri Apr 1 23:13:43 2016
# Created: Sat Apr 2 15:29:18 2016
# by: PyQt4 UI code generator 4.10.4
#
# WARNING! All changes made in this file will be lost!
@ -123,18 +123,7 @@ class Ui_MainWindow(object):
self.label.setText(_translate("MainWindow", "輸入文字", None))
self.pushButton.setText(_translate("MainWindow", "查詢", None))
self.pushButton_2.setText(_translate("MainWindow", "清空", None))
self.label_2.setText(_translate("MainWindow", "<html><head/><body><p>您查詢的行列碼為:\n"
"<table style=\"vertical-align:top;\">\n"
"<tr>\n"
"<td><span style=\" font-size:18pt;\">越</span></td>\n"
"<td >4^3v1^2v<br/>4^1^</td>\n"
"</tr>\n"
"<tr>\n"
"<td><span style=\" font-size:18pt;\">的</span></td>\n"
"<td >9-0^9-6-<br/>5^</td>\n"
"</tr>\n"
"</table>\n"
"</html>", None))
self.menu_Help.setTitle(_translate("MainWindow", "&Help", None))
self.action_About.setText(_translate("MainWindow", "&About...", None))
self.label_2.setText(_translate("MainWindow", "<html><head/><body><p><br/></p></body></html>", None))
self.menu_Help.setTitle(_translate("MainWindow", "說明 (&H)", None))
self.action_About.setText(_translate("MainWindow", "關於 findarray30code (&A)", None))

17
ui.ui
View file

@ -120,18 +120,7 @@
</sizepolicy>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;您查詢的行列碼為:
&lt;table style=&quot;vertical-align:top;&quot;&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span style=&quot; font-size:18pt;&quot;&gt;越&lt;/span&gt;&lt;/td&gt;
&lt;td &gt;4^3v1^2v&lt;br/&gt;4^1^&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span style=&quot; font-size:18pt;&quot;&gt;的&lt;/span&gt;&lt;/td&gt;
&lt;td &gt;9-0^9-6-&lt;br/&gt;5^&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/html&gt;</string>
<string></string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
@ -169,7 +158,7 @@
</property>
<widget class="QMenu" name="menu_Help">
<property name="title">
<string>&amp;Help</string>
<string>說明 (&amp;H)</string>
</property>
<addaction name="action_About"/>
</widget>
@ -178,7 +167,7 @@
<widget class="QStatusBar" name="statusbar"/>
<action name="action_About">
<property name="text">
<string>&amp;About...</string>
<string>關於 findarray30code (&amp;A)</string>
</property>
</action>
</widget>