Guest User

Untitled

a guest
Jun 14th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.58 KB | None | 0 0
  1. sudo apt-get install libgsf-bin python-imaging
  2.  
  3. [Thumbnailer Entry]
  4. TryExec=/usr/bin/gsf-office-thumbnailer
  5. Exec=/usr/bin/gsf-office-thumbnailer -i %i -o %o -s %s
  6. MimeType=application/vnd.oasis.opendocument.graphics;application/vnd.oasis.opendocument.graphics-template;application/vnd.oasis.opendocument.formula;application/vnd.oasis.opendocument.text-master;application/vnd.oasis.opendocument.presentation;application/vnd.oasis.opendocument.presentation-template;application/vnd.oasis.opendocument.spreadsheet;application/vnd.oasis.opendocument.spreadsheet-template;application/vnd.oasis.opendocument.text;application/vnd.oasis.opendocument.text-template;application/vnd.openxmlformats-officedocument.presentationml.presentation;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;application/vnd.openxmlformats-officedocument.wordprocessingml.document
  7.  
  8. #!/usr/bin/env python
  9.  
  10. import gnomevfs
  11. import gtk
  12. import os
  13. import sys
  14. import zipfile
  15. from PIL import Image, ImageEnhance
  16.  
  17. # Alter these varibles to change thumbnail look
  18. ICON_USE_CURRENT_THEME = False
  19. # If not using current theme then use this path
  20. ICON_PATH_BASE = "/usr/share/icons/hicolor/48x48/apps/" # Change this path to alter icons
  21. ICON_PREFIX = "ooo-" #Ubuntu icons
  22. #ICON_PREFIX="openofficeorg-20-" #OOo2 stock icons
  23. #ICON_PREFIX="openofficeorg3-" # OOo3 icons
  24.  
  25. ICON_OPACITY = 0.8 #Opacity of the icon (between 0.0 and 1.0)
  26. THUMBNAIL_BACKGROUND_COLOR = "white" # Color of the background
  27. # Prefix for using mime types
  28. ICON_MIME_PREFIX = "gnome-mime-application-"
  29.  
  30. in_file_path = gnomevfs.get_local_path_from_uri(sys.argv[1])
  31. out_file_path = sys.argv[2]
  32. path_without_thumbs = os.getenv("HOME")+"/Templates"
  33.  
  34. def get_icon(thumbnail_size):
  35. icon_names={"formula":"math","graphics":"draw","presentation":"impress","spreadsheet":"calc","text":"writer"}
  36. #Get file mimetype
  37. file_mime_type=gnomevfs.get_mime_type(in_file_path)
  38. #print file_mime_type
  39. #Get last part of mimetype name.
  40. application_name=file_mime_type.split(".")[-1]
  41. try:
  42. #For OOo2 files we have to find icon name in icon_names
  43. icon_name=icon_names[application_name]
  44. except:
  45. #But for OOo1 files it is equal to icon name (without prefix).
  46. icon_name=application_name
  47. #Load icon
  48. if ICON_USE_CURRENT_THEME:
  49. icon_name = ICON_MIME_PREFIX+ file_mime_type.split("/")[1]
  50. icon = get_current_theme_icon( icon_name )
  51. else:
  52. icon = Image.open(ICON_PATH_BASE+ICON_PREFIX+icon_name +".png").convert("RGBA")
  53. #Set it's opacity
  54. icon = set_icon_opacity(icon,ICON_OPACITY)
  55. #And set it's position in thumbnail
  56. icon_posx=thumbnail_size[0]-icon.size[0]
  57. icon_posy=thumbnail_size[1]-icon.size[1]
  58. icon_width=thumbnail_size[0]
  59. icon_height=thumbnail_size[1]
  60. return {"image":icon,"position":(icon_posx,icon_posy,icon_width,icon_height)}
  61.  
  62. def get_basic_thumbnail():
  63. #Find out if the file is not in Templates directory
  64. if in_file_path.find(path_without_thumbs)!=0:
  65. try:
  66. #Extract thumbnail from OOo file and save it
  67. zip=zipfile.ZipFile(in_file_path,mode="r")
  68. picture=zip.read("Thumbnails/thumbnail.png")
  69. zip.close()
  70. thumbnail=open(out_file_path,"w")
  71. thumbnail.write(picture)
  72. thumbnail.write("/n")
  73. thumbnail.close()
  74. #Open saved thumbnail
  75. image=Image.open(out_file_path).convert("RGBA")
  76. return {"suceeded":True,"image":image,"size":(image.size[0],image.size[1])}
  77.  
  78. except:
  79. return {"suceeded":False}
  80. else:
  81. return {"suceeded":False}
  82.  
  83. # Nicked from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362879
  84. def set_icon_opacity(icon,opacity):
  85. #Returns an image with reduced opacity.
  86. assert opacity >= 0 and opacity <= 1
  87. if icon.mode != 'RGBA':
  88. icon = icon.convert('RGBA')
  89. else:
  90. icon = icon.copy()
  91. alpha = icon.split()[3]
  92. alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
  93. icon.putalpha(alpha)
  94. return icon
  95.  
  96. # Convert GTK pixbuf to PIL Image
  97. def convert_pixbuf_to_image(pb):
  98. assert(pb.get_colorspace() == gtk.gdk.COLORSPACE_RGB)
  99. dimensions = pb.get_width(), pb.get_height()
  100. stride = pb.get_rowstride()
  101. pixels = pb.get_pixels()
  102. mode = pb.get_has_alpha() and "RGBA" or "RGB"
  103. return Image.frombuffer(mode, dimensions, pixels,"raw", mode, stride, 1)
  104.  
  105. # Get the icon from the current GTK theme
  106. def get_current_theme_icon( icon ):
  107. theme = gtk.icon_theme_get_default()
  108. #print theme.list_icons()
  109. pixbuf_icon = theme.load_icon(icon, 46, 0)
  110. return convert_pixbuf_to_image(pixbuf_icon)
  111.  
  112. thumbnail=get_basic_thumbnail()
  113. if thumbnail["suceeded"]:
  114. background=Image.new("RGB", thumbnail["size"], THUMBNAIL_BACKGROUND_COLOR)
  115. icon=get_icon(thumbnail["size"])
  116. thumbnail=thumbnail["image"]
  117. # Add thumbnail
  118. background.paste(thumbnail, None, thumbnail)
  119. # Add icon
  120. background.paste(icon["image"],icon["position"],icon["image"])
  121. # Save thumbnail
  122. background.save(out_file_path,"PNG")
  123.  
  124. <gconfschemafile>
  125. <schemalist>
  126.  
  127. <schema>
  128. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.text/enable</key>
  129. <applyto>/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.text/enable</applyto>
  130. <owner>opendocument-thumb</owner>
  131. <type>bool</type>
  132. <default>true</default>
  133. <locale name="C">
  134. <short></short>
  135. <long></long>
  136. </locale>
  137. </schema>
  138.  
  139.  
  140. <schema>
  141. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.text/command</key>
  142. <applyto>/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.text/command</applyto>
  143. <owner>opendocument-thumb</owner>
  144. <type>string</type>
  145. <default>/usr/bin/opendocument-thumbnailer %u %o</default>
  146. <locale name="C">
  147. <short></short>
  148. <long></long>
  149. </locale>
  150. </schema>
  151.  
  152.  
  153. <schema>
  154. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.spreadsheet/enable</key>
  155. <applyto>/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.spreadsheet/enable</applyto>
  156. <owner>opendocument-thumb</owner>
  157. <type>bool</type>
  158. <default>true</default>
  159. <locale name="C">
  160. <short></short>
  161. <long></long>
  162. </locale>
  163. </schema>
  164.  
  165.  
  166. <schema>
  167. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.spreadsheet/command</key>
  168. <applyto>/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.spreadsheet/command</applyto>
  169. <owner>opendocument-thumb</owner>
  170. <type>string</type>
  171. <default>/usr/bin/opendocument-thumbnailer %u %o</default>
  172. <locale name="C">
  173. <short></short>
  174. <long></long>
  175. </locale>
  176. </schema>
  177. <schema>
  178. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.graphics/enable</key>
  179. <applyto>/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.graphics/enable</applyto>
  180. <owner>opendocument-thumb</owner>
  181. <type>bool</type>
  182. <default>true</default>
  183. <locale name="C">
  184. <short></short>
  185. <long></long>
  186. </locale>
  187. </schema>
  188.  
  189.  
  190. <schema>
  191. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.graphics/command</key>
  192. <applyto>/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.graphics/command</applyto>
  193. <owner>opendocument-thumb</owner>
  194. <type>string</type>
  195. <default>/usr/bin/opendocument-thumbnailer %u %o</default>
  196. <locale name="C">
  197. <short></short>
  198. <long></long>
  199. </locale>
  200. </schema>
  201. <schema>
  202. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.formula/enable</key>
  203. <applyto>/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.formula/enable</applyto>
  204. <owner>opendocument-thumb</owner>
  205. <type>bool</type>
  206. <default>true</default>
  207. <locale name="C">
  208. <short></short>
  209. <long></long>
  210. </locale>
  211. </schema>
  212.  
  213.  
  214. <schema>
  215. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.formula/command</key>
  216. <applyto>/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.formula/command</applyto>
  217. <owner>opendocument-thumb</owner>
  218. <type>string</type>
  219. <default>/usr/bin/opendocument-thumbnailer %u %o</default>
  220. <locale name="C">
  221. <short></short>
  222. <long></long>
  223. </locale>
  224. </schema>
  225. <schema>
  226. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.presentation/enable</key>
  227. <applyto>/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.presentation/enable</applyto>
  228. <owner>opendocument-thumb</owner>
  229. <type>bool</type>
  230. <default>true</default>
  231. <locale name="C">
  232. <short></short>
  233. <long></long>
  234. </locale>
  235. </schema>
  236.  
  237.  
  238. <schema>
  239. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.presentation/command</key>
  240. <applyto>/desktop/gnome/thumbnailers/application@vnd.oasis.opendocument.presentation/command</applyto>
  241. <owner>opendocument-thumb</owner>
  242. <type>string</type>
  243. <default>/usr/bin/opendocument-thumbnailer %u %o</default>
  244. <locale name="C">
  245. <short></short>
  246. <long></long>
  247. </locale>
  248. </schema>
  249.  
  250.  
  251. <schema>
  252. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.sun.xml.writer/enable</key>
  253. <applyto>/desktop/gnome/thumbnailers/application@vnd.sun.xml.writer/enable</applyto>
  254. <owner>opendocument-thumb</owner>
  255. <type>bool</type>
  256. <default>true</default>
  257. <locale name="C">
  258. <short></short>
  259. <long></long>
  260. </locale>
  261. </schema>
  262.  
  263.  
  264. <schema>
  265. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.sun.xml.writer/command</key>
  266. <applyto>/desktop/gnome/thumbnailers/application@vnd.sun.xml.writer/command</applyto>
  267. <owner>opendocument-thumb</owner>
  268. <type>string</type>
  269. <default>/usr/bin/opendocument-thumbnailer %u %o</default>
  270. <locale name="C">
  271. <short></short>
  272. <long></long>
  273. </locale>
  274. </schema>
  275.  
  276.  
  277. <schema>
  278. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.sun.xml.calc/enable</key>
  279. <applyto>/desktop/gnome/thumbnailers/application@vnd.sun.xml.calc/enable</applyto>
  280. <owner>opendocument-thumb</owner>
  281. <type>bool</type>
  282. <default>true</default>
  283. <locale name="C">
  284. <short></short>
  285. <long></long>
  286. </locale>
  287. </schema>
  288.  
  289.  
  290. <schema>
  291. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.sun.xml.calc/command</key>
  292. <applyto>/desktop/gnome/thumbnailers/application@vnd.sun.xml.calc/command</applyto>
  293. <owner>opendocument-thumb</owner>
  294. <type>string</type>
  295. <default>/usr/bin/opendocument-thumbnailer %u %o</default>
  296. <locale name="C">
  297. <short></short>
  298. <long></long>
  299. </locale>
  300. </schema>
  301.  
  302.  
  303. <schema>
  304. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.sun.xml.draw/enable</key>
  305. <applyto>/desktop/gnome/thumbnailers/application@vnd.sun.xml.draw/enable</applyto>
  306. <owner>opendocument-thumb</owner>
  307. <type>bool</type>
  308. <default>true</default>
  309. <locale name="C">
  310. <short></short>
  311. <long></long>
  312. </locale>
  313. </schema>
  314.  
  315.  
  316. <schema>
  317. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.sun.xml.draw/command</key>
  318. <applyto>/desktop/gnome/thumbnailers/application@vnd.sun.xml.draw/command</applyto>
  319. <owner>opendocument-thumb</owner>
  320. <type>string</type>
  321. <default>/usr/bin/opendocument-thumbnailer %u %o</default>
  322. <locale name="C">
  323. <short></short>
  324. <long></long>
  325. </locale>
  326. </schema>
  327.  
  328. <schema>
  329. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.sun.xml.math/enable</key>
  330. <applyto>/desktop/gnome/thumbnailers/application@vnd.sun.xml.math/enable</applyto>
  331. <owner>opendocument-thumb</owner>
  332. <type>bool</type>
  333. <default>true</default>
  334. <locale name="C">
  335. <short></short>
  336. <long></long>
  337. </locale>
  338. </schema>
  339.  
  340.  
  341. <schema>
  342. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.sun.xml.math/command</key>
  343. <applyto>/desktop/gnome/thumbnailers/application@vnd.sun.xml.math/command</applyto>
  344. <owner>opendocument-thumb</owner>
  345. <type>string</type>
  346. <default>/usr/bin/opendocument-thumbnailer %u %o</default>
  347. <locale name="C">
  348. <short></short>
  349. <long></long>
  350. </locale>
  351. </schema>
  352. <schema>
  353. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.sun.xml.impress/enable</key>
  354. <applyto>/desktop/gnome/thumbnailers/application@vnd.sun.xml.impress/enable</applyto>
  355. <owner>opendocument-thumb</owner>
  356. <type>bool</type>
  357. <default>true</default>
  358. <locale name="C">
  359. <short></short>
  360. <long></long>
  361. </locale>
  362. </schema>
  363.  
  364.  
  365. <schema>
  366. <key>/schemas/desktop/gnome/thumbnailers/application@vnd.sun.xml.impress/command</key>
  367. <applyto>/desktop/gnome/thumbnailers/application@vnd.sun.xml.impress/command</applyto>
  368. <owner>opendocument-thumb</owner>
  369. <type>string</type>
  370. <default>/usr/bin/opendocument-thumbnailer %u %o</default>
  371. <locale name="C">
  372. <short></short>
  373. <long></long>
  374. </locale>
  375. </schema>
  376.  
  377. </schemalist>
  378. </gconfschemafile>
Add Comment
Please, Sign In to add comment