当前位置: 首页>>代码示例>>Python>>正文


Python DesktopEntry.new方法代码示例

本文整理汇总了Python中xdg.DesktopEntry.DesktopEntry.new方法的典型用法代码示例。如果您正苦于以下问题:Python DesktopEntry.new方法的具体用法?Python DesktopEntry.new怎么用?Python DesktopEntry.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xdg.DesktopEntry.DesktopEntry的用法示例。


在下文中一共展示了DesktopEntry.new方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Mapping

# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import new [as 别名]
class Mapping(object):
    """
    An object representation of a wiican mapping.

    A wiican mapping must be located in a single directory containing a file 
    with the wminput code, a file containing the metadata (name, description, 
    author, version) and an optional icon file.
    """

    # Mandatory filename for the metadata file
    info_filename = "info.desktop"

    # Mandatory filename for the wminput config file
    mapping_filename = "mapping.wminput"

    def __init__(self, path=None):
        """
        Builds a mapping object.

        Parameters:
        path -  scans the path for building a mapping object if the needed files
                where found. If None it builds an empty mapping. If some of the 
                needed files wasn't found it tries to build a mapping with the 
                found info.

        The Mapping.info_filename and Mapping.mapping_filename class attributes 
        marks the requiered filenames for the metadata file and wminput config file 
        respectively.

        The Mapping.mapping_filename file must contain wminput config file code
        The Mapping.info_filename follows XDG DesktopEntry syntax.
        
        The Mapping.info_filename contains the source of the optional associated
        icon. If no icon found or no icon directive it falls back to default 
        icon.

        There are three posibilities for icon setting:

        - An absolute path where the icon it's stored
        - Icon filename if it's stored in the same dir as Mapping.info_filename
        - Theme-icon-name for auto-getting the icon from the icon theme
        """

        self.__path = path

        # Getting freedesktop definition file
        self.__info = DesktopEntry()

        if path and os.path.exists(os.path.join(path, Mapping.info_filename)):
            self.__info.parse(os.path.join(path, Mapping.info_filename))
        else:
            self.__info.new(self.info_filename)
            self.__info.set("Type", "Wiican Mapping")

        # Getting wminput mapping file
        if path and os.path.exists(os.path.join(path, Mapping.mapping_filename)):
            mapping_fp = open(os.path.join(path, Mapping.mapping_filename), "r")
            self.__mapping = mapping_fp.read()
            mapping_fp.close()
        else:
            self.__mapping = ""

        # Getting icon file path
        icon_name = self.__info.getIcon()
        if path and icon_name in os.listdir(path):  # Icon included
            self.set_icon(os.path.join(path, icon_name))
        elif getIconPath(icon_name):  # Theme icon
            self.set_icon(getIconPath(icon_name))
        else:  # Default icon
            self.set_icon(ICON_DEFAULT)

    def get_path(self):
        """Returns the absolute path where the wiican mapping it's saved.
        It returns None if the mapping it's not saved yet"""

        return self.__path

    def get_name(self):
        """Gets the name of the mapping"""

        return self.__info.getName()

    def set_name(self, name):
        """Sets the name for the mapping"""

        self.__info.set("Name", name)
        self.__info.set("Name", name, locale=True)

    def get_comment(self):
        """Gets the descriptional comment"""

        return self.__info.getComment()

    def set_comment(self, comment):
        """Sets the descriptional comment for the mapping"""

        self.__info.set("Comment", comment)
        self.__info.set("Comment", comment, locale=True)

    def get_icon(self):
#.........这里部分代码省略.........
开发者ID:GNOME,项目名称:wiican,代码行数:103,代码来源:mapping.py


注:本文中的xdg.DesktopEntry.DesktopEntry.new方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。