# HG changeset patch # User paulo # Date 1378800264 25200 # Node ID 0249782e231e5d292b0d0f6fd2b4bd6196ebc779 # Parent 0fbe37b56e845b849f945990b8f8f63951cceef8 pics2: add np_keys and selected thumbnail anchoring diff -r 0fbe37b56e84 -r 0249782e231e pics2/np_keys.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pics2/np_keys.js Tue Sep 10 01:04:24 2013 -0700 @@ -0,0 +1,23 @@ +function getKeypress(e) { + c = null + + if (e.which == null) + c = String.fromCharCode(e.keyCode); // IE + else if (e.which != 0 && e.charCode != 0) + c = String.fromCharCode(e.which); // All others + + if (c != null) { + if (c == 'n') + goHref('next'); + else if (c == 'p') + goHref('prev'); + else if (c == 'u') + goHref('up'); + } +} + +function goHref(id) { + window.location.href = document.getElementById(id).href; +} + +document.onkeypress = getKeypress diff -r 0fbe37b56e84 -r 0249782e231e pics2/pics_app.py --- a/pics2/pics_app.py Thu Aug 22 23:53:56 2013 -0700 +++ b/pics2/pics_app.py Tue Sep 10 01:04:24 2013 -0700 @@ -79,16 +79,12 @@ return (root, header, body) - def _go_thumbnail_links_to_browse_imgs_html_body(self, body, t, b, selclass=None): + def _go_thumbnail_links_to_browse_imgs_html_body(self, body, t, b, a_args={}, img_args={}): thumb_img_url = self._get_pics_url(t) browse_url = self._get_app_url(b) - a = body.a(href=browse_url) - - if selclass is not None: - a.img(src=thumb_img_url, klass=selclass) - else: - a.img(src=thumb_img_url) + a = body.a(href=browse_url, **a_args) + a.img(src=thumb_img_url, **img_args) body.text(' ') @@ -167,7 +163,7 @@ html_p = html_body.p for (t, b) in _get_images(d): if from_img is not None and b == from_img: - self._go_thumbnail_links_to_browse_imgs_html_body(html_p, t, b, "sel2") + self._go_thumbnail_links_to_browse_imgs_html_body(html_p, t, b, img_args={"klass":"sel2", "id":"selected"}) else: self._go_thumbnail_links_to_browse_imgs_html_body(html_p, t, b) @@ -201,6 +197,8 @@ raise AssertionError (html_root, html_header, html_body) = self._get_standard_html_doc(u"%s \u2014 %s of %s" % (d, x, len(imgs))) + + html_header.script('', type="text/javascript", src=self._get_pics_url("np_keys.js")) browse_img_url = self._get_pics_url(img) html_body.p.img(src=browse_img_url) @@ -208,13 +206,21 @@ logging.debug("imgs_circ = %s" % imgs_circ) html_p = html_body.p - for i in imgs_circ: - if i is not None: - (t, b) = i + for (i, img_c) in enumerate(imgs_circ): + if img_c is not None: + (t, b) = img_c + a_args = {} + img_args = {} if b == img: - self._go_thumbnail_links_to_browse_imgs_html_body(html_p, t, d + "?from=" + img, "sel") - else: - self._go_thumbnail_links_to_browse_imgs_html_body(html_p, t, b) + a_args = {"id": "up"} + img_args = {"klass": "sel"} + b = "%s?from=%s#selected" % (d, img) + elif i == v + 1: + a_args = {"id": "next"} + elif i == v - 1: + a_args = {"id": "prev"} + + self._go_thumbnail_links_to_browse_imgs_html_body(html_p, t, b, a_args, img_args) return html_root diff -r 0fbe37b56e84 -r 0249782e231e pics2/pics_test_server.py --- a/pics2/pics_test_server.py Thu Aug 22 23:53:56 2013 -0700 +++ b/pics2/pics_test_server.py Tue Sep 10 01:04:24 2013 -0700 @@ -1,14 +1,38 @@ -import wsgiref.simple_server -import SocketServer +import os +import sys +import signal + +import cherrypy +from cherrypy import wsgiserver import pics_app -class ThreadingWSGIServer(SocketServer.ThreadingMixIn, wsgiref.simple_server.WSGIServer): - pass +def sighandler(signum, frame): + sys.stderr.write("Caught signal: %s \n" % signum) + server.stop() + + +class FileServerRoot: + def default(self, *args): + if len(args) == 0: + raise cherrypy.HTTPError(404) + + filepath = os.path.abspath(os.path.join(*args)) + return cherrypy.lib.static.serve_file(filepath) + + default.exposed = True if __name__ == "__main__": - httpd = ThreadingWSGIServer(('', 8000), wsgiref.simple_server.WSGIRequestHandler) - httpd.set_app(pics_app.app) - httpd.serve_forever() + fileServerApp = cherrypy.Application(FileServerRoot()) + dispatcher = wsgiserver.WSGIPathInfoDispatcher({ + "/pics.fcgi": pics_app.app, + "": fileServerApp, + }) + server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8000), dispatcher) + + signal.signal(signal.SIGINT, sighandler) + signal.signal(signal.SIGTERM, sighandler) + + server.start()