Browse Source

Add new dictionaries (Académie 9e, 8e, 4e)

Fix typo in README, kcnrtl.ui
Add TODO
experimental
Bogdan Cordier 7 years ago
parent
commit
cce732af9a
5 changed files with 91 additions and 37 deletions
  1. 8
    8
      README
  2. 12
    0
      TODO
  3. 26
    12
      kcnrtl/gui/kcnrtl.ui
  4. 43
    15
      kcnrtl/kcnrtl.py
  5. 2
    2
      setup.py

+ 8
- 8
README View File

@@ -2,17 +2,17 @@
2 2
 KCnrtl
3 3
 ======
4 4
 
5
-:Author: Bogdan Cordier bcord@hadaly.fr
5
+:Author: Bogdan Cordier <bcord@hadaly.fr>
6 6
 :Date: 2012-10-05
7 7
 :Copyright: GPLv3
8
-:Version: 0.1
8
+:Version: 0.2b
9 9
 
10 10
 
11 11
 Description
12 12
 ===========
13 13
 
14 14
 KCnrtl is a simple KDE graphical client to access the CNRTL french linguistic resources.
15
-It offers the possibility to check the definitions, synomyms, antonyms of a given
15
+It offers the possibility to check the definitions, synonyms, antonyms of a given
16 16
 french word.
17 17
 
18 18
 Features:
@@ -23,10 +23,10 @@ Features:
23 23
 
24 24
     *The "AMAZING Clipboard mode" :
25 25
       With the "Clipboard mode" you can easily check for a synonym/antonym and replace it in your text.
26
-    To do so, just check the "Clipboard mode" checkbox, copy in the clipboard any word, KCnrtl will do
27
-    an automatic request to the CNRTL website and you can easily copy any synomym or antonym by
28
-    just clicking on them.
29
-    Now you just have to paste it back in you text !
26
+      To do so, just check the "Clipboard mode" checkbox, copy in the clipboard any word, KCnrtl will do
27
+      an automatic request to the CNRTL website and you can easily copy any synonym or antonym by
28
+      just clicking on them.
29
+      Now you just have to paste it back in you text !
30 30
 
31 31
 Planned features:
32 32
 -----------------
@@ -39,7 +39,7 @@ Installation
39 39
 
40 40
 Decompress the archive, you can launch the program by running kcnrtl.sh
41 41
 
42
-TODO
42
+TODO!!
43 43
 
44 44
 Dependencies
45 45
 ============

+ 12
- 0
TODO View File

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

+ 26
- 12
kcnrtl/gui/kcnrtl.ui View File

@@ -6,15 +6,15 @@
6 6
    <rect>
7 7
     <x>0</x>
8 8
     <y>0</y>
9
-    <width>428</width>
10
-    <height>605</height>
9
+    <width>379</width>
10
+    <height>540</height>
11 11
    </rect>
12 12
   </property>
13 13
   <property name="windowTitle">
14 14
    <string>KCnrtl</string>
15 15
   </property>
16 16
   <property name="windowIcon">
17
-   <iconset resource="resources.qrc">
17
+   <iconset resource="../resources/kcnrtl.qrc">
18 18
     <normaloff>:/kcnrtl_icon.svg</normaloff>:/kcnrtl_icon.svg</iconset>
19 19
   </property>
20 20
   <widget class="QWidget" name="centralwidget">
@@ -32,7 +32,7 @@
32 32
     <item row="1" column="0">
33 33
      <widget class="QTabWidget" name="tabWidget">
34 34
       <property name="currentIndex">
35
-       <number>0</number>
35
+       <number>2</number>
36 36
       </property>
37 37
       <widget class="QWidget" name="tab">
38 38
        <attribute name="title">
@@ -60,9 +60,16 @@
60 60
        <attribute name="title">
61 61
         <string>Synonymie</string>
62 62
        </attribute>
