Browse Source

Code cleaning

kcnrtl.sh removed
experimental
Bogdan Cordier 7 years ago
parent
commit
3e349d0c0b
10 changed files with 64 additions and 64 deletions
  1. 0
    1
      MANIFEST.in
  2. 6
    9
      README
  3. 0
    4
      TODO
  4. 1
    0
      kcnrtl.py
  5. 0
    4
      kcnrtl.sh
  6. 11
    8
      kcnrtl/fetchparsebs.py
  7. 3
    3
      kcnrtl/fetchparseqt.py
  8. 34
    26
      kcnrtl/gui/gui.py
  9. 5
    5
      kcnrtl/main.py
  10. 4
    4
      setup.py

+ 0
- 1
MANIFEST.in View File

@@ -8,4 +8,3 @@ include icons/hicolor/16x16/apps/*
include icons/pixmaps/*
include COPYING
include CHANGES
include kcnrtl.sh

+ 6
- 9
README View File

@@ -3,9 +3,9 @@ KCnrtl
======

:Author: Bogdan Cordier <bcord@hadaly.fr>
:Date: 2012-10-05
:Date: 2012-26-05
:Copyright: GPLv3
:Version: 0.4b
:Version: 0.4rc1


Description
@@ -37,17 +37,14 @@ Planned features:
Installation
============

Decompress the archive, you can launch the program by running kcnrtl.sh

TODO!!
Decompress the archive and launch the program by running kcnrtl.py

Requirements
============

*Python: 2.7
*PyQt4: >= 4.6

Optional if you don't use command-line:
*BeautifulSoup4
*Httplib2
*beautifulsoup4
*httplib2
*lxml


+ 0
- 4
TODO View File

@@ -1,13 +1,9 @@
TODO

* Show error when word isn't found
* Switch to Qt backend to remove httplib2 and BeautifulSoup4 dependencies
* Allow to choose word class for antonyms and synonyms
* Add some proximity indicator for synonyms and antonyms as on the CNRTL
* Ajouter un mode de priorité pour les requête en fonction de l'onglet
* Allow to disable automatic copy when item in list is clicked
* Better css stylesheet for definitions
* Add command-line mode
* Add other dictionaries
* Save entries in file to save web request
* Maybe add foreign resources

+ 1
- 0
kcnrtl.py View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from kcnrtl.main import main


+ 0
- 4
kcnrtl.sh View File

@@ -1,4 +0,0 @@
#!/bin/sh
APP_PATH=`dirname "$0"`
PYTHONPATH="$PYTHONPATH:$APP_PATH" exec python2.7 $APP_PATH/kcnrtl/kcnrtl.py $*

+ 11
- 8
kcnrtl/fetchparsebs.py View File

@@ -23,16 +23,19 @@
import httplib2
from bs4 import BeautifulSoup

def getSynoAnto(text, form):
conn = httplib2.Http(".cache")
htmlSource = conn.request("http://www.cnrtl.fr/%s/%s" %
(form, text), "GET")
soup = BeautifulSoup(htmlSource[1], "lxml")
tagy = soup.find_all('td', "%s_format" % (form[:4]))
def get_syno_anto(word, wordclass):
"""
Return synonym or antonym of a given word.
"""
conn = httplib2.Http()
html_source = conn.request("http://www.cnrtl.fr/%s/%s" %
(wordclass, word), "GET")
soup = BeautifulSoup(html_source[1], "lxml")
tagy = soup.find_all('td', "%s_format" % (wordclass[:4]))
i = 0
while i < len(tagy):
tag_a = tagy[i]
i += 1
print tag_a.text
tag = tag_a.text.encode("utf-8")
print tag


+ 3
- 3
kcnrtl/fetchparseqt.py View File

@@ -26,7 +26,7 @@ from PyQt4.QtWebKit import QWebPage
from PyQt4.QtCore import QEventLoop, QUrl


class FetchParse:
class FetchParse(object):
def __init__(self, word, dico, combo1_index, combo2_index, combo2_text, wordclass):
self.word = word
self.dico = dico
@@ -35,7 +35,7 @@ class FetchParse:
self.combo2_text = combo2_text
self.wordclass = wordclass
self.manager = QNetworkAccessManager()
self.manager.finished.connect(self.replyFinished)
self.manager.finished.connect(self.reply_finished)
self.loop = QEventLoop()
self.manager.finished.connect(self.loop.quit)
self._reply = ""
@@ -66,7 +66,7 @@ class FetchParse:
self.manager.get(QNetworkRequest(QUrl(url)))
self.loop.exec_()

def replyFinished(self, datareply):
def reply_finished(self, datareply):
data = datareply.readAll()
page = QWebPage()
page.mainFrame().setContent(data)

+ 34
- 26
kcnrtl/gui/gui.py View File

@@ -26,7 +26,7 @@ from PyQt4.QtCore import QUrl, Qt
from PyQt4.QtGui import QApplication, QMainWindow, QWidget
from kcnrtl.fetchparseqt import FetchParse
from kcnrtl.models import ListModel
from Ui_kcnrtl import Ui_MainWindow
from kcnrtl.gui.Ui_kcnrtl import Ui_MainWindow


def main():
@@ -62,7 +62,7 @@ class Main(QMainWindow):
self.clipboard = QApplication.clipboard()

self.ui.lineEdit.returnPressed.connect(self.updateUi)
self.ui.lineEdit.returnPressed.connect(self.update_ui)

self.ui.comboBox.activated.connect(self.on_combo_change)
@@ -75,47 +75,55 @@ class Main(QMainWindow):



def updateUi(self):
def update_ui(self):
# Check if input text is a word
"""
Update the ui when a new word is entered.
"""
if len(unicode(self.ui.lineEdit.text()).split()) <= 1:
wordclass = "definition"
dico = "Lexi"
lexi = FetchParse(self.ui.lineEdit.text(),dico, self.ui.comboBox.currentIndex(),
self.ui.comboBox_2.currentIndex(), self.ui.comboBox_2.currentText(), wordclass)
result_lexi = lexi.reply
self.ui.webView.setHtml(result_lexi[0])
self.ui.comboBox.clear()
self.ui.comboBox.addItems(result_lexi[1])
wordclass = "synonyme"
dico = "Syno"
syno = FetchParse(self.ui.lineEdit.text(),dico, self.ui.comboBox.currentIndex(),
self.ui.comboBox_2.currentIndex(), self.ui.comboBox_2.currentText(), wordclass)
model = ListModel(syno.reply, self)
self.ui.listView.setModel(model)
wordclass = "antonyme"
dico = "Anto"
anto = FetchParse(self.ui.lineEdit.text(),dico, self.ui.comboBox.currentIndex(),
self.ui.comboBox_2.currentIndex(), self.ui.comboBox_2.currentText(), wordclass)
model = ListModel(anto.reply, self)
self.ui.listView_2.setModel(model)
wordclass = "definition"
dico = "Lexi"
lexi = FetchParse(self.ui.lineEdit.text(), dico, self.ui.comboBox.currentIndex(),
self.ui.comboBox_2.currentIndex(), self.ui.comboBox_2.currentText(), wordclass)
result_lexi = lexi.reply
self.ui.webView.setHtml(result_lexi[0])
self.ui.comboBox.clear()
self.ui.comboBox.addItems(result_lexi[1])
wordclass = "synonyme"
dico = "Syno"
syno = FetchParse(self.ui.lineEdit.text(), dico, self.ui.comboBox.currentIndex(),
self.ui.comboBox_2.currentIndex(), self.ui.comboBox_2.currentText(), wordclass)
model = ListModel(syno.reply, self)
self.ui.listView.setModel(model)
wordclass = "antonyme"
dico = "Anto"
anto = FetchParse(self.ui.lineEdit.text(), dico, self.ui.comboBox.currentIndex(),
self.ui.comboBox_2.currentIndex(), self.ui.comboBox_2.currentText(), wordclass)
model = ListModel(anto.reply, self)
self.ui.listView_2.setModel(model)

else:
self.ui.lineEdit.setText("Veuillez entrer UN mot")

# Copy selected item in list to the clipboard
def on_row_clicked(self, qmodelindex):
"""
Copy selected item in list to the clipboard.
"""
item = qmodelindex.data(Qt.DisplayRole).toString()
self.clipboard.setText(item)
#
def get_from_clipboard(self):
"""
Pass clipboard content as a new word and update ui.
"""
if self.ui.checkBox.isChecked():
self.ui.lineEdit.setText(unicode(self.clipboard.text()))
self.updateUi()
self.update_ui()
#
def on_combo_change(self):
wordclass = "definition"
dico = "Lexi"
lexi = FetchParse(self.ui.lineEdit.text(),dico, self.ui.comboBox.currentIndex(),
lexi = FetchParse(self.ui.lineEdit.text(), dico, self.ui.comboBox.currentIndex(),
self.ui.comboBox_2.currentIndex(), self.ui.comboBox_2.currentText(), wordclass)
result_lexi = lexi.reply
self.ui.webView.setHtml(result_lexi[0])

+ 5
- 5
kcnrtl/main.py View File

@@ -44,14 +44,14 @@ def main():
wordset = args.word

if len(sys.argv) < 2:
from gui.gui import main
exit(main())
from kcnrtl.gui.gui import main as _main
sys.exit(_main())
else:
from fetchparsebs import getSynoAnto
from kcnrtl.fetchparsebs import get_syno_anto
if args.synonym:
getSynoAnto(wordset, "synonymie")
get_syno_anto(wordset, "synonymie")
if args.antonym:
getSynoAnto(wordset, "antonymie")
get_syno_anto(wordset, "antonymie")

if __name__ == '__main__':
main()

+ 4
- 4
setup.py View File

@@ -1,21 +1,21 @@
#!/usr/bin/env python

import os
from distutils.core import setup
from setuptools import setup, find_packages

def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(name='KCnrtl',
version='0.4b',
version='0.4rc1',
description='Qt graphical client for the CNRTL french linguistic resources',
license = "GPLv3",
author="Bogdan Cordier",
author_email="bcord@hadaly.fr",
url="http://code.lm7.fr/p/kcnrtl/",
download_url="http://code.lm7.fr/p/kcnrtl/downloads/",
packages=['kcnrtl'],
requires=['BeautifulSoup4','httplib2'],
packages=find_packages(),
requires=['beautifulsoup4', 'httplib2', 'lxml'],
long_description=read('README'),
classifiers=[
"Development Status :: 4 - Beta",

Loading…
Cancel
Save