Skip to content
This repository has been archived by the owner on Jul 10, 2021. It is now read-only.

Commit

Permalink
wepsyte: Show a web site and shut the fuck up
Browse files Browse the repository at this point in the history
I needed to get a "p" and a "y" in the name because it's a python
script. Yeah.
  • Loading branch information
vain committed May 3, 2014
1 parent 763fa6a commit abcbab4
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions wepsyte
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python2.7

# Based on:
# http://www.eurion.net/python-snippets/snippet/Webkit%20Browser.html

import argparse
import pygtk
import gtk
import webkit
import gobject
import sys

class Browser:
def __init__(self, args):
gobject.threads_init()
self.window = gtk.Window()
self.window.connect('delete_event', self.delete_event)
self.window.connect('destroy', self.destroy)

self.web_view = webkit.WebView()
self.web_view.open(args.url)
self.web_view.set_zoom_level(args.zoom)

if args.auto_reload:
self.web_view.connect('load-error', self.load_error)

scroll_window = gtk.ScrolledWindow(None, None)
scroll_window.add(self.web_view)

vbox = gtk.VBox(False, 0)
vbox.add(scroll_window)

self.window.add(vbox)

if args.fullscreen:
self.window.fullscreen()

self.window.show_all()

def main(self):
gtk.main()

def destroy(self, *args, **kwargs):
gtk.main_quit()

def delete_event(self, *args, **kwargs):
return False

def load_error(self, *args, **kwargs):
gtk.timeout_add(2000, self.reload_page)

def reload_page(self):
self.web_view.reload()
return False

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--fullscreen', action='store_true')
parser.add_argument('-z', '--zoom', type=float, default=1.0)
parser.add_argument('-r', '--auto-reload', action='store_true')
parser.add_argument('url')
args = parser.parse_args()

browser = Browser(args)
browser.main()

0 comments on commit abcbab4

Please sign in to comment.