(migrate to new syntaxhighlight) |
|||
| Line 6: | Line 6: | ||
See the section on Events above. | 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: < | + | 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: |
| + | |||
| + | <syntaxhighlight lang="javascript"> | ||
plasmoid.formFactorChanged = function() { | plasmoid.formFactorChanged = function() { | ||
| Line 12: | Line 14: | ||
} | } | ||
| − | </ | + | </syntaxhighlight> |
The following callbacks are used to notify the Plasmoid of changes in its running environment: | The following callbacks are used to notify the Plasmoid of changes in its running environment: | ||
| Line 31: | Line 33: | ||
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: | 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: | ||
| − | + | <br> | |
| − | < | + | <syntaxhighlight lang="javascript"> |
| − | + | plasmoid.addEventListener('popupEvent', function(shown) { print('shown? ' + shown) } ) | |
| + | </syntaxhighlight> | ||
| + | <br> | ||
This would also suppress any calls to plasmoid.popupEvent. | This would also suppress any calls to plasmoid.popupEvent. | ||
| Line 85: | Line 89: | ||
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: | ||
| − | < | + | |
| + | <syntaxhighlight lang="javascript"> | ||
plasmoid.paintInterface = function(painter) { /* painting code goes here*/ } | plasmoid.paintInterface = function(painter) { /* painting code goes here*/ } | ||
| − | </ | + | </syntaxhighlight> |
| + | <br> | ||
See the Painting section below for information about helpful classes and functions that can be used when implementing a paintInterface function. | See the Painting section below for information about helpful classes and functions that can be used when implementing a paintInterface function. | ||
| Line 104: | Line 110: | ||
Functions: | Functions: | ||
| − | * ''string'' '''file(string type[, string fileName])''': returns the path to a file in the Plasmoid package of the given type, optionally with a file name to match, e.g. < | + | * ''string'' '''file(string type[, string fileName])''': returns the path to a file in the Plasmoid package of the given type, optionally with a file name to match, e.g. <br> |
| + | <syntaxhighlight lang="javascript">var path = plasmoid.file("mainscript")</syntaxhighlight> | ||
| + | <br> | ||
| + | or | ||
| + | <br> | ||
| + | <syntaxhighlight lang="javascript">var pm = new QPixmap(plasmoid.file("images", "mypixmap.png"))</syntaxhighlight> | ||
* ''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 | ||
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: