Exemple #1
0
def testUI2():
    #print Parley.dataDirs()
    #print Parley.pluginDirs()
    #return
    forms = Kross.module("forms")
    mydialog = forms.createDialog("MyDialog")
    mydialog.setButtons("Ok|Cancel")
    mydialog.setFaceType("Plain")  #Auto Plain List Tree Tabbed

    print dir(mydialog)
    #for attr in dir(mydialog):
    #print attr, getattr(mydialog,attr)
    mywidget = forms.createWidgetFromUIFile(
        mydialog,
        Parley.pluginDirs()[0] + "./mywidget.ui")
    mydialog.setMainWidget(mywidget)
    mywidget["QTextEdit"].setText("some string")
    #print dir(mywidget["QPushButton"])
    mywidget["QPushButton"].text = "Push me"
    #mywidget.textEdit.setText("soooome string")
    Parley.connect(mywidget["QPushButton"], "pressed()", click)
    #print mywidget
    print dir(mywidget)
    if mydialog.exec_loop():
        if mydialog.result() == "Ok":
            print mywidget["QTextEdit"].text
Exemple #2
0
  def end_td(self):
    #print "end of a table data"
    #print "-" ,self.td_data , "-"
    #print myParser.clearWord(self,self.td_data)

    self.td_data = myParser.clearWord(self,self.td_data)

    #matching on the second column (german) and getting the translation from 2 column's on the left
    if self.td_data.lower() == self.word.lower(): #found word
      #print self.td_data
      self.keyword_found = True
      if self.from_lang == "de": #then get the one that is two td_data behind (using the stack)
        #print "Translation: ", self.td_data_stack[0]
        Parley.addTranslation(self.word,self.from_lang,self.to_lang,self.td_data_stack[0].strip())

    #matching on the first column (not german) and getting the translation from 2 column's on the right
    if self.in_translation_td: #found translation
      if self.from_lang != "de":
        #print "Translation: ", self.td_data
        Parley.addTranslation(self.word,self.from_lang,self.to_lang,self.td_data.strip())
      self.in_translation_td = False
      self.td_after = 0
      self.keyword_found = False

    #append td_data on the stack that keeps the last two ones
    self.td_data_stack.append(self.td_data)
    
    #make it keep only the last 2 td_data (works since we append only one item at a time)
    if len(self.td_data_stack) > 2:
      self.td_data_stack.pop(0)

    self.td_data = ""
    
    self.in_small = False
Exemple #3
0
 def handle_data(self,data):
   if data == "Web definitions": self.stop = True #to make it stop after the web definitions
   if len(self.tags_stack) > 0 and self.tags_stack[len(self.tags_stack)-1] == "<!translation!>":
       #print "data: ", data
       self.words.append(data.strip())
       #print self.word, self.from_lang, self.to_lang
       if self.stop == False:
         w = self.clearWord(data)
         Parley.addTranslation(self.word,self.from_lang,self.to_lang,w)
Exemple #4
0
def testUI2():
  #print Parley.dataDirs()
  #print Parley.pluginDirs()
  #return
  forms = Kross.module("forms")
  mydialog = forms.createDialog("MyDialog")
  mydialog.setButtons("Ok|Cancel")
  mydialog.setFaceType("Plain") #Auto Plain List Tree Tabbed
  
  print dir(mydialog)
  #for attr in dir(mydialog):
    #print attr, getattr(mydialog,attr)
  mywidget = forms.createWidgetFromUIFile(mydialog, Parley.pluginDirs()[0]+"./mywidget.ui")
  mydialog.setMainWidget(mywidget)
  mywidget["QTextEdit"].setText("some string")
  #print dir(mywidget["QPushButton"])
  mywidget["QPushButton"].text = "Push me"
  #mywidget.textEdit.setText("soooome string")
  Parley.connect(mywidget["QPushButton"],"pressed()",click)
  #print mywidget
  print dir(mywidget)
  if mydialog.exec_loop():
      if mydialog.result() == "Ok":
          print mywidget["QTextEdit"].text
Exemple #5
0
    def end_td(self):
        #print "end of a table data"
        #print "-" ,self.td_data , "-"
        #print myParser.clearWord(self,self.td_data)

        self.td_data = myParser.clearWord(self, self.td_data)

        #matching on the second column (german) and getting the translation from 2 column's on the left
        if self.td_data.lower() == self.word.lower():  #found word
            #print self.td_data
            self.keyword_found = True
            if self.from_lang == "de":  #then get the one that is two td_data behind (using the stack)
                #print "Translation: ", self.td_data_stack[0]
                Parley.addTranslation(self.word, self.from_lang, self.to_lang,
                                      self.td_data_stack[0].strip())

        #matching on the first column (not german) and getting the translation from 2 column's on the right
        if self.in_translation_td:  #found translation
            if self.from_lang != "de":
                #print "Translation: ", self.td_data
                Parley.addTranslation(self.word, self.from_lang, self.to_lang,
                                      self.td_data.strip())
            self.in_translation_td = False
            self.td_after = 0
            self.keyword_found = False

        #append td_data on the stack that keeps the last two ones
        self.td_data_stack.append(self.td_data)

        #make it keep only the last 2 td_data (works since we append only one item at a time)
        if len(self.td_data_stack) > 2:
            self.td_data_stack.pop(0)

        self.td_data = ""

        self.in_small = False
