KDE 4.9 PyKDE API Reference

- KDE's Python API

# RunnerContext Class Reference

`from PyKDE4.plasma import *`

Inherits: QObject
Namespace: Plasma

## Detailed Description

RunnerContext plasma/runnercontext.h <Plasma/RunnerContext>

The RunnerContext class provides information related to a search, including the search term, metadata on the search term and collected matches.

## Enumerations

Type | { None, UnknownType, Directory, File, NetworkLocation, Executable, ShellCommand, Help, FileSystem }

## Signals

| matchesChanged ()

## Methods

| __init__ (self, QObject parent=0)
| __init__ (self, Plasma.RunnerContext other, QObject parent=0)
bool | addMatch (self, QString term, Plasma.QueryMatch match)
bool | addMatches (self, QString term, [Plasma.QueryMatch] matches)
bool | isValid (self)
Plasma.QueryMatch | match (self, QString id)
[Plasma.QueryMatch] | matches (self)
QString | mimeType (self)
QString | query (self)
bool | removeMatch (self, QString matchId)
bool | removeMatches (self, QStringList matchIdList)
| reset (self)
| restore (self, KConfigGroup config)
| run (self, Plasma.QueryMatch match)
| save (self, KConfigGroup config)
| setQuery (self, QString term)
| setSingleRunnerQueryMode (self, bool enabled)
bool | singleRunnerQueryMode (self)
Plasma.RunnerContext.Type | type (self)

## Signal Documentation

matchesChanged | ( |  | ) |

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

## Method Documentation

__init__ | ( | self, |
|  | QObject | parent=0
| ) |  |  |

__init__ | ( | self, |
|  | Plasma.RunnerContext | other,
|  | QObject | parent=0
| ) |  |  |

Copy constructor

bool addMatch | ( | self, |
|  | QString | term,
|  | Plasma.QueryMatch | match
| ) |  |  |

Appends a match to the existing list of matches.

If you are going to be adding multiple matches, use addMatches instead.

Parameters:

  | term | the search term that this match was generated for.
  | match | the match to add

Returns:
  true if the match was added, false otherwise.

bool addMatches | ( | self, |
|  | QString | term,
|  | [Plasma.QueryMatch] | matches
| ) |  |  |

Appends lists of matches to the list of matches.

This method is thread safe and causes the matchesChanged() signal to be emitted.

Returns:
  true if matches were added, false if matches were e.g. outdated

bool isValid | ( |  | self ) |

Returns:
  true if this context is no longer valid and therefore matching using it should abort. Most useful as an optimization technique inside of AbstractRunner subclasses in the match method, e.g.:

while (.. a possibly large iteration) { if (!context.isValid()) { return; }

... some processing ... }

While not required to be used within runners, it provies a nice way to avoid unnecessary processing in runners that may run for an extended period (as measured in 10s of ms) and therefore improve the user experience.

Since:
  4.2.3

Plasma.QueryMatch match | ( | self, |
|  | QString | id
| ) |  |  |

Retrieves a match by id.

Parameters:

  | id | the id of the match to return

Returns:
  the match associated with this id, or an invalid QueryMatch object if the id does not eixst

[Plasma.QueryMatch] matches | ( |  | self ) |

Retrieves all available matches for the current search term.

Returns:
  a list of matches

QString mimeType | ( |  | self ) |

The mimetype that the search term refers to, if discoverable.

Returns:
  QString() if the mimetype can not be determined, otherwise the mimetype of the object being referred to by the search string.

QString query | ( |  | self ) |

Returns:
  the current search query term.

bool removeMatch | ( | self, |
|  | QString | matchId
| ) |  |  |

Removes a match from the existing list of matches.

If you are going to be removing multiple matches, use removeMatches instead.

Parameters:

  | matchId | the id of match to remove

Returns:
  true if the match was removed, false otherwise.

Since:
  4.4

bool removeMatches | ( | self, |
|  | QStringList | matchIdList
| ) |  |  |

Removes lists of matches from the existing list of matches.

This method is thread safe and causes the matchesChanged() signal to be emitted.

Parameters:

  | matchIdList | the list of matches id to remove

Returns:
  true if at least one match was removed, false otherwise.

Since:
  4.4

reset | ( |  | self ) |

Resets the search term for this object. This removes all current matches in the process and turns off single runner query mode.

restore | ( | self, |
|  | KConfigGroup | config
| ) |  |  |

Sets the launch counts for the associated match ids

If a runner adds a match to this context, the context will check if the match id has been launched before and increase the matches relevance correspondingly. In this manner, any front end can implement adaptive search by sorting items according to relevance.

Parameters:

  | config | the config group where launch data was stored

run | ( | self, |
|  | Plasma.QueryMatch | match
| ) |  |  |

Run a match using the information from this context

The context will also keep track of the number of times the match was launched to sort future matches according to user habits

Parameters:

  | match | the match to run

save | ( | self, |
|  | KConfigGroup | config
| ) |  |  |

Parameters:

  | config | the config group where launch data should be stored

setQuery | ( | self, |
|  | QString | term
| ) |  |  |

Sets the query term for this object and attempts to determine the type of the search.

setSingleRunnerQueryMode | ( | self, |
|  | bool | enabled
| ) |  |  |

Sets single runner query mode. Note that a call to reset() will turn off single runner query mode.

See also:
  reset()

Since:
  4.4

bool singleRunnerQueryMode | ( |  | self ) |

Returns:
  true if the current query is a single runner query

Since:
  4.4

Plasma.RunnerContext.Type type | ( |  | self ) |

The type of item the search term might refer to.

See also:
  Type

## Enumeration Documentation

Type

Enumerator:

  None = 0 |
  UnknownType = 1 |
  Directory = 2 |
  File = 4 |
  NetworkLocation = 8 |
  Executable = 16 |
  ShellCommand = 32 |
  Help = 64 |
  FileSystem = Directory|File|Executable|ShellCommand |