Skip to content

Instantly share code, notes, and snippets.

@grondilu
Forked from ekohl/dynzoom.py
Created June 1, 2010 09:40
Show Gist options
  • Save grondilu/420762 to your computer and use it in GitHub Desktop.
Save grondilu/420762 to your computer and use it in GitHub Desktop.
a fork for european locales, and with a rounded zoom
#!/usr/bin/env python
# dynzoom.py - dynamic zooming for uzbl, based on dynzoom.js
# Usage:
# @on_event GEOMETRY_CHANGED spawn /path/to/dynzoom.py \@geometry 1024 768
# Where 1024x768 is the resolution where we start to zoom out
import sys, re
" Parses WxH+X+Y into a 4-tuple of ints "
def get_geometry(geo):
return map(int, re.match(r'(\d+)x(\d+)[\+-](\d+)[\+-](\d+)', geo).groups())
" Calculate the zoom level "
def calc_zoom(geo, min_width, min_height):
width, height, x, y = get_geometry(geo)
w = min(1, width/float(min_width))
h = min(1, height/float(min_height))
return (w + h)/2
" Set the zoom level "
def set_zoom(level):
return ('set zoom_level = %.2f\n' % level).replace('.',',')
if __name__ == '__main__':
zoom = calc_zoom(*sys.argv[8:11])
if zoom < .99:
f = open(sys.argv[4], 'a')
f.write(set_zoom(zoom))
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment