本文整理汇总了Python中PySide.QtGui.QIcon.hasThemeIcon方法的典型用法代码示例。如果您正苦于以下问题:Python QIcon.hasThemeIcon方法的具体用法?Python QIcon.hasThemeIcon怎么用?Python QIcon.hasThemeIcon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QIcon
的用法示例。
在下文中一共展示了QIcon.hasThemeIcon方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: iconForMimeType
# 需要导入模块: from PySide.QtGui import QIcon [as 别名]
# 或者: from PySide.QtGui.QIcon import hasThemeIcon [as 别名]
def iconForMimeType(self, mime):
icon = mime.icon()
if QIcon.hasThemeIcon(icon):
return getIcon(icon)
if mime.aliasOf():
return self.iconForMimeType(MimeType(mime.aliasOf()))
for parent in mime.subClassOf():
icon = parent.icon()
if QIcon.hasThemeIcon(icon):
return getIcon(icon)
icon = mime.genericIcon()
if QIcon.hasThemeIcon(icon):
return getIcon(icon)
icon = MimeType(MimeType.DEFAULT_BINARY).icon()
return getIcon(icon)
示例2: get
# 需要导入模块: from PySide.QtGui import QIcon [as 别名]
# 或者: from PySide.QtGui.QIcon import hasThemeIcon [as 别名]
def get(name):
if QFile('icons:{}.svg'.format(name)).exists():
return QIcon('icons:{}.svg'.format(name))
if QIcon.hasThemeIcon(name):
return QIcon.fromTheme(name)
if os.path.exists(name):
return QIcon(name)
return QIcon()
示例3: _action_with_icon
# 需要导入模块: from PySide.QtGui import QIcon [as 别名]
# 或者: from PySide.QtGui.QIcon import hasThemeIcon [as 别名]
def _action_with_icon(self, action_type, icon_names, is_action=False):
if is_action:
action = action_type
else:
action = self.page.action(action_type)
for icon_name in icon_names:
if QIcon.hasThemeIcon(icon_name):
action.setIcon(QIcon.fromTheme(icon_name))
break
self.copy_available.connect(action.setEnabled)
return action
示例4: by_name
# 需要导入模块: from PySide.QtGui import QIcon [as 别名]
# 或者: from PySide.QtGui.QIcon import hasThemeIcon [as 别名]
def by_name(name):
"""Locates and loads an icon for the user, finding by name"""
filename = os.path.join(ICONROOT, "%s.png" % name)
if os.path.isfile(filename):
#pixmap = QPixmap(filename)
#icon = QIcon(pixmap)
icon = QIcon(filename)
return icon
if QIcon.hasThemeIcon(name):
return QIcon.fromTheme(name)
raise KeyError, "No such icon %s exists." % name
示例5: icon
# 需要导入模块: from PySide.QtGui import QIcon [as 别名]
# 或者: from PySide.QtGui.QIcon import hasThemeIcon [as 别名]
def icon(self, name, extension='png', use_inheritance=True,
allow_theme=True):
"""
Find an icon with the given ``name`` and return a
:class:`~PySide.QtGui.QIcon` of that icon. If ``use_inheritance`` is
True and this style doesn't have an icon with the given name, the
icon will be searched for in the style this style inherits.
If ``allow_theme`` is True and the icon can't be located in a style, it
will be retrieved with :func:`PySide.QtGui.QIcon.fromTheme` as a last
resort as long as the style allows the use of system icons.
"""
icon = None
fn = '%s.%s' % (name, extension)
path = profile.join('images', fn)
if self.path_source != profile.SOURCE_PKG_RESOURCES:
file = self.get_path(path, use_inheritance)
if file and os.path.exists(file):
icon = QIcon(file)
else:
if self.has_file(path, use_inheritance):
f = self.get_file(path, use_inheritance=use_inheritance)
if f:
pixmap = QPixmap()
pixmap.loadFromData(f.read())
icon = QIcon(pixmap)
del pixmap
f.close()
if not icon and use_inheritance and self.inherits:
icon = loaded_styles[self.inherits].icon(name, extension,
use_inheritance, allow_theme)
if not icon and allow_theme:
if QIcon.hasThemeIcon(name):
icon = QIcon.fromTheme(name)
if not icon:
icon = QIcon()
return icon
示例6: icon
# 需要导入模块: from PySide.QtGui import QIcon [as 别名]
# 或者: from PySide.QtGui.QIcon import hasThemeIcon [as 别名]
def icon(name, extension=None, style=None, use_inheritance=True,
allow_theme=True, _always_return=True):
"""
Find an icon with the given ``name`` and ``extension`` and return a
:class:`PySide.QtGui.QIcon` for that icon.
================ =========== ============
Argument Default Description
================ =========== ============
name The name of the icon to load.
extension The desired filename extension of the icon to load. If this isn't set, a list of supported formats will be used.
style The style to load the icon from. If this isn't set, the current style will be assumed.
use_inheritance ``True`` Whether or not to search the parent style if the given style doesn't contain an icon.
allow_theme ``True`` Whether or not to fall back on Qt icon themes if an icon cannot be found.
================ =========== ============
"""
if style:
if isinstance(style, basestring):
style = addons.get('style', style)
elif not isinstance(style, StyleInfo):
raise TypeError("Can only activate StyleInfo instances!")
else:
style = _current_style
# If we don't have a style, return a null icon now.
if not style:
return QIcon()
# Right, time to find the icon.
if isinstance(extension, (tuple, list)):
extensions = extension
elif extension:
extensions = [extension]
else:
extensions = (str(ext) for ext in QImageReader.supportedImageFormats())
# Iteration powers, activate!
for ext in extensions:
filename = '%s.%s' % (name, ext)
icon_path = path.join('images', filename)
if style.path.exists(icon_path):
# We've got it, but what is it?
if (not isinstance(style.path_source, basestring) or
style.path_source.startswith('py:')):
# pkg_resource! Do things the fun and interesting way.
with style.path.open(icon_path) as f:
pixmap = QPixmap()
pixmap.loadFromData(f.read())
return QIcon(pixmap)
# Just a regular file. Open normally.
return QIcon(style.path.abspath(icon_path))
# Still here? We didn't find our icon then. If we're inheriting, then call
# icon again for the style we inherit from.
if use_inheritance and style.inherits:
for parent in style.inherits:
result = icon(name, extension, parent, True, False, False)
if result:
return result
# For one last try, see if we can use the theme icons.
if allow_theme and QIcon.hasThemeIcon(name):
return QIcon.fromTheme(name)
# We don't have an icon. Return a null QIcon.
if _always_return:
return QIcon()