KDE 4.7 PyKDE API Reference

- KDE's Python API

# KIconLoader Class Reference

`from PyKDE4.kdeui import *`

Inherits: QObject

## Detailed Description

Iconloader for KDE.

KIconLoader will load the current icon theme and all its base themes. Icons will be searched in any of these themes. Additionally, it caches icons and applies effects according to the user's preferences.

In KDE, it is encouraged to load icons by "Group". An icon group is a location on the screen where icons are being used. Standard groups are: Desktop, Toolbar, MainToolbar, Small and Panel. Each group has some centrally configured properties bound to it, including the icon size and effects. This makes it possible to offer a consistent icon look in all KDE applications.

The standard groups are defined below.

- KIconLoader.Desktop: Icons in the iconview of konqueror, kdesktop and similar apps.
- KIconLoader.Toolbar: Icons in toolbars.
- KIconLoader.MainToolbar: Icons in the main toolbars.
- KIconLoader.Small: Various small (typical 16x16) places: titlebars, listviews
and menu entries.
- KIconLoader.Panel: Icons in kicker's panel

The icons are stored on disk in an icon theme or in a standalone directory. The icon theme directories contain multiple sizes and/or depths for the same icon. The iconloader will load the correct one based on the icon group and the current theme. Icon themes are stored globally in share/icons, or, application specific in share/apps/$appdir/icons.

The standalone directories contain just one version of an icon. The directories that are searched are: $appdir/pics and $appdir/toolbar. Icons in these directories can be loaded by using the special group "User".

## Enumerations
Context | { Any, Action, Application, Device, FileSystem, MimeType, Animation, Category, Emblem, Emote, International, Place, StatusIcon }
Group | { NoGroup, Desktop, FirstGroup, Toolbar, MainToolbar, Small, Panel, Dialog, LastGroup, User }
MatchType | { MatchExact, MatchBest }
States | { DefaultState, ActiveState, DisabledState, LastState }
StdSizes | { SizeSmall, SizeSmallMedium, SizeMedium, SizeLarge, SizeHuge, SizeEnormous }
Type | { Fixed, Scalable, Threshold }
## Signals
| iconLoaderSettingsChanged ()
## Methods
| __init__ (self, QString appname=QString(), KStandardDirs dirs=0, QObject parent=0)
| __init__ (self, KComponentData componentData, QObject parent=0)
| addAppDir (self, QString appname)
| addExtraDesktopThemes (self)
| drawOverlays (self, QStringList overlays, QPixmap pixmap, KIconLoader.Group group, int state=KIconLoader.DefaultState)
bool | extraDesktopThemesAdded (self)
KIconEffect | iconEffect (self)
QString | iconPath (self, QString name, int group_or_size, bool canReturnNull=0)
QPixmap | loadIcon (self, QString name, KIconLoader.Group group, int size=0, int state=KIconLoader.DefaultState, QStringList overlays=QStringList(), QString path_store=0, bool canReturnNull=0)
QPixmap | loadMimeTypeIcon (self, QString iconName, KIconLoader.Group group, int size=0, int state=KIconLoader.DefaultState, QStringList overlays=QStringList(), QString path_store=0)
| newIconLoader (self)
QStringList | queryIconsByDir (self, QString iconsDir)
| reconfigure (self, QString _appname, KStandardDirs _dirs)
KIconTheme | theme (self)
## Static Methods
KIconLoader | global_ ()
QPixmap | unknown ()

## Signal Documentation

iconLoaderSettingsChanged | ( |  | ) |

Emitted by newIconLoader once the new settings have been loaded

Signal syntax:
  `QObject.connect(source, SIGNAL("iconLoaderSettingsChanged()"), target_slot)`

## Method Documentation

__init__ | ( | self, |
|  | QString | appname=QString(),
|  | KStandardDirs | dirs=0,
|  | QObject | parent=0
| ) |  |  |

Constructs an iconloader.

Parameters:

  | appname | Add the data directories of this application to the icon search path for the "User" group. The default argument adds the directories of the current application.
  | dirs | the KStandardDirs object to use. If null the global one is used

Usually, you use the default iconloader, which can be accessed via KIconLoader.global(), so you hardly ever have to create an iconloader object yourself. That one is the current KComponentData's (typically KApplication's) iconloader.

__init__ | ( | self, |
|  | KComponentData | componentData,
|  | QObject | parent=0
| ) |  |  |

Constructs an iconloader.

Parameters:

  | componentData | the KComponentData to use to create this icon loader.

Usually, you use the default iconloader, which can be accessed via KIconLoader.global(), so you hardly ever have to create an iconloader object yourself. That one is the current KComponentData's (typically KApplication's) iconloader.

addAppDir | ( | self, |
|  | QString | appname
| ) |  |  |

Adds appname to the list of application specific directories.

Parameters:

  | appname | The application name.

addExtraDesktopThemes | ( |  | self ) |

Adds all the default themes from other desktops at the end of the list of icon themes.

drawOverlays | ( | self, |
|  | QStringList | overlays,
|  | QPixmap | pixmap,
|  | KIconLoader.Group | group,
|  | int | state=KIconLoader.DefaultState
| ) |  |  |

Draws overlays on the specified pixmap, it takes the width and height of the pixmap into consideration

Parameters:

  | overlays | to draw
  | pixmap | to draw on

Since:
  4.7

bool extraDesktopThemesAdded | ( |  | self ) |

Returns if the default icon themes of other desktops have been added to the list of icon themes where icons are searched.

KIconEffect iconEffect | ( |  | self ) |

Returns a pointer to the KIconEffect object used by the icon loader.

Returns:
  the KIconEffect.

