本文整理汇总了Python中dominate.tags.td方法的典型用法代码示例。如果您正苦于以下问题:Python tags.td方法的具体用法?Python tags.td怎么用?Python tags.td使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dominate.tags
的用法示例。
在下文中一共展示了tags.td方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_images
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import td [as 别名]
def add_images(self, ims, txts, links, width=400):
"""add images to the HTML file
Parameters:
ims (str list) -- a list of image paths
txts (str list) -- a list of image names shown on the website
links (str list) -- a list of hyperref links; when you click an image, it will redirect you to a new page
"""
self.t = table(border=1, style="table-layout: fixed;") # Insert a table
self.doc.add(self.t)
with self.t:
with tr():
for im, txt, link in zip(ims, txts, links):
with td(style="word-wrap: break-word;", halign="center", valign="top"):
with p():
with a(href=os.path.join('images', link)):
img(style="width:%dpx" % width, src=os.path.join('images', im))
br()
p(txt)
示例2: add_images
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import td [as 别名]
def add_images(self, ims, txts, links, K, width=400):
"""add images to the HTML file
Parameters:
ims (str list) -- a list of image paths
txts (str list) -- a list of image names shown on the website
links (str list) -- a list of hyperref links; when you click an image, it will redirect you to a new page
"""
self.t = table(border=1, style="table-layout: fixed;") # Insert a table
self.doc.add(self.t)
with self.t:
with tr():
for im, txt, link in zip(ims, txts, links):
with td(style="word-wrap: break-word;", halign="center", valign="top"):
with p():
with a(href=os.path.join('images', link)):
if txt == 'refs':
img(style="width:%dpx" % K*width, src=os.path.join('images', im))
else:
img(style="width:%dpx" % width, src=os.path.join('images', im))
br()
if txt == 'refs':
p(txt+':K='+str(K))
else:
p(txt)
示例3: add_table
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import td [as 别名]
def add_table(table):
with dtags.table().add(dtags.tbody()):
for row in table:
with dtags.tr():
for col_idx, col_val in enumerate(row[1:]):
if col_idx == 0:
dtags.td().add(dtags.a("{}".format(col_val), href=row[0]))
else:
if isinstance(col_val, float):
col_val = "{0:.5f}".format(col_val)
dtags.td().add("{}".format(col_val))
示例4: make_image_table
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import td [as 别名]
def make_image_table(doc, img_root, img_folders, shuffle=False, max_imgs=20):
# Get all images for each folder
all_images = []
for img_folder in img_folders:
img_names = [
os.path.join(img_folder, name)
for name in sorted(os.listdir(os.path.join(img_root, img_folder)))
]
if shuffle:
random.shuffle(img_names)
all_images.append(img_names[:max_imgs])
# Arrange as list [{0: img_1_folder_0, 1:img_1_folder_1, ..}, ]
max_len = max([len(images) for images in all_images])
all_arranged_imgs = []
# Generate for each row dictionary of folder_idx: img_path
for idx in range(max_len):
idx_dic = {}
for folder_idx, img_names in enumerate(all_images):
if idx < len(img_names):
idx_dic[folder_idx] = img_names[idx]
all_arranged_imgs.append(idx_dic)
num_folders = len(img_folders)
with doc:
with dtags.article(cls="markdown-body"):
with dtags.table().add(dtags.tbody()):
for arranged_imgs in all_arranged_imgs:
with dtags.tr():
for folder_idx in range(num_folders):
if folder_idx in arranged_imgs:
img_path = arranged_imgs[folder_idx]
dtags.td().add(dtags.img(src=img_path))
else:
dtags.td()
示例5: _write_body
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import td [as 别名]
def _write_body(self, write_attr: bool) -> None:
tags, raw = _get_tags_module()
tbody_tag = tags.tbody()
for row_idx, (values, value_dp_list) in enumerate(
zip(self._table_value_matrix, self._table_value_dp_matrix)
):
tr_tag = tags.tr()
for value, value_dp, column_dp in zip(values, value_dp_list, self._column_dp_list):
td_tag = tags.td(raw(MultiByteStrDecoder(value).unicode_str))
default_style = self._get_col_style(column_dp.column_index)
style = self._fetch_style_from_filter(row_idx, column_dp, value_dp, default_style)
if write_attr:
if style.align == Align.AUTO:
td_tag["align"] = value_dp.align.align_string
else:
td_tag["align"] = style.align.align_string
if style.vertical_align != VerticalAlign.BASELINE:
td_tag["valign"] = style.vertical_align.align_str
style_tag = self.__make_style_tag(style=style)
if style_tag:
td_tag["style"] = style_tag
tr_tag += td_tag
tbody_tag += tr_tag
self._table_tag += tbody_tag
self._write_line(self._table_tag.render(indent=self.indent_string))