Пример #1
0
    def __redraw(self):

        if (not self.__dom): return

        w, h = self.__widget.size_request()
        imgw, imgh = self.__image_size
        if (imgw == 0 or imgh == 0):
            log ("Warning: The desklet is broken. Image height or width is 0",
                 "Please contact the author to fix the problem.")
            return

        # crappy SVG needs the size to be given; just set it here so that it
        # dynamically takes the correct size
        self.__dom["width"] = str(w or 100)
        self.__dom["height"] = str(h or 100)

        # so that's why the XML parser inserted an empty <g> node... :)
        g = self.__dom.get_children()[0]
        g["transform"] = "scale(%f, %f)" % (float(w) / imgw,
                                            float(h) / imgh)

        svg.render(self.__widget, w, h, str(self.__dom))
Пример #2
0
    def set_prop(self, key, value):

        if (key == "window-flags"):
            self.update_observer(self.OBS_FLAGS, value)

        elif (key == "desktop-borders"):
            self.update_observer(self.OBS_BORDERS, value)

        elif (key == "title"):
            self.update_observer(self.OBS_TITLE, value)

        elif (key == "icon"):
            filename = self.get_full_path(value)
            loader = gtk.gdk.PixbufLoader()
            try:
                data = vfs.read_entire_file(filename)
            except:
                return
            try:
                loader.write(data, len(data))
            except:
                log("Warning: Invalid image format.")
                return

            loader.close()
            pixbuf = loader.get_pixbuf()
            self.update_observer(self.OBS_ICON, pixbuf)

        elif (key == "shape"):
            if (value.lstrip().startswith("<")):
                from utils.DOM import DOM
                try:
                    from utils import svg
                except ImportError:
                    log("Could not import svg module!")
                    return
                w, h, = self.size_request()
                if (not w or not h): return
                root = DOM(value).get_root()
                root["width"] = `w`
                root["height"] = `h`
                img = gtk.Image()
                svg.render(img, w, h, str(root))
                pixbuf = img.get_pixbuf()

            else:
                filename = self.get_full_path(value)
                loader = gtk.gdk.PixbufLoader()
                try:
                    data = vfs.read_entire_file(filename)
                except:
                    log("Couldn't read file %s", (filename,))
                    return
                try:
                    loader.write(data, len(data))
                except:
                    log("Warning: Invalid image format.")
                    return

                loader.close()
                pixbuf = loader.get_pixbuf()

            pix, mask = pixbuf.render_pixmap_and_mask(1)
            self.update_observer(self.OBS_SHAPE, mask)