文件操作 - background-image.py
返回文件管理
返回主菜单
删除本文件
文件: /usr/share/doc/python-caja/examples/background-image.py
编辑文件内容
from gi.repository import Caja, GObject, Gio SUPPORTED_FORMATS = 'image/jpeg', 'image/png' BACKGROUND_SCHEMA = 'org.mate.background' BACKGROUND_KEY = 'picture-uri' class BackgroundImageExtension(GObject.GObject, Caja.MenuProvider): def __init__(self): self.bgsettings = Gio.Settings.new(BACKGROUND_SCHEMA) def menu_activate_cb(self, menu, file): if file.is_gone(): return self.bgsettings[BACKGROUND_KEY] = file.get_uri() def get_file_items(self, window, files): if len(files) != 1: return file = files[0] # We're only going to put ourselves on images context menus if not file.get_mime_type() in SUPPORTED_FORMATS: return # Mate can only handle file: # In the future we might want to copy the file locally if file.get_uri_scheme() != 'file': return item = Caja.MenuItem(name='Caja::set_background_image', label='Use as background image', tip='Set the current image as a background image') item.connect('activate', self.menu_activate_cb, file) return item, def get_background_items(self, window, file): return []
修改文件时间
将文件时间修改为当前时间的前一年
删除文件