diff --git a/README b/README index 73a6e7a..55d5742 100644 --- a/README +++ b/README @@ -5,34 +5,34 @@ KCnrtl :Author: Bogdan Cordier :Date: 2012-10-05 :Copyright: GPLv3 -:Version: 0.3b +:Version: 0.4b Description =========== KCnrtl is a simple Qt graphical client to access the CNRTL french linguistic resources. -It offers the possibility to check the definitions, synonyms, antonyms of a given -french word. Features: --------- - *Check the definitions, synomyms, antonyms of any given french word - For now the TLFi (Trésor de la Langue Française) is the only available dictionary. + *Check the synomyms, antonyms (CLI & GUI), definitions (GUI only) of any given french word - *The "AMAZING Clipboard mode" : + *Dictionaries available for now: + -TLFi (Trésor de la Langue Française informatisé) + -Dictionnaire de l'Académie Française 9th, 8th & 4th Edition + + *Clipboard mode (GUI only) : With the "Clipboard mode" you can easily check for a synonym/antonym and replace it in your text. To do so, just check the "Clipboard mode" checkbox, copy in the clipboard any word, KCnrtl will do an automatic request to the CNRTL website and you can easily copy any synonym or antonym by - just clicking on them. + just clicking on them in the result list. Now you just have to paste it back in you text ! Planned features: ----------------- - *cli client - *access to other dictionary offered by the CNRTL (Dictionnaire de l'Académie française 9e, etc) + *access to other dictionaries offered by the CNRTL (Dictionnaire du Moyen Français, etc) Installation ============ @@ -44,6 +44,10 @@ TODO!! Requirements ============ -*Python:2.7 -*PyQT4 +*Python: 2.7 +*PyQt4: >= 4.6 + +Optional if you don't use command-line: +*BeautifulSoup4 +*Httplib2 diff --git a/icons/hicolor/128x128/apps/kcnrtl.png b/icons/hicolor/128x128/apps/kcnrtl.png new file mode 100644 index 0000000..6e4f103 Binary files /dev/null and b/icons/hicolor/128x128/apps/kcnrtl.png differ diff --git a/icons/hicolor/16x16/apps/kcnrtl.png b/icons/hicolor/16x16/apps/kcnrtl.png new file mode 100644 index 0000000..5b84db9 Binary files /dev/null and b/icons/hicolor/16x16/apps/kcnrtl.png differ diff --git a/icons/hicolor/32x32/apps/kcnrtl.png b/icons/hicolor/32x32/apps/kcnrtl.png new file mode 100644 index 0000000..aae2bcc Binary files /dev/null and b/icons/hicolor/32x32/apps/kcnrtl.png differ diff --git a/icons/hicolor/64x64/apps/kcnrtl.png b/icons/hicolor/64x64/apps/kcnrtl.png new file mode 100644 index 0000000..36dbf94 Binary files /dev/null and b/icons/hicolor/64x64/apps/kcnrtl.png differ diff --git a/icons/kcnrtl.ico b/icons/kcnrtl.ico new file mode 100644 index 0000000..a4e03ff Binary files /dev/null and b/icons/kcnrtl.ico differ diff --git a/icons/pixmaps/kcnrtl.xpm b/icons/pixmaps/kcnrtl.xpm new file mode 100644 index 0000000..45eb0a2 --- /dev/null +++ b/icons/pixmaps/kcnrtl.xpm @@ -0,0 +1,305 @@ +/* XPM */ +static char *kcnrtl[] = { +/* columns rows colors chars-per-pixel */ +"56 56 243 2 ", +" c #55F522530015", +". c #5C1A24B10032", +"X c #5F5F2F2F0F0F", +"o c #61E426D10000", +"O c #65CC28A60038", +"+ c #6BF02AEA000C", +"@ c #63632E2E0C0C", +"# c #73FA2E190002", +"$ c #68E731300C8C", +"% c #7BFE315E0002", +"& c #7575343408B3", +"* c #66E63838199A", +"= c #78223B9013BE", +"- c #72723DE81B1B", +"; c #7DFD41C01A9B", +": c #727242422323", +"> c #75754C4B3030", +", c #797950503434", +"< c #840034840009", +"1 c #8A0A36CD0000", +"2 c #8DFF38960010", +"3 c #85853B3B0B0B", +"4 c #93F93AE60007", +"5 c #9BA83DF50006", +"6 c #82823F3F1515", +"7 c #FFFF00BF00BF", +"8 c #FFFF0CB70CB7", +"9 c #FFFF14471447", +"0 c #FFFF1AD21AD2", +"q c #F6F622222222", +"w c #FFFF23E423E4", +"e c #FFFF2AC42AC4", +"r c #FFA933893389", +"t c #FFCB3B6E3B6E", +"y c #9E9E40EB0202", +"u c #931242820D4D", +"i c #9AEF44440AB5", +"p c #8B8B44441494", +"a c #8CE249F41D1D", +"s c #97164ACA17D8", +"d c #A3914135001E", +"f c #A7A746C70606", +"g c #ABAB44A00025", +"h c #B1DC471C002B", +"j c #B49448E90141", +"k c #BBF44AF50000", +"l c #B8B851510C0C", +"z c #A34D4CF71414", +"x c #A4A44DCE1515", +"c c #B73755D61494", +"v c #88324B4B22CD", +"b c #90904D4D2020", +"n c #9E1E54D42323", +"m c #92E755552C2C", +"M c #9B9B55D62828", +"N c #9A1A58D82D2D", +"B c #91915ADA3636", +"V c #9E1E5EDE34B4", +"C c #A1A156AC24CF", +"Z c #A3A35D072E2E", +"A c #A2A25EDF32B3", +"S c #BBBB61B72626", +"D c #B86264642BD6", +"F c #ABEB63233272", +"G c #A33C64973BA2", +"H c #ACAC68683A90", +"J c #B6B66A6A36B7", +"K c #B9B96D6D3B3B", +"L c #BDBD71713DBE", +"P c #C1C14E4E0181", +"I c #CC4B521200E1", +"U c #C5C456560C0C", +"Y c #D3AB55550129", +"T c #D3D25B5B0B8B", +"R c #C0BF59581515", +"E c #C7C760601A1A", +"W c #D5D462B7166C", +"Q c #DBDA5C5C2C2B", +"! c #C0C066E72B2B", +"~ c #D7D76D6D2E2E", +"^ c #C8C76E6D3131", +"/ c #C4C470703838", +"( c #83835E5E4545", +") c #8E8E67674D4D", +"_ c #9C1B6AEB4A4A", +"` c #8E8E6D6C5656", +"' c #94936E6E5555", +"] c #97D773335ADA", +"[ c #A471699C4310", +"{ c #AC006D1743EE", +"} c #A34D6C1647F2", +"| c #B0B06F6F4444", +" . c #AD57731D4C4C", +".. c #BE3E73734242", +"X. c #B58276424C7F", +"o. c #B9B976B64ACB", +"O. c #AC5675CB51A7", +"+. c #AB2A7BFC5CDC", +"@. c #B4B47C7C5757", +"#. c #BBBB7C2651FC", +"$. c #8F8F7C7C6F6F", +"%. c #9A447B2566BC", +"&. c #A2A27F7F6868", +"*. c #D2D25A5A5A5A", +"=. c #E0E04D4D4D4D", +"-. c #F1F144444444", +";. c #FFFF43434343", +":. c #FFFF4DCD4DCD", +">. c #E0E058585858", +",. c #F6F650505050", +"<. c #FF3E53135313", +"1. c #FF295BDB5B5B", +"2. c #C646797945C5", +"3. c #C71B7A2446F1", +"4. c #CD4D7E7E4ACA", +"5. c #EEEE60604A4A", +"6. c #F5F562625F5F", +"7. c #FD7D686864E5", +"8. c #FFFF6BFE6BFE", +"9. c #FFFF75F575F5", +"0. c #FFFF7CFC7CFC", +"q. c #BD6782D75CB2", +"w. c #959583837777", +"e. c #A6FC84DA6E18", +"r. c #BB1085DB63B9", +"t. c #A62589897777", +"y. c #ACAC92117F7F", +"u. c #DADA82824848", +"i. c #DEDE87074CCC", +"p. c #CD2285855555", +"a. c #C46E85DB5CB2", +"s. c #CBCB88885C5C", +"d. c #D757898955D6", +"f. c #D4D4894957D8", +"g. c #EB6B900F5353", +"h. c #EDED96965D5D", +"j. c #C645898960E0", +"k. c #C4438E8E6B6B", +"l. c #D0D08C8C6060", +"z. c #CDCD922B6A9D", +"x. c #DC3194EA65BB", +"c. c #D8D895956913", +"v. c #DFDF9B9B6DC3", +"b. c #C7C79696760F", +"n. c #E53A964062B8", +"m. c #E58F99436666", +"M. c #E6E69B9B6A6A", +"N. c #F6F69D9D6262", +"B. c #F2F29F1F68E8", +"V. c #E5E59F9F7070", +"C. c #DCDCA12078F8", +"Z. c #FEFEA0A06262", +"A. c #FD3CA6A66D6D", +"S. c #EABFA7517AFA", +"D. c #FDFDABEB75B5", +"F. c #F6F6AD137C49", +"G. c #FEA8B1067D7D", +"H. c #84EB84B7849E", +"J. c #8CBB8CBB8CBB", +"K. c #9431941D941D", +"L. c #9B9B97979595", +"P. c #9C409C409C40", +"I. c #B7368B8B8B8B", +"U. c #AD0295EB8731", +"Y. c #B1B19A198A8A", +"T. c #A3229A199414", +"R. c #B4339C1C9494", +"E. c #B6B6A4A49999", +"W. c #A38EA38EA38E", +"Q. c #ABABA8A8A7A7", +"!. c #ABCBABABABAB", +"~. c #BCBCAFAFA6A6", +"^. c #B535B535B535", +"/. c #B8B8B7B7B7B7", +"(. c #BCCABCCABCCA", +"). c #C4C49F9F8686", +"_. c #C0C096969696", +"`. c #FFFF853C853C", +"'. c #FFFF8AF88AF8", +"]. c #FFFF94609460", +"[. c #FFFF9BCE9BCE", +"{. c #DF5FA9A98585", +"}. c #DADAABAB8C8C", +"|. c #C544A7A79494", +" X c #D1D1AAAA9191", +".X c #EC41AE58852F", +"XX c #E9E9B2B28E8E", +"oX c #F4F4B2078585", +"OX c #FECBB4E7841D", +"+X c #F635B6368B4B", +"@X c #FF47BA4C8C8C", +"#X c #E867B7379615", +"$X c #ED42BABA9999", +"%X c #F348B9639393", +"&X c #FE46BE2B936E", +"*X c #C1C1AF2FA2A2", +"=X c #CA49B5B5A827", +"-X c #D3D3BB3AAB2A", +";X c #CCCCBCBCB2B2", +":X c #FFFFA40AA40A", +">X c #FFFFAB86AB86", +",X c #FFFFB2F2B2F2", +" Y.CXCXCXCXCXMX * U.nXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCXCXBX ` BXCXCXMX*X @ e.cXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCXCXeX $ A A.2.V i.M . . . o ] fXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCXCXY. o a i.h.F 2.h.a o o o O ] fXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCXCX` . a J Z.4.N h.d.= O O O + _ aXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCXCX: . . . o 6 M h.N.F ..A.2.# O O O # B 4XCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCXcX . . . . o o & Z 2.A.d.A n.B.F # # + # # m -XCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCX;X . . . o o o O + F A B.A.H { D.n.b # # % % # m =XCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCXt. . . . . o o o O O O n H d.D.n.V m.G.p.6 % % % % < b |.BXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCX( . . . o o o O O O O + p o.H D.D.o.| G.F...< % % < % < a b.MXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCXX . . . . o o o O O + + + # & 4.A m.D.M.A x.OXS.F < < < < 1 1 u b.MXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXfX . . o o o o O O + O + + + # # 2.o.o.G.G.#.| OXOXv.s 1 1 1 1 2 2 s r.bXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCX*X . . . . o o o O + O + + # + # # # n x.G S.OXS.G z.@X@Xf.u 1 1 2 2 4 4 5 q.jXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCX%. . . . . o o o O O + + + + + # # # # % p M.| s.OXOXa.{ oX@X+X..2 4 2 4 4 4 4 5 X.pXCXCXCXCXCXCXCXCXCXCXCX", +"CXCX, . . . o o o o O + O + + # + # # # # % % 3 f.l.[ oX@XoX .z.1X&X.XD 4 4 5 4 5 5 y y o.pXCXCXCXCXCXCXCXCXCX", +"CXVX. . . o o o O O O + + O # + # # # # % % % % % J F.[ c.&X&Xz.[ +X2X2XM.z 5 5 5 5 y y y d K 9XCXCXCXCXCXCXCX", +"CXrX. . . o o o o o + O O + + + # # # # # % % % % < < C .Xs. .@X&X+XO.k.2X2X2Xl.i d 5 d d y d d g L 9XCXCXCXCXCX", +"CXR.. . . o o o O O O + + # + # # # # % # % % < < < < < u V.S.[ .X&X2XC.} XX6X6X%X2.d d d g g g g g z.CXCXCXCXCX", +"CX] . . . o o O O O O + + + + # # # # # % % % % % < < < 1 3 4.&X@.@.2X2X2X@.r.6X8X8X.XS d d g g g g kXCXCXCXCXCX", +"CX: . . o o o O O O + + + # # + # # # % % % % % % < < < 1 1 1 J @XC.} %X6X6X{._ XX8X8X8XM.c g g g s.CXCXCXCXCXCX", +"nX. . o o o o O + + + + + + # # # % # % % % < % < < 1 < 1 1 2 2 C +X%XO.z.6X6X7Xr.r.8X8X#X{.j g h hXCXCXCXCXCXCX", +"4X. o o o O O O O + + # # # # # # # % % % % < < < < 1 1 1 2 2 2 4 i .X6Xb.O.&X6X#X).=XzXzX Xh h 2.CXCXCXCXCXCXCX", +"y.o . o O O O O + + + + + # # # % % % % < % < < < 1 1 1 2 2 2 2 2 4 M.6X$X X=XyXyXzXzXyXzXD h h 0XCXCXCXCXCXCXCX", +") . o o O O O O + + # # + # # % % % % % < % < < < 1 1 1 2 2 2 4 4 4 3XtXtXtXyXyXyXyXyXyX-Xh h / CXCXCXCXCXCXCXCX", +"- o o O O O + + + + + # # # # % # % % % % < < < 1 1 1 2 2 2 4 4 4 n tXtXtXtXtXtXyXyXyXyX2.h j 5XCXCXCXCXCXCXCXCX", +"@ o O o O O O + + # + # # % # # % % % < < < < < 1 1 1 2 2 2 4 4 5 O.wXwXtXtXtXtXtXtXyX4Xh j ! CXCXCXCXCXCXCXCXCX", +"- o O O O + O # + + # # # # % % % % < % < < < 1 < 1 1 2 2 2 4 4 5 Y.wXwXwXwXtXtXtXtXtXa.j j #XCXCXCXCXCXCXCXCXCX", +"&.O O O + O + # # # # # # % % % % % < < < 1 < 1 1 1 2 2 4 4 4 4 4 ~.wXwXwXwXwXwXtXtXeXl j R VXCXCXCXCXCXCXCXCXCX", +"nX- O O + + + + + # # # # # % % % < % < < < 1 1 1 2 2 2 4 4 4 4 z qXqXqXwXwXwXwXwXwXb.k k {.CXCXCXCXCXCXCXCXCXCX", +"CXaX= O + + # # # # # # % % % % % < < < < 1 1 1 2 2 4 4 4 4 5 4 { qXqXqXqXqXwXwXwXwXc k U BXCXCXCXCXCXCXCXCXCXCX", +"CXCXfX= + O # + # # # % # % % % < < < < < 1 1 2 2 2 4 4 4 4 4 5 e.qX(.qXqXqXqXqXwX).k k C.CXCXCXCXCXCXCXCXCXCXCX", +"CXCXCXfX; + # # # # # % % % % < < < < 1 < 1 1 2 2 2 4 4 4 5 5 5 E.(.(.qXqXqXqXqXqXD k U NXCXCXCXCXCXCX0.CXCXCXCX", +"CXCXCXCXjX; + # # # # % % % < % % < < 1 1 1 2 2 2 4 4 4 4 4 4 i /.(.(.(.(.(.(.qX*Xk k x.CXCXCXCXCXCXCXw `.CXCXCX", +"CXCXCXCXCXjXv # % # % % % % % < < 1 < 1 1 1 2 2 4 4 4 4 5 5 5 A ^././.(.(.(.(.(.2.P P kXCXCXCXCXCXCXCXe 7 uXCXCX", +"CXCXCXCXCXCXxXv # % % % % % < < < < 1 1 1 1 2 4 4 4 4 4 4 5 5 +.^.^.^./.(.(.(.~.k P d.CXCXCXCXCXuX'.`.0 7 e VXCX", +"CXCXCXCXCXCXCXxXv % % % < < < < < 1 1 1 1 2 2 2 4 4 4 5 5 5 5 U.!.^._.>.-.t :.1.5.Q dXCXCXCXCXCXVX8.0 7 7 7 '.CX", +"CXCXCXCXCXCXCXCXnXm % < % < < < < 1 1 1 2 2 4 4 4 4 4 5 5 5 y Q.!.!.=.w r ;.<.8.9.0.[.mXCXCXCXCXCXVX;.8 7 7 9 VX", +"CXCXCXCXCXCXCXCXCXnXm % % < < 1 1 1 1 2 2 4 4 4 4 4 5 5 5 5 C !.!.!.q e t :.7.9.`.].].>XCXCXCXCXCXCXuX8 7 7 7 :X", +"CXCXCXCXCXCXCXCXCXCXnXN < < < < 1 1 2 2 2 2 4 4 4 5 4 5 5 5 } !.!.I.0 e ;.<.8.0.].:X>X>XvXCXCXCXCXCXCXt 7 7 7 <.", +"CXCXCXCXCXCXCXCXCXCXCXMXV < 1 1 1 1 2 2 2 4 4 4 4 5 5 5 5 5 t.W.W.*.0 r ,.6.8.`.[.>XXw 7 7 7 <.", +"CXCXCXCXCXCXCXCXCXCXCXCXCXCXCXBX{ 2 2 4 4 4 5 5 5 5 d d d %.L.P.P.P.W.T.I I XXCXCXuX[.:X[.'.].'.8.;.e 9 7 7 7 uX", +"CXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXX.4 4 4 5 4 5 5 5 d 5 d w.L.P.L.P.P.#.Y T VXCXCXgX'.'.`.0.8.1.;.t w 8 7 7 0.CX", +"CXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXVXX.2 5 4 5 5 5 5 d d z K.K.L.P.L.L.U I V.CXCXCXCX].9.9.8.1.<.t e 0 7 9 :XCXCX", +"CXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXVX#.5 5 5 5 d 5 d d A J.K.K.K.L.+.I T NXCXCXCXCXVX>X8.1.:.;.t ;.1.>XVXCXCXCX", +"CXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXq.5 5 5 5 d d d ' J.J.K.K.K.E Y n.CXCXCXCXCXCXCXCXVXVXVXCXCXCXCXCXCXCXCX", +"CXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXVXq.5 d d d d d $.J.J.J.J.e.Y Y lXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXBXj.d d d d f H.J.J.J.J.D Y g.CXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXa.d d d z H.H.H.J.w.I Y dXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXz.d d z H.H.H.H.J Y u.CXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXz.g h ] H.H.%.Y Y sXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX}.g I S S Y Y %XCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX", +"CXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXpX^ W W i.sXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCXCX" +}; diff --git a/kcnrtl.py b/kcnrtl.py new file mode 100755 index 0000000..b331e95 --- /dev/null +++ b/kcnrtl.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python + +from kcnrtl.main import main + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/kcnrtl/fetchparsebs.py b/kcnrtl/fetchparsebs.py new file mode 100644 index 0000000..609c2b6 --- /dev/null +++ b/kcnrtl/fetchparsebs.py @@ -0,0 +1,38 @@ +#-*- coding: utf-8 -*- + +######################################################################## +# This file is part of KCnrtl # +# # +# # +# Copyright (C) 2012 Bogdan Cordier    # +# # +# KCnrtl is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# KCnrtl is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see .# +######################################################################## + +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])) + i = 0 + while i < len(tagy): + tag_a = tagy[i] + i += 1 + print tag_a.text + + diff --git a/kcnrtl/fetchparseqt.py b/kcnrtl/fetchparseqt.py new file mode 100644 index 0000000..6711772 --- /dev/null +++ b/kcnrtl/fetchparseqt.py @@ -0,0 +1,107 @@ +#-*- coding: utf-8 -*- + +######################################################################## +# This file is part of KCnrtl # +# # +# # +# Copyright (C) 2012 Bogdan Cordier    # +# # +# KCnrtl is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# KCnrtl is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see .# +######################################################################## + + +from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest +from PyQt4.QtWebKit import QWebPage +from PyQt4.QtCore import QEventLoop, QUrl + + +class FetchParse: + def __init__(self, word, dico, combo1_index, combo2_index, combo2_text, wordclass): + self.word = word + self.dico = dico + self.combo1_index = combo1_index + self.combo2_index = combo2_index + self.combo2_text = combo2_text + self.wordclass = wordclass + self.manager = QNetworkAccessManager() + self.manager.finished.connect(self.replyFinished) + self.loop = QEventLoop() + self.manager.finished.connect(self.loop.quit) + self._reply = "" + + def _get_reply(self): + self.fetch(self.dico) + return self._reply + + reply = property(_get_reply) + + def fetch(self, dico): + if dico == "Lexi": + if not self.combo2_index: + url = ("http://www.cnrtl.fr/definition/%s//%s" % + (self.word, self.combo1_index)) + if self.combo2_index > 0: + acad = unicode(self.combo2_text) + acadnum = filter(lambda x: x.isdigit(), acad) + acadnumf = "academie" + str(acadnum) + url = ("http://www.cnrtl.fr/definition/%s/%s//%s" % + (acadnumf, self.word, self.combo1_index)) + if dico == "Syno": + url = ("http://www.cnrtl.fr/synonymie/%s" % + (self.word)) + if dico == "Anto": + url = ("http://www.cnrtl.fr/antonymie/%s" % + (self.word)) + self.manager.get(QNetworkRequest(QUrl(url))) + self.loop.exec_() + + def replyFinished(self, datareply): + data = datareply.readAll() + page = QWebPage() + page.mainFrame().setContent(data) + webpage = page.mainFrame().documentElement() + if self.wordclass == "definition": + result = webpage.findAll("div#contentbox") + a = "" + if not self.combo2_index: + a = "div.tlf_cvedette" + if 1 <= self.combo2_index <= 3: + a = "span.tlf_cvedette" + result_to_remove = webpage.findAll(a) + string_to_remove = result_to_remove.first().toInnerXml() + final_page = result.first().toInnerXml() + resultf = final_page.replace(string_to_remove, '') + + result_box = webpage.findFirst('div#vtoolbar') + result_test = result_box.findAll("a[href]") + self.formtype = [] + i = 0 + while i < len(result_test): + multdef_a = unicode(result_test.at(i).toPlainText()) + # Delete digits in definition title + multdef_clean = ''.join(c for c in + multdef_a if not c.isdigit()) + self.formtype.append(multdef_clean) + i += 1 + self._reply = resultf, self.formtype + if self.wordclass == "synonyme" or self.wordclass == "antonyme": + self._reply = [] + result = webpage.findAll("td." + self.wordclass[:4] + "_format") + tag = [] + i = 0 + while i < len(result): + tag.append(result.at(i).firstChild().toPlainText()) + i += 1 + self._reply = tag + diff --git a/kcnrtl/gui/Ui_kcnrtl.py b/kcnrtl/gui/Ui_kcnrtl.py index b95ea43..7942fef 100644 --- a/kcnrtl/gui/Ui_kcnrtl.py +++ b/kcnrtl/gui/Ui_kcnrtl.py @@ -93,7 +93,7 @@ class Ui_MainWindow(object): self.checkBox.setText(QtGui.QApplication.translate("MainWindow", "Clipboard Mode", None, QtGui.QApplication.UnicodeUTF8)) from PyQt4 import QtWebKit -import resources.kcnrtl_rc +from kcnrtl.resources import kcnrtl_rc if __name__ == "__main__": import sys diff --git a/kcnrtl/gui/gui.py b/kcnrtl/gui/gui.py new file mode 100755 index 0000000..6bf0e19 --- /dev/null +++ b/kcnrtl/gui/gui.py @@ -0,0 +1,124 @@ +#!/usr/bin/python +#-*- coding: utf-8 -*- + +######################################################################## +# This file is part of KCnrtl # +# # +# # +# Copyright (C) 2012 Bogdan Cordier    # +# # +# KCnrtl is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# KCnrtl is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see .# +######################################################################## + +import sys +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 + + +def main(): + app = QApplication(sys.argv) + myapp = Main() + myapp.show() + sys.exit(app.exec_()) + + +class Main(QMainWindow): + def __init__(self, parent=None): + super(QWidget, self).__init__(parent) + + self.ui = Ui_MainWindow() + + self.ui.setupUi(self) + + self.ui.lineEdit.selectAll() + + self.ui.lineEdit.setFocus() + + self.ui.comboBox.setCurrentIndex(0) + + self.ui.checkBox.setChecked(False) + + + self.dictionaries = [str("TLFi").decode("utf-8", "strict"), + str("Académie 9e Ed.").decode("utf-8", "strict"), + str("Académie 8e Ed.").decode("utf-8", "strict"), + str("Académie 4e Ed.").decode("utf-8", "strict"), + ] + self.ui.comboBox_2.addItems(self.dictionaries) + + self.clipboard = QApplication.clipboard() + + self.ui.lineEdit.returnPressed.connect(self.updateUi) + + self.ui.comboBox.activated.connect(self.on_combo_change) + + self.ui.webView.settings().setUserStyleSheetUrl( + QUrl.fromLocalFile(':/lexi.css')) + + self.ui.listView.clicked.connect(self.on_row_clicked) + + self.clipboard.dataChanged.connect(self.get_from_clipboard) + + + + def updateUi(self): + # Check if input text is a word + 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) + + else: + self.ui.lineEdit.setText("Veuillez entrer UN mot") + + # Copy selected item in list to the clipboard + def on_row_clicked(self, qmodelindex): + item = qmodelindex.data(Qt.DisplayRole).toString() + self.clipboard.setText(item) +# + def get_from_clipboard(self): + if self.ui.checkBox.isChecked(): + self.ui.lineEdit.setText(unicode(self.clipboard.text())) + self.updateUi() +# + def on_combo_change(self): + 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]) + +if __name__ == "__main__": + main() diff --git a/kcnrtl/kcnrtl.py b/kcnrtl/kcnrtl.py deleted file mode 100755 index 30c77c7..0000000 --- a/kcnrtl/kcnrtl.py +++ /dev/null @@ -1,191 +0,0 @@ -#!/usr/bin/python -#-*- coding: utf-8 -*- - -######################################################################## -# KCnrtl - A simple Qt graphical client to access the CNRTL # -# french linguistic resources. # -# # -# Copyright (C) 2012 Bogdan Cordier    # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see .# -######################################################################## - -import sys -from PyQt4.QtCore import QEventLoop, QUrl, QAbstractListModel, QModelIndex, QVariant, Qt -from PyQt4.QtGui import QApplication, QMainWindow, QWidget -from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest -from PyQt4.QtWebKit import QWebPage -from gui.Ui_kcnrtl import Ui_MainWindow - - -def main(): - app = QApplication(sys.argv) - myapp = Main() - myapp.show() - sys.exit(app.exec_()) - - -class Main(QMainWindow): - def __init__(self, parent=None): - super(QWidget, self).__init__(parent) - - self.ui = Ui_MainWindow() - - self.ui.setupUi(self) - - self.ui.lineEdit.selectAll() - - self.ui.lineEdit.setFocus() - - self.ui.comboBox.setCurrentIndex(0) - - self.ui.checkBox.setChecked(False) - - self.manager = QNetworkAccessManager() - - self.dictionaries = [str("TLFi").decode("utf-8", "strict"), - str("Académie 9e Ed.").decode("utf-8", "strict"), - str("Académie 8e Ed.").decode("utf-8", "strict"), - str("Académie 4e Ed.").decode("utf-8", "strict"), - ] - self.ui.comboBox_2.addItems(self.dictionaries) - - self.clipboard = QApplication.clipboard() - - self.ui.lineEdit.returnPressed.connect(self.updateUi) - - self.ui.comboBox.activated.connect(self.on_combo_change) - - self.ui.webView.settings().setUserStyleSheetUrl( - QUrl.fromLocalFile(':/lexi.css')) - - self.ui.listView.clicked.connect(self.on_row_clicked) - - self.clipboard.dataChanged.connect(self.get_from_clipboard) - - self.manager.finished.connect(self.replyFinished) - - self.loop = QEventLoop() - - self.manager.finished.connect(self.loop.quit) - - self.tagform = [] - - def updateUi(self): - # Check if input text is a word - if len(unicode(self.ui.lineEdit.text()).split()) <= 1: - self.formtype = "definition" - self.fetch("Lexi") - self.ui.comboBox.clear() - self.ui.comboBox.addItems(self.tagform) - self.formtype = "synonyme" - self.fetch("Syno") - self.formtype = "antonyme" - self.fetch("Anto") - else: - self.ui.lineEdit.setText("Veuillez entrer UN mot") - - # Copy selected item in list to the clipboard - def on_row_clicked(self, qmodelindex): - item = qmodelindex.data(Qt.DisplayRole).toString() - self.clipboard.setText(item) -# - def get_from_clipboard(self): - if self.ui.checkBox.isChecked(): - self.ui.lineEdit.setText(unicode(self.clipboard.text())) - self.updateUi() -# - def on_combo_change(self): - self.formtype = "definition" - self.fetch("Lexi") - - - def fetch(self, dico): - if dico == "Lexi": - if not self.ui.comboBox_2.currentIndex(): - url = ("http://www.cnrtl.fr/definition/%s//%s" % - (self.ui.lineEdit.text(), self.ui.comboBox.currentIndex())) - if self.ui.comboBox_2.currentIndex() > 0: - acad = unicode(self.ui.comboBox_2.currentText()) - acadnum = filter(lambda x: x.isdigit(), acad) - acadnumf = "academie" + str(acadnum) - url = ("http://www.cnrtl.fr/definition/%s/%s//%s" % - (acadnumf, self.ui.lineEdit.text(), self.ui.comboBox.currentIndex())) - if dico == "Syno": - url = ("http://www.cnrtl.fr/synonymie/%s" % - (self.ui.lineEdit.text())) - if dico == "Anto": - url = ("http://www.cnrtl.fr/antonymie/%s" % - (self.ui.lineEdit.text())) - self.manager.get(QNetworkRequest(QUrl(url))) - self.loop.exec_() - - def replyFinished(self, reply): - data = reply.readAll() - page = QWebPage() - page.mainFrame().setContent(data) - webpage = page.mainFrame().documentElement() - if self.formtype == "definition": - result = webpage.findAll("div#contentbox") - if not self.ui.comboBox_2.currentIndex(): - result_to_remove = webpage.findAll("div.tlf_cvedette") - if 1 <= self.ui.comboBox_2.currentIndex() <= 3: - result_to_remove = webpage.findAll("span.tlf_cvedette") - string_to_remove = result_to_remove.first().toInnerXml() - final_page = result.first().toInnerXml() - resultf = final_page.replace(string_to_remove, '') - self.ui.webView.setHtml(resultf) - - result_box = webpage.findFirst('div#vtoolbar') - result_test = result_box.findAll("a[href]") - self.tagform = [] - i = 0 - while i < len(result_test): - multdef_a = unicode(result_test.at(i).toPlainText()) - # Delete digits in definition title - multdef_clean = ''.join(c for c in - multdef_a if not c.isdigit()) - self.tagform.append(multdef_clean) - i += 1 - if self.formtype == "synonyme" or "antonyme": - result = webpage.findAll("td." + self.formtype[:4] + "_format") - tag = [] - i = 0 - while i < len(result): - tag.append(result.at(i).firstChild().toPlainText()) - i += 1 - model = ListModel(tag, self) - if self.formtype == "synonyme": - self.ui.listView.setModel(model) - if self.formtype == "antonyme": - self.ui.listView_2.setModel(model) - -class ListModel(QAbstractListModel): - def __init__(self, datain, parent=None, *args): - """ datain: a list where each item is a row - """ - QAbstractListModel.__init__(self, parent, *args) - self.listdata = datain - - def rowCount(self, parent=QModelIndex()): - return len(self.listdata) - - def data(self, index, role): - if index.isValid() and role == Qt.DisplayRole: - return QVariant(self.listdata[index.row()]) - else: - return QVariant() - -if __name__ == "__main__": - main() diff --git a/kcnrtl/main.py b/kcnrtl/main.py new file mode 100755 index 0000000..b234a19 --- /dev/null +++ b/kcnrtl/main.py @@ -0,0 +1,57 @@ +#!/usr/bin/python +#-*- coding: utf-8 -*- + +######################################################################## +# This file is part of KCnrtl # +# # +# # +# Copyright (C) 2012 Bogdan Cordier    # +# # +# KCnrtl is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# KCnrtl is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see .# +######################################################################## + + +import argparse +import sys + +def main(): + cmd = argparse.ArgumentParser(description="Check for synonyms or antonyms", + prog='kcnrtl', usage='%(prog)s --help [options] word') + + cmd.add_argument('word', default="", nargs='?', + help="The word to look for") + + cmd.add_argument('-s', '--synonym', action="store_true", + help="Display synonyms of any word") + + cmd.add_argument('-a', '--antonym', action="store_true", + help="Display antonyms of any word") + + args = cmd.parse_args() + + if 'word' in args: + wordset = args.word + + if len(sys.argv) < 2: + from gui.gui import main + exit(main()) + else: + from fetchparsebs import getSynoAnto + if args.synonym: + getSynoAnto(wordset, "synonymie") + if args.antonym: + getSynoAnto(wordset, "antonymie") + +if __name__ == '__main__': + main() diff --git a/kcnrtl/models.py b/kcnrtl/models.py new file mode 100644 index 0000000..c233407 --- /dev/null +++ b/kcnrtl/models.py @@ -0,0 +1,17 @@ +from PyQt4.QtCore import QModelIndex, QVariant, Qt, QAbstractListModel + +class ListModel(QAbstractListModel): + def __init__(self, datain, parent=None, *args): + """ datain: a list where each item is a row + """ + QAbstractListModel.__init__(self, parent, *args) + self.listdata = datain + + def rowCount(self, parent=QModelIndex()): + return len(self.listdata) + + def data(self, index, role): + if index.isValid() and role == Qt.DisplayRole: + return QVariant(self.listdata[index.row()]) + else: + return QVariant() \ No newline at end of file diff --git a/kcnrtl/resources/kcnrtl_icon.svg b/kcnrtl/resources/kcnrtl_icon.svg new file mode 100644 index 0000000..5e3a7b4 --- /dev/null +++ b/kcnrtl/resources/kcnrtl_icon.svg @@ -0,0 +1,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/setup.py b/setup.py index acf3639..76bdf12 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() setup(name='KCnrtl', - version='0.3b', + version='0.4b', description='Qt graphical client for the CNRTL french linguistic resources', license = "GPLv3", author="Bogdan Cordier", @@ -15,10 +15,12 @@ setup(name='KCnrtl', url="http://code.lm7.fr/p/kcnrtl/", download_url="http://code.lm7.fr/p/kcnrtl/downloads/", packages=['kcnrtl'], + requires=['BeautifulSoup4','httplib2'], long_description=read('README'), classifiers=[ "Development Status :: 4 - Beta", - "Environment :: X11 Applications :: Qt" + "Environment :: X11 Applications :: Qt", + "Environment :: Console", "Topic :: Utilities", "Natural Language :: French", "Intended Audience :: Education"