3:b876b898560b
Anton Shestakov <engored@ya.ru>, Sun, 14 Sep 2014 23:07:17 +0900
Split cheatsheets into vim and python, build separately.

previous change 1:794840b6d903

html2png.py

Permissions: -rwxr-xr-x

Other formats: Feeds:
#!/usr/bin/env python
import sys
import glib
import gtk
import webkit
class SimpleBrowser(object):
# http://kmandla.wordpress.com/2010/05/24/the-1-2kb-python-browser-script/
# taken from there and adapted to be stupid and take screenshots
def __init__(self, url, output_filename):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
self.window.connect('delete_event', self.close_application)
screen = self.window.get_screen()
self.webview = webkit.WebView()
self.webview.set_size_request(screen.get_width(), screen.get_height())
self.window.add(self.webview)
self.window.set_title('%s' % url)
self.window.show_all()
self.window.fullscreen()
self.webview.connect(
'document-load-finished', self.screenshot, output_filename)
self.webview.open(url)
@staticmethod
def screenshot(webview, frame, output_filename):
def callback():
width, height = webview.window.get_size()
pb = gtk.gdk.Pixbuf('rgb', False, 8, width, height)
cm = gtk.gdk.colormap_get_system()
pb.get_from_drawable(webview.window, cm, 0, 0, 0, 0, width, height)
pb.save(output_filename, 'png')
gtk.main_quit()
glib.timeout_add_seconds(1, callback) # delay until rendering finishes
def close_application(self, widget, event, data=None):
gtk.main_quit()
if __name__ == '__main__':
if len(sys.argv) == 3:
gtk.gdk.threads_init()
SimpleBrowser(sys.argv[1], sys.argv[2])
gtk.main()
else:
print 'usage:', sys.argv[0], 'INPUT OUTPUT'