...
authorPierre Ratinaud <ratinaud@univ-tlse2.fr>
Fri, 1 Aug 2014 21:10:54 +0000 (23:10 +0200)
committerPierre Ratinaud <ratinaud@univ-tlse2.fr>
Fri, 1 Aug 2014 21:10:54 +0000 (23:10 +0200)
PrintRScript.py
ProfList.py
corpus.py
dialog.py
functions.py
import_txm.py
iramuteq.py
listlex.py
search_list.py
textwordcloud.py
tree.py

index fae8dcb..995b483 100644 (file)
@@ -535,16 +535,16 @@ def dendroandbarplot(table, rownames, colnames, rgraph, tmpgraph, intxt = False,
         """ % (ffr(dendro),ffr(rgraph),  ffr(tmpgraph))
     return txt
 
-def barplot(table, rownames, colnames, rgraph, tmpgraph, intxt = False) :
+def barplot(table, parametres, intxt = False) :
     if not intxt :
         txttable = 'c(' + ','.join([','.join(line) for line in table]) + ')'
     #width = 100 + (15 * len(rownames)) + (100 * len(colnames))
     #height =  len(rownames) * 15
-    rownb = len(rownames)
+    rownb = len(parametres['rownames'])
     #if height < 400 :
     #    height = 400
-    rownames = 'c("' + '","'.join(rownames) + '")'
-    colnames = 'c("' + '","'.join(colnames) + '")'
+    rownames = 'c("' + '","'.join(parametres['rownames']) + '")'
+    colnames = 'c("' + '","'.join(parametres['colnames']) + '")'
 
     if not intxt :
         #FIXME
@@ -577,58 +577,68 @@ def barplot(table, rownames, colnames, rgraph, tmpgraph, intxt = False) :
         """ % (txttable, rownb, rownames, colnames)
     else :
         txt = intxt
-    txt += """
-        source("%s")
-        color = rainbow(nrow(di))
-        width <- 100 + (10*length(rownames(di))) + (100 * length(colnames(di)))
-        height <- nrow(di) * 15
-        if (height < 400) { height <- 400}
-        open_file_graph("%s",width = width, height = height)
-       par(mar=c(0,0,0,0))
-           layout(matrix(c(1,2),1,2, byrow=TRUE),widths=c(3,lcm(7)))
-        par(mar=c(6,2,1,0))
-        yp = ifelse(length(toinf), 0.2, 0)
-        ym = ifelse(length(tominf), 0.2, 0)
-        ymin <- ifelse(!length(which(di < 0)), 0, min(di) - ym)
-        coord <- barplot(as.matrix(di), beside = TRUE, col = color, space = c(0.1,0.6), ylim=c(ymin, max(di) + yp), las = 2)
-        if (length(toinf)) {
-            coordinf <- coord[toinf]
-            valinf <- di[toinf]
-            text(x=coordinf, y=valinf + 0.1, 'i')
-        }
-        if (length(tominf)) {
-            coordinf <- coord[toinf]
-            valinf <- di[toinf]
-            text(x=coordinf, y=valinf - 0.1, 'i')
-        }            
-        c <- colMeans(coord)
-        c1 <- c[-1]
-        c2 <- c[-length(c)]
-        cc <- cbind(c1,c2)
-        lcoord <- apply(cc, 1, mean)
-        abline(v=lcoord)
-        if (min(di) < 0) {
-            amp <- abs(max(di) - min(di))
-        } else {
-            amp <- max(di)
-        }
-        if (amp < 10) {
-            d <- 2
-        } else {
-            d <- signif(amp%%/%%10,1)
-        }
-        mn <- round(min(di))
-        mx <- round(max(di))
-        for (i in mn:mx) {
-            if ((i/d) == (i%%/%%d)) { 
-                abline(h=i,lty=3)
+    if not 'tree' in parametres :
+        txt += """
+            source("%s")
+            color = rainbow(nrow(di))
+            width <- %i
+            height <- %i
+            open_file_graph("%s",width = width, height = height, svg = %s)
+               par(mar=c(0,0,0,0))
+           layout(matrix(c(1,2),1,2, byrow=TRUE),widths=c(3,lcm(7)))
+            par(mar=c(8,4,1,0))
+            yp = ifelse(length(toinf), 0.2, 0)
+            ym = ifelse(length(tominf), 0.2, 0)
+            ymin <- ifelse(!length(which(di < 0)), 0, min(di) - ym)
+            coord <- barplot(as.matrix(di), beside = TRUE, col = color, space = c(0.1,0.6), ylim=c(ymin, max(di) + yp), las = 2)
+            if (length(toinf)) {
+                coordinf <- coord[toinf]
+                valinf <- di[toinf]
+                text(x=coordinf, y=valinf + 0.1, 'i')
             }
-        }
-        par(mar=c(0,0,0,0))
-        plot(0, axes = FALSE, pch = '')
-        legend(x = 'center' , rownames(di), fill = color)
-        dev.off()
-        """ % (rgraph, ffr(tmpgraph))    
+            if (length(tominf)) {
+                coordinf <- coord[toinf]
+                valinf <- di[toinf]
+                text(x=coordinf, y=valinf - 0.1, 'i')
+            }            
+            c <- colMeans(coord)
+            c1 <- c[-1]
+            c2 <- c[-length(c)]
+            cc <- cbind(c1,c2)
+            lcoord <- apply(cc, 1, mean)
+            abline(v=lcoord)
+            if (min(di) < 0) {
+                amp <- abs(max(di) - min(di))
+            } else {
+                amp <- max(di)
+            }
+            if (amp < 10) {
+                d <- 2
+            } else {
+                d <- signif(amp%%/%%10,1)
+            }
+            mn <- round(min(di))
+            mx <- round(max(di))
+            for (i in mn:mx) {
+                if ((i/d) == (i%%/%%d)) { 
+                    abline(h=i,lty=3)
+                }
+            }
+            par(mar=c(0,0,0,0))
+            plot(0, axes = FALSE, pch = '')
+            legend(x = 'center' , rownames(di), fill = color)
+            dev.off()
+            """ % (ffr(parametres['rgraph']), parametres['width'], parametres['height'], ffr(parametres['tmpgraph']), parametres['svg'])    
+    else :
+        txt += """
+        load("%s")
+        library(ape)
+        source("%s")
+        width = %i
+        height = %i
+        open_file_graph("%s", width=width, height=height, svg = %s)
+        plot.dendro.lex(tree.cut1$tree.cl, di)
+        """ % (ffr(parametres['tree']), ffr(parametres['rgraph']), parametres['width'], parametres['height'], ffr(parametres['tmpgraph']), parametres['svg'])
     return txt
 
 #def RAfcUci(DictAfcUciOut, nd=2, RscriptsPath='', PARCEX='0.8'):
