parley
Scripting::Parley Class Reference
Parley scripting class (main entry point of a Parley Kross script). More...
#include <parley.h>

Public Types | |
| enum | Flags { NoInformation = 0x0, Masculine = 0x1, Feminine = 0x2, Neuter = 0x4, Singular = 0x10, Dual = 0x20, Plural = 0x40, Verb = 0x100, Noun = 0x200, Pronoun = 0x400, Adjective = 0x800, Adverb = 0x1000, Article = 0x2000, Conjunction = 0x4000, First = 0x10000, Second = 0x20000, Third = 0x40000, Nominative = 0x80000, Genitive = 0x100000, Dative = 0x200000, Accusative = 0x400000, Ablative = 0x800000, Locative = 0x1000000, Vocative = 0x2000000, Definite = 0x4000000, Indefinite = 0x8000000, Regular = 0x10000000, Irregular = 0x20000000 } |
Public Slots | |
| void | addTranslation (QString word, QString fromLanguage, QString toLanguage, QString translation) |
| QStringList | dataDirs () |
| QString | localeName (QString locale) |
| QStringList | locales () |
| QObject * | newAction (const QString &name, const QString &text=QString()) |
| QObject * | newDocument () |
| void | open (QString filename) |
| QStringList | pluginDirs () |
| QVariantList | selectedEntries () |
| QVariantList | selectedTranslations () |
Signals | |
| void | translateWord (const QString &word, const QString &fromLanguage, const QString &toLanguage) |
| void | translationFinished (const QString &word, const QString &fromLanguage, const QString &toLanguage) |
| void | translationStarted (const QString &word, const QString &fromLanguage, const QString &toLanguage) |
Public Member Functions | |
| Parley (Editor *editor) | |
| ~Parley () | |
| QObject * | activeLesson () |
| void | callTranslateWord (const QString &word, const QString &fromLanguage, const QString &toLanguage) |
| QObject * | getDocument () |
| Translator * | translator () |
Properties | |
| QObject | activeLesson |
| QObject | doc |
| QObject | document |
Detailed Description
Parley scripting class (main entry point of a Parley Kross script).
Parley class is the main entry point of Parley scripting classes. Through it you can access the Document class (Parley.doc or Parley.document) which provides functionality for viewing/modifying a Parley document (KEduVocDocument), that means access lessons, entries, document languages etc.
The Parley class has to do more with the active Parley application. Here it follows a list of possible usages of Parley class:
- Add a new Action to the script menu (see Parley::newAction() function)
- Add a new translation script (see Parley::translateWord() signal)
- Have direct access to the active lesson (see Parley::activeLesson property)
- Have access to various enumerations (see Parley::Number, Parley::Case, Parley::Person, Parley::Gender and Parley::Definiteness enumerations)
- Create a new Parley Document (see Parley::newDocument() function)
Signals and Slots: To connect a script function (slot) to a signal you just define a function with the same name as the signal or use the Parley.connect function:
#how to connect a function to a signal (example with Parley::translateWord() signal) def translateFromInternet(word,fromLang,toLang): print "Translating from Internet!!.." Parley.connect("translateWord(const QString &,const QString &,const QString &)",translateFromInternet)
Definition at line 149 of file parley.h.
Member Enumeration Documentation
Constructor & Destructor Documentation
| Scripting::Parley::Parley | ( | Editor * | editor | ) |
Definition at line 39 of file parley.cpp.
| Scripting::Parley::~Parley | ( | ) |
Definition at line 45 of file parley.cpp.
Member Function Documentation
| QObject* Scripting::Parley::activeLesson | ( | ) |
| void Scripting::Parley::addTranslation | ( | QString | word, | |
| QString | fromLanguage, | |||
| QString | toLanguage, | |||
| QString | translation | |||
| ) | [slot] |
Adds the found translation of the word from language fromLanguage to language toLanguage to Parley translations to be used for translating lesson entries (or anything else).
This function is ment to be used by scripts to add a translation of a word by parsing either online or offline dictionaries.
#example usage of addTranslation function import Parley #function called by Parley whenever a translation of a word is needed def translateWord(word,fromLang,toLang): <<look for the word translation>> Parley.addTranslation(word,fromLang,toLang,foundWord) <<look for more translations>>
- Parameters:
-
word Translated word fromLanguage From language toLanguage To language translation Translation of word
Definition at line 58 of file parley.cpp.
| void Scripting::Parley::callTranslateWord | ( | const QString & | word, | |
| const QString & | fromLanguage, | |||
| const QString & | toLanguage | |||
| ) |
Definition at line 51 of file parley.cpp.
| QStringList Scripting::Parley::dataDirs | ( | ) | [inline, slot] |
Gives the language name of the given locale.
- Parameters:
-
locale Language locale
- Returns:
- Language name
Definition at line 70 of file parley.cpp.
| QStringList Scripting::Parley::locales | ( | ) | [slot] |
Returns a list of all available locales (to be used by the scripts).
- Returns:
Definition at line 64 of file parley.cpp.
| QObject * Scripting::Parley::newAction | ( | const QString & | name, | |
| const QString & | text = QString() | |||
| ) | [slot] |
Creates and adds to the Scripts menu a new KAction (see KAction documentation).
#how to add two new Scripts menu entries import Parley def convertLessonToPDF(): print "Converting lesson to PDF.." def convertLessonToHTML(): print "Converting lesson to HTML.." #one way of creating a new action newaction_pdf = Parley.newAction("convert_lesson_pdf") newaction_pdf.text="Convert Lesson to PDF" Parley.connect(newaction_pdf,"triggered()",convertLessonToPDF) #second way of creating a new action (short) newaction_html = Parley.newAction("convert_lesson_html","Convert Lesson to HTML") Parley.connect(newaction_html,"triggered()",convertLessonToHTML)
- Parameters:
-
name Unique action name text Action's text (what text appears in the scripts menu)
- Returns:
- A reference to a KAction object (accessible by scripts)
Definition at line 143 of file parley.cpp.
| QObject* Scripting::Parley::newDocument | ( | ) | [inline, slot] |
Creates a new document and returns a reference to it.
#how to create a new document, add lessons, add entries and save it to a kvtml file import Parley #create new document doc = Parley.newDocument() doc.title = "New document" #set identifiers doc.appendNewIdentifier("English","en_US") doc.appendNewIdentifier("French","fr") #lessons l1 = doc.newLesson("Lesson1") doc.rootLesson.appendChildLesson(l1) #add a new entry (first way) e = l1.newEntry() e.setTranslation(0,"dog") e.setTranslation(1,"chien") l1.appendEntry(e) #add a new entry (second way) ee = l1.newEntry(["glass","verre"]) l1.appendEntry(ee) #third way ee = l1.appendNewEntry(["book","livre"]) #add a new lesson (fast way) l2 = doc.appendNewLesson("Lesson 2") #add a new child lesson under "Lesson 2" l3 = doc.appendNewLesson("Lesson 3",l2) #add a new entry (third way) l2.appendNewEntry(["I","je"]); l3.appendNewEntry(["good morning","bonjour"]) #save document doc.saveAs("/home/kde-devel/test_new_document.kvtml")
- Returns:
- A Document object, the newly created lesson
| void Scripting::Parley::open | ( | QString | filename | ) | [slot] |
- Todo:
- Make this function working (not very important function)
Definition at line 75 of file parley.cpp.
| QStringList Scripting::Parley::pluginDirs | ( | ) | [inline, slot] |
| QVariantList Scripting::Parley::selectedEntries | ( | ) | [slot] |
Returns a list of Expression objects (the selected entries of the active lesson).
Definition at line 87 of file parley.cpp.
| QVariantList Scripting::Parley::selectedTranslations | ( | ) | [slot] |
Returns a list of Translation objects (the selected translations of the active lesson).
Definition at line 114 of file parley.cpp.
| void Scripting::Parley::translateWord | ( | const QString & | word, | |
| const QString & | fromLanguage, | |||
| const QString & | toLanguage | |||
| ) | [signal] |
Slots (script functions) connected to this signal are called when a translation of word is requested.
Note that a script function with the same name as a signal will be automatically connected to that signal when the script is activated.
#example usage of translateWord signal import Parley #function called by Parley whenever a translation of a word is needed def translateWord(word,fromLang,toLang): <<look for the word translation>> Parley.addTranslation(word,fromLang,toLang,foundWord) <<look for more translations>>
- Parameters:
-
word Word to translate fromLanguage The language of wordto translate fromtoLanguage The language you want to translate to
| void Scripting::Parley::translationFinished | ( | const QString & | word, | |
| const QString & | fromLanguage, | |||
| const QString & | toLanguage | |||
| ) | [signal] |
| void Scripting::Parley::translationStarted | ( | const QString & | word, | |
| const QString & | fromLanguage, | |||
| const QString & | toLanguage | |||
| ) | [signal] |
| Translator* Scripting::Parley::translator | ( | ) | [inline] |
Property Documentation
QObject * Scripting::Parley::activeLesson [read] |
QObject Scripting::Parley::doc [read] |
Abreviation of document property (same as Parley.document).
QObject Scripting::Parley::document [read] |
The documentation for this class was generated from the following files:
KDE 4.4 API Reference