Applet Class Reference
from PyKDE4.plasma import *
Inherits: QGraphicsWidget → QObject
Subclasses: Plasma.Containment, Plasma.GLApplet
Namespace: Plasma
Detailed Description
Applet plasma/applet.h <Plasma/Applet>
The base Applet class
Applet provides several important roles for add-ons widgets in Plasma.
First, it is the base class for the plugin system and therefore is the interface to applets for host applications. It also handles the life time management of data engines (e.g. all data engines accessed via Applet.dataEngine(const QString&) are properly deref'd on Applet destruction), background painting (allowing for consistent and complex look and feel in just one line of code for applets), loading and starting of scripting support for each applet, providing access to the associated plasmoid package (if any) and access to configuration data.
See techbase.kde.org for tutorials on writing Applets using this class.
Method Documentation
__init__ | ( | self, | ||
QGraphicsItem | parent=0, | |||
QString | serviceId=QString(), | |||
long | appletId=0 | |||
) |
- Parameters:
-
parent the QGraphicsItem this applet is parented to serviceId the name of the .desktop file containing the information about the widget appletId a unique id used to differentiate between multiple instances of the same Applet type
__init__ | ( | self, | ||
QGraphicsItem | parent, | |||
QString | serviceId, | |||
long | appletId, | |||
QVariantList | args | |||
) |
- Parameters:
-
parent the QGraphicsItem this applet is parented to serviceId the name of the .desktop file containing the information about the widget appletId a unique id used to differentiate between multiple instances of the same Applet type args a list of strings containing two entries: the service id and the applet id
- Since:
- 4.3
__init__ | ( | self, | ||
QObject | parent, | |||
QVariantList | args | |||
) |
This constructor is to be used with the plugin loading systems found in KPluginInfo and KService. The argument list is expected to have two elements: the KService service ID for the desktop entry and an applet ID which must be a base 10 number.
- Parameters:
-
parent a QObject parent; you probably want to pass in 0 args a list of strings containing two entries: the service id and the applet id
__init__ | ( | self, | ||
QString | packagePath, | |||
long | appletId, | |||
QVariantList | args | |||
) |
- Internal:
- This constructor is to be used with the Package loading system.
- Parameters:
-
parent a QObject parent; you probably want to pass in 0 args a list of strings containing two entries: the service id and the applet id
- Since:
- 4.3
activate | ( | self ) |
Emitted when activation is requested due to, for example, a global keyboard shortcut. By default the wiget is given focus.
- Signal syntax:
QObject.connect(source, SIGNAL("activate()"), target_slot)
Adds the action to our collection under the given name
addAssociatedWidget | ( | self, | ||
QWidget | widget | |||
) |
associate actions with this widget, including ones added after this call. needed to make keyboard shortcuts work.
appletDestroyed | ( | self, | ||
Plasma.Applet | applet | |||
) |
Emitted when the applet is deleted
- Signal syntax:
QObject.connect(source, SIGNAL("appletDestroyed(Applet*)"), target_slot)
appletTransformedByUser | ( | self ) |
Emitted when the user completes a transformation of the applet.
- Signal syntax:
QObject.connect(source, SIGNAL("appletTransformedByUser()"), target_slot)
appletTransformedItself | ( | self ) |
Emitted when the applet changes its own geometry or transform.
- Signal syntax:
QObject.connect(source, SIGNAL("appletTransformedItself()"), target_slot)
Plasma.AspectRatioMode aspectRatioMode | ( | self ) |
- Returns:
- the preferred aspect ratio mode for placement and resizing
Plasma.Applet.BackgroundHints backgroundHints | ( | self ) |
- Returns:
- BackgroundHints flags combination telling if the standard background is shown and if it has a drop shadow
QString category | ( | KPluginInfo | applet | |
) |
Get the category of the given applet
- Parameters:
-
applet a KPluginInfo object for the applet
Get the category of the given applet
- Parameters:
-
appletName the name of the applet
QString category | ( | self ) |
Returns the category the applet is in, as specified in the .desktop file.
KConfigGroup config | ( | self ) |
Returns the KConfigGroup to access the applets configuration.
This config object will write to an instance specific config file named <appletname><instanceid>rc in the Plasma appdata directory.
KConfigGroup config | ( | self, | ||
QString | group | |||
) |
Returns a config group with the name provided. This ensures that the group name is properly namespaced to avoid collision with other applets that may be sharing this config file
- Parameters:
-
group the name of the group to access
configChanged | ( | self ) |
Called when applet configuration values have changed.
configNeedsSaving | ( | self ) |
Emitted when an applet has changed values in its configuration and wishes for them to be saved at the next save point. As this implies disk activity, this signal should be used with care.
- Note:
- This does not need to be emitted from saveState by individual applets.
- Signal syntax:
QObject.connect(source, SIGNAL("configNeedsSaving()"), target_slot)
Plasma.ConfigLoader configScheme | ( | self ) |
Returns the config skeleton object from this applet's package, if any.
- Returns:
- config skeleton object, or 0 if none
bool configurationRequired | ( | self ) |
- Returns:
- true if the applet currently needs to be configured, otherwise, false
constraintsEvent | ( | self, | ||
Plasma.Constraints | constraints | |||
) |
Called when any of the geometry constraints have been updated.
This is always called prior to painting and should be used as an opportunity to layout the widget, calculate sizings, etc.
Do not call update() from this method; an update() will be triggered at the appropriate time for the applet.
- Parameters:
-
constraints the type of constraints that were updated
@property constraint
Plasma.Containment containment | ( | self ) |
- Returns:
- the Containment, if any, this applet belongs to
Plasma.Context context | ( | self ) |
Returns the workspace context which the applet is operating in
[QActio] contextualActions | ( | self ) |
Returns a list of context-related QAction instances.
This is used e.g. within the DesktopView to display a contextmenu.
- Returns:
- A list of actions. The default implementation returns an empty list.
createConfigurationInterface | ( | self, | ||
KConfigDialog | parent | |||
) |
Reimplement this method so provide a configuration interface, parented to the supplied widget. Ownership of the widgets is passed to the parent widget.
- Parameters:
-
parent the dialog which is the parent of the configuration widgets
QStringList customCategories | ( | self ) |
- Returns:
- the list of custom categories known to libplasma
- Since:
- 4.3
Plasma.DataEngine dataEngine | ( | self, | ||
QString | name | |||
) |
Loads the given DataEngine
Tries to load the data engine given by name. Each engine is only loaded once, and that instance is re-used on all subsequent requests.
If the data engine was not found, an invalid data engine is returned (see DataEngine.isValid()).
Note that you should <em>not</em> delete the returned engine.
- Parameters:
-
name Name of the data engine to load
- Returns:
- pointer to the data engine if it was loaded, or an invalid data engine if the requested engine could not be loaded
destroy | ( | self ) |
Destroys the applet; it will be removed nicely and deleted. Its configuration will also be deleted.
bool destroyed | ( | self ) |
- Returns:
- true if destroy() was called; useful for Applets which should avoid certain tasks if they are about to be deleted permanently
Plasma.Extender extender | ( | self ) |
- Returns:
- the extender of this applet.
flushPendingConstraintsEvents | ( | self ) |
Sends all pending contraints updates to the applet. Will usually be called automatically, but can also be called manually if needed.
focusInEvent | ( | self, | ||
QFocusEvent | event | |||
) |
Reimplemented from QGraphicsItem
QFont font | ( | self ) |
- Returns:
- the font currently set for this widget
Plasma.FormFactor formFactor | ( | self ) |
Returns the current form factor the applet is being displayed in.
- See also:
- Plasma.FormFactor
geometryChanged | ( | self ) |
Emitted whenever the applet makes a geometry change, so that views can coordinate themselves with these changes if they desire.
- Signal syntax:
QObject.connect(source, SIGNAL("geometryChanged()"), target_slot)
KConfigGroup globalConfig | ( | self ) |
Returns a KConfigGroup object to be shared by all applets of this type.
This config object will write to an applet-specific config object named plasma_<appletname>rc in the local config directory.
KShortcut globalShortcut | ( | self ) |
- Returns:
- the global shortcut associated with this wiget, or an empty shortcut if no global shortcut is associated.
bool hasAuthorization | ( | self, | ||
QString | constraint | |||
) |
Returns true if the applet is allowed to perform functions covered by the given constraint eg. hasAuthorization("FileDialog") returns true if applets are allowed to show filedialogs.
- Since:
- 4.3
bool hasConfigurationInterface | ( | self ) |
- Returns:
- true if this plasmoid provides a GUI configuration
bool hasFailedToLaunch | ( | self ) |
If for some reason, the applet fails to get up on its feet (the library couldn't be loaded, necessary hardware support wasn't found, etc..) this method returns true
hoverEnterEvent | ( | self, | ||
QGraphicsSceneHoverEvent | event | |||
) |
Reimplemented from QGraphicsLayoutItem
hoverLeaveEvent | ( | self, | ||
QGraphicsSceneHoverEvent | event | |||
) |
Reimplemented from QGraphicsLayoutItem
QString icon | ( | self ) |
Returns the icon related to this applet
long id | ( | self ) |
- Returns:
- the id of this applet
Plasma.ImmutabilityType immutability | ( | self ) |
- Returns:
- The type of immutability of this applet
init | ( | self ) |
This method is called once the applet is loaded and added to a Corona. If the applet requires a QGraphicsScene or has an particularly intensive set of initialization routines to go through, consider implementing it in this method instead of the constructor.
Note: paintInterface may get called before init() depending on initialization order. Painting is managed by the canvas (QGraphisScene), and may schedule a paint event prior to init() being called.
initExtenderItem | ( | self, | ||
Plasma.ExtenderItem | item | |||
) |
Gets called when and extender item has to be initialized after a plasma restart. If you create ExtenderItems in your applet, you should implement this function to again create the widget that should be shown in this extender item. This function might look something like this:
SuperCoolWidget *widget = new SuperCoolWidget(); dataEngine("engine")->connectSource(item->config("dataSourceName"), widget); item->setWidget(widget);
You can also add one or more custom qactions to this extender item in this function.
Note that by default, not all ExtenderItems are persistent. Only items that are detached, will have their configuration stored when plasma exits.
initScriptExtenderItem | ( | self, | ||
Plasma.ExtenderItem | item | |||
) |
Emitted when an ExtenderItem in a scripting applet needs to be initialized
- Signal syntax:
QObject.connect(source, SIGNAL("initScriptExtenderItem(ExtenderItem*)"), target_slot)
bool isBusy | ( | self ) |
- Returns:
- true if the applet is busy and is showing an indicator widget for that
bool isContainment | ( | self ) |
- Returns:
- true if this Applet is currently being used as a Containment, false otherwise
bool isPopupShowing | ( | self ) |
- Returns:
- true is there is a popup assoiated with this Applet showing, such as the dialog of a PopupApplet. May be reimplemented for custom popup implementations.
bool isRegisteredAsDragHandle | ( | self, | ||
QGraphicsItem | item | |||
) |
- Parameters:
-
item the item to look for if it is registered or not
- Returns:
- true if it is registered, false otherwise
Reimplemented from QGraphicsItem
Returns a list of all known applets.
- Parameters:
-
category Only applets matchin this category will be returned. Useful in conjunction with knownCategories. If "Misc" is passed in, then applets without a Categories= entry are also returned. If an empty string is passed in, all applets are returned. parentApp the application to filter applets on. Uses the X-KDE-ParentApp entry (if any) in the plugin info. The default value of QString() will result in a list containing only applets not specifically registered to an application.
- Returns:
- list of applets
KPluginInfo.List listAppletInfoForMimetype | ( | QString | mimetype | |
) |
Returns a list of all known applets associated with a certain mimetype.
- Returns:
- list of applets
QStringList listCategories | ( | QString | parentApp=QString(), | |
bool | visibleOnly=1 | |||
) |
Returns a list of all the categories used by installed applets.
- Parameters:
-
parentApp the application to filter applets on. Uses the X-KDE-ParentApp entry (if any) in the plugin info. The default value of QString() will result in a list containing only applets not specifically registered to an application.
- Returns:
- list of categories
- Parameters:
-
visibleOnly true if it should only return applets that are marked as visible
Plasma.Applet load | ( | QString | name, | |
long | appletId=0, | |||
QVariantList | args=QVariantList() | |||
) |
Attempts to load an applet
Returns a pointer to the applet if successful. The caller takes responsibility for the applet, including deleting it when no longer needed.
- Parameters:
-
name the plugin name, as returned by KPluginInfo.pluginName() appletId unique ID to assign the applet, or zero to have one assigned automatically. args to send the applet extra arguments
- Returns:
- a pointer to the loaded applet, or 0 on load failure
Plasma.Applet load | ( | KPluginInfo | info, | |
long | appletId=0, | |||
QVariantList | args=QVariantList() | |||
) |
Attempts to load an applet
Returns a pointer to the applet if successful. The caller takes responsibility for the applet, including deleting it when no longer needed.
- Parameters:
-
info KPluginInfo object for the desired applet appletId unique ID to assign the applet, or zero to have one assigned automatically. args to send the applet extra arguments
- Returns:
- a pointer to the loaded applet, or 0 on load failure
Plasma.Applet loadPlasmoid | ( | QString | path, | |
long | appletId=0, | |||
QVariantList | args=QVariantList() | |||
) |
Attempts to load an apppet from a package
Returns a pointer to the applet if successful. The caller takes responsibility for the applet, including deleting it when no longer needed.
- Parameters:
-
path the path to the package appletId unique ID to assign the applet, or zero to have one assigned automatically. args to send the applet extra arguments
- Returns:
- a pointer to the loaded applet, or 0 on load failure
- Since:
- 4.3
Plasma.Location location | ( | self ) |
Returns the location of the scene which is displaying applet.
- See also:
- Plasma.Location
lower | ( | self ) |
Causes this applet to lower below all the other applets.
QRectF mapFromView | ( | self, | ||
QGraphicsView | view, | |||
QRect | rect | |||
) |
Maps a QRect from a view's coordinates to local coordinates.
- Parameters:
-
view the view from which rect should be mapped rect the rect to be mapped
QRect mapToView | ( | self, | ||
QGraphicsView | view, | |||
QRectF | rect | |||
) |
Maps a QRectF from local coordinates to a view's coordinates.
- Parameters:
-
view the view to which rect should be mapped rect the rect to be mapped
messageButtonPressed | ( | self, | ||
Plasma.MessageButton | button | |||
) |
Emitted when the user clicked on a button of the message overlay
- See also:
- showMessage
- See also:
- Plasma.MessageButton
- Since:
- 4.3
- Signal syntax:
QObject.connect(source, SIGNAL("messageButtonPressed(const MessageButton)"), target_slot)
mouseMoveEvent | ( | self, | ||
QGraphicsSceneMouseEvent | event | |||
) |
- Internal:
- manage the mouse movement to drag the applet around
mousePressEvent | ( | self, | ||
QGraphicsSceneMouseEvent | event | |||
) |
QString name | ( | self ) |
Returns the user-visible name for the applet, as specified in the .desktop file.
- Returns:
- the user-visible name for the applet.
Plasma.Package package | ( | self ) |
Accessor for the associated Package object if any. Generally, only Plasmoids come in a Package.
- Returns:
- the Package object, or 0 if none
Plasma.PackageStructure.Ptr packageStructure | ( | ) |
- Returns:
- a package structure representing a Theme
paintInterface | ( | self, | ||
QPainter | painter, | |||
QStyleOptionGraphicsItem | option, | |||
QRect | contentsRect | |||
) |
This method is called when the interface should be painted.
- Parameters:
-
painter the QPainter to use to do the paintiner option the style options object contentsRect the rect to paint within; automatically adjusted for the background, if any
paintWindowFrame | ( | self, | ||
QPainter | painter, | |||
QStyleOptionGraphicsItem | option, | |||
QWidget | widget | |||
) |
QString pluginName | ( | self ) |
Returns the plugin name for the applet
Reccomended position for a popup window like a menu or a tooltip given its size
- Parameters:
-
s size of the popup
- Returns:
- reccomended position
raise_ | ( | self ) |
Causes this applet to raise above all other applets.
registerAsDragHandle | ( | self, | ||
QGraphicsItem | item | |||
) |
Register the widgets that manage mouse clicks but you still want to be able to drag the applet around when holding the mouse pointer on that widget.
Calling this results in an eventFilter being places on the widget.
- Parameters:
-
item the item to watch for mouse move
releaseVisualFocus | ( | self ) |
This signal indicates that an application launch, window creation or window focus event was triggered. This is used, for instance, to ensure that the Dashboard view in Plasma hides when such an event is triggered by an item it is displaying.
- Signal syntax:
QObject.connect(source, SIGNAL("releaseVisualFocus()"), target_slot)
removeAssociatedWidget | ( | self, | ||
QWidget | widget | |||
) |
un-associate actions from this widget, including ones added after this call. needed to make keyboard shortcuts work.
resizeEvent | ( | self, | ||
QGraphicsSceneResizeEvent | event | |||
) |
Reimplemented from QGraphicsItem
restore | ( | self, | ||
KConfigGroup | group | |||
) |
Restores state information about this applet saved previously in save(KConfigGroup&).
This method does not need to be reimplmented by Applet subclasses, but can be useful for Applet specializations (such as Containment) to do so.
save | ( | self, | ||
KConfigGroup | group | |||
) |
Saves state information about this applet that will be accessed when next instantiated in the restore(KConfigGroup&) method.
This method does not need to be reimplmented by Applet subclasses, but can be useful for Applet specializations (such as Containment) to do so.
Applet subclasses may instead want to reimplement saveState().
saveState | ( | self, | ||
KConfigGroup | config | |||
) |
When called, the Applet should write any information needed as part of the Applet's running state to the configuration object in config() and/or globalConfig().
Applets that always sync their settings/state with the config objects when these settings/states change do not need to reimplement this method.
bool sceneEventFilter | ( | self, | ||
QGraphicsItem | watched, | |||
QEvent | event | |||
) |
- Internal:
- scene event filter; used to manage applet dragging
QRect screenRect | ( | self ) |
This method returns screen coordinates for the widget; this method can be somewhat expensive and should ONLY be called when screen coordinates are required. For example when positioning top level widgets on top of the view to create the appearance of unit. This should NOT be used for popups (@see popupPosition) or for normal widget use (use Plasma. widgets or QGraphicsProxyWidget instead).
- Returns:
- a rect of the applet in screen coordinates.
setAspectRatioMode | ( | self, | ||
Plasma.AspectRatioMode | a0 | |||
) |
Sets the preferred aspect ratio mode for placement and resizing
setBackgroundHints | ( | self, | ||
Plasma.Applet.BackgroundHints | hints | |||
) |
Sets the BackgroundHints for this applet
- See also:
- BackgroundHint
- Parameters:
-
hints the BackgroundHint combination for this applet
setBusy | ( | self, | ||
bool | busy | |||
) |
Shows a busy indicator that overlays the applet
- Parameters:
-
busy show or hide the busy indicator
setConfigurationRequired | ( | self, | ||
bool | needsConfiguring, | |||
QString | reason=QString() | |||
) |
When the applet needs to be configured before being usable, this method can be called to show a standard interface prompting the user to configure the applet
- Parameters:
-
needsConfiguring true if the applet needs to be configured, or false if it doesn't reason a translated message for the user explaining that the applet needs configuring; this should note what needs to be configured
setCustomCategories | ( | self, | ||
QStringList | categories | |||
) |
Sets the list of custom categories that are used in addition to the default set of categories known to libplasma for Applets. @arg categories a list of categories
- Since:
- 4.3
setFailedToLaunch | ( | self, | ||
bool | failed, | |||
QString | reason=QString() | |||
) |
Call this method when the applet fails to launch properly. An optional reason can be provided.
Not that all children items will be deleted when this method is called. If you have pointers to these items, you will need to reset them after calling this method.
- Parameters:
-
failed true when the applet failed, false when it succeeded reason an optional reason to show the user why the applet failed to launch
setGlobalShortcut | ( | self, | ||
KShortcut | shortcut | |||
) |
Sets the global shorcut to associate with this widget.
setHasConfigurationInterface | ( | self, | ||
bool | hasInterface | |||
) |
Sets whether or not this applet provides a user interface for configuring the applet.
It defaults to false, and if true is passed in you should also reimplement createConfigurationInterface()
- Parameters:
-
hasInterface whether or not there is a user interface available
setImmutability | ( | self, | ||
Plasma.ImmutabilityType | immutable | |||
) |
Sets the immutability type for this applet (not immutable, user immutable or system immutable) @arg immutable the new immutability type of this applet
QPainterPath shape | ( | self ) |
Reimplemented from QGraphicsItem
bool shouldConserveResources | ( | self ) |
Whether the applet should conserve resources. If true, try to avoid doing stuff which is computationally heavy. Try to conserve power and resources.
- Returns:
- true if it should conserve resources, false if it does not.
showConfigurationInterface | ( | self ) |
Lets the user interact with the plasmoid options. Called when the user selects the configure entry from the context menu.
Unless there is good reason for overriding this method, Applet subclasses should actually override createConfigurationInterface instead. A good example of when this isn't plausible is when using a dialog prepared by another library, such as KPropertiesDialog from libkfile.
Shows a message as an overlay of the applet: the message has an icon, text and (optional) buttons
- Parameters:
-
icon the icon that will be shown message the message string that will be shown. If the message is empty nothng will be shown and if there was a message already it will be hidden buttons an OR combination of all the buttons needed
- See also:
- Plasma.MessageButtons
- See also:
- messageButtonPressed
- Since:
- 4.3
QSizeF sizeHint | ( | self, | ||
Qt.SizeHint | which, | |||
QSizeF | constraint=QSizeF() | |||
) |
Reimplemented from QGraphicsLayoutItem
sizeHintChanged | ( | self, | ||
Qt.SizeHint | which | |||
) |
Emitted by Applet subclasses when they change a sizeHint and wants to announce the change
- Signal syntax:
QObject.connect(source, SIGNAL("sizeHintChanged(SizeHint)"), target_slot)
QVariantList startupArguments | ( | self ) |
- Returns:
- the list of arguments which the applet was called with
- Since:
- KDE4.3
timerEvent | ( | self, | ||
QTimerEvent | event | |||
) |
Reimplemented from QObject
int type | ( | self ) |
Reimplemented from QGraphicsItem
unregisterAsDragHandle | ( | self, | ||
QGraphicsItem | item | |||
) |
Unregister a widget registered with registerAsDragHandle.
- Parameters:
-
item the item to unregister
updateConstraints | ( | self, | ||
Plasma.Constraints | constraints=Plasma.AllConstraints | |||
) |
Called when any of the geometry constraints have been updated. This method calls constraintsEvent, which may be reimplemented, once the Applet has been prepared for updating the constraints.
- Parameters:
-
constraints the type of constraints that were updated
QGraphicsView view | ( | self ) |
Returns the view this widget is visible on, or 0 if none can be found.
- Warning:
- do NOT assume this will always return a view! a null view probably means that either plasma isn't finished loading, or your applet is on an activity that's not being shown anywhere.
Enumeration Documentation
BackgroundHint |
Description on how draw a background for the applet
- Enumerator:
-
NoBackground = 0 StandardBackground = 1 TranslucentBackground = 2 DefaultBackground = StandardBackground
anonymous |
- Enumerator:
-
Type = Plasma::AppletType