Example #1
0
    def __init__(self, path, width=0, height=0):
        """Create a document instance from file or totally new.
        @path: Path of the requested image.
        @width: If no path given, width of new document.
        @height: If no path given, height of new document."""

        # Allow debug tracking.
        main.log.allow_tracking(self)

        # If path given.
        self.path = path
        if path:

            # If given file is openraster, load it.
            name, ext = os.path.splitext(path)
            if ext == '.ora':
                ora = OpenRaster(path)
                width, height = ora.get_size()
                self.mime = 'image/openraster'
                self.configure(width, height)
                self.layers = Layers(self)
                ora.load(self)

            # If given file is an image loadable by gtk, load it.
            else:
                info, width, height = gtk.gdk.pixbuf_get_file_info(path)
                self.mime = info['mime_types'][0]
                self.configure(width, height)
                self.layers = Layers(self)
                self.layers.append_from_path(path)
                self.layers.active.name = _('Original')

        # If not path given, create a blank document.
        else:
            self.configure(width, height)
            self.layers = Layers(self)
            self.layers.append_blank(width, height, True)

        # Set canvas and action tracker.
        self.canvas = Canvas(self)
        self.actions = Actions(self)