index 5e58a99..8c30c72 100644 (file)
@@ -20,14 +20,14 @@ import  wx.lib.mixins.listctrl  as  listmix
 #from tabsimi import DoSimi
 from listlex import ListForSpec
 from chemins import ConstructPathOut, ffr
-from dialog import PrefExport, PrefUCECarac, SearchDial, message
+from dialog import PrefExport, PrefUCECarac, SearchDial, message, MessageImage, BarFrame
 from tableau import Tableau
 from search_tools import SearchFrame
 import webbrowser
 #import cStringIO
 import tempfile
 import codecs
-from functions import exec_rcode, MessageImage, progressbar, treat_var_mod, doconcorde
+from functions import exec_rcode, progressbar, treat_var_mod, doconcorde
 from PrintRScript import barplot
 from textclassechd import ClasseCHD
 from shutil import copyfile
@@ -444,18 +444,19 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
                 if word in fchistable :
                     tableout.append(vchistable[fchistable.index(word)])
                     kwords.append(word)
-            tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
-            txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
-            tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
-            file = open(tmpscript,'w')
-            file.write(txt)
-            file.close()
-            exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
-            win = MessageImage(self,u"Graphique", size=(700, 500))
-            win.addsaveimage(tmpgraph)
-            txt = "<img src='%s'>" % tmpgraph
-            win.HtmlPage.SetPage(txt)
-            win.Show(True)
+            BarFrame(self.Source.parent, tableout, title, kwords)
+#             tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
+#             txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
+#             tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
+#             file = open(tmpscript,'w')
+#             file.write(txt)
+#             file.close()
+#             exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
+#             win = MessageImage(self,u"Graphique", size=(700, 500))
+#             win.addsaveimage(tmpgraph)
+#             txt = "<img src='%s'>" % tmpgraph
+#             win.HtmlPage.SetPage(txt)
+#             win.Show(True)
         else :
             dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
             dial.CenterOnParent()
@@ -625,28 +626,29 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
         tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
         nbcl = len(title)
         nbwords = len(words)
-        txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
-        #print 'ATTENTION TEST R'
-        #txt = """
-        #sink('/Users/pierre/Desktop/qdfqsdfqsdfqsdf.txt')
-        #Sys.getlocale()
-        #sink()
-        #"""
-        tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
-        file = open(tmpscript,'w')
-        file.write(txt)
-        file.close()
-        exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
-        w = 100 + (20 * nbwords) + (100 * nbcl)
-        h = 100 + (nbwords * 15)
-        if w > 1100 : w = 1100
-        if h > 800 : h = 800
-        if h < 450 : h = 450
-        win = MessageImage(self, u"Graphique", size=(w, h))
-        win.addsaveimage(tmpgraph)
-        txt = "<img src='%s'>" % tmpgraph
-        win.HtmlPage.SetPage(txt)
-        win.Show(True)
+        BarFrame(self.Source.parent, tableout, title, words)
+#         txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
+#         #print 'ATTENTION TEST R'
+#         #txt = """
+#         #sink('/Users/pierre/Desktop/qdfqsdfqsdfqsdf.txt')
+#         #Sys.getlocale()
+#         #sink()
+#         #"""
+#         tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
+#         file = open(tmpscript,'w')
+#         file.write(txt)
+#         file.close()
+#         exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
+#         w = 100 + (20 * nbwords) + (100 * nbcl)
+#         h = 100 + (nbwords * 15)
+#         if w > 1100 : w = 1100
+#         if h > 800 : h = 800
+#         if h < 450 : h = 450
+#         win = MessageImage(self, u"Graphique", size=(w, h))
+#         win.addsaveimage(tmpgraph)
+#         txt = "<img src='%s'>" % tmpgraph
+#         win.HtmlPage.SetPage(txt)
+#         win.Show(True)
 
     def onlexdendro(self, evt):
         if 'corpus' in dir(self.Source):
@@ -662,35 +664,7 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
         fchistable = [line[0] for line in chistable]
         words = self.getselectedwords()
         tableout = [vchistable[fchistable.index(word)] for word in words]
