# encoding utf-8
#以html打开本目录下的图片
import os,sys
import xml.etree.ElementTree as ET
html = ET.Element("html")
head = ET.SubElement(html,"head")
title = ET.SubElement(head,"title")
title.text=unicode('本目录图片集','utf-8')
script1 = ET.SubElement(head,"script")
script1.set('language','javascript')
script1.text='''
function setVisibleAll(tableId,visible){
var trs= document.getElementById(tableId).getElementsByTagName('TR');
for(var i=0;i!=trs.length;i++){
var tr = trs[i];
tr.style['display']=visible;
}
}
function showOne(tableId,trId){
var trs= document.getElementById(tableId).getElementsByTagName('TR');
for(var i=0;i!=trs.length;i++){
var tr = trs[i];
if(tr['id']==trId){
tr.style['display']='table-row';
}else{
tr.style['display']='none';
}
}
}
'''
body = ET.SubElement(html,"body")
i=0
j=0
for d,sd,asf in os.walk("."):
table = ET.Element("table")
tableId = "table"+str(i)
table.set('id',tableId)
j=0
pTread = ET.Element("table")
firstRow=ET.SubElement(pTread,"tr")
showAll = ET.SubElement(firstRow,"td")
showAll.set("style","width:50px;")
showAll.set("colspan",'2')
showAll.text=unicode('显示全部','utf-8')
showAll.set('onclick',"setVisibleAll('"+tableId+"','table-row');")
hideAll = ET.SubElement(firstRow,"td")
hideAll.set("style","width:50px;")
hideAll.set("colspan",'2')
hideAll.text=unicode('隐藏全部','utf-8')
hideAll.set('onclick',"setVisibleAll('"+tableId+"','none');")
for f in asf:
subfix = f.split(".")[-1]
if subfix in ["jpg","png"]:
tr = ET.SubElement(table,"tr")
trId = tableId+"-"+str(j)
tr.set('id',trId)
tr.set('style',"display:none;")
td = ET.SubElement(tr,"td")
img = ET.SubElement(td,"img")
src = unicode(d+'\\'+f,'gbk')
#print src
img.set("src",src)
if j%20==0:
showTr = ET.SubElement(pTread,"tr")
showJ = ET.SubElement(showTr,"td")
showJ.text=str(j+1)
if j%2==0:
showJ.set("bgColor","#AA88AA")
else:
showJ.set("bgColor","#88AA88")
showJ.set("style","width:50px;")
showJ.set('onclick',"showOne('"+tableId+"','"+trId+"');")
j=j+1
if len(table)==0:
continue
ET.SubElement(body,"hr")
div = ET.SubElement(body,"div")
div.set('onmouseover',"this.style.cursor = 'hand'")
div.set('onmouseout',"this.style.cursor = 'default'")
#图片集主题
selecterTitle = ET.SubElement(firstRow,"td")
selecterTitle.set('colspan','8')
selecterTitle.text=unicode(d,'gbk')
#
div.append(table)
div.append(pTread)
i=i+1
tree = ET.ElementTree(html)
tree.write("index.htm",'gbk')
评论0