comparison pics2/pics_app.py @ 63:1913f36338b4

center clock circle and digital text
author paulo
date Thu, 21 Aug 2014 01:33:14 -0700
parents 0249782e231e
children 6318de36e334
comparison
equal deleted inserted replaced
3:e25dadc6786d 4:05b0ea037863
43 def _numeric_pad_basename(path, maxdigits=20): 43 def _numeric_pad_basename(path, maxdigits=20):
44 return os.path.basename(path).zfill(maxdigits) 44 return os.path.basename(path).zfill(maxdigits)
45 45
46 46
47 def _get_images(d): 47 def _get_images(d):
48 exts = [".jpg", ".webm"]
49
48 thumb_fns = glob.glob(os.path.join(d, "thumbs", "*.jpg")) 50 thumb_fns = glob.glob(os.path.join(d, "thumbs", "*.jpg"))
49 thumb_fns = sorted(thumb_fns, key=_numeric_pad_basename) 51 thumb_fns = sorted(thumb_fns, key=_numeric_pad_basename)
50 logging.debug("thumb_fns = %s" % thumb_fns) 52 logging.debug("thumb_fns = %s" % thumb_fns)
51 53
52 browse_fns = [os.path.join(d, "browse", os.path.basename(i)) for i in thumb_fns] 54 browse_dir = os.path.join(d, "browse")
55 browse_contents = set(os.listdir(browse_dir))
56 logging.debug("browse_contents = %s" % browse_contents)
57
58 browse_fns = []
59 for i in thumb_fns:
60 i_basename = os.path.splitext(os.path.basename(i))[0]
61 try:
62 for j in exts:
63 browse_fn_basename = i_basename + j
64 if browse_fn_basename in browse_contents:
65 browse_fns.append(os.path.join(browse_dir, browse_fn_basename))
66 raise StopIteration
67 except StopIteration:
68 pass
69 else:
70 raise RuntimeError("Cannot find browse image for %s" % i)
53 logging.debug("browse_fns = %s" % browse_fns) 71 logging.debug("browse_fns = %s" % browse_fns)
54 72
55 return zip(thumb_fns, browse_fns) 73 return zip(thumb_fns, browse_fns)
56 74
57 75
85 103
86 a = body.a(href=browse_url, **a_args) 104 a = body.a(href=browse_url, **a_args)
87 a.img(src=thumb_img_url, **img_args) 105 a.img(src=thumb_img_url, **img_args)
88 106
89 body.text(' ') 107 body.text(' ')
108
109
110 def _go_browse_image_html_body(self, body, img):
111 browse_img_url = self._get_pics_url(img)
112
113 ext = os.path.splitext(img)[1]
114 if ext == ".webm":
115 body.video(src=browse_img_url, autoplay="true", loop="true")
116 else:
117 body.img(src=browse_img_url)
90 118
91 119
92 def __init__(self, environ): 120 def __init__(self, environ):
93 self._environ = environ 121 self._environ = environ
94 self._page_func = None 122 self._page_func = None
198 226
199 (html_root, html_header, html_body) = self._get_standard_html_doc(u"%s \u2014 %s of %s" % (d, x, len(imgs))) 227 (html_root, html_header, html_body) = self._get_standard_html_doc(u"%s \u2014 %s of %s" % (d, x, len(imgs)))
200 228
201 html_header.script('', type="text/javascript", src=self._get_pics_url("np_keys.js")) 229 html_header.script('', type="text/javascript", src=self._get_pics_url("np_keys.js"))
202 230
203 browse_img_url = self._get_pics_url(img) 231 self._go_browse_image_html_body(html_body.p, img)
204 html_body.p.img(src=browse_img_url)
205 232
206 logging.debug("imgs_circ = %s" % imgs_circ) 233 logging.debug("imgs_circ = %s" % imgs_circ)
207 234
208 html_p = html_body.p 235 html_p = html_body.p
209 for (i, img_c) in enumerate(imgs_circ): 236 for (i, img_c) in enumerate(imgs_circ):