KDE 4.7 PyKDE API Reference

- KDE's Python API

# ExtenderItem Class Reference

`from PyKDE4.plasma import *`

Inherits: QGraphicsWidget → QObject
Namespace: Plasma

## Detailed Description

ExtenderItem plasma/extenderitem.h <Plasma/ExtenderItem>

Provides detachable items for an Extender

This class wraps around a QGraphicsWidget and provides drag&drop handling, a draghandle, title and ability to display qactions as a row of icon, ability to expand, collapse, return to source and tracks configuration associated with this item for you.

Typical usage of ExtenderItems in your applet could look like this:

     if (!extender()->hasItem("networkmonitoreth0")) {
         ExtenderItem *item = new ExtenderItem(extender());
         //name can be used to later access this item through extender()->item(name):
         item->setName("networkmonitoreth0");
         item->config().writeEntry("device", "eth0");
         initExtenderItem(item);
     }

Note that we first check if the item already exists: ExtenderItems are persistent between sessions so we can't blindly add items since they might already exist.

You'll then need to implement the initExtenderItem function. Having this function in your applet makes sure that detached extender items get restored after plasma is restarted, just like applets are. That is also the reason that we write an entry in item->config(). In this function you should instantiate a QGraphicsWidget or QGraphicsItem and call the setWidget function on the ExtenderItem. This is the only correct way of adding actual content to a extenderItem. An example:

     void MyApplet.initExtenderItem(Plasma.ExtenderItem *item)
     {
         QGraphicsWidget *myNetworkMonitorWidget = new NetworkMonitorWidget(item);
         dataEngine("networktraffic")->connectSource(item->config().readEntry("device", ""),
                                                     myNetworkMonitorWidget);
         item->setWidget(myNetworkMonitorWidget);
     }

## Signals
| destroyed (Plasma.ExtenderItem item)
## Methods
| __init__ (self, Plasma.Extender hostExtender, long extenderItemId=0)
QAction | action (self, QString name)
| addAction (self, QString name, QAction action)
long | autoExpireDelay (self)
KConfigGroup | config (self)
| destroy (self)
Plasma.Extender | extender (self)
Plasma.ExtenderGroup | group (self)
| hideCloseButton (self)
| hoverLeaveEvent (self, QGraphicsSceneHoverEvent event)
| hoverMoveEvent (self, QGraphicsSceneHoverEvent event)
QIcon | icon (self)
bool | isCollapsed (self)
bool | isDetached (self)
bool | isGroup (self)
bool | isTransient (self)
| mouseDoubleClickEvent (self, QGraphicsSceneMouseEvent event)
| mouseMoveEvent (self, QGraphicsSceneMouseEvent event)
| mousePressEvent (self, QGraphicsSceneMouseEvent event)
| mouseReleaseEvent (self, QGraphicsSceneMouseEvent event)
| moveEvent (self, QGraphicsSceneMoveEvent event)
QString | name (self)
| paint (self, QPainter painter, QStyleOptionGraphicsItem option, QWidget widget)
| resizeEvent (self, QGraphicsSceneResizeEvent event)
| returnToSource (self)
bool | sceneEventFilter (self, QGraphicsItem watched, QEvent event)
| setAutoExpireDelay (self, long time)
| setCollapsed (self, bool collapsed)
| setExtender (self, Plasma.Extender extender, QPointF pos=QPointF(-1,-1))
| setGroup (self, Plasma.ExtenderGroup group)
| setGroup (self, Plasma.ExtenderGroup group, QPointF pos)
| setIcon (self, QString icon)
| setIcon (self, QIcon icon)
| setName (self, QString name)
| setTitle (self, QString title)
| setTransient (self, bool transient)
| setWidget (self, QGraphicsItem widget)
| showCloseButton (self)
QSizeF | sizeHint (self, Qt::SizeHint which, QSizeF constraint)
QString | title (self)
QGraphicsItem | widget (self)

## Signal Documentation

destroyed | ( | Plasma.ExtenderItem | item
| ) |  |  |

Emitted when the extender item is destroyed

Since:
  4.4.1

Signal syntax:
  `QObject.connect(source, SIGNAL("destroyed(Plasma::ExtenderItem*)"), target_slot)`

## Method Documentation

__init__ | ( | self, |
|  | Plasma.Extender | hostExtender,
|  | long | extenderItemId=0
| ) |  |  |

The constructor takes care of adding this item to an extender.

Parameters:

  | hostExtender | The extender the extender item belongs to.
  | extenderItemId | the id of the extender item. Use the default 0 to assign a new, unique id to this extender item.

QAction action | ( | self, |
|  | QString | name
| ) |  |  |

Returns:
  the QAction with the given name from our collection. By default the action collection contains a "movebacktosource" action which will be only shown when the item is detached.

addAction | ( | self, |
|  | QString | name,
|  | QAction | action
| ) |  |  |

Parameters:

  | name | the name to store the action under in our collection.
  | action | the action to add. Actions will be displayed as an icon in the drag handle.

long autoExpireDelay | ( |  | self ) |

Returns:
  whether or not this extender item has an auto expire delay.

KConfigGroup config | ( |  | self ) |

fetch the configuration of this widget.

Returns:
  the configuration of this widget.

destroy | ( |  | self ) |

