#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import sys
import shutil
root = os.getcwd()
#total_list = 0
def htmlResult(path_result,total_list=0):
html = open('index.html', 'w')
html.write("""
<html>
<head>
<head>
<meta charset="UTF-8">
<script language="javascript">
function setUrl(str){
//alert("in getUrl method");
//alert(str);
// get total list from html
var total_pages = document.getElementById("total").value;
//alert("total_pages...: "+total_pages);
// current page
var curr = document.getElementById("current").value;
//alert(curr)
var old_url = document.getElementById("pic").src; // current img src
//alert(old_url);
var new_url = "";
var old_str_num = "";
var old_int_num = 0;
var new_int_num = 0;
var old_str = "";
var new_str = "";
var schedule = "";
// set new img src
var under = old_url.lastIndexOf("_")
var colon = old_url.lastIndexOf(".")
old_str_num = old_url.substring(under+1,colon);
old_int_num = parseInt(old_url.substring(under+1,colon));
old_str = "_" + old_str_num + ".JPG";
new_str = "_" + new_int_num + ".JPG"
if(str == "pre"){
if(old_str_num == "1"){
//alert("It's already the first page!");
}
else{
new_int_num = old_int_num - 1;
new_str = "_" + new_int_num + ".JPG";
new_url = old_url.replace(old_str, new_str); // new img src
document.getElementById("pic").src = new_url;
document.getElementById("current").value=new_int_num ;
schedule = new_int_num / parseInt(total_pages) * 100 + "%";
document.getElementById("hei").style.width = schedule;
}
}
if(str == "first"){
//alert("go to the first page!!");
if(old_str_num == "1"){
//alert("It's already the first page!!!");
}
else{
new_str = "_1.JPG";
new_url = old_url.replace(old_str, new_str); // new img src
document.getElementById("pic").src = new_url;
document.getElementById("current").value="1";
new_int_num = 1;
schedule = new_int_num / parseInt(total_pages) * 100 + "%";
document.getElementById("hei").style.width = schedule;
}
}
if(str == "next"){
//alert("go to the next page");
if(old_str_num == total_pages){
//alert("It's already the last page!!!");
}
else{
new_int_num = old_int_num + 1;
new_str = "_" + new_int_num + ".JPG"
new_url = old_url.replace(old_str, new_str); // new img src
document.getElementById("pic").src = new_url;
document.getElementById("current").value=new_int_num;
schedule = new_int_num / parseInt(total_pages) * 100 + "%";
document.getElementById("hei").style.width = schedule;
}
}
if(str == "last"){
//alert("go to the last page!!!");
if(old_str_num == total_pages){
//alert("It's already the last page!!!");
}
else{
new_str = "_"+ total_pages + ".JPG";
new_url = old_url.replace(old_str, new_str); // new img src
document.getElementById("pic").src = new_url;
document.getElementById("current").value=total_pages;
schedule = 100 + "%";
document.getElementById("hei").style.width = schedule;
}
}
}
function previous(){
setUrl("pre");
}
function first(){
setUrl("first");
}
function next(){
setUrl("next");
}
function last(){
setUrl("last");
}
</script>
<style>
body{
background-color:#c0c0c0;
text-align:center;
}
img{width:66%;}
</style>
</head>
</head>
<body>
<div style="width:100%;">
""")
files = os.listdir(path_result)
for file in files:
#print file
if file.endswith('.JPG'):
#global total_list
total_list +=1
file_path = path_result + "\\" + file
print file_path
if total_list == 1:
html.write('<center><div style="width:66%;margin-top:6%;">')
#html.write("<img id='pic' src='%s' /></div></center>" % file_path)
html.write("<div><img id='pic' src='%s' />" % file_path)
html.write('</div>')
#break
#print total_list
#html.write('</br></br></br></br></br></br>')
#html.write('<center>') ## <div style="width:100%;"><div sytle="width:64%">
## get the path where the
#print(sys.argv[0])
abs_path = root + "\\" + sys.argv[0]
script_path = abs_path.split('\\')[-1]
abs_has_pic = abs_path.replace(script_path,"picture")
first_pic = abs_has_pic + "\\first.PNG"
pre_pic = abs_has_pic + "\\pre.PNG"
next_pic = abs_has_pic + "\\next.PNG"
last_pic = abs_has_pic + "\\last.PNG"
resu_float = format(float(1)/float(total_list),'.2f')
resu = resu_float.replace('0.','') + "%"
html.write('<div style="background-color:#F4F4F4; width:66%; height:4%; border:1px solid #B9B9BA">')
#html.write('<div style="float:left; padding-left:4%; padding-top:1%;"><input type="image" id="first" src="C:\\picture\\first.PNG" onclick="first()" /></div> ') #C:\\picture\\first.PNG
html.write('<div style="float:left; margin-left:2%; padding-top:1%;"><input type="image" id="first" src="')
html.write(first_pic)
html.write('" onclick="first()" /></div>')
#html.write('<div style="float:left; padding-left:4%; padding-top:1%;"><input type="image" id="pre" src="C:\\picture\\pre.PNG" onclick="previous()" /></div> ')
html.write('<div style="float:left; margin-left:2%; padding-top:1%;"><input type="image" id="pre" src="')
html.write(pre_pic)
html.write('" onclick="previous()" /></div>')
#html.write('<div style="float:left; padding-left:4%; padding-top:1%;"><input type="image" id="next" src="C:\\picture\\next.PNG" onclick="next()" /></div>&