X-Git-Url: http://iramuteq.org/git?a=blobdiff_plain;f=listlex.py;h=3a11826cf412c37b9e5329fdeb46d8b848895d3f;hb=a2a0a470ca446cb6cdf9e942d54b6cd2eed306c9;hp=43f4564b81c6bb8960e734fb4f45c42dc7754047;hpb=781cbc21fec22eccd64bf7706aac10a0e2757814;p=iramuteq
diff --git a/listlex.py b/listlex.py
index 43f4564..3a11826 100644
--- a/listlex.py
+++ b/listlex.py
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
+#Author: Pierre Ratinaud
+#Copyright (c) 2008-2020 Pierre Ratinaud
+#modification pour python 3 : Laurent Mérat, 6x7 - mai 2020
+#License: GNU/GPL
#----------------------------------------------------------------------------
-# Author: Pierre Ratinaud
-#
-
#comes from ListCtrl.py from the demo tool of wxPython:
# Author: Robin Dunn & Gary Dumer
#
@@ -12,93 +13,129 @@
# Licence: wxWindows license
#----------------------------------------------------------------------------
+#------------------------------------
+# import des modules python
+#------------------------------------
import os
import sys
-import wx
-import wx.lib.mixins.listctrl as listmix
-import cStringIO
import tempfile
-from functions import exec_rcode, MessageImage
+from operator import itemgetter
+
+import langue
+langue.run()
+
+#------------------------------------
+# import des modules wx
+#------------------------------------
+import wx
+import wx.lib.mixins.listctrl as listmix
+
+#------------------------------------
+# import des fichiers du projet
+#------------------------------------
+from functions import exec_rcode, doconcorde
from chemins import ffr
from PrintRScript import barplot
-from dialog import SearchDial
-#---------------------------------------------------------------------------
+from dialog import SearchDial, message, BarGraphDialog, BarFrame
-#class List(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
-# def __init__(self, parent, ID, pos=wx.DefaultPosition,
-# size=wx.DefaultSize, style=0):
-# wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
-# listmix.ListCtrlAutoWidthMixin.__init__(self)
class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin):
- def __init__(self, parent,gparent, dlist,first):
+
+ def __init__(self, parent,gparent, dlist = {}, first = [], usefirst = False, menu = True):
wx.ListCtrl.__init__( self, parent, -1, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES)
self.parent=parent
self.gparent=gparent
self.dlist=dlist
self.first = first
-
+ self.tgen = False
+ self.tgenlem = False
+ if 'etoiles' in dir(self.gparent) and not usefirst :
+ self.etoiles = self.gparent.etoiles
+ else :
+ self.etoiles = []
+ for val in self.first :
+ if val.startswith('X.') :
+ val = val.replace('X.', '*')
+ self.etoiles.append(val)
+ self.menu = menu
+ #def start(self) :
search_id = wx.NewId()
self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id)])
self.SetAcceleratorTable(self.accel_tbl)
-
self.il = wx.ImageList(16, 16)
a={"sm_up":"GO_UP","sm_dn":"GO_DOWN","w_idx":"WARNING","e_idx":"ERROR","i_idx":"QUESTION"}
- for k,v in a.items():
- s="self.%s= self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_%s,wx.ART_TOOLBAR,(16,16)))" % (k,v)
+ for k,v in list(a.items()):
+ s="self.%s= self.il.Add(wx.ArtProvider.GetBitmap(wx.ART_%s,wx.ART_TOOLBAR,(16,16)))" % (k,v)
exec(s)
self.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
-
tID = wx.NewId()
-
self.attr1 = wx.ListItemAttr()
self.attr1.SetBackgroundColour((230, 230, 230))
self.attr2 = wx.ListItemAttr()
self.attr2.SetBackgroundColour("light blue")
-
- self.dlist = dlist
-
+ self.attrselected = wx.ListItemAttr()
+ self.attrselected.SetBackgroundColour("red")
+ self.selected = {}
i=0
- for name in first :
+ for name in ['formes'] + self.etoiles :
self.InsertColumn(i,name,wx.LIST_FORMAT_LEFT)
i+=1
-
self.SetColumnWidth(0, 180)
-
- for i in range(1,len(first)-1):
- self.SetColumnWidth(i, len(first[i]) * 10)
-
- self.itemDataMap = dlist
- self.itemIndexMap = dlist.keys()
- self.SetItemCount(len(dlist))
-
- #listmix.ListCtrlAutoWidthMixin.__init__(self)
- listmix.ColumnSorterMixin.__init__(self, len(first))
- self.SortListItems(1, 0)
-
-#-----------------------------------------------------------------------------------------
+ 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 = list(self.dlist.keys())
+ self.SetItemCount(len(self.dlist))
+ listmix.ColumnSorterMixin.__init__(self, len(self.first) + 1)
+ self.SortListItems(1, False)
+ #-----------------------------------------------------------------------------------------
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self)
-
+ self.Bind(wx.EVT_LIST_ITEM_ACTIVATED , self.OnPopupTwo, self)
# for wxMSW
self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
-
# for wxGTK
self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
-
#-----------------------------------------------------------------------------------------
-
+
+ def OnGetItemColumnImage(self, item, col):
+ return -1
+
+ def OnGetItemImage(self, item):
+ pass
+
+ def RefreshData(self, data):
+ self.itemDataMap = data
+ self.itemIndexMap = list(data.keys())
+ self.SetItemCount(len(data))
+ self.Refresh()
+
+ def checkcolumnwidth(self, width) :
+ if width < 80 :
+ return 80
+ else :
+ return width
+
def OnGetItemText(self, item, col):
index=self.itemIndexMap[item]
s = self.itemDataMap[index][col]
- return s
+ if isinstance(s, (int, float)):
+ return str(s)
+ else:
+ return s #modification pour python 3
def OnGetItemAttr(self, item):
- if item % 2 :
- return self.attr1
+ index=self.itemIndexMap[item]
+ if self.IsSelected(index) == False :
+ if item % 2 :
+ return self.attr1
+ else :
+ return self.attr2
else :
- return self.attr2
+ return self.attrselected
+ def GetItemByWord(self, word):
+ return [ val for val in self.dlist if self.dlist[val][0] == word ][0]
# Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
def GetListCtrl(self):
@@ -112,12 +149,16 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor
x = event.GetX()
y = event.GetY()
item, flags = self.HitTest((x, y))
-
if flags & wx.LIST_HITTEST_ONITEM:
self.Select(item)
-
event.Skip()
+ def GetString(self, evt):
+ return self.getselectedwords()[0]
+
+ def GetSelections(self):
+ return self.getselectedwords()
+
def getColumnText(self, index, col):
item = self.GetItem(index, col)
return item.GetText()
@@ -127,116 +168,174 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor
s = self.itemDataMap[index]
return s
- def SortItems(self,sorter=cmp):
- items = list(self.itemDataMap.keys())
- items.sort(sorter)
- self.itemIndexMap = items
- # redraw the list
- self.Refresh()
-
+# def SortItems(self,sorter=cmp): # modification pour python 3
+ def SortItems(self, sorter=None):
+ listTemp = sorted(self.itemDataMap.items(),
+ key=lambda x:x[1][self._col], reverse= (self._colSortFlag[self._col]!=True))
+ dlist = dict([[line[0],line[1]] for line in listTemp])
+ self.itemDataMap = dlist
+ self.itemIndexMap = list(dlist.keys())
+ self.Refresh() # redraw the list
+
def OnItemSelected(self, event):
- self.currentItem = event.m_itemIndex
+ self.currentItem = event.GetIndex() #event.m_itemIndex
event.Skip()
def onsearch(self, evt) :
self.dial = SearchDial(self, self, 0, True)
self.dial.CenterOnParent()
- self.dial.ShowModal()
- self.dial.Destroy()
+ self.dial.Show()
+ #self.dial.Destroy()
def OnRightClick(self, event):
-
- # only do this part the first time so the events are only bound once
- if not hasattr(self, "popupID1"):
- self.popupID1 = wx.NewId()
- self.popupID2 = wx.NewId()
- self.popupID3 = wx.NewId()
- self.popup_Tgen_glob = 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)
- # 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, "Graphique")
- #menu.Append(self.popup_Tgen_glob, "Tgen global")
-
- self.PopupMenu(menu)
- menu.Destroy()
-
+ if self.menu :
+ # only do this part the first time so the events are only bound once
+ if not hasattr(self, "popupID1"):
+ self.popupID1 = wx.NewId()
+ self.popupID2 = wx.NewId()
+ self.popupID3 = wx.NewId()
+ self.popup_Tgen_glob = wx.NewId()
+ self.onmaketgen = wx.NewId()
+ self.ID_stcaract = wx.NewId()
+ self.id_tgendetails = wx.NewId()
+ # on attache les événements aux éléments
+ 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, _("Associated forms"))
+ menu.Append(self.popupID2, _("Concordance"))
+ menu.Append(self.popupID3, _("Graphic"))
+ menu_stcaract = wx.Menu()
+ self.menuid = {}
+ 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.Append(-1, _("Typical text segments"), menu_stcaract) #modifié
+ menu.Append(self.onmaketgen, _("Make Tgen"))
+ else :
+ menu.Append(self.id_tgendetails, _('Tgen details'))
+ self.PopupMenu(menu)
+ menu.Destroy()
+
+ def getselectedwords(self) :
+ words = [self.getColumnText(self.GetFirstSelected(), 0)]
+ last = self.GetFirstSelected()
+ while self.GetNextSelected(last) != -1:
+ last = self.GetNextSelected(last)
+ words.append(self.getColumnText(last, 0))
+ return words
def OnPopupOne(self, event):
activenotebook = self.parent.nb.GetSelection()
page = self.parent.nb.GetPage(activenotebook)
corpus = page.corpus
- word = self.getColumnText(self.GetFirstSelected(), 0)
+ word = self.getselectedwords()[0]
lems = corpus.getlems()
rep = []
for forme in lems[word].formes :
- rep.append([corpus.getforme(forme).forme, corpus.getforme(forme).freq])
- win = message(self, -1, u"Formes associées", size=(300, 200), style=wx.DEFAULT_FRAME_STYLE)
- win.html = '\n' + '
'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n'
- win.HtmlPage.SetPage(win.html)
+ rep.append([corpus.getforme(forme).forme, corpus.getforme(forme).freq])
+ rep.sort(key = itemgetter(1), reverse = True)
+ items = dict([[i, '' + '\t:\t'.join([str(val) for val in forme]) + ''] for i, forme in enumerate(rep)])
+ win = message(self, items, _("Associated forms"), (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 OnPopupTwo(self, event):
+ def onstcaract(self, evt) :
+ ind = self.menuid[evt.Id]
+ limite = 50
+ minind = 2
activenotebook = self.parent.nb.GetSelection()
page = self.parent.nb.GetPage(activenotebook)
item=self.getColumnText(self.GetFirstSelected(), 0)
corpus = page.corpus
- win = message(self, -1, u"Concordancier", size=(600, 200),style = wx.DEFAULT_FRAME_STYLE)
- avap=60
- listmot = corpus.getlems()[item].formes
- uce_ok = corpus.getlemuces(item)
- txt = '
score : %.2f |