Beispiel #1
0
def GetSubpictures(father=None,pattern='.*'):
    """Return handles and names of all the subpictures satisfy the regular pattern
    subpicture means view,subview or component.
    father: parent handle of subpicture.
    return views if father is None.
    return: [(handle,name),(handle,name)...]
    """
    ees = []
    try:
        if father==None:
            ee = kcs_draft.element_child_first_get()
        else:
            ee = kcs_draft.element_child_first_get(father)
        name=kcs_draft.subpicture_name_get(ee)
        ees.append((ee,name))
        while True:
            try:
                ee = kcs_draft.element_sibling_next_get(ee)
                name=kcs_draft.subpicture_name_get(ee)
                ees.append((ee,name))
            except:
                break
    except:
        return []
    return [ee for ee in ees if re.match(pattern,ee[1])!=None]
Beispiel #2
0
def ShowNote():
    hNoteList=[] #获得note列表
    try:
        subView=ktDraft.GetKtSubView(SUB_VIEW_NAME)
        comp=kcs_draft.element_child_first_get(subView)
        compName=kcs_draft.subpicture_name_get(comp)
        if compName.startswith("NOTE_"):
            hNoteList.append(comp)
        while True:
            try:
                comp=kcs_draft.element_sibling_next_get(comp)
                compName=kcs_draft.subpicture_name_get(comp)
                if compName.startswith("NOTE_"):
                    hNoteList.append(comp)
            except:
                break
    except Exception,e:
        kcs_ui.message_noconfirm(e.message)
        return
Beispiel #3
0
def GetKtSubView(subViewName): #obsolete, do not use it.
    view=GetKtView()
    print view
    """返回指定名称的subview,若没有则新建一个"""
    try:
        subView = kcs_draft.element_child_first_get(view)
        name = kcs_draft.subpicture_name_get(subView)
        if name == subViewName:
            return subView
        while True:
            subView = kcs_draft.element_sibling_next_get(subView)
            name = kcs_draft.subpicture_name_get(subView)
            if name == subViewName:
                return subView
    except:
        csm=CurrentSubpictureManager()
        csm.Set(view)
        subView = kcs_draft.subview_new(subViewName)
        csm.Back()
        return subView
Beispiel #4
0
def DeleteNote():
    pt=Point2D()
    res=kcs_ui.point2D_req("请选择要删除的批注",pt)
    if res[0]==kcs_util.ok():
        try:
            hText=kcs_draft.text_identify(pt)
            comp=kcs_draft.element_parent_get(hText)
            compName=kcs_draft.subpicture_name_get(comp)
            if compName.startswith("NOTE_"):
                kcs_draft.element_delete(comp)
        except Exception,e:
            kcs_ui.message_noconfirm(e.message)
Beispiel #5
0
def GetID(hSubView):
    """获得批注编号"""
    index=1
    try:
        comp=kcs_draft.element_child_first_get(hSubView)
        name=kcs_draft.subpicture_name_get(comp)
        if name.startswith("NOTE_"):
            n=int(name[5:])
            index=max(index,n)
        while True:
            try:
                comp=kcs_draft.element_sibling_next_get(comp)
                name=kcs_draft.subpicture_name_get(comp)
                if name.startswith("NOTE_"):
                    n=int(name[5:])
                    index=max(index,n)
            except:
                break
    except:
        return index
    return index+1
Beispiel #6
0
def ChangeColumnText():
    pt=Point2D()
    res=kcs_ui.point2D_req('Please select the column',pt)
    if res[0]==kcs_util.ok():
        hdView=kcs_draft.view_identify(res[1])
        comp=kcs_draft.component_identify(res[1])
        #get column index from comp name
        name=kcs_draft.subpicture_name_get(comp)
        colIndex=int(name[2:].split('X')[0])
        table=Table(hdView)
        res=kcs_ui.string_req('Please enter the string','iknot')
        if res[0]==kcs_util.ok():
            table.ChangeColumnText(colIndex, res[1])
Beispiel #7
0
 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)
