USA Linux Users Group Forum Index
Log in Register FAQ Memberlist Search USA Linux Users Group Forum Index Album

Background Rotation for Gnome (Python, in development)

 
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming
View previous topic :: View next topic  
Author Message
Lord.DragonFly.of.Dawn
Advanced Member


Joined: 18 Jul 2024
Posts: 607
Location: South Portland, Maine, USA, Earth, Sol System

PostPosted: Fri Jul 18, 2024 8:33 pm    Post subject: Background Rotation for Gnome (Python, in development) Reply with quote

I have created a python script for changing my desktop background at regular intervals (5 minutes). I am currently working on working out some bugs and trying to add new features. Any help/suggestions/praise or <sarcasm>anonymous boxes of scorpions delivered to my doorstep </sarcasm> will be appreciated and welcome!

A basic install of python 2.4 or 2.5 will run this script and it may work for earlier versions (not tested).

Currently the script only works for gnome, but i plan on adding detection of and ability to change the images for other GUi's too (KDE, xfce)

Code:
#!/usr/bin/python
# Created by: Lord.DragonFly.of.Dawn
# Contact at: Lord.DragonFly.of.Dawn (at) gmail (dot) com
#
# Created on: 2024.06.14
# Last edited: 2024.06.23
#
# This program is free software: You can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version three
# of the License or (at your option) any later version
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Public License for more details.
#
# You should have recieved a copy of the GNU General Public
# License along with this program. If not, see
# < http://www.gnu.org/licenses/ >

#TODO - Add ability to cache images and include multiple source directories
#TODO - add support for KDE too and autodetect which one is running.

# We need some imports.
# Let us move around the system and stuff
import os

# Let us collect file names and stuff
import glob

# Let us pick an image at random
import random

# Allow Sleep
import time

# Sleep time in seconds: 300 = 5 minutes
SLEEP_TIME = 300

# List file types that are valid for display.
FILE_TYPES=['*.jpg','*.JPG','*.jpeg','*.JPEG','*.gif','*.GIF','*.png','*.PNG','*.svg','*.SVG']

# Set up the file location to pull images from. Try users custom backgrounds
# first but fall back on system backgrounds if not found
IMAGE_LOCATION=os.getenv("HOME")+"/.backgrounds"
if not os.path.isdir(IMAGE_LOCATION):
   IMAGE_LOCATION="/usr/share/pixmaps/backgrounds"

# Move to the selected location.
os.chdir(IMAGE_LOCATION)

# Gather images
#TODO - Allow multiple source directories
IMAGES=[]
for type in FILE_TYPES:
   IMAGES[0:0]=glob.glob(type)

#FIXME - Images with special characters in filename. i.e: |\/*![](); Fix with correct escape sequences
while True:
   # Pick an image at random
   CHOICE=random.randrange(0,len(IMAGES))

   # Set the gnome background
   os.system("gconftool-2 -t str --set /desktop/gnome/background/picture_filename \""+IMAGE_LOCATION+"/"+IMAGES[CHOICE]+"\"")
   os.system("gconftool-2 -t str --set /desktop/gnome/background/picture_options \"wallpaper\"")

   time.sleep (SLEEP_TIME)



_________________
ArchLinux x86_64 - Custom Built Desktop
ArchLinux x86_64 - Compaq CQ50 Laptop
ArchLinux i686 - Acer Aspire One Netbook
ArchLinux i686 - Dell Presario ze2000 (w/ shattered LCD)

PuppyLinux, CloneZilla, PartedMagic, DBAN - rescue thumbdrives
Windows 7 (x86_64 desktop alternate boot)
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All content © 2024-2009 - Usa Linux Users Group
This forum is powered by phpBB. © 2024-2009 phpBB Group
Theme created by phpBBStyles.com and modified by Crouse