modifico adaptando a la nueva version que usa gsettings

This commit is contained in:
Mauro Torrez 2011-05-22 02:43:27 -03:00
parent 3105dcf2fa
commit f16280ebea

View File

@ -25,6 +25,8 @@ import gtk
import commands import commands
import os import os
import ConfigParser
# Check for new pygtk: this is new class in PyGtk 2.4 # Check for new pygtk: this is new class in PyGtk 2.4
if gtk.pygtk_version < (2,3,90): if gtk.pygtk_version < (2,3,90):
print "PyGtk 2.3.90 or later required for this example" print "PyGtk 2.3.90 or later required for this example"
@ -33,10 +35,11 @@ if gtk.pygtk_version < (2,3,90):
class App: class App:
path = None path = None
disp = None disp = None
conffile = "/etc/gdm3/greeter.gconf-defaults" conffile = "/etc/gdm3/greeter.gsettings"
image = gtk.Image() image = gtk.Image()
screenw = -1 screenw = -1
screenh = -1 screenh = -1
config = ConfigParser.RawConfigParser()
# redraw the screen thumbnail with currently selected file and disposition # redraw the screen thumbnail with currently selected file and disposition
def redraw(self): def redraw(self):
@ -155,54 +158,25 @@ class App:
# read GDM3 configuration file, and set correspondig variables # read GDM3 configuration file, and set correspondig variables
def read_config( self ): def read_config( self ):
with open( self.conffile, 'r') as conf: self.config.read(self.conffile)
for line in conf: _uri = self.config.get( 'org.gnome.desktop.background', 'picture-uri' )
m1 = re.match(r"^\s*/desktop/gnome/background/picture_filename\s+(\S.*)$", line) _opt = self.config.get( 'org.gnome.desktop.background', 'picture-options' )
m2 = re.match(r"^\s*/desktop/gnome/background/picture_options\s+(\w+)", line)
if m1: self.path = _uri[8:-1]
if os.path.isfile( m1.group(1)): self.disp = _opt[1:-1]
print "Image file option read: " + m1.group(1)
self.path = m1.group(1)
else:
print "Image file not found"
self.path = None
elif m2: print "Image file option read: " + self.path
print "Image disposition option read: " + m2.group(1) print "Image disposition option read: " + self.disp
self.disp = m2.group(1)
# save GDM3 options file, replacing the options with the current ones # save GDM3 options file, replacing the options with the current ones
def save_config( self, widget=None ): def save_config( self, widget=None ):
with open(self.conffile, 'r') as conf: self.config.set( 'org.gnome.desktop.background', 'picture-uri', '\'file://'+self.path+'\'' )
out = "" self.config.set( 'org.gnome.desktop.background', 'picture-options', '\''+self.disp+'\'' )
for line in conf: with open( self.conffile, 'wb') as configfile:
m1 = re.match(r"^\s*/desktop/gnome/background/picture_filename", line) self.config.write(configfile)
m2 = re.match(r"^\s*/desktop/gnome/background/picture_options", line)
# if the current line matchs the picture_filename option, replace
# it with a new one containing the current value of path
if m1:
out += "/desktop/gnome/background/picture_filename " \
+ self.path + "\n"
# else if it macthes the picture_options option, put the
# value of disp instead
elif m2:
out += "/desktop/gnome/background/picture_options "\
+ self.disp + "\n"
# else copy the line as-is
else:
out += line
# save the file putting in there the value of out
with open(self.conffile, 'w') as f:
f.write(out)
print "Configuration file saved."
# close event. don't know if or what it should do # close event. don't know if or what it should do
def close(self, widget, event, data=None): def close(self, widget, event, data=None):