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


Python DesktopEntry.getVersion方法代码示例

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


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

示例1: Mapping

# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import getVersion [as 别名]

#.........这里部分代码省略.........
        self.__info.set("Comment", comment, locale=True)

    def get_icon(self):
        """
        Gets the associated icon. 
        If no icon found or no icon directive it falls back to default icon.
        """

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

    def set_icon(self, icon_path):
        """
        Sets the icon for the mapping. 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.__info.set("Icon", icon_path)

    def get_authors(self):
        """Gets the mapping author/s"""

        return self.__info.get("X-Authors")

    def set_authors(self, authors):
        """Sets the author/s for the mapping"""

        self.__info.set("X-Authors", authors)

    def get_version(self):
        """Gets the version of the mapping"""

        return self.__info.get("X-Version")

    def set_version(self, version):
        """Sets the version of the mapping"""

        self.__info.set("X-Version", version)

    def get_mapping(self):
        """Gets the wminput config code"""

        return self.__mapping

    def set_mapping(self, mapping):
        """Sets the wminput config code"""

        self.__mapping = mapping

    def write(self, dest_path=None):
        """
        Saves the mapping object by writing the files in the mapping directory.

        The metadata it's saved in Mapping.info_filename file.
        The wminput config code it's saved in Mapping.mapping_filename file.
        The associated icon it's copied to the mapping directory.
        """
        if not dest_path:
            if not self.__path:
                raise MappingError, _("No path provided for writing mapping")
            dest_path = self.__path
        elif not os.path.exists(dest_path):
            os.mkdir(dest_path)

        icon_path = self.get_icon()
        icon_filename = os.path.basename(icon_path)
        if not icon_path == os.path.join(dest_path, icon_filename):
            shutil.copy(icon_path, dest_path)
            self.set_icon(icon_filename)

        self.__info.write(os.path.join(dest_path, Mapping.info_filename))

        mapping_fp = open(os.path.join(dest_path, Mapping.mapping_filename), "w")
        mapping_fp.write(self.__mapping)
        mapping_fp.close()

        # Clean not useful files
        for item in [
            x
            for x in os.listdir(dest_path)
            if not x in [Mapping.info_filename, Mapping.mapping_filename, icon_filename]
        ]:
            os.unlink(os.path.join(dest_path, item))

        self.__path = dest_path

    def __repr__(self):
        return "Mapping <" + self.__info.get("Name", locale=False) + " " + str(self.__info.getVersion()) + ">"
开发者ID:GNOME,项目名称:wiican,代码行数:104,代码来源:mapping.py


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