X-Git-Url: http://iramuteq.org/git?a=blobdiff_plain;f=listlex.py;h=285745aa7d31dadbb5292be6f0b9e45b98cbba15;hb=00cb7159f4b39c7640aaf13f10570f31c2601ba6;hp=7664614cfb98dc20a3e0dcec14394015007bd31b;hpb=6919f2ef8d85c176c7be824b606c4b71142e10fd;p=iramuteq
diff --git a/listlex.py b/listlex.py
index 7664614..285745a 100644
--- a/listlex.py
+++ b/listlex.py
@@ -16,17 +16,16 @@ import os
import sys
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, BarFrame
from operator import itemgetter
#---------------------------------------------------------------------------
class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin):
- def __init__(self, parent,gparent, dlist = {}, first = [], menu = True):
+ def __init__(self, parent,gparent, dlist = {}, first = [], usefirst = False, menu = True):
#def __init__(self, parent) :
wx.ListCtrl.__init__( self, parent, -1, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES)
self.parent=parent
@@ -34,7 +33,8 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor
self.dlist=dlist
self.first = first
self.tgen = False
- if 'etoiles' in dir(self.gparent) :
+ self.tgenlem = False
+ if 'etoiles' in dir(self.gparent) and not usefirst :
self.etoiles = self.gparent.etoiles
else :
self.etoiles = []
@@ -42,7 +42,6 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor
if val.startswith(u'X.') :
val = val.replace(u'X.', u'*')
self.etoiles.append(val)
-
self.menu = menu
#def start(self) :
@@ -69,14 +68,14 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor
self.selected = {}
i=0
- for name in [u'formes'] + self.first :
+ for name in [u'formes'] + self.etoiles :
self.InsertColumn(i,name,wx.LIST_FORMAT_LEFT)
i+=1
self.SetColumnWidth(0, 180)
- for i in range(0,len(self.first)):
- self.SetColumnWidth(i + 1, self.checkcolumnwidth(len(self.first[i]) * 10))
+ for i in range(0,len(self.etoiles)):
+ self.SetColumnWidth(i + 1, self.checkcolumnwidth(len(self.etoiles[i]) * 10))
self.itemDataMap = self.dlist
self.itemIndexMap = self.dlist.keys()
@@ -186,29 +185,33 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor
self.popup_Tgen_glob = wx.NewId()
self.onmaketgen = wx.NewId()
self.ID_stcaract = wx.NewId()
+ self.id_tgendetails = wx.NewId()
- self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
- self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
- self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
- self.Bind(wx.EVT_MENU, self.OnTgen_glob, id=self.popup_Tgen_glob)
- self.Bind(wx.EVT_MENU, self.OnMakeTgen, id=self.onmaketgen)
+ self.Bind(wx.EVT_MENU, self.OnPopupOne, id = self.popupID1)
+ self.Bind(wx.EVT_MENU, self.OnPopupTwo, id = self.popupID2)
+ self.Bind(wx.EVT_MENU, self.OnPopupThree, id = self.popupID3)
+ self.Bind(wx.EVT_MENU, self.OnTgen_glob, id = self.popup_Tgen_glob)
+ self.Bind(wx.EVT_MENU, self.OnMakeTgen, id = self.onmaketgen)
+ self.Bind(wx.EVT_MENU, self.OnTgenDetails, id = self.id_tgendetails)
#self.Bind(wx.EVT_MENU, self.onstcaract, id = self.ID_stcaract)
# make a menu
menu = wx.Menu()
# add some items
- menu.Append(self.popupID1, u"Formes associées")
- menu.Append(self.popupID2, u"Concordancier")
- menu.Append(self.popupID3, u"Graphique")
+ menu.Append(self.popupID1, _(u"Associated forms").decode('utf8'))
+ menu.Append(self.popupID2, _(u"Concordance").decode('utf8'))
+ menu.Append(self.popupID3, _(u"Graphic").decode('utf8'))
menu_stcaract = wx.Menu()
self.menuid = {}
- for i, et in enumerate(self.etoiles) :
- nid = wx.NewId()
- self.menuid[nid] = i
- menu_stcaract.Append(nid, et)
- self.Bind(wx.EVT_MENU, self.onstcaract, id = nid)
- menu.AppendMenu(-1, u"Segments de texte caractéristiques", menu_stcaract)
- #menu.Append(self.popup_Tgen_glob, "Tgen global")
- menu.Append(self.onmaketgen, "Make Tgen")
+ if not self.tgen :
+ for i, et in enumerate(self.etoiles) :
+ nid = wx.NewId()
+ self.menuid[nid] = i
+ menu_stcaract.Append(nid, et)
+ self.Bind(wx.EVT_MENU, self.onstcaract, id = nid)
+ menu.AppendMenu(-1, _(u"Typical text segments").decode('utf8'), menu_stcaract)
+ menu.Append(self.onmaketgen, _(u"Make Tgen").decode('utf8'))
+ else :
+ menu.Append(self.id_tgendetails, _(u'Tgen details').decode('utf8'))
self.PopupMenu(menu)
menu.Destroy()
@@ -230,9 +233,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 = '\n' + '
'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n'
- win.HtmlPage.SetPage(win.html)
+ items = dict([[i, '' + '\t:\t'.join([str(val) for val in forme]) + ''] for i, forme in enumerate(rep)])
+ win = message(self, items, _(u"Associated forms").decode('utf8'), (300, 200))
+ #win = message(self, u"Formes associées", (300, 200))
+ #win.html = '\n' + '
'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n'
+ #win.HtmlPage.SetPage(win.html)
win.Show(True)
def onstcaract(self, evt) :
@@ -246,15 +251,10 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor
parametres = page.parametres
paneff = self.gparent.ListPanEff
panchi = self.gparent.ListPan
- #etoiles = self.gparent.etoiles
et = self.etoiles[ind]
-
- #if et.startswith(u'X.') :
- # et = et.replace(u'X.', u'*')
uces = corpus.getucesfrometoile(et)
self.la = [panchi.dlist[i][0] for i in range(0, len(panchi.dlist)) if panchi.dlist[i][ind+1] >= minind ]
self.lchi = [panchi.dlist[i][ind+1] for i in range(0, len(panchi.dlist)) if panchi.dlist[i][ind+1] >= minind ]
- #lfreq = [paneff.dlist[i][ind+1] for i in range(0, len(panchi.dlist)) if panchi.dlist[i][ind+1] >= minind ]
if max(self.lchi) == float('inf') :
nchi = []
for val in self.lchi :
@@ -275,9 +275,7 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor
nuces = [val[1] for val in ntab2]
ucis_txt, ucestxt = doconcorde(corpus, nuces, self.la)
items = dict([[i, '
'.join([ucis_txt[i], '
' % ntab2[i][0], ucestxt[i]])] for i in range(0,len(ucestxt))])
- win = message(self, items, u"Segments de texte caractéristiques - %s" % self.first[ind], (900, 600))
- #win.html = '\n' + '
'.join(['
'.join([ucis_txt[i], '' % ntab2[i][0], ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n'
- #win.HtmlPage.SetPage(win.html)
+ win = message(self, items, ' - '.join([_(u"Typical text segments").decode('utf8'), "%s" % self.first[ind]]), (900, 600))
win.Show(True)
def OnPopupTwo(self, event):
@@ -287,15 +285,17 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor
corpus = page.corpus
else :
corpus = self.parent.parent.parent.corpus
- item=self.getColumnText(self.GetFirstSelected(), 0)
- uce_ok = corpus.getlemuces(item)
ira = wx.GetApp().GetTopWindow()
- ucis_txt, ucestxt = doconcorde(corpus, uce_ok, [item])
+ item=self.getColumnText(self.GetFirstSelected(), 0)
+ if not self.tgen :
+ uce_ok = corpus.getlemuces(item)
+ wordlist = [item]
+ else :
+ uce_ok = corpus.gettgenst(self.tgens[item])
+ wordlist = [val for val in self.tgens[item] if val in corpus.lems]
+ ucis_txt, ucestxt = doconcorde(corpus, uce_ok, wordlist)
items = dict([[i, '
'.join([ucis_txt[i], ucestxt[i]])] for i in range(0,len(ucestxt))])
- win = message(ira, items, u"Concordancier - %s" % item, (800, 500))
- #win = message(ira, u"Concordancier", (800, 500))
- #win.html = ('\n%s
' % item) + '
'.join(['
'.join([ucis_txt[i], ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n'
- #win.HtmlPage.SetPage(win.html)
+ win = message(ira, items, ' - '.join([_(u"Concordance").decode('utf8'), "%s" % item]), (800, 500), uceids = uce_ok)
win.Show(True)
def getinf(self, txt) :
@@ -313,20 +313,10 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor
last = self.GetNextSelected(last)
data = self.GetItemData(last)
datas += [data]
- colnames = self.etoiles
+ 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 = "" % tmpgraph
- win.HtmlPage.SetPage(txt)
- win.Show(True)
+ BarFrame(self.parent, table, colnames, rownames)
def OnTgen_glob(self, evt) :
activenotebook = self.parent.nb.GetSelection()
@@ -356,11 +346,58 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor
with open(tmpscript, 'w') as f :
f.write(txt)
exec_rcode(self.parent.RPath, tmpscript, wait = True)
- win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
+ win = MessageImage(self, -1, _(u"Graphic").decode('utf8'), size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
win.addsaveimage(tmpgraph)
txt = "" % tmpgraph
win.HtmlPage.SetPage(txt)
win.Show(True)
+ def OnTgenDetails(self, evt):
+ if 'nb' in dir(self.parent) :
+ activenotebook = self.parent.nb.GetSelection()
+ page = self.parent.nb.GetPage(activenotebook)
+ corpus = page.corpus
+ else :
+ corpus = self.parent.parent.parent.corpus
+ ira = wx.GetApp().GetTopWindow()
+ item=self.getColumnText(self.GetFirstSelected(), 0)
+ wordlist = [val for val in self.tgens[item] if val in corpus.lems]
+ wordlist = dict(zip(wordlist,wordlist))
+ res = dict([[val, self.tgenlem[val]] for val in self.tgenlem if self.tgenlem[val][0] in wordlist])
+ win = ListLexFrame(self, ira, corpus, res, self.etoiles)
+ win.Show()
+
+
def OnMakeTgen(self, evt):
self.parent.tree.OnTgenEditor(self.getselectedwords())
+
+class ListLexFrame ( wx.Frame ):
+
+ def __init__( self, parent, ira, corpus, data, columns ):
+ wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
+
+ self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
+
+ bSizer1 = wx.BoxSizer( wx.VERTICAL )
+
+
+ self.listlex = ListForSpec(self, ira, data, columns)
+ bSizer1.Add( self.listlex, 5, wx.ALL|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()
+
+ self.Centre( wx.BOTH )
+
+ def __del__( self ):
+ pass