Created
June 29, 2015 22:06
-
-
Save ArseniyShestakov/2223acd7fb12d819f02c to your computer and use it in GitHub Desktop.
Simple Python script for monitor testing: show images fullscreen
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
#!/usr/bin/env python | |
# https://gist.github.com/ArseniyShestakov/969f27d4a2437fe60cd1 | |
import os, sys, gtk, argparse | |
from os import path | |
from itertools import cycle | |
# Check command line options | |
parser = argparse.ArgumentParser(description='Simple fullscreen image view') | |
parser.add_argument('imagedir', nargs='?', default=path.join(os.getcwd(), "img"), help="directory with background images") | |
parser.add_argument('-a', '--noauto', action="store_false", help="disable auto rotation") | |
parser.add_argument('-m', '--nomanual', action="store_false", help="disable manual rotation") | |
parser.add_argument('-d', '--delay', type=int, default=10, help='delay between images (default: 10 seconds)') | |
args = parser.parse_args() | |
def getfiles(): | |
global args | |
return [f for f in os.listdir(args.imagedir) if path.isfile(path.join(args.imagedir, f)) and f.endswith(('.gif', '.png', '.jpg'))] | |
files = getfiles() | |
if not files: | |
print "No images in " + args.imagedir | |
exit() | |
def changebg(widget, event): | |
global args, files | |
changebg.idx = (changebg.idx + 1) % len(files) | |
background = path.join(args.imagedir, files[changebg.idx]) | |
pixbuf = gtk.gdk.pixbuf_new_from_file(background) | |
widget.window.draw_pixbuf(widget.style.bg_gc[gtk.STATE_NORMAL], pixbuf, 0, 0, 0,0) | |
changebg.idx = 0 | |
def autochange(): | |
global args, imagebox | |
gtk.timeout_add(args.delay*1000, autochange) | |
changebg(imagebox, None) | |
# Init UI | |
w = gtk.Window() | |
w.set_default_size(200, 200) | |
w.add_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.SCROLL_MASK) | |
w.connect('destroy', gtk.main_quit) | |
imagebox = gtk.Fixed() | |
w.add(imagebox) | |
if args.nomanual: | |
w.connect("key-press-event", changebg) | |
w.connect("button-press-event", changebg) | |
w.connect("scroll-event", changebg) | |
w.show_all() | |
w.fullscreen() | |
# Initially set background | |
changebg(imagebox, None) | |
# Activate auto rotation if enabled | |
if args.noauto: | |
autochange() | |
# Start UI | |
gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment