Browse Source

Code cleaning

kcnrtl.sh removed
Bogdan Cordier 6 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/*
8 8
 include icons/pixmaps/*
9 9
 include COPYING
10 10
 include CHANGES
11
-include kcnrtl.sh

+ 6
- 9
README View File

@@ -3,9 +3,9 @@ KCnrtl
3 3
 ======
4 4
 
5 5
 :Author: Bogdan Cordier <bcord@hadaly.fr>
6
-:Date: 2012-10-05
6
+:Date: 2012-26-05
7 7
 :Copyright: GPLv3
8
-:Version: 0.4b
8
+:Version: 0.4rc1
9 9
 
10 10
 
11 11
 Description
@@ -37,17 +37,14 @@ Planned features:
37 37
 Installation
38 38
 ============
39 39
 
40
-Decompress the archive, you can launch the program by running kcnrtl.sh
41
-
42
-TODO!!
40
+Decompress the archive and launch the program by running kcnrtl.py
43 41
 
44 42
 Requirements
45 43
 ============
46 44
 
47 45
 *Python: 2.7
48 46
 *PyQt4: >= 4.6
49
-
50
-Optional if you don't use command-line:
51
-*BeautifulSoup4
52
-*Httplib2
47
+*beautifulsoup4
48
+*httplib2
49
+*lxml
53 50
 

+ 0
- 4
TODO View File

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

+ 1
- 0
kcnrtl.py View File

@@ -1,4 +1,5 @@
1 1
 #!/usr/bin/env python
2
+#-*- coding: utf-8 -*-
2 3
 
3 4
 from kcnrtl.main import main
4 5
 

+ 0
- 4
kcnrtl.sh View File

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

+ 11
- 8
kcnrtl/fetchparsebs.py View File

@@ -23,16 +23,19 @@
23 23
 import httplib2
24 24
 from bs4 import BeautifulSoup
25 25
 
26
-def getSynoAnto(text, form):
27
-    conn = httplib2.Http(".cache")
28
-    htmlSource = conn.request("http://www.cnrtl.fr/%s/%s" %
29
-                                  (form, text), "GET")
30
-    soup = BeautifulSoup(htmlSource[1], "lxml")
31
-    tagy = soup.find_all('td', "%s_format" % (form[:4]))
26
+def get_syno_anto(word, wordclass):
27
+    """
28
+    Return synonym or antonym of a given word.
29
+    """
30
+    conn = httplib2.Http()
31
+    html_source = conn.request("http://www.cnrtl.fr/%s/%s" %
32
+                                  (wordclass, word), "GET")
33
+    soup = BeautifulSoup(html_source[1], "lxml")
34
+    tagy = soup.find_all('td', "%s_format" % (wordclass[:4]))
32 35
     i = 0
33 36
     while i < len(tagy):
34 37
         tag_a = tagy[i]
35 38
         i += 1
36
-        print tag_a.text
37
-
39
+        tag = tag_a.text.encode("utf-8")
40
+        print tag
38 41
 

+ 3
- 3
kcnrtl/fetchparseqt.py View File

@@ -26,7 +26,7 @@ from PyQt4.QtWebKit import QWebPage
26 26
 from PyQt4.QtCore import QEventLoop, QUrl
27 27
 
28 28
 
29
-class FetchParse:
29
+class FetchParse(object):
30 30
     def __init__(self, word, dico, combo1_index, combo2_index, combo2_text, wordclass):
31 31
         self.word = word
32 32
         self.dico = dico
@@ -35,7 +35,7 @@ class FetchParse:
35 35
         self.combo2_text = combo2_text
36 36
         self.wordclass = wordclass
37 37
         self.manager = QNetworkAccessManager()
38
-        self.manager.finished.connect(self.replyFinished)
38
+        self.manager.finished.connect(self.reply_finished)
39 39
         self.loop = QEventLoop()
40 40
         self.manager.finished.connect(self.loop.quit)
41 41
         self._reply = ""
@@ -66,7 +66,7 @@ class FetchParse:
66 66
         self.manager.get(QNetworkRequest(QUrl(url)))
67 67
         self.loop.exec_()
68 68
 
69
-    def replyFinished(self, datareply):
69
+    def reply_finished(self, datareply):
70 70
         data = datareply.readAll()
71 71
         page = QWebPage()
72 72
         page.mainFrame().setContent(data)

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

@@ -26,7 +26,7 @@ from PyQt4.QtCore import QUrl, Qt
26 26
 from PyQt4.QtGui import  QApplication, QMainWindow, QWidget
27 27
 from kcnrtl.fetchparseqt import FetchParse
28 28
 from kcnrtl.models import ListModel
29
-from Ui_kcnrtl import Ui_MainWindow
29
+from kcnrtl.gui.Ui_kcnrtl import Ui_MainWindow
30 30
 
31 31
 
32 32
 def main():
@@ -62,7 +62,7 @@ class Main(QMainWindow):
62 62
         
63 63
         self.clipboard = QApplication.clipboard()
64 64
 
65
-        self.ui.lineEdit.returnPressed.connect(self.updateUi)
65
+        self.ui.lineEdit.returnPressed.connect(self.update_ui)
66 66
 
67 67
         self.ui.comboBox.activated.connect(self.on_combo_change)
68 68
         
@@ -75,47 +75,55 @@ class Main(QMainWindow):
75 75
 
76 76
 
77 77
 
78
-    def updateUi(self):
78
+    def update_ui(self):
79 79
         # Check if input text is a word
80
+        """
81
+        Update the ui when a new word is entered.
82
+        """
80 83
         if len(unicode(self.ui.lineEdit.text()).split()) <= 1:
81
-             wordclass = "definition"
82
-             dico = "Lexi"
83
-             lexi = FetchParse(self.ui.lineEdit.text(),dico, self.ui.comboBox.currentIndex(),
84
-                                self.ui.comboBox_2.currentIndex(), self.ui.comboBox_2.currentText(), wordclass)
85
-             result_lexi = lexi.reply
86
-             self.ui.webView.setHtml(result_lexi[0])
87
-             self.ui.comboBox.clear()
88
-             self.ui.comboBox.addItems(result_lexi[1])
89
-             wordclass = "synonyme"
90
-             dico = "Syno"
91
-             syno = FetchParse(self.ui.lineEdit.text(),dico, self.ui.comboBox.currentIndex(),
92
-                                self.ui.comboBox_2.currentIndex(), self.ui.comboBox_2.currentText(), wordclass)
93
-             model = ListModel(syno.reply, self)
94
-             self.ui.listView.setModel(model)
95
-             wordclass = "antonyme"
96
-             dico = "Anto"
97
-             anto = FetchParse(self.ui.lineEdit.text(),dico, self.ui.comboBox.currentIndex(),
98
-                                self.ui.comboBox_2.currentIndex(), self.ui.comboBox_2.currentText(), wordclass)
99
-             model = ListModel(anto.reply, self)
100
-             self.ui.listView_2.setModel(model)
84
+            wordclass = "definition"
85
+            dico = "Lexi"
86
+            lexi = FetchParse(self.ui.lineEdit.text(), dico, self.ui.comboBox.currentIndex(),
87
+                self.ui.comboBox_2.currentIndex(), self.ui.comboBox_2.currentText(), wordclass)
88
+            result_lexi = lexi.reply
89
+            self.ui.webView.setHtml(result_lexi[0])
90
+            self.ui.comboBox.clear()
91
+            self.ui.comboBox.addItems(result_lexi[1])
92
+            wordclass = "synonyme"
93
+            dico = "Syno"
94
+            syno = FetchParse(self.ui.lineEdit.text(), dico, self.ui.comboBox.currentIndex(),
95
+                self.ui.comboBox_2.currentIndex(), self.ui.comboBox_2.currentText(), wordclass)
96
+            model = ListModel(syno.reply, self)
97
+            self.ui.listView.setModel(model)
98
+            wordclass = "antonyme"
99
+            dico = "Anto"
100
+            anto = FetchParse(self.ui.lineEdit.text(), dico, self.ui.comboBox.currentIndex(),
101
+                self.ui.comboBox_2.currentIndex(), self.ui.comboBox_2.currentText(), wordclass)
102
+            model = ListModel(anto.reply, self)
103
+            self.ui.listView_2.setModel(model)
101 104
 
102 105
         else:
103 106
             self.ui.lineEdit.setText("Veuillez entrer UN mot")
104 107
 
105
-    # Copy selected item in list to the clipboard
106 108
     def on_row_clicked(self, qmodelindex):
109
+        """
110
+        Copy selected item in list to the clipboard.
111
+        """
107 112
         item = qmodelindex.data(Qt.DisplayRole).toString()
108 113
         self.clipboard.setText(item)
109 114
 #
110 115
     def get_from_clipboard(self):
116
+        """
117
+        Pass clipboard content as a new word and update ui.
118
+        """
111 119
         if self.ui.checkBox.isChecked():
112 120
             self.ui.lineEdit.setText(unicode(self.clipboard.text()))
113
-            self.updateUi()
121
+            self.update_ui()
114 122
 #
115 123
     def on_combo_change(self):
116 124
         wordclass = "definition"
117 125
         dico = "Lexi"
118
-        lexi = FetchParse(self.ui.lineEdit.text(),dico, self.ui.comboBox.currentIndex(),
126
+        lexi = FetchParse(self.ui.lineEdit.text(), dico, self.ui.comboBox.currentIndex(),
119 127
             self.ui.comboBox_2.currentIndex(), self.ui.comboBox_2.currentText(), wordclass)
120 128
         result_lexi = lexi.reply
121 129
         self.ui.webView.setHtml(result_lexi[0])

+ 5
- 5
kcnrtl/main.py View File

@@ -44,14 +44,14 @@ def main():
44 44
         wordset = args.word
45 45
 
46 46
     if len(sys.argv) < 2:
47
-        from gui.gui import main
48
-        exit(main())
47
+        from kcnrtl.gui.gui import main as _main
48
+        sys.exit(_main())
49 49
     else:
50
-        from fetchparsebs import getSynoAnto
50
+        from kcnrtl.fetchparsebs import get_syno_anto
51 51
         if args.synonym:
52
-            getSynoAnto(wordset, "synonymie")
52
+            get_syno_anto(wordset, "synonymie")
53 53
         if args.antonym:
54
-            getSynoAnto(wordset, "antonymie")
54
+            get_syno_anto(wordset, "antonymie")
55 55
 
56 56
 if __name__ == '__main__':
57 57
     main()

+ 4
- 4
setup.py View File

@@ -1,21 +1,21 @@
1 1
 #!/usr/bin/env python
2 2
 
3 3
 import os
4
-from distutils.core import setup
4
+from setuptools import setup, find_packages
5 5
 
6 6
 def read(fname):
7 7
     return open(os.path.join(os.path.dirname(__file__), fname)).read()
8 8
 
9 9
 setup(name='KCnrtl',
10
-      version='0.4b',
10
+      version='0.4rc1',
11 11
       description='Qt graphical client for the CNRTL french linguistic resources',
12 12
       license = "GPLv3", 
13 13
       author="Bogdan Cordier",
14 14
       author_email="bcord@hadaly.fr",
15 15
       url="http://code.lm7.fr/p/kcnrtl/",
16 16
       download_url="http://code.lm7.fr/p/kcnrtl/downloads/", 
17
-      packages=['kcnrtl'],
18
-      requires=['BeautifulSoup4','httplib2'],
17
+      packages=find_packages(),
18
+      requires=['beautifulsoup4', 'httplib2', 'lxml'],
19 19
       long_description=read('README'),
20 20
       classifiers=[
21 21
         "Development Status :: 4 - Beta",

Loading…
Cancel
Save