Exemple #6
0
def newDocument():
    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)
    #first way
    e = l1.newEntry()
    e.setTranslation(0, "dog")
    e.setTranslation(1, "chien")
    l1.appendEntry(e)
    #second way
    ee = l1.newEntry(["glass", "verre"])
    l1.appendEntry(ee)
    #third way
    ee = l1.appendNewEntry(["book", "livre"])

    #new lesson (fast way)
    l2 = doc.appendNewLesson("Lesson 2")
    l2.appendNewEntry(["I", "je"])

    #new lesson under Lesson 2
    l3 = doc.appendNewLesson("Lesson 3", l2)
    l3.appendNewEntry(["good morning", "bonjour"])

    l5 = doc.newLesson("Lesson 5")
    doc.appendLesson(l5)

    #fl = doc.findLesson("Lesson 3")
    #if fl != None:
    #print "found"
    #print fl.name
    #else:
    #print "not found"

    #save document
    doc.saveAs("/home/kde-devel/test_new_document.kvtml")
Exemple #7
0
def newDocument():
  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)
  #first way
  e = l1.newEntry()
  e.setTranslation(0,"dog")
  e.setTranslation(1,"chien")
  l1.appendEntry(e)
  #second way
  ee = l1.newEntry(["glass","verre"])
  l1.appendEntry(ee)
  #third way
  ee = l1.appendNewEntry(["book","livre"])
  
  #new lesson (fast way)
  l2 = doc.appendNewLesson("Lesson 2")
  l2.appendNewEntry(["I","je"]);
  
  #new lesson under Lesson 2
  l3 = doc.appendNewLesson("Lesson 3",l2)
  l3.appendNewEntry(["good morning","bonjour"])
  
  l5 = doc.newLesson("Lesson 5")
  doc.appendLesson(l5)
  
  #fl = doc.findLesson("Lesson 3")
  #if fl != None:
    #print "found"
    #print fl.name
  #else:
    #print "not found"
  
  #save document
  doc.saveAs("/home/kde-devel/test_new_document.kvtml")
Exemple #8
0
def markAsKnown():
    for tr in Parley.selectedTranslations():
        tr.grade = 7
Exemple #9
0
def registerActions():
    newaction = Parley.newAction("my_script1")
    print newaction
    newaction.text = "My script 1"
    Parley.connect(newaction, "triggered()", actionFunction)

    newaction2 = Parley.newAction("my_script1", "My script 2a")
    Parley.connect(newaction2, "triggered()", actionFunction2)

    newaction3 = Parley.newAction("my_script1", "ui")
    Parley.connect(newaction3, "triggered()", testUI)

    newaction4 = Parley.newAction("my_script1", "ui2")
    Parley.connect(newaction4, "triggered()", testUI2)

    newaction5 = Parley.newAction("my_script1", "pyQt")
    Parley.connect(newaction5, "triggered()", testPyQt)

    newaction6 = Parley.newAction("my_script1", "pyKDE")
    Parley.connect(newaction6, "triggered()", testPyKDE)

    return
Exemple #10
0
def fetchSound():
    print "fetching sound"
    tr = Parley.selectedTranslations()
    for word in tr:
        print "checking sound for " + word.text
        fetchSoundForTranslation(word)
def getLocale(trans):
    sel_entries = Parley.selectedEntries()
    for entry in sel_entries:
        for i in entry.translationIndices():
            if entry.translation(i).text == trans.text:
                return Parley.doc.identifier(i).locale
    assert(f[46] == u"present")
    c[u"Présent de l'indicatif"] = f[47:53]
    assert(f[54] == u"imperfect")
    c[u"Imparfait de l'indicatif"] = f[55:61]
    assert(f[54] == u"imperfect")
    c[u"Passé simple de l'indicatif"] = f[63:69]
    c[u"Futur simple de l'indicatif"] = f[71:77]
    c[u"Présent du conditionnel"] = f[79:85]
    return c

def testParser(f):
    print "No parser defined for this language. The conjugation table follows:"
    for i in xrange(len(f)):
        print i, f[i]