63
-       <layout class="QVBoxLayout" name="verticalLayout_2">
64
-        <item>
65
-         <widget class="QListView" name="listView"/>
63
+       <layout class="QGridLayout" name="gridLayout_2">
64
+        <item row="0" column="0">
65
+         <layout class="QVBoxLayout" name="verticalLayout">
66
+          <item>
67
+           <widget class="QComboBox" name="comboBox_3"/>
68
+          </item>
69
+          <item>
70
+           <widget class="QListView" name="listView"/>
71
+          </item>
72
+         </layout>
66 73
         </item>
67 74
        </layout>
68 75
       </widget>
@@ -70,9 +77,16 @@
70 77
        <attribute name="title">
71 78
         <string>Antonymie</string>
72 79
        </attribute>
73
-       <layout class="QVBoxLayout" name="verticalLayout_4">
74
-        <item>
75
-         <widget class="QListView" name="listView_2"/>
80
+       <layout class="QGridLayout" name="gridLayout_3">
81
+        <item row="0" column="0">
82
+         <layout class="QVBoxLayout" name="verticalLayout_2">
83
+          <item>
84
+           <widget class="QComboBox" name="comboBox_4"/>
85
+          </item>
86
+          <item>
87
+           <widget class="QListView" name="listView_2"/>
88
+          </item>
89
+         </layout>
76 90
         </item>
77 91
        </layout>
78 92
       </widget>
@@ -102,7 +116,7 @@
102 116
     <rect>
103 117
      <x>0</x>
104 118
      <y>0</y>
105
-     <width>428</width>
119
+     <width>379</width>
106 120
      <height>21</height>
107 121
     </rect>
108 122
    </property>
@@ -117,7 +131,7 @@
117 131
   </customwidget>
118 132
  </customwidgets>
119 133
  <resources>
120
-  <include location="kcnrtl.qrc"/>
134
+  <include location="../resources/kcnrtl.qrc"/>
121 135
  </resources>
122 136
  <connections/>
123 137
 </ui>

+ 43
- 15
kcnrtl/kcnrtl.py View File

@@ -52,17 +52,24 @@ class Main(QMainWindow):
52 52
         self.ui.comboBox.setCurrentIndex(0)
53 53
 
54 54
         self.ui.checkBox.setChecked(False)
55
-
55
+                
56
+        self.dictionaries = [u"TLFi",
57
+                             u"Académie 9e Ed.",
58
+                             u"Académie 8e Ed.",
59
+                             u"Académie 4e Ed.",
60
+                                ]
61
+        self.ui.comboBox_2.addItems(self.dictionaries)
62
+        
56 63
         self.clipboard = QApplication.clipboard()
57 64
 
58 65
         self.ui.lineEdit.returnPressed.connect(self.updateUi)
59 66
 
60
-        self.ui.comboBox.activated.connect(self.changeCombo)
67
+        self.ui.comboBox.activated.connect(self.onComboChange)
61 68
         
62 69
         self.ui.webView.settings().setUserStyleSheetUrl(
63
-                                               QUrl.fromLocalFile(":/lexi.css"))
70
+                                               QUrl.fromLocalFile(':/lexi.css'))
64 71
 
65
-        self.ui.listView.clicked.connect(self.rowClicked)
72
+        self.ui.listView.clicked.connect(self.onRowClicked)
66 73
 
67 74
         self.clipboard.dataChanged.connect(self.autoGetFromClipboard)
68 75
 
@@ -82,18 +89,27 @@ class Main(QMainWindow):
82 89
 
83 90
         except:
84 91
             self.ui.lineEdit.setText("Veuillez entrer un mot")
92
+            
93
+#    # TODO: Dynamically adjust dictionaries name to windows size
94
+#    def resizeEvent(self, event):
95
+#        if event.size().width() < 449:
96
+#            i = 0
97
+#            while i  <= len(self.ui.comboBox_2):
98
+#                self.ui.comboBox_2.setItemText(i, self.dictionaries_short[i])
99
+#            print 'size', event.size().width()
100
+        
85 101
 
86 102
     # Copy selected item in list to the clipboard
87
-    def rowClicked(self, qmodelindex):
88
-        self.item = qmodelindex.data(Qt.DisplayRole).toString()
89
-        self.clipboard.setText(self.item)
103
+    def onRowClicked(self, qmodelindex):
104
+        item = qmodelindex.data(Qt.DisplayRole).toString()
105
+        self.clipboard.setText(item)
90 106
 
