mejoras varias. mejor manejo de no-imágenes, archivos no encontrados, espacios en nombres, paths vacíos.

This commit is contained in:
Mauro Torrez 2010-10-14 00:00:28 -03:00
parent d874888f29
commit 20c65a331e

View File

@ -23,6 +23,7 @@ pygtk.require('2.0')
import gtk import gtk
import commands import commands
import os
# 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):
@ -30,7 +31,7 @@ if gtk.pygtk_version < (2,3,90):
raise SystemExit raise SystemExit
class App: class App:
path = "/usr/share/images/desktop-base/moreblue-orbit-gdm.svg" path = None
disp = "stretched" disp = "stretched"
conffile = "/etc/gdm3/greeter.gconf-defaults" conffile = "/etc/gdm3/greeter.gconf-defaults"
image = gtk.Image() image = gtk.Image()
@ -41,7 +42,20 @@ class App:
def redraw(self): def redraw(self):
# new pixbuf from current path # new pixbuf from current path
try:
readimg = gtk.gdk.pixbuf_new_from_file(self.path) readimg = gtk.gdk.pixbuf_new_from_file(self.path)
except:
readimg = None
print "WARNING: Unable to load image."
# create an pixbuf for the thumbnail and fill it with a background pattern
thumbpixbuf = gtk.gdk.Pixbuf( gtk.gdk.COLORSPACE_RGB, True, 8,
int(self.screenw/4.0),
int(self.screenh/4.0) )
thumbpixbuf.fill(0x88888888)
thumbpixbuf.saturate_and_pixelate(thumbpixbuf, 0.0, True)
if readimg is not None:
imgw = readimg.get_width() imgw = readimg.get_width()
imgh = readimg.get_height() imgh = readimg.get_height()
@ -49,17 +63,6 @@ class App:
disp_ratio = float(self.screenw)/float(self.screenh) disp_ratio = float(self.screenw)/float(self.screenh)
img_ratio = float(imgw)/float(imgh) img_ratio = float(imgw)/float(imgh)
# actual width of the image on the screen thumbnail
thumbw = -1
thumbh = -1
# create an pixbuf for the thumbn, and fill it with a "background" pattern
thumbpixbuf = gtk.gdk.Pixbuf( gtk.gdk.COLORSPACE_RGB, True, 8,
int(self.screenw/4.0),
int(self.screenh/4.0) )
thumbpixbuf.fill(0x88888888)
thumbpixbuf.saturate_and_pixelate(thumbpixbuf, 0.0, True)
# switch between the different disposition styles # switch between the different disposition styles
if self.disp == "zoom": if self.disp == "zoom":
@ -148,18 +151,23 @@ class App:
# finally draw the gtk.Image from the pixbuf # finally draw the gtk.Image from the pixbuf
self.image.set_from_pixbuf(thumbpixbuf) self.image.set_from_pixbuf(thumbpixbuf)
# 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: with open( self.conffile, 'r') as conf:
for line in conf: for line in conf:
m1 = re.match(r"\s*/desktop/gnome/background/picture_filename\s+((?:\S*(?:(?<=\\)\s)*)+)", line) m1 = re.match(r"^\s*/desktop/gnome/background/picture_filename\s+(\S.*)$", line)
m2 = re.match(r"\s*/desktop/gnome/background/picture_options\s+(\w+)", line) m2 = re.match(r"^\s*/desktop/gnome/background/picture_options\s+(\w+)", line)
if m1: if m1:
if os.path.isfile( m1.group(1)):
print "Image file option read: " + m1.group(1) print "Image file option read: " + m1.group(1)
self.path = m1.group(1) self.path = m1.group(1)
else:
print "Image file not found"
self.path = None
elif m2: elif m2:
print "Image disposition option read: " + m2.group(1) print "Image disposition option read: " + m2.group(1)
@ -172,8 +180,8 @@ class App:
out = "" out = ""
for line in conf: for line in conf:
m1 = re.match(r"\s*/desktop/gnome/background/picture_filename\s+((?:\S*(?:(?<=\\)\s)*)+)", line) m1 = re.match(r"^\s*/desktop/gnome/background/picture_filename", line)
m2 = re.match(r"\s*/desktop/gnome/background/picture_options\s+(\w+)", line) m2 = re.match(r"^\s*/desktop/gnome/background/picture_options", line)
# if the current line matchs the picture_filename option, replace # if the current line matchs the picture_filename option, replace
# it with a new one containing the current value of path # it with a new one containing the current value of path
@ -274,6 +282,7 @@ class App:
i+=1 i+=1
self.combo.set_active( i ) self.combo.set_active( i )
if self.path is not None:
self.filedialog.set_filename(self.path) self.filedialog.set_filename(self.path)
#self.window.set_border_width(4) #self.window.set_border_width(4)