• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

parley

Scripting Namespace Reference

Contains all the classes exposed to Kross scripts. More...

Classes

class  Container
 KEduVocContainer wrapping class for Kross scripts (inherited by Lesson). More...
class  Document
 KEduVocDocument wrapping class for Kross scripts. More...
class  Expression
 This class represents. More...
class  Identifier
 Identifier class can be accessed from Document class and is used for specifying the document languages, articles and personal pronouns. More...
class  Lesson
 KEduVocLesson wrapping class for Kross scripts. More...
class  Parley
 Parley scripting class (main entry point of a Parley Kross script). More...
class  Text
 Scripting::Text class object provides methods and properties for accessing Parley text's value and grades. More...
class  Translation
 KEduVocTranslation wrapper class for scripting with Kross. More...

Functions

QList< KEduVocLesson * > flattenLessons (KEduVocLesson *rootLesson)

Detailed Description

Contains all the classes exposed to Kross scripts.

Main entry point is the Scripting::Parley class which allows us to access all the other Scripting classes (see code below).

Class Hierarchy:

  • Parley
    • Document
      • Lesson (inherits Container)
        • Expression (known as Entry in functions)
          • Translation (inherits Text)
    • Identifier

How to create a new Parley script (full example)

Each Parley script must be accompanied by a .desktop file, both put in the plugins folder in parley data directory (usually in /usr/share/apps/parley/plugins/). In this example the desktop file is "example.desktop" and the script file is "example.py".

The desktop file provides information about the script's functionality, author and specifies the script file that implements it. This information will appear in the Scripts Manager (Scripts->Script Manager in main menu) and the user will be able to enable/disable the script. If the script is enabled then it'll be loaded every time Parley starts up.

Content of example.desktop (/usr/share/apps/parley/plugins/example.desktop)

[Desktop Entry]
Encoding=UTF-8
Icon=mypluginicon
Type=Service
ServiceTypes=KPluginInfo

Name=Example Parley Script
Comment=This Script offers two actions: 1) Move to new lesson 2) Mark as known for the Scripts menu
Script=example.py

X-KDE-PluginInfo-Author=Avgoustinos Kadis
X-KDE-PluginInfo-Email=avgoustinos.kadis@kdemail.net
X-KDE-PluginInfo-Name=parley_example_script
X-KDE-PluginInfo-Version=1.1
X-KDE-PluginInfo-Website=http://edu.kde.org/parley
X-KDE-PluginInfo-Category=examples
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true

The script file will contain the functions (script functionality) and some code for creating an action for the Scripts menu. In the example below, the functions are moveSelectedToNewLesson() and markAsKnown() and they are called by the two actions that are added to the scripts menu (action1 and action2).

When the script file is loaded all the global code (outside of any function) is executed. This way we can register the Scripts menu actions and connect them with script functions (see example below for how to do this).

Another way to have a function called is by connecting it to a Parley signal (see Parley::translateWord() and the example in Detailed Description of the Parley class).

Content of example.py (/usr/share/apps/parley/plugins/example.py)

#!/usr/bin/env kross
import Parley

#FUNCTIONS

#moves selected entries to a new lesson
def moveSelectedToNewLesson():
  selected_entries = Parley.selectedEntries()
  if len(selected_entries) > 0:
    newlesson = Parley.doc.appendNewLesson("New Lesson")
    for entry in selected_entries:
      newlesson.appendEntry(entry)

#marks the selected translations as known (grade 7)
def markAsKnown():
  for tr in Parley.selectedTranslations():
    tr.grade = 7

#SCRIPT MENU

#create a new action for the Scripts menu (action1)
action1 = Parley.newAction("example_action1","Move to new lesson")
action1.statusTip="Moves the selected rows to a new lesson"
Parley.connect(action1,"triggered()",moveSelectedToNewLesson)


#create a new action for the Scripts menu (action2)
action2 = Parley.newAction("example_action2","Mark as known (highest grade)")
action2.statusTip="Sets the grade selected translations to 7 (highest grade)"
Parley.connect(action2,"triggered()",markAsKnown)

After creating the Script action and being able to call a function you can start adding your own code, using the documentation provided for the scripting classes and by seeing other examples.

For debugging use the standard output and observed it in the terminal.


Function Documentation

QList<KEduVocLesson*> Scripting::flattenLessons ( KEduVocLesson *  rootLesson  ) 

Definition at line 46 of file lesson.cpp.

parley

Skip menu "parley"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  •     lib
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal