import sys from os import path from xml.sax.saxutils import quoteattr, escape import argparse import tempfile from subprocess import check_call parser = argparse.ArgumentParser() parser.add_argument('--browser', help='debug in browser', action='store_true', default=False, ) parser.add_argument('image') args = parser.parse_args() src = path.abspath(args.image) if not path.isfile(src): sys.exit('not a file: {!r}'.format(src)) src = 'file://' + src css = """ body { font-family: Ubuntu; font-size: 20px; background: #000; margin: 0px; } #pic { display: block; margin: auto; } #toolbar { margin: auto; height: 100%; width: 400px; position: fixed; height: 50px; left: 0; right: 0; bottom: 11px; z-index: 10; color: #fff; background: #555; opacity: 0.6; border-radius: 5.0; } .hide { display: none; } """ js = """ var View = { load: function() { View.toolbar = document.getElementById('toolbar'); View.restart(); window.onmousemove = View.on_mousemove; }, restart: function() { if (View.timeoutID) { clearTimeout(View.timeoutID); } else { View.toolbar.classList.remove('hide'); } View.timeoutID = setInterval(View.on_timeout, 3000); }, on_timeout: function() { clearTimeout(View.timeoutID); View.timeoutID = null; View.toolbar.classList.add('hide'); }, on_mousemove: function() { View.restart(); }, } """ html = u"""
Stuff
""".format(src=quoteattr(src), css=escape(css), js=escape(js)).encode('utf-8') if args.browser: (fileno, tmp) = tempfile.mkstemp(suffix='.html') open(tmp, 'wb').write(html) check_call(['firefox', tmp]) sys.exit() import gtk import webkit window = gtk.Window() window.set_title('Image Viewer') window.set_default_size(800, 600) window.connect('destroy', gtk.main_quit) scroll = gtk.ScrolledWindow() scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) window.add(scroll) view = webkit.WebView() scroll.add(view) view.load_string(html, 'text/html', 'utf-8', 'file:///') window.show_all() gtk.main()