Skip to content

Commit

Permalink
支持按字搜索
Browse files Browse the repository at this point in the history
  • Loading branch information
testacount1 committed Sep 29, 2018
1 parent e09755f commit abe3a87
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
27 changes: 18 additions & 9 deletions wubicodeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,31 @@ def 创建控件(self):

搜索区 = Frame(细节区)
搜索区.pack()
搜索Unicode值 = StringVar(value="")
Unicode值输入 = Entry(搜索区, textvariable=搜索Unicode值)
Unicode值输入.pack(side="left")
搜索值 = StringVar(value="")
搜索输入 = Entry(搜索区, textvariable=搜索值)
搜索输入.pack(side="left")

搜索Unicode = Button(搜索区, text="搜索Unicode",
command=lambda: self.搜索Unicode(搜索Unicode值.get()))
搜索Unicode.pack(side="right")
搜索 = Button(搜索区, text="按Unicode或字搜索",
command=lambda: self.按Unicode或字搜索(搜索值.get()))
搜索.pack(side="right")

#导出按钮 = Button(细节区, text="导出文件", command=self.导出文件)
#导出按钮.pack()

def 搜索Unicode(self, Unicode值输入):
if self.字符表.按Unicode码置当前字符(Unicode值输入):
def 按Unicode或字搜索(self, 搜索框输入):
已找到 = False
输入为字 = len(搜索框输入) == 1
if (输入为字):
已找到 = self.字符表.按字置当前字符(搜索框输入)
else:
已找到 = self.字符表.按Unicode码置当前字符(搜索框输入)
if 已找到:
self.刷新控件()
else:
print("未找到Unicode码: " + Unicode值输入)
if (输入为字):
print("未找到字: " + 搜索框输入)
else:
print("未找到Unicode码: " + 搜索框输入)

def 刷新图片显示(self, 图片显示, 字体名):
图片 = self.按字体取图片(字体名)
Expand Down
13 changes: 11 additions & 2 deletions 字符表.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def 取当前字符区间(self):
else:
开始序号 = 末字符序号
return (开始序号, 结束序号)

def 取当前字符(self):
# TODO: 判断序号范围
return self.字符列表[self.当前字符序号]
Expand Down Expand Up @@ -59,7 +59,6 @@ def 取所有字符(self):
# 测试用: 3400 - A第一个, 20000 -B第一个
# 支持大小写
# TODO: 避免线性查找
# TODO: 支持按字搜索
def 按Unicode码置当前字符(self, unicode码):
Unicode值输入 = unicode码.upper()
字符序号 = -1
Expand All @@ -69,3 +68,13 @@ def 按Unicode码置当前字符(self, unicode码):
self.置当前字符序号(字符序号)
return True
return False

# 按字搜索
def 按字置当前字符(self, ):
字符序号 = -1
for 字符 in self.字符列表:
字符序号 += 1
if ( == 字符[1]):
self.置当前字符序号(字符序号)
return True
return False

0 comments on commit abe3a87

Please sign in to comment.