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


Python DesktopEntry.removeKey方法代码示例

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


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

示例1: test_write_file

# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import removeKey [as 别名]
 def test_write_file(self):
     de = DesktopEntry()
     de.parse(self.test_file)
     de.removeKey("Name")
     de.addGroup("Hallo")
     de.set("key", "value", "Hallo")
     
     new_file = os.path.join(self.tmpdir, "test.desktop")
     de.write(new_file, trusted=True)
     
     with io.open(new_file, encoding='utf-8') as f:
         contents = f.read()
     
     assert "[Hallo]" in contents, contents
     assert re.search("key\s*=\s*value", contents), contents
     
     # This is missing the Name key, and has an unknown Hallo group, so it
     # shouldn't validate.
     new_entry = DesktopEntry(new_file)
     self.assertRaises(ValidationError, new_entry.validate)
开发者ID:flyser,项目名称:pyxdg,代码行数:22,代码来源:test-desktop.py

示例2: Autostart

# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import removeKey [as 别名]
class Autostart(gobject.GObject):
    __gsignals__ = {
        'changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_BOOLEAN,)),
    }

    def __init__(self):
        gobject.GObject.__init__(self)
        self.config = Config.Config(tgcm.country_support)

        # Determine the path for XDG autostart dirs
        self.autofile_name = 'tgcm-%s.desktop' % tgcm.country_support
        self.user_autodir = None
        for foo in BaseDirectory.load_config_paths('autostart'):
            if foo.startswith(os.path.expanduser('~')):
                self.user_autodir = foo
            else:
                self.system_autodir = foo

        self.__create_desktop_entry_if_necessary()

        # Listen to file changes
        myfile = gio.File(self.user_autofile)
        self.desktopentry_monitor = myfile.monitor_file()
        self.desktopentry_monitor.connect('changed', self.on_desktopentry_changed)

    def __create_desktop_entry_if_necessary(self):
        # Create user autostart dir if it does not exists
        if self.user_autodir is None:
            self.user_autodir = BaseDirectory.save_config_path('autostart')

        # It it does not exists an autostart file for TGCM in userdir,
        # create a copy from the global one
        self.user_autofile = os.path.join(self.user_autodir, self.autofile_name)
        if not os.path.exists(self.user_autofile):
            autofile_path = os.path.join(self.system_autodir, self.autofile_name)
            shutil.copy(autofile_path, self.user_autofile)

            # Honor 'launch-startup' policy in regional-info.xml file
            self.desktopentry = DesktopEntry(self.user_autofile)
            is_autostart = self.config.check_policy('launch-startup')
            self.set_enabled(is_autostart)
        else:
            self.desktopentry = DesktopEntry(self.user_autofile)


    def is_enabled(self):
        self.__create_desktop_entry_if_necessary()

        # Check if the DesktopEntry object has an autostart attribute
        if self.desktopentry.hasKey('X-GNOME-Autostart-enabled'):
            is_autostart = self.desktopentry.get('X-GNOME-Autostart-enabled', \
                    type='boolean')
        else:
            is_autostart = True

        if self.desktopentry.hasKey('Hidden'):
            is_shown = not self.desktopentry.get('Hidden', type='boolean')
        else:
            is_shown = True

        return is_shown and is_autostart

    def set_enabled(self, value):
        self.__create_desktop_entry_if_necessary()

        value = str(value).lower()
        self.desktopentry.set('X-GNOME-Autostart-enabled', value)
        self.desktopentry.removeKey('Hidden')
        self.desktopentry.write()

    def on_desktopentry_changed(self, monitor, myfile, other_file, event):
        if event == gio.FILE_MONITOR_EVENT_DELETED:
            self.__create_desktop_entry_if_necessary()

        is_enabled = self.is_enabled()
        self.emit('changed', is_enabled)
开发者ID:calabozo,项目名称:tgcmlinux,代码行数:78,代码来源:Autostart.py


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