QString iconPath | ( | self, |
|  | QString | name,
|  | int | group_or_size,
|  | bool | canReturnNull=0
| ) |  |  |

Returns the path of an icon.

Parameters:

  | name | The name of the icon, without extension. If an absolute path is supplied for this parameter, iconPath will return it directly.
  | group_or_size | If positive, search icons whose size is specified by the icon group group_or_size. If negative, search icons whose size is - group_or_size. See KIconLoader.Group and KIconLoader.StdSizes
  | canReturnNull | Can return a null string? If not, a path to the "unknown" icon will be returned.

Returns:
  the path of an icon, can be null or the "unknown" icon when not found, depending on canReturnNull.

QPixmap loadIcon | ( | self, |
|  | QString | name,
|  | KIconLoader.Group | group,
|  | int | size=0,
|  | int | state=KIconLoader.DefaultState,
|  | QStringList | overlays=QStringList(),
|  | QString | path_store=0,
|  | bool | canReturnNull=0
| ) |  |  |

Loads an icon. It will try very hard to find an icon which is suitable. If no exact match is found, a close match is searched. If neither an exact nor a close match is found, a null pixmap or the "unknown" pixmap is returned, depending on the value of the canReturnNull parameter.

Parameters:

  | name | The name of the icon, without extension.
  | group | The icon group. This will specify the size of and effects to be applied to the icon.
  | size | If nonzero, this overrides the size specified by group. See KIconLoader.StdSizes.
  | state | The icon state: DefaultState, ActiveState or DisabledState. Depending on the user's preferences, the iconloader may apply a visual effect to hint about its state.
  | overlays | a list of emblem icons to overlay, by name. the emblem prefix is applied automatically to each name, e.g. "zip" becomes "emblem-zip"
  | path_store | If not null, the path of the icon is stored here, if the icon was found. If the icon was not found path_store is unaltered even if the "unknown" pixmap was returned.
  | canReturnNull | Can return a null pixmap? If false, the "unknown" pixmap is returned when no appropriate icon has been found. <em>Note:</em> a null pixmap can still be returned in the event of invalid parameters, such as empty names, negative sizes, and etc.

Returns:
  the QPixmap. Can be null when not found, depending on

canReturnNull.

QPixmap loadMimeTypeIcon | ( | self, |
|  | QString | iconName,
|  | KIconLoader.Group | group,
|  | int | size=0,
|  | int | state=KIconLoader.DefaultState,
|  | QStringList | overlays=QStringList(),
|  | QString | path_store=0
| ) |  |  |

Loads an icon for a mimetype. This is basically like loadIcon except that extra desktop themes are loaded if necessary.

Parameters:

  | iconName | The name of the icon, without extension, usually from KMimeType.
  | group | The icon group. This will specify the size of and effects to be applied to the icon.
  | size | If nonzero, this overrides the size specified by group. See KIconLoader.StdSizes.
  | state | The icon state: DefaultState, ActiveState or DisabledState. Depending on the user's preferences, the iconloader may apply a visual effect to hint about its state.
  | path_store | If not null, the path of the icon is stored here.
  | overlays | a list of emblem icons to overlay, by name. the emblem prefix is applied automatically to each name, e.g. "zip" becomes "emblem-zip"

Returns:
  the QPixmap. Can not be null, the "unknown" pixmap is returned when no appropriate icon has been found.

newIconLoader | ( |  | self ) |

Re-initialize the global icon loader

QStringList queryIconsByDir | ( | self, |
|  | QString | iconsDir
| ) |  |  |

Returns a list of all icons (*.png or *.xpm extension) in the given directory.

Parameters:

  | iconsDir | the directory to search in

Returns:
  A QStringList containing the icon paths

reconfigure | ( | self, |
|  | QString | _appname,
|  | KStandardDirs | _dirs
| ) |  |  |

Called by KComponentData.newIconLoader to reconfigure the icon loader.

Parameters:

  | _appname | the new application name
  | _dirs | the new standard directories. If 0, the directories from KGlobal will be taken.

KIconTheme theme | ( |  | self ) |

Returns a pointer to the current theme. Can be used to query available and default sizes for groups.

Note:
  The KIconTheme will change if reconfigure() is called and therefore it's not recommended to store the pointer anywhere.

Returns:
  a pointer to the current theme. 0 if no theme set.

## Static Method Documentation

KIconLoader global_ | ( |  | ) |

Returns the global icon loader initialized with the global KComponentData.

Returns:
  global icon loader

QPixmap unknown | ( |  | ) |

Returns the unknown icon. An icon that is used when no other icon can be found.

Returns:
  the unknown pixmap

## Enumeration Documentation

Context

Defines the context of the icon.

Enumerator:

  Any |
  Action |
  Application |
  Device |
  FileSystem |
  MimeType |
  Animation |
  Category |
  Emblem |
  Emote |
  International |
  Place |
  StatusIcon |

Group

The group of the icon.

Enumerator:

  NoGroup = -1 |
  Desktop = 0 |
  FirstGroup = 0 |
  Toolbar |
  MainToolbar |
  Small |
  Panel |
  Dialog |
  LastGroup |
  User |

MatchType

The type of a match.

Enumerator:

  MatchExact |
  MatchBest |

States

Defines the possible states of an icon.

Enumerator:

  DefaultState |
  ActiveState |
  DisabledState |
  LastState |

StdSizes

These are the standard sizes for icons.

Enumerator:

  SizeSmall = 16 |
  SizeSmallMedium = 22 |
  SizeMedium = 32 |
  SizeLarge = 48 |
  SizeHuge = 64 |
  SizeEnormous = 128 |

Type

The type of the icon.

Enumerator:

  Fixed |
  Scalable |
  Threshold |