Beispiel #8
0
def GetKtComponent(compName, subView): #obsolete, do not use it.
    """返回指定名称的component,若没有则新建一个"""
    # subView=GetTitSubView(subViewName)
    name = kcs_draft.subpicture_name_get(subView)
    try:
        comp = kcs_draft.element_child_first_get(subView)
        name = kcs_draft.subpicture_name_get(comp)
        if name == compName:
            return comp
        while True:
            comp = kcs_draft.element_sibling_next_get(comp)
            name = kcs_draft.subpicture_name_get(comp)
            kcs_ui.message_noconfirm(name)
            if name == compName:
                return comp
    except:
        old = kcs_draft.subpicture_current_get()
        kcs_draft.subpicture_current_set(subView)
        comp = kcs_draft.component_new(compName)
        if len(old) == 3:
            kcs_draft.subpicture_current_set(old[2])
        return comp
Beispiel #9
0
def MoveColumn():
    pt=Point2D()
    res=kcs_ui.point2D_req('Please select the column',pt)
    if res[0]==kcs_util.ok():
        hdView=kcs_draft.view_identify(res[1])
        comp=kcs_draft.component_identify(res[1])
        
        #get column index from comp name
        name=kcs_draft.subpicture_name_get(comp)
        colIndex=int(name[2:].split('X')[0])
        table=Table(hdView)
        res=kcs_ui.int_req('Please enter the offset',100)
        if res[0]==kcs_util.ok():
            table.MoveColumn(colIndex, res[1])
Beispiel #10
0
def AddNote():
    res=kcs_ui.string_req("请输入标注内容")
    if res[0]==kcs_util.ok():
        content=res[1]
        cor1=Point2D()
        cor2=Point2D()
        res=kcs_ui.point2D_req("请选择标注点",cor1)
        if res[0]==kcs_util.ok():
            res=kcs_ui.point2D_req("请选择标注文字位置",cor2)
            if res[0]==kcs_util.ok(): #开始标注
                #记录原来状态
                old=kcs_draft.subpicture_current_get()
                
                #创建component
                subView=ktDraft.GetKtSubView(SUB_VIEW_NAME)
                #检查是否在KNOT_VIEW下
                parent=kcs_draft.element_parent_get(subView)
                parentName=kcs_draft.subpicture_name_get(parent)
                if parentName!="KNOT_VIEW":
                    return
                kcs_draft.subpicture_current_set(subView)
                compName="NOTE_"+str(GetID(subView))
                comp=kcs_draft.component_new(compName)
                kcs_draft.subpicture_current_set(comp)
                
                #写文字
                txt=Text(content)
                txt.SetPosition(cor2)
                txt.SetColour(Colour("Red"))
                txt.SetFont("黑体")
                txt.SetHeight(5)
                hTxt=kcs_draft.text_new(txt)
                
                #画边框
                rect=Rectangle2D()
                rect=kcs_draft.element_extent_get(hTxt)
                offset=1
                rect.SetCorner1(Point2D(rect.Corner1.X-offset,rect.Corner1.Y-offset))
                rect.SetCorner2(Point2D(rect.Corner2.X+offset,rect.Corner2.Y+offset))
                hd=kcs_draft.rectangle_new(rect)
                kcs_draft.element_colour_set(hd,Colour("Red"))
                
                #画引线
                sta=cor1
                end=rect.GetCorner1()
                if end.X<sta.X:
                    end.SetX(end.X+rect.Corner2.X-rect.Corner1.X)
                if end.Y<sta.Y:
                    end.SetY(end.Y+rect.Corner2.Y-rect.Corner1.Y)
                line=Rline2D(sta,end)
                hd=kcs_draft.line_new(line)
                kcs_draft.element_colour_set(hd,Colour("Red"))
                
                #画圆圈
                circle=Circle2D(sta,2)
                hd=kcs_draft.circle_new(circle)
                kcs_draft.element_colour_set(hd,Colour("Red"))
                
                #恢复原来状态
                if len(old)==3:
                    kcs_draft.subpicture_current_set(old[2])
                else:
                    kcs_draft.subpicture_current_set()
Beispiel #11
0
     if compName.startswith("NOTE_"):
         hNoteList.append(comp)
     while True:
         try:
             comp=kcs_draft.element_sibling_next_get(comp)
             compName=kcs_draft.subpicture_name_get(comp)
             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: