Code cleaning
authorBogdan Cordier <bcord@hadaly.fr>
Sat, 26 May 2012 04:34:24 +0000 (06:34 +0200)
committerBogdan Cordier <bcord@hadaly.fr>
Sat, 26 May 2012 04:34:24 +0000 (06:34 +0200)
kcnrtl.sh removed

MANIFEST.in
README
TODO
kcnrtl.py
kcnrtl.sh [deleted file]
kcnrtl/fetchparsebs.py
kcnrtl/fetchparseqt.py
kcnrtl/gui/gui.py
kcnrtl/main.py
setup.py

index 5a479e8..2110573 100644 (file)
@@ -8,4 +8,3 @@ include icons/hicolor/16x16/apps/*
 include icons/pixmaps/*
 include COPYING
 include CHANGES
-include kcnrtl.sh
diff --git a/README b/README
index 55d5742..d294a5a 100644 (file)
--- a/README
+++ b/README
@@ -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
 
diff --git a/TODO b/TODO
index 46a506f..3b05b67 100644 (file)
--- a/TODO
+++ b/TODO
@@ -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
index b331e95..6c95121 100755 (executable)
--- a/kcnrtl.py
+++ b/kcnrtl.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+#-*- coding: utf-8 -*-
 
 from kcnrtl.main import main
 
diff --git a/kcnrtl.sh b/kcnrtl.sh
deleted file mode 100755 (executable)
index 7133bc2..0000000
--- a/kcnrtl.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-APP_PATH=`dirname "$0"`
-PYTHONPATH="$PYTHONPATH:$APP_PATH" exec python2.7 $APP_PATH/kcnrtl/kcnrtl.py $*
index 609c2b6..86cac3d 100644 (file)
 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
 
index 6711772..65cf88a 100644 (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)
index 6bf0e19..789a603 100755 (executable)
@@ -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])
index b234a19..b70f20b 100755 (executable)
@@ -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()
index 76bdf12..c7205ad 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -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",