Plasma.ExtenderItem

KDE 4.2 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:

     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);

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);
     }

## 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)
| hideCloseButton (self)
| hoverLeaveEvent (self, QGraphicsSceneHoverEvent event)
| hoverMoveEvent (self, QGraphicsSceneHoverEvent event)
QIcon | icon (self)
bool | isCollapsed (self)
bool | isDetached (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)
| setAutoExpireDelay (self, long time)
| setCollapsed (self, bool collapsed)
| setExtender (self, Plasma.Extender extender, QPointF pos=QPointF(-1,-1))
| setIcon (self, QString icon)
| setIcon (self, QIcon icon)
| setName (self, QString name)
| setTitle (self, QString title)
| setWidget (self, QGraphicsItem widget)
| showCloseButton (self)
QString | title (self)
QGraphicsItem | widget (self)

## 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.

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 it's original source.

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.

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'.

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

Parameters:

  | icon | the icon name to display in the extender item's drag handle. Defaults to the source applet's icon. This icon name will also be stored in the item's configuration, so you don't have to manually store/restore this information.

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.

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

Parameters:

  | widget | The widget that should be wrapped into the extender item.

showCloseButton | ( |  | self ) |

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

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.