forked from bartvdbraak/blender
patch [#25972] blender-thumbnailer.py: GVFS support
from Shinsuke Irie (irie) with some minor edits. Shinsuke's description from the tracker: --- I have implemented GVFS framework support of blender-thumbnailer.py which allows some file managers like Nautilus and Thunar to show thumbnails in trash or network directories. If Python's gio module is available, the thumbnailer uses it to access to filesystems mounted via GVFS. This change shouldn't affect desktop environments other than GNOME and XFCE. A function gvfs_open() in this patch is defined to solve a stupid incompatibility between Python file object and GIO Seekable object. On Ubuntu 10.10, I confirmed thumbnails can be generated for file://, trash://, sftp://, and smb://.
This commit is contained in:
parent
4eb76a1a90
commit
30552f9f46
@ -24,27 +24,49 @@
|
|||||||
Thumbnailer runs with python 2.6 and 3.x.
|
Thumbnailer runs with python 2.6 and 3.x.
|
||||||
To run automatically with nautilus:
|
To run automatically with nautilus:
|
||||||
gconftool --type boolean --set /desktop/gnome/thumbnailers/application@x-blender/enable true
|
gconftool --type boolean --set /desktop/gnome/thumbnailers/application@x-blender/enable true
|
||||||
gconftool --type string --set /desktop/gnome/thumbnailers/application@x-blender/command "blender-thumbnailer.py %i %o"
|
gconftool --type string --set /desktop/gnome/thumbnailers/application@x-blender/command "blender-thumbnailer.py %u %o"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
|
||||||
|
def open_wrapper_get():
|
||||||
|
""" wrap OS spesific read functionality here, fallback to 'open()'
|
||||||
|
"""
|
||||||
|
|
||||||
|
def open_gio(path, mode):
|
||||||
|
g_file = gio.File(path).read()
|
||||||
|
g_file.orig_seek = g_file.seek
|
||||||
|
|
||||||
|
def new_seek(offset, whence=0):
|
||||||
|
return g_file.orig_seek(offset, [1, 0, 2][whence])
|
||||||
|
|
||||||
|
g_file.seek = new_seek
|
||||||
|
return g_file
|
||||||
|
|
||||||
|
try:
|
||||||
|
import gio
|
||||||
|
return open_gio
|
||||||
|
except ImportError:
|
||||||
|
return open
|
||||||
|
|
||||||
|
|
||||||
def blend_extract_thumb(path):
|
def blend_extract_thumb(path):
|
||||||
import os
|
import os
|
||||||
|
open_wrapper = open_wrapper_get()
|
||||||
|
|
||||||
# def MAKE_ID(tag): ord(tag[0])<<24 | ord(tag[1])<<16 | ord(tag[2])<<8 | ord(tag[3])
|
# def MAKE_ID(tag): ord(tag[0])<<24 | ord(tag[1])<<16 | ord(tag[2])<<8 | ord(tag[3])
|
||||||
REND = 1145980242 # MAKE_ID(b'REND')
|
REND = 1145980242 # MAKE_ID(b'REND')
|
||||||
TEST = 1414743380 # MAKE_ID(b'TEST')
|
TEST = 1414743380 # MAKE_ID(b'TEST')
|
||||||
|
|
||||||
blendfile = open(path, 'rb')
|
blendfile = open_wrapper(path, 'rb')
|
||||||
|
|
||||||
head = blendfile.read(12)
|
head = blendfile.read(12)
|
||||||
|
|
||||||
if head[0:2] == b'\x1f\x8b': # gzip magic
|
if head[0:2] == b'\x1f\x8b': # gzip magic
|
||||||
import gzip
|
import gzip
|
||||||
blendfile.close()
|
blendfile.close()
|
||||||
blendfile = gzip.open(path, 'rb')
|
blendfile = gzip.GzipFile('', 'rb', 0, open_wrapper(path, 'rb'))
|
||||||
head = blendfile.read(12)
|
head = blendfile.read(12)
|
||||||
|
|
||||||
if not head.startswith(b'BLENDER'):
|
if not head.startswith(b'BLENDER'):
|
||||||
|
Loading…
Reference in New Issue
Block a user