91 107
     def autoGetFromClipboard(self):
92 108
         if self.ui.checkBox.isChecked():
93 109
             self.ui.lineEdit.setText(unicode(self.clipboard.text()))
94 110
             self.updateUi()
95 111
 
96
-    def changeCombo(self):
112
+    def onComboChange(self):
97 113
         self.getLexi(self.typed)
98 114
         self.lexiContent()
99 115
     
@@ -116,10 +132,14 @@ class Main(QMainWindow):
116 132
         return soup
117 133
 
118 134
     def lexiContent(self):
119
-        tagy = soup.find_all('div', {'id': 'contentbox'})
120
-        tag = str(tagy[0])
135
+        tagkeep = soup.find_all('div', {'id': 'contentbox'})
136
+        if not self.ui.comboBox_2.currentIndex():
137
+            tagrm = soup.find_all('div', {'class': 'tlf_cvedette'})
138
+        if 1 <= self.ui.comboBox_2.currentIndex() <= 3:
139
+            tagrm = soup.find_all('span', {'class': 'tlf_cvedette'})
140
+        tag = str(tagkeep[0]).replace(str(tagrm[0]),'')
121 141
         self.ui.webView.setHtml(tag.decode('utf8'))
122
-        return tagy
142
+        return tag
123 143
 
124 144
     # Check if there is more than one definition
125 145
     def lexiForm(self):
@@ -137,11 +157,19 @@ class Main(QMainWindow):
137 157
         return tagform
138 158
 
139 159
     def getHtml(self, text, form):
140
-        conn = httplib2.Http(".cache")
160
+        conn = httplib2.Http('.kcnrtl_cache')
141 161
         numdef = self.ui.comboBox.currentIndex()
142 162
         if form == "definition":
143
-            htmlSource = conn.request("http://www.cnrtl.fr/%s/%s//%s" %
163
+            if not self.ui.comboBox_2.currentIndex():
164
+                htmlSource = conn.request("http://www.cnrtl.fr/%s/%s//%s" %
144 165
                                         (form, text, numdef), "GET")
166
+            if self.ui.comboBox_2.currentIndex() > 0:
167
+                acad = unicode(self.ui.comboBox_2.currentText())
168
+                acadnum = filter(lambda x: x.isdigit(), acad)
169
+                acadnumf = "academie" + str(acadnum)
170
+                htmlSource = conn.request("http://www.cnrtl.fr/%s/%s/%s//%s" %
171
+                                          (form, acadnumf, text, numdef), "GET")
172
+
145 173
         else:
146 174
             htmlSource = conn.request("http://www.cnrtl.fr/%s/%s" %
147 175
                                         (form, text), "GET")
@@ -149,8 +177,8 @@ class Main(QMainWindow):
149 177
         
150 178
     # Delete cache directory on close
151 179
     def closeEvent(self, event):
152
-        shutil.rmtree('.cache')
153
-        print "closed"
180
+        shutil.rmtree('.kcnrtl_cache')
181
+        
154 182
 
155 183
 class ListModel(QAbstractListModel):
156 184
     def __init__(self, datain, parent=None, *args):

+ 2
- 2
setup.py View File

@@ -7,7 +7,7 @@ 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.1b',
10
+      version='0.2b',
11 11
       description='KDE graphical client for the CNRTL linguistic resources',
12 12
       license = "GPLv3", 
13 13
       author="Bogdan Cordier",
@@ -15,7 +15,7 @@ setup(name='KCnrtl',
15 15
       url="http://code.lm7.fr/p/kcnrtl/",
16 16
       download_url="http://code.lm7.fr/p/kcnrtl/downloads/", 
17 17
       packages=['kcnrtl', 'kcnrtl.gui',  'kcnrtl.resources'],
18
-      requires=['httplib2', 'bs4'], 
18
+      requires=['httplib2', 'beautifulsoup4'],
19 19
       long_description=read('README'),
20 20
       classifiers=[
21 21
         "Development Status :: 4 - Beta",

Loading…
Cancel
Save