-        tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
-        txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
-        rownames = 'c("' + '","'.join(words) + '")'
-        colnames = 'c("' + '","'.join(title) + '")'
-        nbcl = len(title)
-        rownb = len(words)
-        txt = """
-        load("%s")
-        di <- matrix(data=%s, nrow=%i, byrow = TRUE)
-        rownames(di)<- %s
-        colnames(di) <- %s
-        library(ape)
-        source("%s")
-        height <- (30*ncol(di)) + (15*nrow(di))
-        height <- ifelse(height <= 400, 400, height)
-        width <- 500
-        open_file_graph("%s", width=width, height=height)
-        plot.dendro.lex(tree.cut1$tree.cl, di)
-        """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
-        tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
-        file = open(tmpscript,'w')
-        file.write(txt)
-        file.close()
-        exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
-        win = MessageImage(self, u"Graphique", size=(700, 500))
-        win.addsaveimage(tmpgraph)
-        txt = "<img src='%s'>" % tmpgraph
-        win.HtmlPage.SetPage(txt)
-        win.Show(True)
+        BarFrame(self.Source.parent, tableout, title, words, tree = self.Source.pathout['Rdendro'])
 
     def make_concord(self, uces, title, color = 'red') :
         corpus = self.Source.corpus
index 4a2140d..42b3d72 100644 (file)
--- a/corpus.py
+++ b/corpus.py
@@ -1200,7 +1200,7 @@ class BuildCorpus :
         self.cf.execute('CREATE INDEX ideff ON eff (id);')
         self.c.close()
         self.cf.close()
-        #backup corpora
+        #backup corpus
         self.conn_corpus = sqlite3.connect(self.corpus.pathout['corpus.db'])
         self.ccorpus = self.conn_corpus.cursor()
         self.ccorpus.execute('CREATE TABLE IF NOT EXISTS etoiles (uci INTEGER, et TEXT, paras TEXT);')
@@ -1428,7 +1428,7 @@ class BuildFromAlceste(BuildCorpus) :
             if iduci != -1  and iduce != -1:
                 self.backup_uce()
             else : 
-                log.info(_(u"No Text in corpora. Are you sure of the formatting ?"))
+                log.info(_(u"No Text in corpus. Are you sure of the formatting ?"))
                 raise Exception('TextBeforeTextMark %i' % linenb)
         except UnicodeDecodeError :
             raise Exception("CorpusEncoding")
index cc1752e..ae59c3b 100755 (executable)
--- a/dialog.py
+++ b/dialog.py
@@ -8,8 +8,11 @@ import  wx.lib.colourselect as csel
 import wx.lib.sized_controls as sc
 import wx.lib.filebrowsebutton as filebrowse
 import locale
-from functions import DoConf
+from functions import DoConf, exec_rcode
 import os
+from shutil import copyfile
+from PrintRScript import barplot
+import tempfile
 import sys
 from KeyFrame import AlcOptFrame
 #---------------------------------------------------------------------------
@@ -913,7 +916,7 @@ class PrefExport(wx.Dialog):
         sizer = wx.BoxSizer(wx.VERTICAL)
         box = wx.BoxSizer(wx.HORIZONTAL)
         box3 = wx.BoxSizer(wx.HORIZONTAL)
-        self.label_lem = wx.StaticText(self, -1, _(u"Lemmatised corpora").decode('utf8'))
+        self.label_lem = wx.StaticText(self, -1, _(u"Lemmatised corpus").decode('utf8'))
         box3.Add(self.label_lem, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, 5)
         self.radio_lem = wx.RadioBox(self, -1, u"", choices= [ _(u"yes").decode('utf8'), _(u"no").decode('utf8') ], majorDimension=0, style=wx.RA_SPECIFY_ROWS)
         box3.Add(self.radio_lem, 0, wx.ALIGN_RIGHT, 5)
@@ -1241,7 +1244,7 @@ class PrefSegProf(wx.Dialog) :
         
         self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
         bSizer1 = wx.BoxSizer( wx.VERTICAL )
-        txt = _(u"Be carefull : computation of repeated segments profiles can be very long on large corpora").decode('utf8')
+        txt = _(u"Be carefull : computation of repeated segments profiles can be very long on large corpus").decode('utf8')
         self.label = wx.StaticText( self, wx.ID_ANY, txt, wx.DefaultPosition, wx.DefaultSize, 0 ) 
         bSizer1.Add( self.label, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5 )
 
@@ -1249,7 +1252,7 @@ class PrefSegProf(wx.Dialog) :
         fgSizer1.SetFlexibleDirection( wx.BOTH )
         fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
         
