Browse Source

Code cleaning

Updated README
Updated requirements in setup.py
experimental
Bogdan Cordier 7 years ago
parent
commit
1c1c908454
3 changed files with 48 additions and 144 deletions
  1. 6
    7
      README
  2. 38
    133
      kcnrtl/kcnrtl.py
  3. 4
    4
      setup.py

+ 6
- 7
README View File

@@ -5,13 +5,13 @@ KCnrtl
5 5
 :Author: Bogdan Cordier <bcord@hadaly.fr>
6 6
 :Date: 2012-10-05
7 7
 :Copyright: GPLv3
8
-:Version: 0.2b
8
+:Version: 0.3b
9 9
 
10 10
 
11 11
 Description
12 12
 ===========
13 13
 
14
-KCnrtl is a simple KDE graphical client to access the CNRTL french linguistic resources.
14
+KCnrtl is a simple Qt graphical client to access the CNRTL french linguistic resources.
15 15
 It offers the possibility to check the definitions, synonyms, antonyms of a given
16 16
 french word.
17 17
 
@@ -41,10 +41,9 @@ Decompress the archive, you can launch the program by running kcnrtl.sh
41 41
 
42 42
 TODO!!
43 43
 
44
-Dependencies
44
+Requirements
45 45
 ============
46 46
 
47
-*httplib2
48
-*BeautifulSoup4
49
-*PyQT
50
- 
47
+*Python:2.7
48
+*PyQT4
49
+

+ 38
- 133
kcnrtl/kcnrtl.py View File

@@ -1,35 +1,32 @@
1 1
 #!/usr/bin/python
2 2
 #-*- coding: utf-8 -*-
3
-#
4
-# KCnrtl is a simple and messy KDE graphical client to access
5
-# the CNRTL linguistic resources
6
-#
7
-# Copyright (C) 2012 Bogdan Cordier
8
-#
9
-# This program is free software: you can redistribute it and/or modify
10
-# it under the terms of the GNU General Public License as published by
11
-# the Free Software Foundation, either version 3 of the License, or
12
-# (at your option) any later version.
13
-#
14
-# This program is distributed in the hope that it will be useful,
15
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
-# GNU General Public License for more details.
18
-#
19
-# You should have received a copy of the GNU General Public License
20
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 3
 
4
+########################################################################
5
+# KCnrtl - A simple Qt graphical client to access the CNRTL            #
6
+# french linguistic resources.                                         #
7
+#                                                                      #
8
+# Copyright (C) 2012 Bogdan Cordier                                    #
9
+#                                                                      #
10
+# This program is free software: you can redistribute it and/or modify #
11
+# it under the terms of the GNU General Public License as published by #
12
+# the Free Software Foundation, either version 3 of the License, or    #
13
+# (at your option) any later version.                                  #
14
+#                                                                      #
15
+# This program is distributed in the hope that it will be useful,      #
16
+# but WITHOUT ANY WARRANTY; without even the implied warranty of       #
17
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        #
18
+# GNU General Public License for more details.                         #
19
+#                                                                      #
20
+# You should have received a copy of the GNU General Public License    #
21
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.#
22
+########################################################################
22 23
 
23 24
 import sys
24
-import httplib2
25
-from bs4 import BeautifulSoup
26
-from PyQt4.QtCore import *
27
-from PyQt4.QtGui import *
28
-from PyQt4.QtNetwork import *
25
+from PyQt4.QtCore import QEventLoop, QUrl, QAbstractListModel, QModelIndex, QVariant, Qt
26
+from PyQt4.QtGui import  QApplication, QMainWindow, QWidget
27
+from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest
29 28
 from PyQt4.QtWebKit import QWebPage
30 29
 from gui.Ui_kcnrtl import Ui_MainWindow
31
-import re
32
-import shutil
33 30
 
34 31
 
35 32
 def main():
@@ -57,10 +54,10 @@ class Main(QMainWindow):
57 54
 
58 55
         self.manager = QNetworkAccessManager()
59 56
                 
