Plasma.Extender

KDE 4.2 PyKDE API Reference

- KDE's Python API

# Extender Class Reference

`from PyKDE4.plasma import *`

Inherits: QGraphicsWidget → QObject
Namespace: Plasma

## Detailed Description

Extender plasma/extender.h <Plasma/Extender>

Extends applets to allow detachable parts

An Extender is a widget that visually extends the normal contents of an applet with additional dynamic widgets called ExtenderItems. These ExtenderItems can be detached by the user and dropped either on another Extender or on the canvas directly.

This widget allows using ExtenderItems in your applet. Extender takes care of the presentation of a collection of ExtenderItems and keeps track of ExtenderItems that originate in it.

The default Extender implementation displays extender items in a vertical layout with spacers that appear when dropping an ExtenderItem over it.

If you wish to have a different presentation of extender items, you can choose to subclass Extender and reimplement the extenderItem* events and, optionally, the saveState function.

To use an Extender in you applet, you'll have to instantiate one. A call to extender() in your applet will create an extender on your applet if you haven't got one already. Every applet can contain only one extender. Think of it as a decorator that adds some functionality to applets that require it. Never instantiate an Extender before init() in your applet. This won't work correctly since a scene is required when an Extender is instantiated.

As soon as an Extender is instantiated, ExtenderItems contained previously in this Extender are restored using the initExtenderItem function from the applet the items originally came from. For more information on how this works and how to use ExtenderItems in general, see the ExtenderItem API documentation.

## Enumerations
Appearance | { NoBorders, BottomUpStacked, TopDownStacked }
## Signals
| geometryChanged ()
| itemAttached (Plasma.ExtenderItem a0)
| itemDetached (Plasma.ExtenderItem a0)
## Methods
| __init__ (self, Plasma.Applet applet)
Plasma.Extender.Appearance | appearance (self)
[Plasma::ExtenderIte] | attachedItems (self)
[Plasma::ExtenderIte] | detachedItems (self)
QString | emptyExtenderMessage (self)
Plasma.FrameSvg.EnabledBorders | enabledBordersForItem (self, Plasma.ExtenderItem item)
| geometryChanged (self)
Plasma.ExtenderItem | item (self, QString name)
| itemAddedEvent (self, Plasma.ExtenderItem item, QPointF pos)
| itemAttached (self, Plasma.ExtenderItem a0)
QVariant | itemChange (self, QGraphicsItem.GraphicsItemChange change, QVariant value)
| itemDetached (self, Plasma.ExtenderItem a0)
| itemHoverEnterEvent (self, Plasma.ExtenderItem item)
| itemHoverLeaveEvent (self, Plasma.ExtenderItem item)
| itemHoverMoveEvent (self, Plasma.ExtenderItem item, QPointF pos)
| itemRemovedEvent (self, Plasma.ExtenderItem item)
[Plasma::ExtenderIte] | items (self)
| mousePressEvent (self, QGraphicsSceneMouseEvent event)
| resizeEvent (self, QGraphicsSceneResizeEvent event)
| saveState (self)
| setAppearance (self, Plasma.Extender.Appearance appearance)
| setEmptyExtenderMessage (self, QString message)

## Method Documentation

__init__ | ( | self, |
|  | Plasma.Applet | applet
| ) |  |  |

Creates an extender. Note that extender expects applet to have a config(), and needs a scene because of that. So you should only instantiate an extender in init() or later, not in an applet's constructor. The constructor also takes care of restoring ExtenderItems that were contained in this extender before, so ExtenderItems are persistent between sessions.

Parameters:

  | applet | The applet this extender is part of. Null is not allowed here.

Plasma.Extender.Appearance appearance | ( |  | self ) |

Returns:
  the current way of rendering extender items that is used.

[Plasma::ExtenderIte] attachedItems | ( |  | self ) |

Returns:
  a list of all attached extender items.

[Plasma::ExtenderIte] detachedItems | ( |  | self ) |

Returns:
  a list of all detached extender items.

QString emptyExtenderMessage | ( |  | self ) |

Returns:
  The text to be shown whenever the applet's layout is empty.