Destroys the extender item. As opposed to calling delete on this class, destroy also removes the config group associated with this item.

Plasma.Extender extender | ( |  | self ) |

Returns:
  the extender this items belongs to.

Plasma.ExtenderGroup group | ( |  | self ) |

Returns:
  the group this item belongs to.

Since:
  4.3

hideCloseButton | ( |  | self ) |

Hides the close button in this item's drag handle.

hoverLeaveEvent | ( | self, |
|  | QGraphicsSceneHoverEvent | event
| ) |  |  |

hoverMoveEvent | ( | self, |
|  | QGraphicsSceneHoverEvent | event
| ) |  |  |

QIcon icon | ( |  | self ) |

Returns:
  the icon being displayed in the extender item's drag handle.

bool isCollapsed | ( |  | self ) |

Returns:
  whether or not the extender item is collapsed.

bool isDetached | ( |  | self ) |

Returns:
  whether or not this item is detached from its original source.

bool isGroup | ( |  | self ) |

Returns:
  whether or not this is an ExtenderGroup.

Since:
  4.3

bool isTransient | ( |  | self ) |

Returns:
  true if the ExtenderItem is transient.

Since:
  4.6

mouseDoubleClickEvent | ( | self, |
|  | QGraphicsSceneMouseEvent | event
| ) |  |  |

mouseMoveEvent | ( | self, |
|  | QGraphicsSceneMouseEvent | event
| ) |  |  |

mousePressEvent | ( | self, |
|  | QGraphicsSceneMouseEvent | event
| ) |  |  |

mouseReleaseEvent | ( | self, |
|  | QGraphicsSceneMouseEvent | event
| ) |  |  |

moveEvent | ( | self, |
|  | QGraphicsSceneMoveEvent | event
| ) |  |  |

QString name | ( |  | self ) |

Returns:
  the name of the item.

paint | ( | self, |
|  | QPainter | painter,
|  | QStyleOptionGraphicsItem | option,
|  | QWidget | widget
| ) |  |  |

resizeEvent | ( | self, |
|  | QGraphicsSceneResizeEvent | event
| ) |  |  |

returnToSource | ( |  | self ) |

Returns the extender item to its source applet.

bool sceneEventFilter | ( | self, |
|  | QGraphicsItem | watched,
|  | QEvent | event
| ) |  |  |

setAutoExpireDelay | ( | self, |
|  | long | time
| ) |  |  |

Parameters:

  | time | (in ms) before this extender item destroys itself unless it is detached, in which case this extender stays around. 0 means forever and is the default.

setCollapsed | ( | self, |
|  | bool | collapsed
| ) |  |  |

Collapse or expand the extender item. Defaults to false.

setExtender | ( | self, |
|  | Plasma.Extender | extender,
|  | QPointF | pos=QPointF(-1,-1)
| ) |  |  |

Parameters:

  | extender | the extender this item belongs to.
  | pos | the position in the extender this item should be added. Defaults to 'just append'.

setGroup | ( | self, |
|  | Plasma.ExtenderGroup | group
| ) |  |  |

Parameters:

  | group | the group you want this item to belong to. Note that you can't nest ExtenderGroups.
  | group | the new group
  | pos | position inside the extender group

Since:
  4.5

setGroup | ( | self, |
|  | Plasma.ExtenderGroup | group,
|  | QPointF | pos
| ) |  |  |

Parameters:

  | group | the group you want this item to belong to. Note that you can't nest ExtenderGroups.
  | group | the new group
  | pos | position inside the extender group

Since:
  4.5

setIcon | ( | self, |
|  | QString | icon
| ) |  |  |

Parameters:

  | icon | the icon to display in the extender item's drag handle. Defaults to the source applet's icon.

setIcon | ( | self, |
|  | QIcon | icon
| ) |  |  |

Parameters:

  | icon | the icon to display in the extender item's drag handle. Defaults to the source applet's icon.

setName | ( | self, |
|  | QString | name
| ) |  |  |

You can assign names to extender items to look them up through the item() function. Make sure you only use unique names. This name will be stored in the item's configuration.

Parameters:

  | name | the name of the item. Defaults to an empty string.

setTitle | ( | self, |
|  | QString | title
| ) |  |  |

Parameters:

  | title | the title that will be shown in the extender item's dragger. Default is no title. This title will also be stored in the item's configuration, so you don't have to manually store/restore this information for your extender items.

setTransient | ( | self, |
|  | bool | transient
| ) |  |  |

Set the ExtenderItem as transient: won't be saved in the Plasma config and won't be restored. This is intended for items that have contents valid only for this session.

Parameters:

  | transient | true if the ExtenderItem will be transient

Since:
  4.6

setWidget | ( | self, |
|  | QGraphicsItem | widget
| ) |  |  |

Parameters:

  | widget | The widget that should be wrapped into the extender item. It has to be a QGraphicsWidget.

showCloseButton | ( |  | self ) |

Shows a close button in this item's drag handle. By default a close button will not be shown.

QSizeF sizeHint | ( | self, |
|  | Qt::SizeHint | which,
|  | QSizeF | constraint
| ) |  |  |

QString title | ( |  | self ) |

Returns:
  the title shown in the extender item's dragger.

QGraphicsItem widget | ( |  | self ) |

Returns:
  The widget that is wrapped into the extender item.