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


Python DesktopEntry.get方法代码示例

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


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

示例1: __create_model

# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import get [as 别名]
    def __create_model(self, all = False, comment = False):
        model = self.get_model()
        model.clear()

        allitems = []
        allitems.extend(self.useritems)
        allitems.extend(self.systemitems)

        for item in allitems:
            try:
                desktopentry = DesktopEntry(item)
            except:
                continue

            if desktopentry.get("Hidden"):
                if not all:
                    continue
            iter = model.append()
            enable = desktopentry.get("X-GNOME-Autostart-enabled")
            if enable == "false":
                enable = False
            else:
                enable = True
            
            iconname = desktopentry.get('Icon', locale = False)
            if not iconname:
               iconname = desktopentry.get('Name', locale = False)
               if not iconname:
                   iconname = desktopentry.getName()

            icon = get_icon_with_name(iconname, 32)

            try:
                name = desktopentry.getName()
            except:
                name = desktopentry.get('Name', locale=False)

            if comment:
                comment = desktopentry.getComment()
                if not comment:
                    comment = _("No description")
                description = "<b>%s</b>\n%s" % (name, comment)
            else:
                description = "<b>%s</b>" % name

            model.set(iter,
                      COLUMN_ACTIVE, enable,
                      COLUMN_ICON, icon,
                      COLUMN_PROGRAM, description,
                      COLUMN_PATH, item)
开发者ID:actiononmail,项目名称:ubuntu-tweak,代码行数:52,代码来源:autostart.py

示例2: init

# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import get [as 别名]
    def init(self, info, progress):
        """
        If needed, perform long initialisation tasks here.

        info is a dictionary with useful information.  Currently it contains
        the following values:

          "values": a dict mapping index mnemonics to index numbers

        The progress indicator can be used to report progress.
        """

        # Read the value indexes we will use
        values = info["values"]
        self.val_popcon = values.get("app-popcon", -1)

        self.indexers = [Indexer(lang, self.val_popcon, progress) for lang in [None] + list(self.langs)]
        self.entries = {}

        progress.begin("Reading .desktop files from %s" % APPINSTALLDIR)
        for f in os.listdir(APPINSTALLDIR):
            if f[0] == "." or not f.endswith(".desktop"):
                continue
            entry = DesktopEntry(os.path.join(APPINSTALLDIR, f))
            pkg = entry.get("X-AppInstall-Package")
            self.entries.setdefault(pkg, []).append((f, entry))
        progress.end()
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:29,代码来源:app-install.py

示例3: __init__

# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import get [as 别名]
class VeraCCModule:
	""" An object representing a Vera Control Center module. """
		
	def __init__(self, module_name, module_path):
		""" Initialize the object """
				
		self.module_is_external = False
		self.module_name = module_name
		self.module_path = module_path
	
		self.launcher_icon = None
		self.launcher_name = None
		self.launcher_comment = None
		self.launcher_section = None
			
		self.module_launcher = DesktopEntry(os.path.join(self.module_path, "%s.desktop" % self.module_name))
			
		# Icon
		self.launcher_icon = self.module_launcher.getIcon()
		if not self.launcher_icon:
			self.launcher_icon = "preferences-system"

		#ICON_THEME.connect("changed", lambda x: self.replace_icon(icon))
		
		# Name
		self.launcher_name = self.module_launcher.getName()
		
		# Comment
		self.launcher_comment = self.module_launcher.getComment()
		
		# Section
		self.launcher_section = self.module_launcher.get("X-VeraCC-Section")
		
		# Keywords
		self.launcher_keywords = [x.lower() for x in self.module_launcher.getKeywords()]
		
		# External?
		_exec = self.module_launcher.getExec()
		if _exec:
			# Yeah!
			self.module_is_external = True
			self.module_path = _exec
开发者ID:vera-desktop,项目名称:vera-control-center,代码行数:44,代码来源:module.py

示例4: Autostart

# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import get [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

示例5: Mapping

# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import get [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

示例6: TranslationCatalog

# 需要导入模块: from xdg.DesktopEntry import DesktopEntry [as 别名]
# 或者: from xdg.DesktopEntry.DesktopEntry import get [as 别名]
				language = translation.replace(".po","")
				self.languages[language] = polib.pofile(os.path.join(source_dir, translation))
				
catalog = TranslationCatalog("./po/vera-control-center-module-updates")

# Search for desktop files
desktop_files = []

for directory, dirnames, filenames in os.walk("."):
	for file_ in filenames:
		if file_.endswith(".desktop"):
			entry = DesktopEntry(os.path.join(directory, file_))
			
			for key in ("Name", "Comment", "Keywords"):
				try:
					source = entry.get(key)
				except:
					continue
				
				for lang, obj in TranslationCatalog.languages.items():
					found = obj.find(source)
					if found and found.msgstr != "":
						# xdg's IniFile supports the locale= keyword,
						# but it supports only a boolean value. The locale
						# is hardcoded to the one of the current system.
						# We workaround this by specifying the right key
						# right now.
						entry.set("%s[%s]" % (key, lang), found.msgstr)
			
			entry.write()
开发者ID:semplice,项目名称:vera-control-center-module-updates,代码行数:32,代码来源:dump_translations_to_desktopentries.py


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