本文整理汇总了Python中xdg.DesktopEntry.DesktopEntry.hasKey方法的典型用法代码示例。如果您正苦于以下问题:Python DesktopEntry.hasKey方法的具体用法?Python DesktopEntry.hasKey怎么用?Python DesktopEntry.hasKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xdg.DesktopEntry.DesktopEntry
的用法示例。
在下文中一共展示了DesktopEntry.hasKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import hasKey [as 别名]
def test_basic(self):
entry = DesktopEntry(self.test_file)
assert entry.hasKey("Categories")
assert not entry.hasKey("TryExec")
assert entry.hasGroup("Desktop Action Window")
assert not entry.hasGroup("Desktop Action Door")
示例2: Autostart
# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import hasKey [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)