(Created page with '== The Global plasmoid Object == There is a global object available to the Plasmoid called, appropriately, "plasmoid". It has a number of useful properties (some of which are r...') |
|||
| Line 1: | Line 1: | ||
| − | + | = The Global plasmoid Object = | |
| − | + | ||
There is a global object available to the Plasmoid called, appropriately, "plasmoid". It has a number of useful properties (some of which are read only, but many of which are read/write), functions, constant values and callbacks. Each are enumerated below. | There is a global object available to the Plasmoid called, appropriately, "plasmoid". It has a number of useful properties (some of which are read only, but many of which are read/write), functions, constant values and callbacks. Each are enumerated below. | ||
| − | + | = Callbacks = | |
See the section on Events above. | See the section on Events above. | ||
| Line 39: | Line 38: | ||
Further documentation on these callbacks can be found in the relevant sections below. | Further documentation on these callbacks can be found in the relevant sections below. | ||
| − | + | = Environment = | |
A set of read-only properties (and in most cases notification functions) that tell the Plasmoid about its current environment: | A set of read-only properties (and in most cases notification functions) that tell the Plasmoid about its current environment: | ||
| Line 59: | Line 58: | ||
* '''userConfiguring''': true if the user configuration interface is currently being displayed. | * '''userConfiguring''': true if the user configuration interface is currently being displayed. | ||
| − | + | = Properties = | |
A set of read/write properties that allow the Plasmoid to set various visual or functional properties: | A set of read/write properties that allow the Plasmoid to set various visual or functional properties: | ||
| Line 68: | Line 67: | ||
* ''boolean'' '''busy''': set to true when the Plasmoid is currently processing or waiting for data and the user interface should be blocked while doing so; will generally show a full-Plasmoid animated overlay to denote business | * ''boolean'' '''busy''': set to true when the Plasmoid is currently processing or waiting for data and the user interface should be blocked while doing so; will generally show a full-Plasmoid animated overlay to denote business | ||
| − | + | = Geometry = | |
Read Only Properties: | Read Only Properties: | ||
| Line 83: | Line 82: | ||
* '''popupIcon(QIcon("some icon"))''' - set icon to show when the plasmoid is added to the taskbar. NOTE if the plasmoid is made in QML, you MUST specify a default size for the main Item. This size will be used for the plasmoid when added to the taskbar | * '''popupIcon(QIcon("some icon"))''' - set icon to show when the plasmoid is added to the taskbar. NOTE if the plasmoid is made in QML, you MUST specify a default size for the main Item. This size will be used for the plasmoid when added to the taskbar | ||
| − | + | = Painting and Layout = | |
To paint directly on to the canvas, a widget may implement the paintInterface function in the plasmoid object: | To paint directly on to the canvas, a widget may implement the paintInterface function in the plasmoid object: | ||
| Line 101: | Line 100: | ||
* '''failedToLaunch(bool failed[, string reason])''' sets the launch status of the Plasmoid; if set to true, the script will stop executing and the reason message, if any, will be displayed to the user. | * '''failedToLaunch(bool failed[, string reason])''' sets the launch status of the Plasmoid; if set to true, the script will stop executing and the reason message, if any, will be displayed to the user. | ||
| − | + | = Access To Packaged Files = | |
Functions: | Functions: | ||
| Line 109: | Line 108: | ||
* ''bool'' '''include(string filename)''': attempts to include the script defined from the package's code directory | * ''bool'' '''include(string filename)''': attempts to include the script defined from the package's code directory | ||
| − | + | = Configuration Data = | |
Configuration values can be defined using [[Development/Tutorials/Using_KConfig_XT|KConfig XT]] XML files in the {{path|contents/config/}} directory of the Plasmoid's package. The default file that is looked for and used is {{path|contents/config/main.xml}}. | Configuration values can be defined using [[Development/Tutorials/Using_KConfig_XT|KConfig XT]] XML files in the {{path|contents/config/}} directory of the Plasmoid's package. The default file that is looked for and used is {{path|contents/config/main.xml}}. | ||
| − | + | == Accessing Configuration Data == | |
Read-write properties: | Read-write properties: | ||
* ''String'' '''activeConfig''': The current active configuration description. For instance, setting it to "foo" would cause the Plasmoid to try and reference the {{path|contents/config/foo.xml}} KConfigXT file. Setting this to an empty string will switch to the main.xml file. | * ''String'' '''activeConfig''': The current active configuration description. For instance, setting it to "foo" would cause the Plasmoid to try and reference the {{path|contents/config/foo.xml}} KConfigXT file. Setting this to an empty string will switch to the main.xml file. | ||
| Line 121: | Line 120: | ||
* '''writeConfig(String key, any value) ''': writes a value to the configuration store under the given key | * '''writeConfig(String key, any value) ''': writes a value to the configuration store under the given key | ||
| − | + | == User Customization == | |
User customization can be offered by providing a Qt Designer file called {{path|contents/ui/config.ui}} in the Plasmoid's package. | User customization can be offered by providing a Qt Designer file called {{path|contents/ui/config.ui}} in the Plasmoid's package. | ||
| Line 128: | Line 127: | ||
* '''configChanged()''': callback function called when the configuration is changed external to the Plasmoid, e.g. when the user changes settings in a configuration dialog. | * '''configChanged()''': callback function called when the configuration is changed external to the Plasmoid, e.g. when the user changes settings in a configuration dialog. | ||
| − | + | = Context menu = | |
It's possible to add some items to the popup menu of the Plasmoid. | It's possible to add some items to the popup menu of the Plasmoid. | ||
Contents |
There is a global object available to the Plasmoid called, appropriately, "plasmoid". It has a number of useful properties (some of which are read only, but many of which are read/write), functions, constant values and callbacks. Each are enumerated below.
See the section on Events above.
There are some events that are generated by Plasma for the Plasmoid. These can often be caught by providing a function assigned to a specific name in the plasmoid object. For instance, to get notified of form factor changes, one would provide a formFactorChanged method as follows:
plasmoid.formFactorChanged = function() {
print("the form factor has changed to: " + plasmoid.formFactor())
}
The following callbacks are used to notify the Plasmoid of changes in its running environment:
Other callbacks include:
In API v2, all of these callbacks can also be used as events. So, for instance, instead of implementing plasmoid.popupEvent, one could also write:
plasmoid.addEventListener('popupEvent', function(shown) { print('shown? ' + shown) } )
This would also suppress any calls to plasmoid.popupEvent.
Further documentation on these callbacks can be found in the relevant sections below.
A set of read-only properties (and in most cases notification functions) that tell the Plasmoid about its current environment:
A set of read/write properties that allow the Plasmoid to set various visual or functional properties:
Read Only Properties:
Functions:
To paint directly on to the canvas, a widget may implement the paintInterface function in the plasmoid object:
plasmoid.paintInterface = function(painter) { /* painting code goes here*/ }
See the Painting section below for information about helpful classes and functions that can be used when implementing a paintInterface function.
Read/Write Properties:
Functions:
Functions:
var path = plasmoid.file("mainscript") or var pm = new QPixmap(plasmoid.file("images", "mypixmap.png"))
Configuration values can be defined using KConfig XT XML files in the contents/config/ directory of the Plasmoid's package. The default file that is looked for and used is contents/config/main.xml.
Read-write properties:
Functions:
User customization can be offered by providing a Qt Designer file called contents/ui/config.ui in the Plasmoid's package.
Callbacks:
It's possible to add some items to the popup menu of the Plasmoid.
Functions: