mejoras varias. mejor manejo de no-imágenes, archivos no encontrados, espacios en nombres, paths vacíos.
This commit is contained in:
parent
d874888f29
commit
20c65a331e
@ -23,6 +23,7 @@ pygtk.require('2.0')
|
||||
|
||||
import gtk
|
||||
import commands
|
||||
import os
|
||||
|
||||
# Check for new pygtk: this is new class in PyGtk 2.4
|
||||
if gtk.pygtk_version < (2,3,90):
|
||||
@ -30,7 +31,7 @@ if gtk.pygtk_version < (2,3,90):
|
||||
raise SystemExit
|
||||
|
||||
class App:
|
||||
path = "/usr/share/images/desktop-base/moreblue-orbit-gdm.svg"
|
||||
path = None
|
||||
disp = "stretched"
|
||||
conffile = "/etc/gdm3/greeter.gconf-defaults"
|
||||
image = gtk.Image()
|
||||
@ -41,7 +42,20 @@ class App:
|
||||
def redraw(self):
|
||||
|
||||
# new pixbuf from current path
|
||||
try:
|
||||
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()
|
||||
imgh = readimg.get_height()
|
||||
|
||||
@ -49,17 +63,6 @@ class App:
|
||||
disp_ratio = float(self.screenw)/float(self.screenh)
|
||||
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
|
||||
if self.disp == "zoom":
|
||||
|
||||
@ -148,18 +151,23 @@ class App:
|
||||
# finally draw the gtk.Image from the pixbuf
|
||||
self.image.set_from_pixbuf(thumbpixbuf)
|
||||
|
||||
|
||||
# read GDM3 configuration file, and set correspondig variables
|
||||
def read_config( self ):
|
||||
|
||||
with open( self.conffile, 'r') as conf:
|
||||
|
||||
for line in conf:
|
||||
m1 = re.match(r"\s*/desktop/gnome/background/picture_filename\s+((?:\S*(?:(?<=\\)\s)*)+)", line)
|
||||
m2 = re.match(r"\s*/desktop/gnome/background/picture_options\s+(\w+)", 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)
|
||||
|
||||
if m1:
|
||||
if os.path.isfile( m1.group(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 disposition option read: " + m2.group(1)
|
||||
@ -172,8 +180,8 @@ class App:
|
||||
out = ""
|
||||
|
||||
for line in conf:
|
||||
m1 = re.match(r"\s*/desktop/gnome/background/picture_filename\s+((?:\S*(?:(?<=\\)\s)*)+)", line)
|
||||
m2 = re.match(r"\s*/desktop/gnome/background/picture_options\s+(\w+)", line)
|
||||
m1 = re.match(r"^\s*/desktop/gnome/background/picture_filename", line)
|
||||
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
|
||||
@ -274,6 +282,7 @@ class App:
|
||||
i+=1
|
||||
self.combo.set_active( i )
|
||||
|
||||
if self.path is not None:
|
||||
self.filedialog.set_filename(self.path)
|
||||
|
||||
#self.window.set_border_width(4)
|
||||
|
Loading…
x
Reference in New Issue
Block a user