""" % (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
""" % (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'):
#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
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()
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):
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
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);')
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")
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
#---------------------------------------------------------------------------
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)
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 )
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 )
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 )
#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):
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 )
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
def __init__(self, filein, syscoding = 'utf8') :
self.filein = filein
self.syscoding = syscoding
- self.corpora = {}
+ self.corpus = {}
self.openedcorpus = {}
self.openedmatrix = {}
self.orph = []
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
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()
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)
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) :
-#infiledir = '/home/pierre/TXM/corpora/voeux-bin/txm/VOEUX/'
+#infiledir = '/home/pierre/TXM/corpus/voeux-bin/txm/VOEUX/'
#fileout = 'VOEUXExportfromTXM.txt'
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)
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)
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
#---------------------------------------------------------------------------
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) :
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()
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):
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
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)
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
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'})
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)
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)
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'))
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()
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')