def get_icon(name, type_=None, base_path=None): if type_ == 'file' or type_ is None: path = name if base_path is not None: path = os.path.join(base_path, path) icon = QIcon(path) if len(icon.availableSizes()) == 0: raise UserWarning('icon "%s" not found' % str(path)) elif type_ == 'resource': icon = QIcon(name) if len(icon.availableSizes()) == 0: raise UserWarning('icon "%s" not found' % str(path)) elif type_ == 'theme': # see http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html icon = QIcon.fromTheme(name) else: raise UserWarning('unknown icon type "%s"' % str(type_)) return icon
def get_icon(name, type_=None, base_path=None): if type_ == 'file' or type_ is None: path = name if base_path is not None: path = os.path.join(base_path, path) icon = QIcon(path) if len(icon.availableSizes()) == 0: raise UserWarning('icon "%s" not found' % str(path)) elif type_ == 'resource': icon = QIcon(name) if len(icon.availableSizes()) == 0: raise UserWarning('icon "%s" not found' % str(path)) elif type_ == 'theme': # see http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html icon = QIcon.fromTheme(name) else: raise UserWarning('unknown icon type "%s"' % str(type_)) return icon
def _enrich_action(self, action, action_attributes, base_path=None): icontype = action_attributes.get('icontype', 'file') if 'icon' in action_attributes and action_attributes[ 'icon'] is not None: if icontype == 'file': path = action_attributes['icon'] if base_path is not None: path = os.path.join(base_path, path) icon = QIcon(path) if len(icon.availableSizes()) == 0: raise UserWarning('icon "%s" not found' % str(path)) elif icontype == 'resource': icon = QIcon(action_attributes['icon']) if len(icon.availableSizes()) == 0: raise UserWarning('icon "%s" not found' % str(path)) elif icontype == 'theme': # see http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html icon = QIcon.fromTheme(action_attributes['icon']) else: raise UserWarning('unknown icon type "%s"' % str(icontype)) action.setIcon(icon) if 'statustip' in action_attributes: action.setStatusTip(action_attributes['statustip'])