60
-        self.dictionaries = [u"TLFi",
61
-                             u"Académie 9e Ed.",
62
-                             u"Académie 8e Ed.",
63
-                             u"Académie 4e Ed.",
57
+        self.dictionaries = [str("TLFi").decode("utf-8", "strict"),
58
+                             str("Académie 9e Ed.").decode("utf-8", "strict"),
59
+                             str("Académie 8e Ed.").decode("utf-8", "strict"),
60
+                             str("Académie 4e Ed.").decode("utf-8", "strict"),
64 61
                                 ]
65 62
         self.ui.comboBox_2.addItems(self.dictionaries)
66 63
         
@@ -68,14 +65,14 @@ class Main(QMainWindow):
68 65
 
69 66
         self.ui.lineEdit.returnPressed.connect(self.updateUi)
70 67
 
71
-        self.ui.comboBox.activated.connect(self.onComboChange)
68
+        self.ui.comboBox.activated.connect(self.on_combo_change)
72 69
         
73 70
         self.ui.webView.settings().setUserStyleSheetUrl(
74 71
                                                QUrl.fromLocalFile(':/lexi.css'))
75 72
 
76
-        self.ui.listView.clicked.connect(self.onRowClicked)
73
+        self.ui.listView.clicked.connect(self.on_row_clicked)
77 74
 
78
-        self.clipboard.dataChanged.connect(self.autoGetFromClipboard)
75
+        self.clipboard.dataChanged.connect(self.get_from_clipboard)
79 76
 
80 77
         self.manager.finished.connect(self.replyFinished)
81 78
 
@@ -96,101 +93,22 @@ class Main(QMainWindow):
96 93
             self.fetch("Syno")
97 94
             self.formtype = "antonyme"
98 95
             self.fetch("Anto")
99
-#            self.typed = unicode(self.ui.lineEdit.text())
100
-#            self.getLexi(self.typed)
101
-#            self.ui.comboBox.clear()
102
-#            self.ui.comboBox.addItems(self.lexiForm())
103
-#            self.lexiContent()
104
-#            self.ui.listView.setModel(self.getSynoAnto("synonymie"))
105
-#            self.ui.listView_2.setModel(self.getSynoAnto("antonymie"))
106 96
         else:
107 97
             self.ui.lineEdit.setText("Veuillez entrer UN mot")
108 98
 
109
-
110
-            
111
-#    # TODO: Dynamically adjust dictionaries name to windows size
112
-#    def resizeEvent(self, event):
113
-#        if event.size().width() < 449:
114
-#            i = 0
115
-#            while i  <= len(self.ui.comboBox_2):
116
-#                self.ui.comboBox_2.setItemText(i, self.dictionaries_short[i])
117
-#            print 'size', event.size().width()
118
-        
119
-
120 99
     # Copy selected item in list to the clipboard
121
-    def onRowClicked(self, qmodelindex):
100
+    def on_row_clicked(self, qmodelindex):
122 101
         item = qmodelindex.data(Qt.DisplayRole).toString()
123 102
         self.clipboard.setText(item)
124 103
 #
125
-    def autoGetFromClipboard(self):
104
+    def get_from_clipboard(self):
126 105
         if self.ui.checkBox.isChecked():
127 106
             self.ui.lineEdit.setText(unicode(self.clipboard.text()))
128 107
             self.updateUi()
129 108
 #
130
-    def onComboChange(self):
109
+    def on_combo_change(self):
131 110
         self.formtype = "definition"
132 111
         self.fetch("Lexi")
133
-    
134
-#    def getSynoAnto(self, form):
135
-#        tag = []
136
-#        soup = BeautifulSoup(self.getHtml(self.typed, form), "lxml")
137
-#        tagy = soup.find_all('td', "%s_format" % (form[:4]))
138
-#        i = 0
139
-#        while i < len(tagy):
140
-#            tag_a = tagy[i]
141
-#            tag.append(tag_a.text)
142
-#            i += 1
143
-#        model = ListModel(tag, self)
144
-#        return model
145
-#
146
-#    def getLexi(self, text):
147
-#        h = self.getHtml(text, "definition")
148
-#        global soup
149
-#        soup = BeautifulSoup(h, "lxml")
150
-#
151
-#    def lexiContent(self):
152
-#        tagkeep = soup.find_all('div', {'id': 'contentbox'})
153
-#        if not self.ui.comboBox_2.currentIndex():
154
-#            tagrm = soup.find_all('div', {'class': 'tlf_cvedette'})
155
-#        if 1 <= self.ui.comboBox_2.currentIndex() <= 3:
156
-#            tagrm = soup.find_all('span', {'class': 'tlf_cvedette'})
157
-#        tag = str(tagkeep[0]).replace(str(tagrm[0]),'')
158
-#        self.ui.webView.setHtml(tag.decode('utf8'))
159
-#        return tag
160
-#
161
-#    # Check if there is more than one definition
162
-#    def lexiForm(self):
163
-#        a = re.compile("return sendRequest\(5,'/definition/.*")
164
-#        multdef = soup.find_all('a', {'onclick': a})
165
-#        tagform = []
166
-#        i = 0
167
-#        while i < len(multdef):
168
-#            multdef_a = multdef[i]
169
-#            # Delete digits in definition title
170
-#            multdef_clean = ''.join(c for c in
171
-#                                    multdef_a.text if not c.isdigit())
172
-#            tagform.append(multdef_clean)
173
-#            i += 1
174
-#        return tagform
175
-#
176
-#    def getHtml(self, text, form):
177
-#        conn = httplib2.Http('.kcnrtl_cache')
178
-#        numdef = self.ui.comboBox.currentIndex()
179
-#        if form == "definition":
180
-#            if not self.ui.comboBox_2.currentIndex():
181
-#                htmlSource = conn.request("http://www.cnrtl.fr/%s/%s//%s" %
182
-#                                          (form, text, numdef), "GET")
183
-#            if self.ui.comboBox_2.currentIndex() > 0:
184
-#                acad = unicode(self.ui.comboBox_2.currentText())
185
-#                acadnum = filter(lambda x: x.isdigit(), acad)
186
-#                acadnumf = "academie" + str(acadnum)
187
-#                htmlSource = conn.request("http://www.cnrtl.fr/%s/%s/%s//%s" %
188
-#                                          (form, acadnumf, text, numdef), "GET")
189
-#
190
-#        else:
191
-#            htmlSource = conn.request("http://www.cnrtl.fr/%s/%s" %
192
-#                                      (form, text), "GET")
193
-#        return htmlSource[1]
194 112
 
195 113
 
196 114
     def fetch(self, dico):
@@ -215,7 +133,6 @@ class Main(QMainWindow):
215 133
 
216 134
     def replyFinished(self, reply):
217 135
         data = reply.readAll()
218
-        #reply.deleteLater()
219 136
         page = QWebPage()
220 137
         page.mainFrame().setContent(data)
221 138
         webpage = page.mainFrame().documentElement()
@@ -241,30 +158,18 @@ class Main(QMainWindow):
241 158
                     multdef_a if not c.isdigit())