Plasma.FrameSvg.EnabledBorders enabledBordersForItem | ( | self, |
|  | Plasma.ExtenderItem | item
| ) |  |  |

This function get's called on every item to determine which background border's to render.

Parameters:

  | item | the item for which it's position or extender has changed.

Returns:
  the borders that have to be enabled on it's background.

geometryChanged | ( |  | self ) |

Fires when an extender's preferred size changes.

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

Plasma.ExtenderItem item | ( | self, |
|  | QString | name
| ) |  |  |

This function can be used for easily determining if a certain item is already displayed in a extender item somewhere, so your applet doesn't duplicate this item. Say the applet displays 'jobs', from an engine which add's a source for every job. In sourceAdded you could do something like: if (!item(source)) { //add an extender item monitoring this source. }

itemAddedEvent | ( | self, |
|  | Plasma.ExtenderItem | item,
|  | QPointF | pos
| ) |  |  |

Get's called after an item has been added to this extender. The bookkeeping has already been done when this function get's called. The only thing left to do is put it somewhere appropriate. The default implementation adds the extenderItem to the appropriate place in a QGraphicsLinearLayout.

Parameters:

  | item | The item that has just been added.
  | pos | The location the item has been dropped in local coordinates.

itemAttached | ( | self, |
|  | Plasma.ExtenderItem | a0
| ) |  |  |

Fires when an extender item is added to this extender.

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

QVariant itemChange | ( | self, |
|  | QGraphicsItem.GraphicsItemChange | change,
|  | QVariant | value
| ) |  |  |

Reimplemented from QGraphicsWidget

itemDetached | ( | self, |
|  | Plasma.ExtenderItem | a0
| ) |  |  |

Fires when an extender item is removed from this extender.

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

itemHoverEnterEvent | ( | self, |
|  | Plasma.ExtenderItem | item
| ) |  |  |

Get's called when an ExtenderItem that get's dragged enters this extender. Default implementation does nothing.

itemHoverLeaveEvent | ( | self, |
|  | Plasma.ExtenderItem | item
| ) |  |  |

Get's called when an ExtenderItem that was previously hovering over this extender moves away from this extender. The default implementation removes any spacer from the layout.

itemHoverMoveEvent | ( | self, |
|  | Plasma.ExtenderItem | item,
|  | QPointF | pos
| ) |  |  |

Gets called when an ExtenderItem is hovering over this extender. Implement this function to give some visual feedback about what will happen when the mouse button is released at that position. The default implementation shows a spacer at the appropriate location in the layout.

Parameters:

  | item | The item that's hovering over this extender. Most useful for obtaining the size of the spacer.
  | pos | The location the item is hovering.

itemRemovedEvent | ( | self, |
|  | Plasma.ExtenderItem | item
| ) |  |  |

Get's called after an item has been removed from this extender. All bookkeeping has already been done when this function get's called.

Parameters:

  | item | The item that has just been removed.

[Plasma::ExtenderIte] items | ( |  | self ) |

Returns:
  a list of all extender items (attached AND detached) where the source applet is this applet.

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

Reimplemented from QGraphicsWidget

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

Reimplemented from QGraphicsWidget

saveState | ( |  | self ) |

This function get's called for every extender when plasma exits. Implement this function to store the current state of this extender (position in a layout for example), so this can be restored when applet starts again. The default implementation stores the y coordinate of every extender item in the config field extenderItemPos.

setAppearance | ( | self, |
|  | Plasma.Extender.Appearance | appearance
| ) |  |  |

Use this function to instruct the extender on how to render it's items. Usually you will want to call this function in your applet's constraintsEvent, allthough this is already done for you when using PopupApplet at base class for your applet. Defaults to NoBorders.

setEmptyExtenderMessage | ( | self, |
|  | QString | message
| ) |  |  |

Parameters:

  | message | The text to be shown whenever the applet's extender is empty. Defaults to i18n'ed "no items".

## Enumeration Documentation

Appearance

Description on how to render the extender's items.

Enumerator:

  NoBorders = 0 |
  BottomUpStacked = 1 |
  TopDownStacked = 2 |