def _set(self,hd): "set by a component handle" #set M,N name=kcs_draft.subpicture_name_get(self.Handle) self.M,self.N=[int(i) for i in name[2:].split('X')] #set Text and Rectangle ees=ktDraft.GetSubElements(hd) for ee in ees: if kcs_draft.element_is_text(ee): tempText=Text() kcs_draft.text_properties_get(ee,tempText) self.String=tempText.String self.Rect=kcs_draft.element_extent_get(hd)
def ReplaceOne(hdText): "replace one text" txt=Text() kcs_draft.text_properties_get(hdText,txt) res=kcs_ui.string_req('请输入要替换的文本',txt.String) if res[0]==kcs_util.ok(): old = kcs_draft.subpicture_current_get() #make the old subpicture father = kcs_draft.element_parent_get(hdText) # 文字所在图层 txt.SetString(res[1]) kcs_draft.element_delete(hdText) # 删除原文字 kcs_draft.subpicture_current_set(father) # 重设图层 kcs_draft.text_new(txt) # 写文字 if len(old) == 3: kcs_draft.subpicture_current_set(old[2]) else: kcs_draft.subpicture_current_set()
def FindString(content): """返回所有匹配的Text handle""" region = GetRegion() hds = [] try: hds = kcs_draft.text_capture(region) except: kcs_ui.message_noconfirm("没有找到文字") return [] txtList = [] for hd in hds[1:]: txt = Text() kcs_draft.text_properties_get(hd, txt) if txt.GetString().upper() == content.upper(): txtList.append(hd) return txtList
def AlignBottom(): "Align texts to the left." hds=SelectTexts() tList=[] for hd in hds[1:]: t=Text() kcs_draft.text_properties_get(hd,t) tList.append((hd,t)) y=min([t[1].GetPosition().Y for t in tList]) csm=ktDraft.CurrentSubpictureManager() for hd,t in tList: csm.Set(hd) kcs_draft.element_delete(hd) t.Position.Y=y kcs_draft.text_new(t) csm.Back()
def AlignRight(): "Align texts to the left." hds=SelectTexts() tList=[] for hd in hds[1:]: t=Text() kcs_draft.text_properties_get(hd,t) tList.append((hd,t)) x=max([t[1].GetPosition().X for t in tList]) csm=ktDraft.CurrentSubpictureManager() for hd,t in tList: csm.Set(hd) rect=kcs_draft.element_extent_get(hd) width=abs(rect.Corner1.X-rect.Corner2.X) kcs_draft.element_delete(hd) t.Position.X=x-width kcs_draft.text_new(t) csm.Back()
def Amplifier(step): "set the text bigger or smaller by given step" while True: hdText=SelectText() if hdText!=None: csm=ktDraft.CurrentSubpictureManager() t = Text() kcs_draft.text_properties_get(hdText, t) if t.GetHeight()<2: print 'can not be smaller' return else: csm.Set(hdText) kcs_draft.element_delete(hdText) t.SetHeight(t.GetHeight()+step) kcs_draft.text_new(t) csm.Back() else: break
def Replace(hdList): res = kcs_ui.answer_req("文字替换", "是否要替换文字?") if res == kcs_util.yes(): txt = Text() kcs_draft.text_properties_get(hdList[0], txt) res = kcs_ui.string_req("请输入要替换的文字", txt.GetString()) if res[0] == kcs_util.ok(): content = res[1] old = kcs_draft.subpicture_current_get() for hd in hdList: father = kcs_draft.element_parent_get(hd) # 文字所在图层 kcs_draft.text_properties_get(hd, txt) txt.SetString(content) kcs_draft.element_delete(hd) # 删除原文字 kcs_draft.subpicture_current_set(father) # 重设图层 kcs_draft.text_new(txt) # 写文字 if len(old) == 3: kcs_draft.subpicture_current_set(old[2]) else: kcs_draft.subpicture_current_set()
def FormatRegion(): pt = Point2D() res = kcs_ui.point2D_req("请选择文字获取文字属性", pt) if res[0] == kcs_util.ok(): hd = kcs_draft.text_identify(pt) ori = Text() kcs_draft.text_properties_get(hd, ori) objs = SelectTexts() old = kcs_draft.subpicture_current_get() # 当前图层 for obj in objs[1:]: # 重写文字 father = kcs_draft.element_parent_get(obj) # 文字所在图层 t = Text() kcs_draft.text_properties_get(obj, t) ori.SetString(t.GetString()) ori.SetPosition(t.GetPosition()) kcs_draft.element_delete(obj) # 删除原文字 kcs_draft.subpicture_current_set(father) # 重设图层 kcs_draft.text_new(ori) # 写文字 if len(old) == 3: kcs_draft.subpicture_current_set(old[2]) else: kcs_draft.subpicture_current_set()
def FormatSingle(): pt = Point2D() res = kcs_ui.point2D_req("请选择文字获取文字属性", pt) if res[0] == kcs_util.ok(): hd = kcs_draft.text_identify(pt) ori = Text() kcs_draft.text_properties_get(hd, ori) # old = kcs_draft.subpicture_current_get() # 当前图层 while True: "select single text" pt2=Point2D() res = kcs_ui.point2D_req("请选择要替换的文字", pt2) if res[0]==kcs_util.ok(): hdText=kcs_draft.text_identify(pt2) father = kcs_draft.element_parent_get(hdText) # 文字所在图层 t = Text() kcs_draft.text_properties_get(hdText, t) ori.SetString(t.GetString()) ori.SetPosition(t.GetPosition()) kcs_draft.element_delete(hdText) # 删除原文字 kcs_draft.subpicture_current_set(father) # 重设图层 kcs_draft.text_new(ori) # 写文字 else: break
if compName.startswith("NOTE_"): hNoteList.append(comp) except: break except Exception,e: kcs_ui.message_noconfirm(e.message) return sList=Stringlist("ok") #获得批注内容列表 for hNote in hNoteList: noteName=kcs_draft.subpicture_name_get(hNote) #找到文字 try: ee=kcs_draft.element_child_first_get(hNote) txt=Text() if kcs_draft.element_is_text(ee): txt=kcs_draft.text_properties_get(ee,txt) sList.AddString(noteName+" : "+txt.GetString()) continue while True: ee=kcs_draft.element_sibling_next_get(ee) if kcs_draft.element_is_text(ee): txt=kcs_draft.text_properties_get(ee.txt) sList.AddString(noteName+" : "+txt.GetString()) break except Exception,e: kcs_ui.message_noconfirm(e.message) sList.StrList=sList.StrList[1:] res=kcs_ui.string_select("批注","批注列表","请选择批注",sList) #显示批注列表 if res[0]==kcs_util.ok(): index=res[1] hNote=hNoteList[index-1]