Skip to content

Instantly share code, notes, and snippets.

@ArseniyShestakov
Created June 29, 2015 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArseniyShestakov/2223acd7fb12d819f02c to your computer and use it in GitHub Desktop.
Save ArseniyShestakov/2223acd7fb12d819f02c to your computer and use it in GitHub Desktop.
Simple Python script for monitor testing: show images fullscreen
#!/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