-        self.m_staticText1 = wx.StaticText( self, wx.ID_ANY, _(u"Lemmatised corpora").decode('utf8'), wx.DefaultPosition, wx.DefaultSize, 0 )
+        self.m_staticText1 = wx.StaticText( self, wx.ID_ANY, _(u"Lemmatised corpus").decode('utf8'), wx.DefaultPosition, wx.DefaultSize, 0 )
         self.m_staticText1.Wrap( -1 )
         fgSizer1.Add( self.m_staticText1, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
         
@@ -2263,7 +2266,7 @@ class CorpusPref ( wx.Dialog ):
         fgSizer1.SetFlexibleDirection( wx.BOTH )
         fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
         
-        self.m_staticText7 = wx.StaticText( self.m_panel1, wx.ID_ANY, _(u"Corpora").decode('utf8'), wx.DefaultPosition, wx.DefaultSize, 0 )
+        self.m_staticText7 = wx.StaticText( self.m_panel1, wx.ID_ANY, _(u"corpus").decode('utf8'), wx.DefaultPosition, wx.DefaultSize, 0 )
         self.m_staticText7.Wrap( -1 )
         fgSizer1.Add( self.m_staticText7, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, 5 )
         
@@ -2557,7 +2560,7 @@ class ConcordList(wx.HtmlListBox):
         #self.Bind(wx.EVT_LISTBOX_DCLICK, self.Download)
   
     def OnGetItem(self, index):
-        return self.concord[index] + '<br>'
+        return self.concord[index] #+ '<br>'
 
 class message(wx.Frame):
     def __init__(self, parent, items, title, size, save = True):
@@ -2628,7 +2631,7 @@ class ExtractDialog ( wx.Dialog ):
         fgSizer1.SetFlexibleDirection( wx.BOTH )
         fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
         
-        self.m_staticText1 = wx.StaticText( self, wx.ID_ANY, _(u"Corpora").decode('utf8'), wx.DefaultPosition, wx.DefaultSize, 0 )
+        self.m_staticText1 = wx.StaticText( self, wx.ID_ANY, _(u"corpus").decode('utf8'), wx.DefaultPosition, wx.DefaultSize, 0 )
         self.m_staticText1.Wrap( -1 )
         fgSizer1.Add( self.m_staticText1, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, 5 )
         
@@ -2991,7 +2994,194 @@ class SubTextFromMetaDial ( wx.Dialog ):
     def __del__( self ):
         pass
 
+class BarGraphDialog ( wx.Dialog ):
+    
+    def __init__( self, parent, width, height ):
+        wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Preferences", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE )
+        
+        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
+        
+        bSizer1 = wx.BoxSizer( wx.VERTICAL )
+        
+        bSizer2 = wx.BoxSizer( wx.HORIZONTAL )
+        
+        self.m_staticText1 = wx.StaticText( self, wx.ID_ANY, u"Size", wx.DefaultPosition, wx.DefaultSize, 0 )
+        self.m_staticText1.Wrap( -1 )
+        bSizer2.Add( self.m_staticText1, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+        
+        sizeradioChoices = [ u"automatic", u"manual" ]
+        self.sizeradio = wx.RadioBox( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, sizeradioChoices, 1, wx.RA_SPECIFY_COLS )
+        self.sizeradio.SetSelection( 0 )
+        bSizer2.Add( self.sizeradio, 0, wx.ALIGN_TOP|wx.ALL, 5 )
+        
+        fgSizer1 = wx.FlexGridSizer( 0, 2, 0, 0 )
+        fgSizer1.SetFlexibleDirection( wx.BOTH )
+        fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
+        
+        self.m_staticText2 = wx.StaticText( self, wx.ID_ANY, u"width", wx.DefaultPosition, wx.DefaultSize, 0 )
+        self.m_staticText2.Wrap( -1 )
+        fgSizer1.Add( self.m_staticText2, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+        
+        self.widthsp = wx.SpinCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.SP_ARROW_KEYS, 0, 1000000, 600 )
+        fgSizer1.Add( self.widthsp, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+        
+        self.m_staticText3 = wx.StaticText( self, wx.ID_ANY, u"height", wx.DefaultPosition, wx.DefaultSize, 0 )
+        self.m_staticText3.Wrap( -1 )
+        fgSizer1.Add( self.m_staticText3, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+        
+        self.heightsp = wx.SpinCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.SP_ARROW_KEYS, 1, 10000000, 400 )
+        fgSizer1.Add( self.heightsp, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+        
+        
+        bSizer2.Add( fgSizer1, 1, wx.EXPAND, 5 )
+        
+        
+        bSizer1.Add( bSizer2, 1, wx.EXPAND, 5 )
+        
+        bSizer3 = wx.BoxSizer( wx.HORIZONTAL )
+        
+        self.m_staticText4 = wx.StaticText( self, wx.ID_ANY, u"Image format", wx.DefaultPosition, wx.DefaultSize, 0 )
+        self.m_staticText4.Wrap( -1 )
+        bSizer3.Add( self.m_staticText4, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+        
+        formatChoices = [ u"png", u"svg" ]
+        self.format = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, formatChoices, 0 )
+        self.format.SetSelection( 0 )
+        bSizer3.Add( self.format, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+        
+        
+        bSizer1.Add( bSizer3, 1, wx.EXPAND, 5 )
+        
+        m_sdbSizer1 = wx.StdDialogButtonSizer()
+        self.m_sdbSizer1OK = wx.Button( self, wx.ID_OK )
+        m_sdbSizer1.AddButton( self.m_sdbSizer1OK )
+        self.m_sdbSizer1Cancel = wx.Button( self, wx.ID_CANCEL )
+        m_sdbSizer1.AddButton( self.m_sdbSizer1Cancel )
+        m_sdbSizer1.Realize();
+        
+        bSizer1.Add( m_sdbSizer1, 0, wx.EXPAND, 5 )
+        
+        
+        self.SetSizer( bSizer1 )
+        self.Layout()
+        bSizer1.Fit( self )
+        
+        self.Centre( wx.BOTH )
+        
+        # Connect Events
+        self.sizeradio.Bind( wx.EVT_RADIOBOX, self.OnSizeRadio )
+        
+        self.widthsp.SetValue(width)
+        self.heightsp.SetValue(height)
+        self.widthsp.Enable(False)
+        self.heightsp.Enable(False)
+        self.m_sdbSizer1OK.SetFocus()
+    
+    def __del__( self ):
+        pass
+    
+    
+    # Virtual event handlers, overide them in your derived class
+    def OnSizeRadio( self, event ):
+        if self.sizeradio.GetSelection() == 0 :
+            self.widthsp.Enable(False)
+            self.heightsp.Enable(False)
+        else :
+            self.widthsp.Enable(True)
+            self.heightsp.Enable(True)         
+        event.Skip()
 
+class MessageImage(wx.Frame):
+    def __init__(self, parent, parametres, title, size):
+        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = title, pos = wx.DefaultPosition, size = size, style = wx.DEFAULT_FRAME_STYLE )
+        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
+        self.parametres = parametres
+        self.imageFile = self.parametres['tmpgraph']
+        if parametres['svg'] == 'TRUE' :
+            self.imagename = u"image.svg"
+        else :
+            self.imagename = u"iamge.png"
+        self.HtmlPage = wx.html.HtmlWindow(self, -1)
+        self.HtmlPage.SetMinSize(size)
+        if "gtk2" in wx.PlatformInfo:
+            self.HtmlPage.SetStandardFonts()
+        self.HtmlPage.SetFonts('Courier', 'Courier')
+        
+        self.button_1 = wx.Button(self, wx.ID_CANCEL)
+        self.button_2 = wx.Button(self, wx.ID_SAVE)
+        self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
+        self.Bind(wx.EVT_BUTTON, self.OnSaveImage, self.button_2)
+        self.do_layout()
+
+    def do_layout(self):
+        self.sizer_1 = wx.BoxSizer(wx.VERTICAL)
+        self.sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
+        self.sizer_1.Add(self.HtmlPage, 2, wx.EXPAND, 0)
+
+        self.m_sdbSizer1 = wx.StdDialogButtonSizer()
+        self.m_sdbSizer1.AddButton(  self.button_2 )
+        self.m_sdbSizer1.AddButton(  self.button_1 )
+        self.m_sdbSizer1.Realize()
+        self.sizer_1.Add(self.m_sdbSizer1, 0, wx.EXPAND, 5)
+        self.SetSizer(self.sizer_1)
+        self.Layout()
+        self.sizer_1.Fit( self )
 
+    def OnCloseMe(self, event):
+        self.Destroy()
 
-
+    def OnSaveImage(self, event) :
+        dlg = wx.FileDialog(
+            self, message="Enregistrer sous...", defaultDir=os.getcwd(),
+            defaultFile= self.imagename, wildcard=self.parametres['wildcard'], style=wx.SAVE | wx.OVERWRITE_PROMPT
+            )
+        dlg.SetFilterIndex(2)
+        dlg.CenterOnParent()
+        if dlg.ShowModal() == wx.ID_OK:
+            path = dlg.GetPath()
+            copyfile(self.imageFile, path)
+
+class BarFrame :
+    def __init__(self, ira, table, colnames, rownames, tree = False):
+        if not tree :
+            width = 100 + (10*len(rownames)) + (100 * len(colnames))
+            height = len(rownames) * 15
+            if height < 400 : 
+                height = 400
+        else :
+            width = 500
+            height = (35 * len(colnames)) + (15 * len(rownames))
+        dial = BarGraphDialog(ira, width, height)
+        val = dial.ShowModal()
+        if val == wx.ID_OK :
+            tmpgraph = tempfile.mktemp(dir=ira.TEMPDIR)        
+            if dial.format.GetSelection() == 0 :
+                svg = 'FALSE'
+                wildcard = "png|*.png"
+            else :
+                svg = 'TRUE'
+                wildcard = "svg|*.svg"
+            parametres = {'width' : dial.widthsp.GetValue(),
+                          'height': dial.heightsp.GetValue(),
+                          'colnames' : colnames,
+                          'rownames' : rownames,
+                          'tmpgraph' : tmpgraph,
+                          'rgraph' : ira.RscriptsPath['Rgraph'],
+                          'svg' : svg,
+                          'wildcard' : wildcard}
+            if tree :
+                parametres['tree'] = tree
+            txt = barplot(table, parametres)
+            tmpscript = tempfile.mktemp(dir=ira.TEMPDIR)
+            with open(tmpscript,'w') as f :
+                f.write(txt)
+            exec_rcode(ira.RPath, tmpscript, wait = True)
+            win = MessageImage(ira, parametres, u"Graphique", size=(700, 500))
+            if svg == 'FALSE' :
+                txt = "<img src='%s'>" % tmpgraph
+            else :
+                txt = """Copiez ce lien dans votre navigateur : <br>
+                        <a href="%s">%s</a>""" % (tmpgraph, tmpgraph)
+            win.HtmlPage.SetPage(txt)
+            win.Show(True)
+        dial.Destroy()           
\ No newline at end of file
index cef90ca..884e62f 100644 (file)
@@ -73,7 +73,7 @@ class History :
     def __init__(self, filein, syscoding = 'utf8') :
         self.filein = filein
         self.syscoding = syscoding
-        self.corpora = {}
+        self.corpus = {}
         self.openedcorpus = {}
         self.openedmatrix = {}
         self.orph = []
@@ -102,6 +102,9 @@ class History :
     def add(self, analyse) :
         log.info('add to history %s' % analyse.get('corpus_name', 'pas un corpus'))
         tosave = {'uuid' : analyse['uuid'], 'ira': analyse['ira'], 'type' : analyse['type']}
+        if tosave['uuid'] in self.corpus :
+            log.info('problem : this uuid is already in history : %s' % tosave['uuid'])
+            return
         if analyse.get('corpus', False) :
             if analyse['uuid'] in self.analyses :
                 return
@@ -117,6 +120,8 @@ class History :
                 self.orph.append(tosave)
         else :
             tosave['corpus_name'] = analyse['corpus_name']
+            #self.ordercorpus[tosave['uuid']] = len(history)
+            #self.corpus[tosave['uuid']] = analyse
             self.history.append(tosave)
         self.write()
         self.read()
@@ -158,6 +163,7 @@ class History :
             self.history.pop(self.ordercorpus[analyse['uuid']])
             if analyse['uuid'] in self.openedcorpus :
                 del self.openedcorpus[analyse['uuid']]
+            log.info('delete corpus : %s' % analyse['uuid'])
         elif analyse['uuid'] in self.analyses :
             todel = [i for i, ana in enumerate(self.corpus[analyse['corpus']]['analyses']) if ana['uuid'] == analyse['uuid']][0]
             self.history[self.ordercorpus[analyse['corpus']]]['analyses'].pop(todel)
@@ -660,54 +666,7 @@ def read_list_file(filename, encoding = sys.getdefaultencoding()):
         ncontent=[line.replace('\n','').split(';') for line in content if line.strip() != '']
     return ncontent
         
-class MessageImage(wx.Frame):
-    def __init__(self, parent,title, size):
-        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = title, pos = wx.DefaultPosition, size = size, style = wx.DEFAULT_FRAME_STYLE )
-        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
-        self.imageFile = False
-        self.imagename = u"chi_classe.png"
-        self.HtmlPage = wx.html.HtmlWindow(self, -1)
-        self.HtmlPage.SetMinSize(size)
-        if "gtk2" in wx.PlatformInfo:
-            self.HtmlPage.SetStandardFonts()
-        self.HtmlPage.SetFonts('Courier', 'Courier')
-        
-        self.button_1 = wx.Button(self, wx.ID_CANCEL)
-        self.button_2 = wx.Button(self, wx.ID_SAVE)
-        self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
-        self.Bind(wx.EVT_BUTTON, self.OnSaveImage, self.button_2)
-        self.do_layout()
-
-    def do_layout(self):
-        self.sizer_1 = wx.BoxSizer(wx.VERTICAL)
-        self.sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
-        self.sizer_1.Add(self.HtmlPage, 2, wx.EXPAND, 0)
-
-        self.m_sdbSizer1 = wx.StdDialogButtonSizer()
-        self.m_sdbSizer1.AddButton(  self.button_2 )
-        self.m_sdbSizer1.AddButton(  self.button_1 )
-        self.m_sdbSizer1.Realize()
-        self.sizer_1.Add(self.m_sdbSizer1, 0, wx.EXPAND, 5)
-        self.SetSizer(self.sizer_1)
-        self.Layout()
-        self.sizer_1.Fit( self )
 
-    def addsaveimage(self, imageFile) :
-        self.imageFile = imageFile
-        
-    def OnCloseMe(self, event):
-        self.Destroy()
-
-    def OnSaveImage(self, event) :
-        dlg = wx.FileDialog(
-            self, message="Enregistrer sous...", defaultDir=os.getcwd(),
-            defaultFile= self.imagename, wildcard="png|*.png", style=wx.SAVE | wx.OVERWRITE_PROMPT
-            )
-        dlg.SetFilterIndex(2)
-        dlg.CenterOnParent()
-        if dlg.ShowModal() == wx.ID_OK:
-            path = dlg.GetPath()
-            copyfile(self.imageFile, path)
             
 
 def progressbar(self, maxi) :
index bc55fc2..675a9c9 100644 (file)
@@ -11,7 +11,7 @@ import glob
 
 
 
-#infiledir = '/home/pierre/TXM/corpora/voeux-bin/txm/VOEUX/'
+#infiledir = '/home/pierre/TXM/corpus/voeux-bin/txm/VOEUX/'
 #fileout = 'VOEUXExportfromTXM.txt'
 
 
index 1b6a1e4..c848364 100644 (file)
@@ -191,7 +191,7 @@ class IraFrame(wx.Frame):
         item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
         file_menu.AppendItem(item)
         
-        item = wx.MenuItem(file_menu, ID_OpenText, _(u"Open a text corpora").decode('utf8'), _(u"Open a text corpora").decode('utf8'))
+        item = wx.MenuItem(file_menu, ID_OpenText, _(u"Open a text corpus").decode('utf8'), _(u"Open a text corpus").decode('utf8'))
         item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
         file_menu.AppendItem(item)
         
@@ -598,6 +598,7 @@ vous devez signaler le chemin de l'éxecutable de R dans les préférences."""
         del busy
         if builder.res == wx.ID_OK :
             corpus = builder.doanalyse()
+            print corpus.parametres['uuid']
             self.history.add(corpus.parametres)
             self.tree.OnItemAppend(corpus.parametres)
             OpenAnalyse(self, corpus.parametres)
index 5f22405..e0c7173 100644 (file)
@@ -18,10 +18,10 @@ import  wx
 import  wx.lib.mixins.listctrl  as  listmix
 import cStringIO
 import tempfile
-from functions import exec_rcode, MessageImage, doconcorde
+from functions import exec_rcode, doconcorde
 from chemins import ffr
 from PrintRScript import barplot
-from dialog import SearchDial, message
+from dialog import SearchDial, message, BarGraphDialog, MessageImage, BarFrame
 from operator import itemgetter
 #---------------------------------------------------------------------------
 
@@ -230,9 +230,11 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor
         for forme in lems[word].formes :
             rep.append([corpus.getforme(forme).forme, corpus.getforme(forme).freq])
         rep.sort(key = itemgetter(1), reverse = True)
-        win = message(self, u"Formes associées", (300, 200))
-        win.html = '<html>\n' + '<br>'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n</html>'
-        win.HtmlPage.SetPage(win.html)
+        items = dict([[i, '<font face="courier">' + '\t:\t'.join([str(val) for val in forme]) + '</font>'] for i, forme in enumerate(rep)])
+        win = message(self, items, u"Formes associées", (300, 200))
+        #win = message(self, u"Formes associées", (300, 200))
+        #win.html = '<html>\n' + '<br>'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n</html>'
+        #win.HtmlPage.SetPage(win.html)
         win.Show(True)
     
     def onstcaract(self, evt) :
@@ -316,17 +318,7 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor
         colnames = self.first
         table = [[self.getinf(val) for val in line[1:]] for line in datas]
         rownames = [val[0] for val in datas]
-        tmpgraph = tempfile.mktemp(dir=self.parent.TEMPDIR)
-        txt = barplot(table, rownames, colnames, self.parent.RscriptsPath['Rgraph'], tmpgraph)
-        tmpscript = tempfile.mktemp(dir=self.parent.TEMPDIR)
-        with open(tmpscript,'w') as f :
-            f.write(txt)
-        exec_rcode(self.parent.RPath, tmpscript, wait = True)
-        win = MessageImage(self, u"Graphique", size=(700, 500))
-        win.addsaveimage(tmpgraph)
-        txt = "<img src='%s'>" % tmpgraph
-        win.HtmlPage.SetPage(txt)
-        win.Show(True)
+        BarFrame(self.parent, table, colnames, rownames)
 
     def OnTgen_glob(self, evt) :
         activenotebook = self.parent.nb.GetSelection()
index 42d1765..7485984 100644 (file)
@@ -18,10 +18,9 @@ import  wx
 import  wx.lib.mixins.listctrl  as  listmix
 import cStringIO
 import tempfile
-from functions import exec_rcode, MessageImage
-from dialog import message
+from functions import exec_rcode
+from dialog import message, BarFrame
 from chemins import ffr
-from PrintRScript import barplot, dendroandbarplot
 #---------------------------------------------------------------------------
 
 class SearchList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin): #wx.Panel, listmix.ColumnSorterMixin):
@@ -265,17 +264,18 @@ class SearchList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSort
         colnames = self.first[2:]
         rownames = [val[1] for val in datas]
         table = [[str(val) for val in line[2:]] for line in datas]
-        tmpgraph = tempfile.mktemp(dir=self.parent.parent.TEMPDIR)
-        txt =  barplot(table, rownames, colnames, self.parent.parent.RscriptsPath['Rgraph'], tmpgraph)
-        tmpscript = tempfile.mktemp(dir=self.parent.parent.TEMPDIR)
-        with open(tmpscript,'w') as f :
-            f.write(txt)
-        exec_rcode(self.parent.parent.RPath, tmpscript, wait = True)
-        win = MessageImage(self, u"Graphique", size=(700, 500))
-        win.addsaveimage(tmpgraph)
-        txt = "<img src='%s'>" % tmpgraph
-        win.HtmlPage.SetPage(txt)
-        win.Show(True)
+        BarFrame(self.parent.parent, table, colnames, rownames)
+#         tmpgraph = tempfile.mktemp(dir=self.parent.parent.TEMPDIR)
+#         txt =  barplot(table, rownames, colnames, self.parent.parent.RscriptsPath['Rgraph'], tmpgraph)
+#         tmpscript = tempfile.mktemp(dir=self.parent.parent.TEMPDIR)
+#         with open(tmpscript,'w') as f :
+#             f.write(txt)
+#         exec_rcode(self.parent.parent.RPath, tmpscript, wait = True)
+#         win = MessageImage(self, u"Graphique", size=(700, 500))
+#         win.addsaveimage(tmpgraph)
+#         txt = "<img src='%s'>" % tmpgraph
+#         win.HtmlPage.SetPage(txt)
+#         win.Show(True)
 
     def ongraphdendro(self, evt) :
         corpus = self.parent.corpus
@@ -289,13 +289,14 @@ class SearchList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSort
         rownames = [val[1] for val in datas]
         table = [[str(val) for val in line[2:]] for line in datas]
         tmpgraph = tempfile.mktemp(dir=self.parent.parent.TEMPDIR)
-        txt =  dendroandbarplot(table, rownames, colnames, self.parent.parent.RscriptsPath['Rgraph'], tmpgraph, dendro=corpus.dictpathout['Rdendro'])
-        tmpscript = tempfile.mktemp(dir=self.parent.parent.TEMPDIR)
-        with open(tmpscript,'w') as f :
-            f.write(txt)
-        exec_rcode(self.parent.parent.RPath, tmpscript, wait = True)
-        win = MessageImage(self, u"Graphique", size=(700, 500))
-        win.addsaveimage(tmpgraph)
-        txt = "<img src='%s'>" % tmpgraph
-        win.HtmlPage.SetPage(txt)
-        win.Show(True)
+        BarFrame(self.parent.parent, table, colnames, rownames, tree = corpus.dictpathout['Rdendro'])
+#         txt =  dendroandbarplot(table, rownames, colnames, self.parent.parent.RscriptsPath['Rgraph'], tmpgraph, dendro=corpus.dictpathout['Rdendro'])
+#         tmpscript = tempfile.mktemp(dir=self.parent.parent.TEMPDIR)
+#         with open(tmpscript,'w') as f :
+#             f.write(txt)
+#         exec_rcode(self.parent.parent.RPath, tmpscript, wait = True)
+#         win = MessageImage(self, u"Graphique", size=(700, 500))
+#         win.addsaveimage(tmpgraph)
+#         txt = "<img src='%s'>" % tmpgraph
+#         win.HtmlPage.SetPage(txt)
+#         win.Show(True)
index a85866a..fab7c5a 100644 (file)
@@ -6,13 +6,13 @@
 
 from analysetxt import AnalyseText
 from guifunct import getPage, getCorpus, SelectColumn
-from ConfigParser import RawConfigParser
-from functions import sortedby, progressbar, CreateIraFile, exec_rcode, check_Rresult, MessageImage
+#from ConfigParser import RawConfigParser
+from functions import sortedby, progressbar 
 from dialog import StatDialog, PrefWordCloud
 from PrintRScript import WordCloudRScript
 #from ttparser import * 
 import tempfile
-from time import sleep
+#from time import sleep
 import wx
 import os
 import logging
diff --git a/tree.py b/tree.py
index 80515fa..8ebbe2e 100644 (file)
--- a/tree.py
+++ b/tree.py
@@ -159,7 +159,7 @@ class LeftTree(CT.CustomTreeCtrl):
                     else :
                         img = 24
                     self.SetItemImage(last, img, CT.TreeItemIcon_Normal)
-                    self.SetItemImage(last, 13, CT.TreeItemIcon_Expanded)
+                    self.SetItemImage(last, img, CT.TreeItemIcon_Expanded)
 
         self.matroot = self.AppendItem(self.root, u'Matrices')
         self.SetPyData(self.matroot, {'uuid': 'matroot'})
@@ -182,7 +182,7 @@ class LeftTree(CT.CustomTreeCtrl):
                         else :
                             img = 24
                         self.SetItemImage(last, img, CT.TreeItemIcon_Normal)
-                        self.SetItemImage(last, 13, CT.TreeItemIcon_Expanded)
+                        self.SetItemImage(last, img, CT.TreeItemIcon_Expanded)
             else :
                 orphmat.append(matrix)     
 
@@ -394,9 +394,9 @@ class LeftTree(CT.CustomTreeCtrl):
                 simi = menu.Append(wx.ID_ANY, _(u"Similarities analysis").decode('utf8'))
                 wdc = menu.Append(wx.ID_ANY, _(u"Wordcloud").decode('utf8'))
                 subcorpus = wx.Menu()
-                subcorpusfrommeta = subcorpus.Append(wx.ID_ANY, _(u'Sub corpora from metadata').decode('utf8'))
-                subcorpusfromtheme = subcorpus.Append(wx.ID_ANY, _(u'Sub corpora from thematic').decode('utf8'))
-                menu.AppendMenu(-1, _(u"SubCorpora").decode('utf8'), subcorpus)
+                subcorpusfrommeta = subcorpus.Append(wx.ID_ANY, _(u'Sub corpus from metadata').decode('utf8'))
+                subcorpusfromtheme = subcorpus.Append(wx.ID_ANY, _(u'Sub corpus from thematic').decode('utf8'))
+                menu.AppendMenu(-1, _(u"Subcorpus").decode('utf8'), subcorpus)
                 menu.AppendSeparator()
                 self.Bind(wx.EVT_MENU, self.OnReinert, reinert)
                 #self.Bind(wx.EVT_MENU, self.OnPam, pam)
@@ -430,8 +430,8 @@ class LeftTree(CT.CustomTreeCtrl):
     
                 profsr = menu.Append(wx.ID_ANY, _(u"Repeated segments profiles").decode('utf8'))
                 profgram = menu.Append(wx.ID_ANY, _(u"POS profiles").decode('utf8'))
-                export_corpus = menu.Append(wx.ID_ANY, _(u"Export corpora").decode('utf8'))
-                colored = menu.Append(wx.ID_ANY, _(u"Colored corpora").decode('utf8'))
+                export_corpus = menu.Append(wx.ID_ANY, _(u"Export corpus").decode('utf8'))
+                colored = menu.Append(wx.ID_ANY, _(u"Colored corpus").decode('utf8'))
                 navig = menu.Append(wx.ID_ANY, _(u"Navigator").decode('utf8'))
                 statclasse = menu.Append(wx.ID_ANY, _(u"Clusters statistics").decode('utf8'))
                 rapport = menu.Append(wx.ID_ANY, _(u"Report").decode('utf8'))
@@ -578,7 +578,7 @@ class LeftTree(CT.CustomTreeCtrl):
             dlg.Destroy()
 
     def OnColored(self, evt) :
-        dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.html', 'title': _(u"Colored corpora").decode('utf8')})
+        dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.html', 'title': _(u"Colored corpus").decode('utf8')})
         dial.fbb.SetValue(os.path.join(os.path.dirname(self.page.dictpathout['ira']), 'corpus_couleur.html'))
         dial.CenterOnParent()
         res = dial.ShowModal()
@@ -928,7 +928,7 @@ class LeftTree(CT.CustomTreeCtrl):
         else :
             img = 24
         self.SetItemImage(child, img, CT.TreeItemIcon_Normal)
-        self.SetItemImage(child, 13, CT.TreeItemIcon_Expanded)
+        self.SetItemImage(child, img, CT.TreeItemIcon_Expanded)
         self.SetItemBold(child, True)
         
         #dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', 'Python')