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

parley

Classes | Functions
Scripting Namespace Reference

Classes

class  Container
 
class  Document
 
class  Expression
 
class  Identifier
 
class  Lesson
 
class  Parley
 
class  Text
 
class  Translation
 

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 level)")
action2.statusTip="Sets the confidence level selected translations to 7 (highest level)"
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.

This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:15:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

parley

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal