def _load_icons():
'''
Load icons for the plugin from 'ICONS_DIRECTORY' folder (files with png format).
Icons are stored as dict: {'name': 'icon'}, where icon is a name of the icon in the factory (or gtk).
For example an icon with name 'name' will have an icon file 'name.png'
in this folder or a 'NO_IMAGE' icon if it is not available.
'''
# Use IconFactory to get the same size for all icons.
factory = gtk.IconFactory()
factory.add_default()
icons = {
NO_IMAGE: gtk.STOCK_MISSING_IMAGE, # icon has no image
SEVERAL_ICONS: gtk.STOCK_DIALOG_QUESTION, # not clear what icon to use
# Icons below can be overwritten if there is a certain file in the 'ICONS_DIRECTORY'.
'apply': gtk.STOCK_APPLY, # additional GTK icon
#'info': gtk.STOCK_INFO, # additional GTK icon
FOLDER_ICON: gtk.STOCK_DIRECTORY, # for pages with children
FOLDER_TAGS_ICON: gtk.STOCK_DIRECTORY, # for pages with children and with tags
FILE_ICON: gtk.STOCK_FILE, # for ordinary pages
FILE_TAGS_ICON: gtk.STOCK_FILE # for ordinary pages with tags
}
# Icons from directory.
dir = data_dir(ICONS_DIRECTORY)
counter = 0 # to count number of loaded icons
if dir:
for file in dir.list('*.png'):
# not all installs have svg support, so only check png for now..
name = file[:-4].lower() # e.g. 'calendar.png' -> 'calendar'
icon_name = 'p_Icon_' + name # e.g. 'Calendar' -> 'p_Icon_calendar'
try:
pixbuf = gtk.gdk.pixbuf_new_from_file(str(dir+file))
icon = gtk.IconSet(pixbuf)
factory.add(icon_name, icon)
icons[name] = icon_name
counter += 1
except:
logger.error('IconTags: Error while loading icons.')
logger.debug('IconTags: {} icons loaded from: {}'.format(counter, dir.path))
else:
logger.debug('''IconTags: Folder with icons doesn't exist.''')
return icons
评论列表
文章目录