242 159
                 self.tagform.append(multdef_clean)
243 160
                 i += 1
244
-        if self.formtype == "synonyme":
245
-            result = webpage.findAll("td.syno_format")
161
+        if self.formtype == "synonyme" or "antonyme":
162
+            result = webpage.findAll("td." + self.formtype[:4] + "_format")
246 163
             tag = []
247 164
             i = 0
248 165
             while i < len(result):
249 166
                 tag.append(result.at(i).firstChild().toPlainText())
250 167
                 i += 1
251 168
             model = ListModel(tag, self)
252
-            self.ui.listView.setModel(model)
253
-            print "3"
254
-        if self.formtype == "antonyme":
255
-            result = webpage.findAll("td.anto_format")
256
-            tag = []
257
-            i = 0
258
-            while i < len(result):
259
-                tag.append(result.at(i).firstChild().toPlainText())
260
-                i += 1
261
-            model2 = ListModel(tag, self)
262
-            self.ui.listView_2.setModel(model2)
263
-            print "4"
264
-    # Delete cache directory on close
265
-#    def closeEvent(self, event):
266
-#        shutil.rmtree('.kcnrtl_cache')
267
-        
169
+            if self.formtype == "synonyme":
170
+                self.ui.listView.setModel(model)
171
+            if self.formtype == "antonyme":
172
+                self.ui.listView_2.setModel(model)
268 173
 
269 174
 class ListModel(QAbstractListModel):
270 175
     def __init__(self, datain, parent=None, *args):

+ 4
- 4
setup.py View File

@@ -7,21 +7,21 @@ 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.2b',
10
+      version='0.3b',
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', 'kcnrtl.gui',  'kcnrtl.resources'],
18
-      requires=['httplib2', 'beautifulsoup4', 'lxml'],
17
+      packages=['kcnrtl'],
19 18
       long_description=read('README'),
20 19
       classifiers=[
21 20
         "Development Status :: 4 - Beta",
22 21
         "Environment :: X11 Applications :: Qt"
23 22
         "Topic :: Utilities",
24
-        "Natural Language :: French", 
23
+        "Natural Language :: French",
24
+        "Intended Audience :: Education"
25 25
         "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
26 26
     ],
27 27
      )

Loading…
Cancel
Save