This repository has been archived by the owner on Jul 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wepsyte: Show a web site and shut the fuck up
I needed to get a "p" and a "y" in the name because it's a python script. Yeah.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |