IconTags.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:zim-icontags-plugin 作者: Pl-M 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号