PDA

View Full Version : using python to locate gnome resources



OgreProgrammer
January 23rd, 2010, 10:26 AM
How can I have my python program ask the system what the desktop background image is/or where it is?

denarced
January 23rd, 2010, 12:36 PM
You could try and parse $HOME/.gnome2/backgrounds.xml
It would appear to contain a list of background-images

denarced
January 23rd, 2010, 12:44 PM
or you could use gnome's own tool to find out
gconftool-2 --get /desktop/gnome/background/picture_filename

unutbu
January 23rd, 2010, 12:57 PM
This code comes from Davyd Madeley's change-background.py (http://oracle.bridgewayconsulting.com.au/~danni/misc/change-background-py.html) script:


import gconf
class GConfClient:
def __init__ (self):
self.__client__ = gconf.client_get_default ()
def get_background (self):
return self.__client__.get_string("/desktop/gnome/background/picture_filename")
def set_background (self, background):
self.__client__.set_string (
"/desktop/gnome/background/picture_filename", background)

client = GConfClient ()
print(client.get_background())

OgreProgrammer
January 25th, 2010, 04:15 AM
Thanks unutbu and denarced. That was exactly what i needed.

Is there also some way for a window to know where it has been placed at after the mouse moves it?

Kegusa
January 25th, 2010, 10:33 PM
Using gnome (gtk) you can determine the position of the window with gtk.Window.get_position().

Take a look at www.pygtk.org for the python docs on gtk, but be warned there is a brickload of docs to dive into!

Not sure if there are other methods to find this out, if there are I'm interested aswell.