Exemplo n.º 1
0
        def tag2html(tag):
            def trim_str(vstr):
                if len(vstr) > MAX_STR_LEN:
                    vstr = vstr[:(MAX_STR_LEN-15)] + " ... " + vstr[-10:]
                return vstr

            if isinstance(tag, PackedTags):
                # inflate packed tags
                return ''.join(tag2html(tag) for tag in tag.dxftags())

            tpl = TAG_TPL
            if tag.code in HANDLE_CODES:  # is handle definition
                tpl = TAG_HANDLE_DEF_TPL
            elif is_pointer_code(tag.code):  # is handle link
                if tag.value in self.entitydb:
                    tpl = TAG_VALID_LINK_TPL
                else:
                    tpl = TAG_INVALID_LINK_TPL

            if tag.code in BINARY_FLAGS:
                vstr = with_bitmask(tag.value)
            else:
                if hasattr(tag, 'tostring'):
                    s = tag.tostring()
                else:
                    s = ustr(tag.value)
                vstr = trim_str(s)

            type_str = tag_type_str(tag.code)
            return tpl.format(code=tag.code, value=escape(vstr), type=escape(type_str))
Exemplo n.º 2
0
        def tag2html(tag: "DXFTag") -> str:
            def trim_str(vstr: str) -> str:
                if len(vstr) > MAX_STR_LEN:
                    vstr = vstr[: (MAX_STR_LEN - 15)] + " ... " + vstr[-10:]
                return vstr

            tpl = TAG_TPL
            if tag.code in HANDLE_CODES:  # is handle definition
                tpl = TAG_HANDLE_DEF_TPL
            elif is_pointer_code(tag.code):  # is handle link
                if tag.value in self.handles:
                    tpl = TAG_VALID_LINK_TPL
                else:
                    tpl = TAG_INVALID_LINK_TPL

            if tag.code in BINARY_FLAGS:
                vstr = with_bitmask(tag.value)  # type: ignore
            else:
                if hasattr(tag, "tostring"):
                    s = tag.tostring()  # type: ignore
                else:
                    s = str(tag.value)
                vstr = trim_str(s)

            type_str = tag_type_str(tag.code)
            return tpl.format(
                code=tag.code, value=escape(vstr), type=escape(type_str)
            )
Exemplo n.º 3
0
        def tag2html(tag):
            def trim_str(vstr):
                if len(vstr) > MAX_STR_LEN:
                    vstr = vstr[:(MAX_STR_LEN - 15)] + " ... " + vstr[-10:]
                return vstr

            tpl = TAG_TPL
            if tag.code in HANDLE_CODES:  # is handle definition
                tpl = TAG_HANDLE_DEF_TPL
            elif is_pointer_code(tag.code):  # is handle link
                if tag.value in self.entitydb:
                    tpl = TAG_VALID_LINK_TPL
                else:
                    tpl = TAG_INVALID_LINK_TPL

            if tag.code in BINARY_FLAGS:
                vstr = with_bitmask(tag.value)
            else:
                vstr = trim_str(ustr(tag.value))

            type_str = tag_type_str(tag.code)
            if type_str == '<bin>':
                if isinstance(tag, CompressedTags):
                    type_str = '<multiple binary encoded data tags compressed to one tag>'
                else:
                    type_str = '<binary encoded data>'
                vstr = ""

            return tpl.format(code=tag.code,
                              value=escape(vstr),
                              type=escape(type_str))
Exemplo n.º 4
0
 def tag_activated(self, index: QModelIndex):
     tag = index.data(role=DXFTagsRole)
     if isinstance(tag, DXFTag):
         code, value = tag
         if is_pointer_code(code):
             if not self.goto_handle(value):
                 self.show_error_handle_not_found(value)
         elif code == 0:
             self.open_web_browser(get_reference_link(value))
Exemplo n.º 5
0
    def collect_all_pointers(self):
        existing_pointers = {}
        for tags in self.entitydb.values():
            handle = tags.get_handle()

            for tag in self.expand_linked_tags(tags):
                if is_pointer_code(tag.code):
                    pointers = existing_pointers.setdefault(tag.value, set())
                    pointers.add(handle)

        return existing_pointers
Exemplo n.º 6
0
def target_pointers(tags: Iterable[DXFTag]) -> Iterable[DXFTag]:
    for tag in tags:
        if is_pointer_code(tag.code):
            yield tag
Exemplo n.º 7
0
def target_pointers(tags):
    for tag in tags:
        if is_pointer_code(tag.code):
            yield tag