def getConjugationTableParser(lang):
    if lang == 'es':
        return spanishParser
    elif lang == "fr":
        return frenchParser
    else:
        return testParser

#create a new action in Parley's script menu
action = Parley.newAction("fetch_conjugations","Fetch Conjugations")
action.statusTip="Fetches conjugations from en.wiktionary.org"
Parley.connect(action,"triggered()",fetchConjugations)

print "We got executed.."

Exemple #13
0
    if not path.exists(filesdir):
        os.mkdir(filesdir)
    filename = filesdir + wikiObject.name.encode('utf-8')
    print filename
    saveas = open(filename,'w')
#   remote = wikiObject.download()
#   workaround: because download method results with http response code 404
    content, response_code = fetch_http_content(
                              wikiObject.imageinfo['url'],
                              {},
                              'GET'
                         )
    print 'HTTP Response code: ', response_code
    if(response_code == 200):
	    saveas.write(content)
    saveas.close()
    return filename

# directory the files are saved to (subdirectory of the document)
def getTargetDirectory():
    filepath = Parley.doc.url
    p,f = path.split(filepath)
    [name,ext] = f.rsplit(".", 1)
    filesdir = p + "/" + name + "_files/"
    return filesdir

#create a new action in Parley's script menu
action = Parley.newAction("fetch_sound",T.i18n("Fetch Sound"))
action.statusTip=T.i18n("Fetches a sound file from commons.wikimedia.org for the selected word")
Parley.connect(action,"triggered()",fetchSound)
Exemple #14
0
    assert (f[54] == u"imperfect")
    c[u"Imparfait de l'indicatif"] = f[55:61]
    assert (f[54] == u"imperfect")
    c[u"Passé simple de l'indicatif"] = f[63:69]
    c[u"Futur simple de l'indicatif"] = f[71:77]
    c[u"Présent du conditionnel"] = f[79:85]
    return c


def testParser(f):
    print "No parser defined for this language. The conjugation table follows:"
    for i in xrange(len(f)):
        print i, f[i]


def getConjugationTableParser(lang):
    if lang == 'es':
        return spanishParser
    elif lang == "fr":
        return frenchParser
    else:
        return testParser


#create a new action in Parley's script menu
action = Parley.newAction("fetch_conjugations", "Fetch Conjugations")
action.statusTip = "Fetches conjugations from en.wiktionary.org"
Parley.connect(action, "triggered()", fetchConjugations)

print "We got executed.."
Exemple #15
0
def registerActions():
  newaction = Parley.newAction("my_script1")
  print newaction
  newaction.text="My script 1"
  Parley.connect(newaction,"triggered()",actionFunction)
  
  newaction2 = Parley.newAction("my_script1","My script 2a")
  Parley.connect(newaction2,"triggered()",actionFunction2)
  
  newaction3 = Parley.newAction("my_script1","ui")
  Parley.connect(newaction3,"triggered()",testUI)
  
  newaction4 = Parley.newAction("my_script1","ui2")
  Parley.connect(newaction4,"triggered()",testUI2)
  
  newaction5 = Parley.newAction("my_script1","pyQt")
  Parley.connect(newaction5,"triggered()",testPyQt)
  
  newaction6 = Parley.newAction("my_script1","pyKDE")
  Parley.connect(newaction6,"triggered()",testPyKDE)

  return
Exemple #16
0
#print Parley.locales()
#print Parley.localeName("en_US")

#doc = Parley.document()
#doc.callFromScriptTest()

#Parley.document.callFromScriptTest()

#doc = Parley.document
#doc.name = "Hi"
#doc.printName()

def translateFromInternet(word,fromLang,toLang):
    print "Translating from Internet!!.."

Parley.connect("translateWord(const QString &,const QString &,const QString &)",translateFromInternet)

print "TEST ACTION"

registerActions()

#print "OPENING DOCUMENT"
##Parley.open('/home/kde-devel/My\ Vocabularies/test.kvtml')

#print "myscript1"
#init()
#Parley.callFromScript()
#Parley.connect("signalTranslateWord(QString)",translate)
#init()

Exemple #17
0
def translateWord(word, fromLang, toLang):
    print "myscript1: Translating Word ...", word, fromLang, toLang
    Parley.addTranslation("Hello", "en_US", "fr", "bonbon")
Exemple #18
0
def fetchConjugations():
    print "wiktionary_conjugations.py: Fetching conjugations for selected translations."
    tr = Parley.selectedTranslations()
    for word in tr:
        fetchConjugationsForTranslation(word)
Exemple #19
0
def translateWord(word,fromLang,toLang):
  print "myscript1: Translating Word ...", word, fromLang, toLang
  Parley.addTranslation("Hello","en_US","fr","bonbon")
