-Author: Oleg BroytMann <phd@phd.pp.ru>
-Copyright (C) 2000-2006 PhiloSoft Design
-"""
-
-__version__ = "$Revision$"[11:-2]
-__author__ = "Oleg BroytMann <phd@phd.pp.ru>"
-__copyright__ = "Copyright (C) 2000-2006 PhiloSoft Design"
-__date__ = "$Date$"[7:-2]
-__revision__ = "$Id$"[5:-2]
-
-
-import sys, os
-
-
-def usage():
- sys.stderr.write("%s version %s\n" % (sys.argv[0], __version__))
- sys.stderr.write("Usage: %s [force]\n" % sys.argv[0])
- sys.exit(0)
-
-def error(error_str, error_code=1):
- sys.stderr.write("%s: Error: %s\n" % (sys.argv[0], error_str))
- sys.exit(error_code)
-
-
-xwininfo = os.popen("xwininfo -root", 'r')
-xwininfo_lines = xwininfo.read()
-rc = xwininfo.close()
-if rc:
- error("calling xwininfo", rc)
-
-screen_width = None
-screen_height = None
-for line in xwininfo_lines.split('\n'):
- line = line.strip()
- if line.startswith("Width: "):
- screen_width = int(line[len("Width: "):])
- elif line.startswith("Height: "):
- screen_height = int(line[len("Height: "):])
-
-if not screen_width or not screen_height:
- error("parsing xwininfo output")
-
-
-from ConfigParser import SafeConfigParser
-
-xsetbg_dir = os.path.join(os.environ["HOME"], "lib", "xsetbg")
-os.chdir(xsetbg_dir)
-
-config = SafeConfigParser()
-config.read("xsetbg.conf")
-
-if config.has_option("images", "directory") or \
- config.has_option("images", "directory0") or \
- config.has_option("images", "directory1"):
- image_dirs = []
- if config.has_option("images", "directory"):
- image_dirs.append(config.get("images", "directory"))
- if config.has_option("images", "directory0"):
- image_dirs.append(config.get("images", "directory0"))
- if config.has_option("images", "directory1"):
- image_dirs.append(config.get("images", "directory1"))
- i = 2
- while True:
- option = "directory%d" % i
- if config.has_option("images", option):
- image_dirs.append(config.get("images", option))
- i += 1
- else:
- break
-else:
- image_dirs = ["images"]
-
-image_dirs = [os.path.join(xsetbg_dir,
- os.path.expandvars(os.path.expanduser(dirname)))
- for dirname in image_dirs
-]
-
-# minimum time in seconds between background image changes
-if config.has_option("xsetbg", "min_pause"):
- min_pause = config.getint("xsetbg", "min_pause")
-else:
- min_pause = 60
-
-borders = config.get("xsetbg", "borders").split(',')
-if config.has_option("xsetbg", "borders"):
- borders = [border.strip() for border in config.get("xsetbg", "borders").split(',')]
-else:
- borders = ["darkcyan", "steelblue", "midnightblue"]
-
-# minimum time in seconds between occurences of the same image
-if config.has_option("xsetbg", "min_delay"):
- min_delay = config.getint("xsetbg", "min_delay")
-else:
- min_delay = 3600*24 # 24 hours
-
-del config