# -*- coding: utf-8 -*-
import os
import sys
import time
import Lokalize
import Editor
import subprocess

null = False
def lookup():
    global null
    if not Editor.isValid(): return
    lang = Project.targetLangCode()
    word = Editor.selectionInSource()
    if not word:
        null = True
        return

    cmd = ["kdialog", "--checklist", "Επιλογή λεξικού", "1", "answers.com", "on", "2", "l10n.kde.org", "on", \
        "3", "microsoft.com", "on", "4", "wordreference.com", "on"]
    ans = subprocess.Popen( cmd, stdout=subprocess.PIPE ).communicate()[0]
    ans = ans.strip()
    ans = ans.split()
    if '"1"' in ans:
        os.system("kfmclient newTab 'http://www.answers.com/topic/{0}'".format(word))
        time.sleep(0.5)
    if '"2"' in ans:
        os.system("kfmclient newTab 'http://l10n.kde.org/dictionary/search-translations.php?package=&filename=&teamcode={0}&search={1}&submitted=Search'".format(lang, word))
        time.sleep(0.5)
    if '"3"' in ans:
        os.system("kfmclient newTab 'http://www.microsoft.com/language/en-us/Search.aspx?sString={0}&langID=el-gr'".format(word))
        time.sleep(0.5)
    if '"4"' in ans:
        os.system("kfmclient newTab 'http://www.wordreference.com/engr/{0}'".format(word))
lookup()
if null:
    os.system("kdialog --title 'Lokalize - Αναζήτηση σε διαδικτυακά λεξικά:' --passivepopup '{0}' 5".format('Δεν έχετε επιλέξει πηγαίο κείμενο'))
    