Exemple #20
0
T = Kross.module("kdetranslation")

#FUNCTIONS

#moves selected entries to a new lesson
def moveSelectedToNewLesson():
  selected_entries = Parley.selectedEntries()
  if len(selected_entries) > 0:
    newlesson = Parley.doc.appendNewLesson(T.i18n("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",T.i18n("Move to new lesson"))
action1.statusTip=T.i18n("Moves the selected vocabulary to a new lesson")
Parley.connect(action1,"triggered()",moveSelectedToNewLesson)


#create a new action for the Scripts menu (action2)
action2 = Parley.newAction("example_action2",T.i18n("Mark as known (highest grade)"))
action2.statusTip=T.i18n("Sets the grade for the selected words to 7 (highest grade)")
Parley.connect(action2,"triggered()",markAsKnown)
Exemple #21
0
def moveSelectedToNewLesson():
  selected_entries = Parley.selectedEntries()
  if len(selected_entries) > 0:
    newlesson = Parley.doc.appendNewLesson(T.i18n("New Lesson"))
    for entry in selected_entries:
      newlesson.appendEntry(entry)
Exemple #22
0
def fetchSound():
    print "fetching sound"
    tr = Parley.selectedTranslations()
    for word in tr:
        print "checking sound for " + word.text
        fetchSoundForTranslation(word)
Exemple #23
0
def markAsKnown():
  for tr in Parley.selectedTranslations():
    tr.grade = 7
def fetchConjugations():
    print "wiktionary_conjugations.py: Fetching conjugations for selected translations."
    tr = Parley.selectedTranslations()
    for word in tr:
        fetchConjugationsForTranslation(word)
Exemple #25
0

#moves selected entries to a new lesson
def moveSelectedToNewLesson():
    selected_entries = Parley.selectedEntries()
    if len(selected_entries) > 0:
        newlesson = Parley.doc.appendNewLesson(T.i18n("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", T.i18n("Move to new lesson"))
action1.statusTip = T.i18n("Moves the selected vocabulary to a new lesson")
Parley.connect(action1, "triggered()", moveSelectedToNewLesson)

#create a new action for the Scripts menu (action2)
action2 = Parley.newAction("example_action2",
                           T.i18n("Mark as known (highest grade)"))
action2.statusTip = T.i18n(
    "Sets the grade for the selected words to 7 (highest grade)")
Parley.connect(action2, "triggered()", markAsKnown)
Exemple #26
0
    print filename
    saveas = open(filename, 'w')
    #   remote = wikiObject.download()
    #   workaround: because download method results with http response code 404
    content, response_code = fetch_http_content(wikiObject.imageinfo['url'],
                                                {}, 'GET')
    print 'HTTP Response code: ', response_code
    if (response_code == 200):
        saveas.write(content)
    saveas.close()
    return filename


# directory the files are saved to (subdirectory of the document)
def getTargetDirectory():
    filepath = Parley.doc.url
    if filepath.startswith('file://'):
        url = urlparse(filepath)
        filepath = path.abspath(path.join(url.netloc, url.path))
    p, f = path.split(filepath)
    [name, ext] = f.rsplit(".", 1)
    filesdir = p + "/" + name + "_files/"
    return filesdir


#create a new action in Parley's script menu
action = Parley.newAction("fetch_sound", T.i18n("Fetch Sound"))
action.statusTip = T.i18n(
    "Fetches a sound file from commons.wikimedia.org for the selected word")
Parley.connect(action, "triggered()", fetchSound)
Exemple #27
0
def moveSelectedToNewLesson():
    selected_entries = Parley.selectedEntries()
    if len(selected_entries) > 0:
        newlesson = Parley.doc.appendNewLesson(T.i18n("New Lesson"))
        for entry in selected_entries:
            newlesson.appendEntry(entry)
Exemple #28
0
def getLocale(trans):
    sel_entries = Parley.selectedEntries()
    for entry in sel_entries:
        for i in entry.translationIndices():
            if entry.translation(i).text == trans.text:
                return Parley.doc.identifier(i).locale
Exemple #29
0
#doc = Parley.document()
#doc.callFromScriptTest()

#Parley.document.callFromScriptTest()

#doc = Parley.document
#doc.name = "Hi"
#doc.printName()


def translateFromInternet(word, fromLang, toLang):
    print "Translating from Internet!!.."


Parley.connect(
    "translateWord(const QString &,const QString &,const QString &)",
    translateFromInternet)

print "TEST ACTION"

registerActions()

#print "OPENING DOCUMENT"
##Parley.open('/home/kde-devel/My\ Vocabularies/test.kvtml')

#print "myscript1"
#init()
#Parley.callFromScript()
#Parley.connect("signalTranslateWord(QString)",translate)
#init()