From a503f041dc4947ee21c1d353ddd05ddb13a5e322 Mon Sep 17 00:00:00 2001 From: Pierre Date: Fri, 23 Nov 2012 20:32:48 +0100 Subject: [PATCH] ... x2 --- Liste.py | 161 +++--- PrintRScript.py | 8 +- ProfList.py | 1299 ++++++++++++++++++++++++++++++++++++--------- Rscripts/afc_graph.R | 14 +- app.fil | 81 +-- chemins.py | 2 + configuration/simitxt.cfg | 39 ++ configuration/stat.cfg | 7 + corpusNG.py | 149 ++++-- dialog.py | 83 +-- functions.py | 41 +- guifunct.py | 60 ++- iracmd.py | 89 ++-- iramuteq.py | 78 +-- layout.py | 31 +- listlex.py | 195 +++---- messages.pot | 62 ++- profile_segment.py | 12 +- search_list.py | 111 ++-- textsimi.py | 7 +- textwordcloud.py | 9 +- tree.py | 76 ++- 22 files changed, 1813 insertions(+), 801 deletions(-) create mode 100644 configuration/simitxt.cfg create mode 100644 configuration/stat.cfg diff --git a/Liste.py b/Liste.py index 86ec3bf..1b283f6 100644 --- a/Liste.py +++ b/Liste.py @@ -22,20 +22,21 @@ import cStringIO #--------------------------------------------------------------------------- -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 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 ListPanel(wx.Panel, listmix.ColumnSorterMixin): +class ListPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin): def __init__(self, parent, gparent, dlist): + 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.source = gparent self.dlist = dlist - wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) + #wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) search_id = wx.NewId() self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id) @@ -43,97 +44,119 @@ class ListPanel(wx.Panel, listmix.ColumnSorterMixin): self.SetAcceleratorTable(self.accel_tbl) self.il = wx.ImageList(16, 16) - self.sm_up = self.il.Add(getSmallUpArrowBitmap()) - self.sm_dn = self.il.Add(getSmallDnArrowBitmap()) - + 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) + exec(s) + self.SetImageList(self.il, wx.IMAGE_LIST_SMALL) tID = wx.NewId() - self.list = List(self, tID, - style=wx.LC_REPORT - | wx.BORDER_NONE - | wx.LC_EDIT_LABELS - | wx.LC_SORT_ASCENDING - ) +#----------------------------------------------------------------------------------------- + self.attr1 = wx.ListItemAttr() + self.attr1.SetBackgroundColour((230, 230, 230)) + self.attr2 = wx.ListItemAttr() + self.attr2.SetBackgroundColour("light blue") + + #def PopulateList(self, dlist): + + #self.InsertColumn(0,'id', wx.LIST_FORMAT_LEFT) +# i=1 + self.InsertColumn(0, 'forme', wx.LIST_FORMAT_RIGHT) + self.InsertColumn(1, 'nb', wx.LIST_FORMAT_RIGHT) + self.InsertColumn(2, 'type', wx.LIST_FORMAT_RIGHT) + #self.InsertColumn(3, '', wx.LIST_FORMAT_RIGHT) + + #ct = 0 +# for key, data in dlist.iteritems(): +# ct += 1 +# index = self.InsertStringItem(sys.maxint, data[0]) +# self.SetStringItem(index, 1, `data[1]`) +# self.SetStringItem(index, 2, data[2]) +# self.SetStringItem(index, 3, '') +# self.SetItemData(index, key) - self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL) - self.PopulateList(dlist) + self.SetColumnWidth(0, 150) + self.SetColumnWidth(1, 100) + self.SetColumnWidth(2, 100) + #self.SetColumnWidth(3, wx.LIST_AUTOSIZE) - self.Bind(wx.EVT_SIZE, self.OnSize) + self.itemDataMap = dlist + self.itemIndexMap = dlist.keys() + self.SetItemCount(len(dlist)) + + #self.Bind(wx.EVT_SIZE, self.OnSize) - self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list) - self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick, self.list) + self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self) + self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick, self) # for wxMSW - self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick) + self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick) # for wxGTK - self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick) - self.itemDataMap = dlist + self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick) + #listmix.ListCtrlAutoWidthMixin.__init__(self) listmix.ColumnSorterMixin.__init__(self, 3) self.SortListItems(1, False) - self.do_greyline() -#----------------------------------------------------------------------------------------- - - def PopulateList(self, dlist): - - #self.list.InsertColumn(0,'id', wx.LIST_FORMAT_LEFT) -# i=1 - self.list.InsertColumn(0, 'forme', wx.LIST_FORMAT_RIGHT) - self.list.InsertColumn(1, 'nb', wx.LIST_FORMAT_RIGHT) - self.list.InsertColumn(2, 'type', wx.LIST_FORMAT_RIGHT) - self.list.InsertColumn(3, '', wx.LIST_FORMAT_RIGHT) - - ct = 0 - for key, data in dlist.iteritems(): - ct += 1 - index = self.list.InsertStringItem(sys.maxint, data[0]) - self.list.SetStringItem(index, 1, `data[1]`) - self.list.SetStringItem(index, 2, data[2]) - self.list.SetStringItem(index, 3, '') - self.list.SetItemData(index, key) - - self.list.SetColumnWidth(0, 150) - self.list.SetColumnWidth(1, 100) - self.list.SetColumnWidth(2, 100) - self.list.SetColumnWidth(3, wx.LIST_AUTOSIZE) - - - self.currentItem = 0 - - def do_greyline(self): - for row in xrange(self.list.GetItemCount()): - if row % 2 : - self.list.SetItemBackgroundColour(row, (230, 230, 230)) - else : - self.list.SetItemBackgroundColour(row, wx.WHITE) + #self.do_greyline() + + #self.currentItem = 0 + + def OnGetItemText(self, item, col): + index=self.itemIndexMap[item] + s = self.itemDataMap[index][col] + return s + + def OnGetItemAttr(self, item): + #index=self.itemIndexMap[item] + #genre=self.itemDataMap[index][2] + if item % 2 : + return self.attr1 + else : + return self.attr2 + +# def do_greyline(self): +# for row in xrange(self.GetItemCount()): +# if row % 2 : +# self.SetItemBackgroundColour(row, (230, 230, 230)) +# else : +# self.SetItemBackgroundColour(row, wx.WHITE) def OnColClick(self, event): - self.do_greyline() + pass + #self.do_greyline() # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py def GetListCtrl(self): - return self.list + return self # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py def GetSortImages(self): return (self.sm_dn, self.sm_up) + def SortItems(self,sorter=cmp): + items = list(self.itemDataMap.keys()) + items.sort(sorter) + self.itemIndexMap = items + + # redraw the list + self.Refresh() + def OnRightDown(self, event): x = event.GetX() y = event.GetY() - item, flags = self.list.HitTest((x, y)) + item, flags = self.HitTest((x, y)) if flags & wx.LIST_HITTEST_ONITEM: - self.list.Select(item) + self.Select(item) event.Skip() def getColumnText(self, index, col): - item = self.list.GetItem(index, col) + item = self.GetItem(index, col) return item.GetText() @@ -172,7 +195,7 @@ class ListPanel(wx.Panel, listmix.ColumnSorterMixin): def OnPopupOne(self, event): corpus = self.gparent.corpus - word = self.getColumnText(self.list.GetFirstSelected(), 0) + word = self.getColumnText(self.GetFirstSelected(), 0) lems = corpus.getlems() rep = [] for forme in lems[word].formes : @@ -186,7 +209,7 @@ class ListPanel(wx.Panel, listmix.ColumnSorterMixin): corpus = self.gparent.corpus win = message(self, -1, u"Concordancier", size=(600, 200), style=wx.DEFAULT_FRAME_STYLE) avap = 60 - item = self.getColumnText(self.list.GetFirstSelected(), 0) + item = self.getColumnText(self.GetFirstSelected(), 0) listmot = corpus.getlems()[item].formes #uce_ok = [corpus.formes[corpus.idformes[forme].forme][1] for forme in listmot] uce_ok = corpus.getlemuces(item)#list(set([tuple(val) for line in uce_ok for val in line])) @@ -240,9 +263,9 @@ class ListPanel(wx.Panel, listmix.ColumnSorterMixin): win.HtmlPage.SetPage(txt) win.Show(True) - def OnSize(self, event): - w, h = self.GetClientSizeTuple() - self.list.SetDimensions(0, 0, w, h) +# def OnSize(self, event): +# w, h = self.GetClientSizeTuple() +# self.SetDimensions(0, 0, w, h) class message(wx.Frame): def __init__(self, *args, **kwds): diff --git a/PrintRScript.py b/PrintRScript.py index 7a847a6..45022f3 100644 --- a/PrintRScript.py +++ b/PrintRScript.py @@ -921,11 +921,15 @@ class WordCloudRScript(PrintRScript) : selected.col <- read.table("%s") toprint <- as.matrix(act[selected.col[,1] + 1,]) rownames(toprint) <- rownames(act)[selected.col[,1] + 1] + maxword <- %i + if (nrow(toprint) > maxword) { + toprint <- as.matrix(toprint[order(toprint[,1], decreasing=TRUE),]) + toprint <- as.matrix(toprint[1:maxword,]) + } open_file_graph("%s", width = %i, height = %i) par(bg=rgb%s) wordcloud(row.names(toprint), toprint[,1], scale=c(%f,%f), random.order=FALSE, colors=rgb%s) dev.off() - """ % (ffr(self.analyse.pathout['actives_eff.csv']), ffr(self.analyse.pathout['selected.csv']), - ffr(self.parametres['graphout']), self.parametres['width'], self.parametres['height'], bg_col, self.parametres['maxcex'], self.parametres['mincex'], txt_col) + """ % (ffr(self.analyse.pathout['actives_eff.csv']), ffr(self.analyse.pathout['selected.csv']), self.parametres['maxword'], ffr(self.parametres['graphout']), self.parametres['width'], self.parametres['height'], bg_col, self.parametres['maxcex'], self.parametres['mincex'], txt_col) self.add(txt) self.write() diff --git a/ProfList.py b/ProfList.py index 3e6f150..73f8ff7 100644 --- a/ProfList.py +++ b/ProfList.py @@ -33,188 +33,221 @@ from textclassechd import ClasseCHD from shutil import copyfile #--------------------------------------------------------------------------- +class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin): + def __init__(self, parent, gparent, profclasse, Alceste=False, cl=0): + wx.ListCtrl.__init__( self, parent, -1, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES) -class ProfListctrl(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 ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin): - def __init__(self, parent, gparent, ProfClasse, Alceste=False, cl=0): self.parent = parent - classe = ProfClasse - self.cl = cl - self.Source = gparent - if 'tableau' in dir(self.Source): - self.tableau = self.Source.tableau self.Alceste = Alceste - self.var_mod = {} - + self.Source = gparent + self.cl = cl - wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) - - search_id = wx.NewId() - searchall_id = wx.NewId() - self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id) - self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id) - self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id), - (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)]) - self.SetAcceleratorTable(self.accel_tbl) - - self.il = wx.ImageList(16, 16) -# self.idx1 = self.il.Add(images.getSmilesBitmap()) - self.sm_up = self.il.Add(getSmallUpArrowBitmap()) - self.sm_dn = self.il.Add(getSmallDnArrowBitmap()) - tID = wx.NewId() - - self.list = ProfListctrl(self, tID, - style=wx.LC_REPORT - | wx.BORDER_NONE - | wx.LC_EDIT_LABELS - | wx.LC_SORT_ASCENDING - ) - line1 = classe.pop(0) - limit = 0 - limitsup = 0 - i = 0 - dictdata = {} - classen = [line for line in classe if line[0] != '*' and line[0] != '*****'] - if len(classen) == 0 : - lenact = 0 - lensup = 0 - lenet = 0 - else : - lenact = [i for i,b in enumerate(classe) if b[0] == '*****'] - if lenact == [] : - lensup = 0 - lenact = [i for i,b in enumerate(classe) if b[0] == '*'] - if lenact == [] : - lenact = len(classen) - lenet = 0 - else : - lenact = 0 - lenet = len(classen) - else : - lenact = lenact[0] - lensup = [i for i,b in enumerate(classe[1:]) if b[0] == '*'] - if lensup != [] : - lensup = lensup[0] - lenact - lenet = len(classen) - lensup - else : - lensup == 0 - lenet = len(classen) - debsup = lenact - - self.lenact = lenact - - debet = lenact + lensup + line1 = profclasse.pop(0) + classen = [line for line in profclasse if line[0] != '*' and line[0] != '*****'] + try : + self.lenact = profclasse.index([u'*****', u'*', u'*', u'*', u'*', u'*', '', '']) + profclasse.pop(self.lenact) + except ValueError: + self.lenact = len(profclasse) + try : + self.lensup = profclasse.index([u'*', u'*', u'*', u'*', u'*', u'*', '', '']) + self.lensup = self.lensup - self.lenact + profclasse.pop(self.lensup) + except ValueError: + self.lensup = 0 + self.lenet = len(profclasse) - (self.lenact + self.lensup) + print self.lenact, self.lensup, self.lenet + for i, line in enumerate(classen) : + line[0] = i dictdata = dict(zip([i for i in range(0,len(classen))], classen)) - self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL) - - self.PopulateList(dictdata, debet, debsup, Alceste) - - self.Bind(wx.EVT_SIZE, self.OnSize) - self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick) - self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list) - - # for wxMSW - self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick) - - # for wxGTK - self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick) - self.itemDataMap = dictdata - listmix.ColumnSorterMixin.__init__(self, 8) - self.do_greyline() -#----------------------------------------------------------------------------------------- - def PopulateList(self, dictdata, limit, limitsup, Alceste): - - - # for normal, simple columns, you can add them like this: - self.list.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT) - self.list.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT) - self.list.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT) - self.list.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT) - self.list.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT) - self.list.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT) - self.list.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT) - self.list.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT) - - for key in dictdata : #.iteritems(): - index = self.list.InsertStringItem(sys.maxint, '%4i' % key) - i = 1 - for val in dictdata[key][1:]: - self.list.SetStringItem(index, i, str(dictdata[key][i])) - i += 1 - self.list.SetItemData(index, key) - - self.list.SetColumnWidth(0, 60) - self.list.SetColumnWidth(1, 70) - self.list.SetColumnWidth(2, 80) - self.list.SetColumnWidth(3, 100) - self.list.SetColumnWidth(4, 70) - self.list.SetColumnWidth(5, wx.LIST_AUTOSIZE) - self.list.SetColumnWidth(6, wx.LIST_AUTOSIZE) - self.list.SetColumnWidth(7, wx.LIST_AUTOSIZE) - - # show how to change the colour of a couple items - for i in range(limitsup, limit): - item = self.list.GetItem(i) - item.SetTextColour(wx.RED) - self.list.SetItem(item) - - for i in range(limit, len(dictdata)): - item = self.list.GetItem(i) - item.SetTextColour(wx.BLUE) - self.list.SetItem(item) - if self.lenact != 0 : - self.la = [self.getColumnText(i,6) for i in range(0, self.lenact)] - self.lchi = [float(self.getColumnText(i,4)) for i in range(0, self.lenact)] - self.lfreq = [int(self.getColumnText(i,1)) for i in range(0, self.lenact)] + self.la = [dictdata[i][6] for i in range(0, self.lenact)] + self.lchi = [dictdata[i][4] for i in range(0, self.lenact)] + self.lfreq = [dictdata[i][1] for i in range(0, self.lenact)] else : self.la = [] self.lchi = [] self.lfreq = [] + + #adding some art + 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) + exec(s) + self.SetImageList(self.il, wx.IMAGE_LIST_SMALL) + + #adding some attributes (colourful background for each item rows) + self.attr1 = wx.ListItemAttr() + self.attr1.SetBackgroundColour((220, 220, 220)) + self.attrsg = wx.ListItemAttr() + self.attrsg.SetBackgroundColour((230, 230, 230)) + self.attr2 = wx.ListItemAttr() + self.attr2.SetBackgroundColour((190, 249, 236)) + self.attr2s = wx.ListItemAttr() + self.attr2s.SetBackgroundColour((211, 252, 244)) + self.attr3 = wx.ListItemAttr() + self.attr3.SetBackgroundColour((245, 180, 180)) + self.attr3s = wx.ListItemAttr() + self.attr3s.SetBackgroundColour((245, 190, 190)) + + + self.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT) + self.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT) + self.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT) + self.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT) + self.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT) + self.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT) + self.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT) + self.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT) + - def do_greyline(self): - for row in xrange(self.list.GetItemCount()): - if row % 2 : - self.list.SetItemBackgroundColour(row, (230, 230, 230)) - else : - self.list.SetItemBackgroundColour(row, wx.WHITE) + self.SetColumnWidth(0, 60) + self.SetColumnWidth(1, 70) + self.SetColumnWidth(2, 80) + self.SetColumnWidth(3, 100) + self.SetColumnWidth(4, 70) + self.SetColumnWidth(5, 60) + self.SetColumnWidth(6, 140) + self.SetColumnWidth(7, wx.LIST_AUTOSIZE) + + #These two should probably be passed to init more cleanly + #setting the numbers of items = number of elements in the dictionary + self.itemDataMap = dictdata + self.itemIndexMap = dictdata.keys() + self.SetItemCount(len(dictdata)) + + #mixins + listmix.ListCtrlAutoWidthMixin.__init__(self) + listmix.ColumnSorterMixin.__init__(self, len(classen[0])) + #sort by genre (column 2), A->Z ascending order (1) + self.SortListItems(0, 1) - # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py - def GetListCtrl(self): - return self.list + #events + #self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected) + #self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated) + #self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected) + self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick) - # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py - def GetSortImages(self): - return (self.sm_dn, self.sm_up) + # for wxMSW + self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick) + # for wxGTK + self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick) - def OnRightDown(self, event): - x = event.GetX() - y = event.GetY() - item, flags = self.list.HitTest((x, y)) + #for searching + search_id = wx.NewId() + searchall_id = wx.NewId() + self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id) + self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id) + self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id), + (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)]) + self.SetAcceleratorTable(self.accel_tbl) - if flags & wx.LIST_HITTEST_ONITEM: - self.list.Select(item) + + def OnColClick(self,event): event.Skip() + def OnItemSelected(self, event): + self.currentItem = event.m_itemIndex + print 'OnItemSelected: "%s", "%s", "%s", "%s"\n' % (self.currentItem, self.GetItemText(self.currentItem), self.getColumnText(self.currentItem, 1), self.getColumnText(self.currentItem, 2)) + #self.log.WriteText('OnItemSelected: "%s", "%s", "%s", "%s"\n' % + # (self.currentItem, + # self.GetItemText(self.currentItem), + # self.getColumnText(self.currentItem, 1), + # self.getColumnText(self.currentItem, 2))) + + def OnItemActivated(self, event): + self.currentItem = event.m_itemIndex + print "OnItemActivated: %s\nTopItem: %s\n" % (self.GetItemText(self.currentItem), self.GetTopItem()) + #self.log.WriteText("OnItemActivated: %s\nTopItem: %s\n" % + # (self.GetItemText(self.currentItem), self.GetTopItem())) def getColumnText(self, index, col): - item = self.list.GetItem(index, col) + item = self.GetItem(index, col) return item.GetText() + def OnItemDeselected(self, evt): + pass + #self.log.WriteText("OnItemDeselected: %s" % evt.m_itemIndex) + + + #--------------------------------------------------- + # These methods are callbacks for implementing the + # "virtualness" of the list... + + def OnGetItemText(self, item, col): + index=self.itemIndexMap[item] + s = self.itemDataMap[index][col] + return s + + def OnGetItemImage(self, item): + index=self.itemIndexMap[item] + genre=self.itemDataMap[index][2] + + if genre=="Rock": + return self.w_idx + elif genre=="Jazz": + return self.e_idx + elif genre=="New Age": + return self.i_idx + else: + return -1 + + def OnGetItemAttr(self, item): + index=self.itemIndexMap[item] + #genre=self.itemDataMap[index][2] + if index < self.lenact : + if item % 2 : + return self.attr1 + else : + return self.attrsg + elif index >= self.lenact and index < (self.lenact + self.lensup) : + if item % 2 : + return self.attr2 + else : + return self.attr2s + elif index >= (self.lenact + self.lensup) : + if item % 2 : + return self.attr3 + else : + return self.attr3s + else : + return None + +# if genre=="Rock": +# return self.attr2 +# elif genre=="Jazz": +# return self.attr1 +# elif genre=="New Age": +# return self.attr3 +# else: +# return None + + #--------------------------------------------------- + # Matt C, 2006/02/22 + # Here's a better SortItems() method -- + # the ColumnSorterMixin.__ColumnSorter() method already handles the ascending/descending, + # and it knows to sort on another column if the chosen columns have the same value. + + def SortItems(self,sorter=cmp): + items = list(self.itemDataMap.keys()) + items.sort(sorter) + self.itemIndexMap = items + + # redraw the list + self.Refresh() - def OnItemSelected(self, event): - self.currentItem = event.m_itemIndex - event.Skip() + # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py + def GetListCtrl(self): + return self + + # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py + def GetSortImages(self): + return (self.sm_dn, self.sm_up) def onsearch(self, evt) : self.dial = SearchDial(self, self, 6, True) @@ -275,8 +308,8 @@ class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin): self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe) self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro) self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport) - # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes) - # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3) + # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes) + # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3) # make a menu menu = wx.Menu() @@ -350,7 +383,7 @@ class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin): chistable.pop(0) vchistable = [line[1:] for line in chistable] fchistable = [line[0] for line in chistable] - word = self.getColumnText(self.list.GetFirstSelected(), 6) + word = self.getColumnText(self.GetFirstSelected(), 6) if len(word.split('_')) > 1 : var = word.split('_')[0] words = [word for word in self.var_mod[var]] @@ -434,7 +467,7 @@ class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin): DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act) def onwordgraph(self, evt): - word = self.getColumnText(self.list.GetFirstSelected(), 6) + word = self.getColumnText(self.GetFirstSelected(), 6) dlg = progressbar(self, 2) corpus = self.Source.corpus uces = corpus.lc[self.cl-1] @@ -483,27 +516,6 @@ class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin): self.tableau.actives[val] = [self.lfreq[i]] DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word) - - def OnPopupOne(self, event): - corpus = self.Source.corpus - #print 'ATTENTION PRINT ET TABLE' - #corpus.make_et_table() - word = self.getColumnText(self.list.GetFirstSelected(), 6) - lems = corpus.getlems() - uces = corpus.lc[self.cl-1] - rep = [] - #FIXME : donner aussi eff reel a la place de nb uce - for forme in lems[word].formes : - ucef = list(set(corpus.getworduces(forme)).intersection(uces)) - #ucef = [uce for uce in corpus.formes[forme][1] if uce in uces] - if ucef != [] : - nb = len(ucef) - rep.append([corpus.getforme(forme).forme, nb]) - 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) - win.Show(True) - def on_graph(self, evt): dlg = progressbar(self, 2) corpus = self.Source.corpus @@ -638,11 +650,11 @@ class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin): chistable.pop(0) vchistable = [line[1:] for line in chistable] fchistable = [line[0] for line in chistable] - words = [self.getColumnText(self.list.GetFirstSelected(), 6)] + words = [self.getColumnText(self.GetFirstSelected(), 6)] tableout = [vchistable[fchistable.index(words[0])]] - last = self.list.GetFirstSelected() - while self.list.GetNextSelected(last) != -1: - last = self.list.GetNextSelected(last) + last = self.GetFirstSelected() + while self.GetNextSelected(last) != -1: + last = self.GetNextSelected(last) word = self.getColumnText(last, 6) words.append(word) tableout.append(vchistable[fchistable.index(word)]) @@ -673,11 +685,11 @@ class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin): chistable.pop(0) vchistable = [line[1:] for line in chistable] fchistable = [line[0] for line in chistable] - words = [self.getColumnText(self.list.GetFirstSelected(), 6)] + words = [self.getColumnText(self.GetFirstSelected(), 6)] tableout = [vchistable[fchistable.index(words[0])]] - last = self.list.GetFirstSelected() - while self.list.GetNextSelected(last) != -1: - last = self.list.GetNextSelected(last) + last = self.GetFirstSelected() + while self.GetNextSelected(last) != -1: + last = self.GetNextSelected(last) word = self.getColumnText(last, 6) words.append(word) tableout.append(vchistable[fchistable.index(word)]) @@ -714,10 +726,10 @@ class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin): def make_concord(self, uces, title, color = 'red') : corpus = self.Source.corpus - ListWord = [self.getColumnText(self.list.GetFirstSelected(), 6)] - last = self.list.GetFirstSelected() - while self.list.GetNextSelected(last) != -1: - last = self.list.GetNextSelected(last) + ListWord = [self.getColumnText(self.GetFirstSelected(), 6)] + last = self.GetFirstSelected() + while self.GetNextSelected(last) != -1: + last = self.GetNextSelected(last) ListWord.append(self.getColumnText(last, 6)) listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes] win = message(self, -1, title, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE) @@ -760,68 +772,825 @@ class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin): win.Show(True) def OnPopupFive(self, event): - word = self.getColumnText(self.list.GetFirstSelected(), 6) + word = self.getColumnText(self.GetFirstSelected(), 6) lk = "http://www.cnrtl.fr/definition/" + word webbrowser.open(lk) def OnPopupSix(self, event): - word = self.getColumnText(self.list.GetFirstSelected(), 6) + word = self.getColumnText(self.GetFirstSelected(), 6) lk = "http://www.cnrtl.fr/etymologie/" + word webbrowser.open(lk) def OnPopupSeven(self, event): - word = self.getColumnText(self.list.GetFirstSelected(), 6) + word = self.getColumnText(self.GetFirstSelected(), 6) lk = "http://www.cnrtl.fr/synonymie/" + word webbrowser.open(lk) def OnPopupHeight(self, event): - word = self.getColumnText(self.list.GetFirstSelected(), 6) + word = self.getColumnText(self.GetFirstSelected(), 6) lk = "http://www.cnrtl.fr/antonymie/" + word webbrowser.open(lk) def OnPopupNine(self, event): - word = self.getColumnText(self.list.GetFirstSelected(), 6) + word = self.getColumnText(self.GetFirstSelected(), 6) lk = "http://www.cnrtl.fr/morphologie/" + word webbrowser.open(lk) def onproxe(self, evt) : - word = self.getColumnText(self.list.GetFirstSelected(), 6) + word = self.getColumnText(self.GetFirstSelected(), 6) lk = "http://www.cnrtl.fr/proxemie/" + word webbrowser.open(lk) +# - def OnSize(self, event): - w, h = self.GetClientSizeTuple() - self.list.SetDimensions(0, 0, w, h) - - def OnColClick(self, event): - self.do_greyline() - - -class wliste(wx.Frame): - def __init__(self, parent, id, title, d, fline, size=(600, 500)): - wx.Frame.__init__(self, parent, id) - self.liste = ListForSpec(self, parent, d, fline) - self.button_1 = wx.Button(self, -1, "Fermer") - self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1) - self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) - self.__do_layout() - - def __do_layout(self): - sizer_1 = wx.BoxSizer(wx.VERTICAL) - sizer_2 = wx.BoxSizer(wx.VERTICAL) - sizer_2.Add(self.liste, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) - sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, 0) - sizer_1.Add(sizer_2, 1, wx.EXPAND, 0) - self.SetAutoLayout(True) - self.SetSizer(sizer_1) - self.Layout() - - def OnCloseMe(self, event): - self.Close(True) - - def OnCloseWindow(self, event): - self.Destroy() - +#--------------------------------------------------------------------------- +#class ProfListctrl(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 ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin): +# def __init__(self, parent, gparent, ProfClasse, Alceste=False, cl=0): +# self.parent = parent +# classe = ProfClasse +# self.cl = cl +# self.Source = gparent +# if 'tableau' in dir(self.Source): +# self.tableau = self.Source.tableau +# self.Alceste = Alceste +# self.var_mod = {} +# +# +# wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) +# +# search_id = wx.NewId() +# searchall_id = wx.NewId() +# self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id) +# self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id) +# self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id), +# (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)]) +# self.SetAcceleratorTable(self.accel_tbl) +# +# self.il = wx.ImageList(16, 16) +## self.idx1 = self.il.Add(images.getSmilesBitmap()) +# self.sm_up = self.il.Add(getSmallUpArrowBitmap()) +# self.sm_dn = self.il.Add(getSmallDnArrowBitmap()) +# tID = wx.NewId() +# +# self.list = ProfListctrl(self, tID, +# style=wx.LC_REPORT +# | wx.BORDER_NONE +# | wx.LC_EDIT_LABELS +# | wx.LC_SORT_ASCENDING +# ) +# line1 = classe.pop(0) +# limit = 0 +# limitsup = 0 +# i = 0 +# dictdata = {} +# classen = [line for line in classe if line[0] != '*' and line[0] != '*****'] +# if len(classen) == 0 : +# lenact = 0 +# lensup = 0 +# lenet = 0 +# else : +# lenact = [i for i,b in enumerate(classe) if b[0] == '*****'] +# if lenact == [] : +# lensup = 0 +# lenact = [i for i,b in enumerate(classe) if b[0] == '*'] +# if lenact == [] : +# lenact = len(classen) +# lenet = 0 +# else : +# lenact = 0 +# lenet = len(classen) +# else : +# lenact = lenact[0] +# lensup = [i for i,b in enumerate(classe[1:]) if b[0] == '*'] +# if lensup != [] : +# lensup = lensup[0] - lenact +# lenet = len(classen) - lensup +# else : +# lensup == 0 +# lenet = len(classen) +# debsup = lenact +# +# self.lenact = lenact +# +# debet = lenact + lensup +# dictdata = dict(zip([i for i in range(0,len(classen))], classen)) +# self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL) +# +# self.PopulateList(dictdata, debet, debsup, Alceste) +# +# self.Bind(wx.EVT_SIZE, self.OnSize) +# self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick) +# self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list) +# +# # for wxMSW +# self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick) +# +# # for wxGTK +# self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick) +# self.itemDataMap = dictdata +# listmix.ColumnSorterMixin.__init__(self, 8) +# self.do_greyline() +##----------------------------------------------------------------------------------------- +# +# def PopulateList(self, dictdata, limit, limitsup, Alceste): +# +# +# # for normal, simple columns, you can add them like this: +# self.list.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT) +# self.list.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT) +# self.list.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT) +# self.list.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT) +# self.list.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT) +# self.list.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT) +# self.list.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT) +# self.list.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT) +# +# for key in dictdata : #.iteritems(): +# index = self.list.InsertStringItem(sys.maxint, '%4i' % key) +# i = 1 +# for val in dictdata[key][1:]: +# self.list.SetStringItem(index, i, str(dictdata[key][i])) +# i += 1 +# self.list.SetItemData(index, key) +# +# self.list.SetColumnWidth(0, 60) +# self.list.SetColumnWidth(1, 70) +# self.list.SetColumnWidth(2, 80) +# self.list.SetColumnWidth(3, 100) +# self.list.SetColumnWidth(4, 70) +# self.list.SetColumnWidth(5, wx.LIST_AUTOSIZE) +# self.list.SetColumnWidth(6, wx.LIST_AUTOSIZE) +# self.list.SetColumnWidth(7, wx.LIST_AUTOSIZE) +# +# # show how to change the colour of a couple items +# for i in range(limitsup, limit): +# item = self.list.GetItem(i) +# item.SetTextColour(wx.RED) +# self.list.SetItem(item) +# +# for i in range(limit, len(dictdata)): +# item = self.list.GetItem(i) +# item.SetTextColour(wx.BLUE) +# self.list.SetItem(item) +# +# if self.lenact != 0 : +# self.la = [self.getColumnText(i,6) for i in range(0, self.lenact)] +# self.lchi = [float(self.getColumnText(i,4)) for i in range(0, self.lenact)] +# self.lfreq = [int(self.getColumnText(i,1)) for i in range(0, self.lenact)] +# else : +# self.la = [] +# self.lchi = [] +# self.lfreq = [] +# +# def do_greyline(self): +# for row in xrange(self.list.GetItemCount()): +# if row % 2 : +# self.list.SetItemBackgroundColour(row, (230, 230, 230)) +# else : +# self.list.SetItemBackgroundColour(row, wx.WHITE) +# +# +# # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py +# def GetListCtrl(self): +# return self.list +# +# # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py +# def GetSortImages(self): +# return (self.sm_dn, self.sm_up) +# +# +# def OnRightDown(self, event): +# x = event.GetX() +# y = event.GetY() +# item, flags = self.list.HitTest((x, y)) +# +# if flags & wx.LIST_HITTEST_ONITEM: +# self.list.Select(item) +# +# event.Skip() +# +# +# def getColumnText(self, index, col): +# item = self.list.GetItem(index, col) +# return item.GetText() +# +# +# def OnItemSelected(self, event): +# self.currentItem = event.m_itemIndex +# event.Skip() +# +# def onsearch(self, evt) : +# self.dial = SearchDial(self, self, 6, True) +# self.dial.CenterOnParent() +# self.dial.ShowModal() +# self.dial.Destroy() +# +# def onsearchall(self, evt) : +# if 'FrameSearch' not in dir(self.Source) : +# self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus) +# self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False) +# self.dial.CenterOnParent() +# self.dial.ShowModal() +# self.dial.Destroy() +# +# def OnRightClick(self, event): +# +# # only do this part the first time so the events are only bound once +# if self.Alceste: +# if not hasattr(self, "popupID1"): +# self.popupID1 = wx.NewId() +# self.popupID2 = wx.NewId() +# self.popupID3 = wx.NewId() +# self.popupID4 = wx.NewId() +# self.popupID5 = wx.NewId() +# self.popupID6 = wx.NewId() +# self.popupID7 = wx.NewId() +# self.popupID8 = wx.NewId() +# self.popupID9 = wx.NewId() +# #self.popupID10 = wx.NewId() +# self.popupIDgraph = wx.NewId() +# self.idseg = wx.NewId() +# self.iducecarac = wx.NewId() +# self.idtablex = wx.NewId() +# self.idchimod = wx.NewId() +# self.idwordgraph = wx.NewId() +# self.popup_proxe = wx.NewId() +# self.idlexdendro = wx.NewId() +# self.idexport = wx.NewId() +# # self.export_classes = 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.OnPopupFour, id=self.popupID4) +# self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5) +# self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6) +# self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7) +# self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8) +# self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9) +# #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10) +# self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph) +# self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg) +# self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac) +# self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex) +# self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod) +# self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph) +# self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe) +# self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro) +# self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport) +# # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes) +# # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3) +# +# # make a menu +# menu = wx.Menu() +# menu.Append(self.popupID1, u"Formes associées") +# menu.Append(self.idtablex, u"Chi2 par classe") +# menu.Append(self.idlexdendro, u"Chi2 par classe + dendro") +# menu.Append(self.idchimod, u"Chi2 modalités de la variable") +# menu.Append(self.idwordgraph, u"Graphe du mot") +# #menu.Append(self.export_classes, u"Exporter le corpus...") +# +# #menu.Append(self.popupID10, u"Spécificités") +# +# menu_conc = wx.Menu() +# menu_conc.Append(self.popupID2, u"dans les uce de la classe") +# menu_conc.Append(self.popupID3, u"dans les uce classées") +# menu_conc.Append(self.popupID4, u"dans toutes les uce") +# menu.AppendMenu(-1, u"Concordancier", menu_conc) +# menu_cnrtl = wx.Menu() +# menu_cnrtl.Append(self.popupID5, u"Définition") +# menu_cnrtl.Append(self.popupID6, u"Etymologie") +# menu_cnrtl.Append(self.popupID7, u"Synonymie") +# menu_cnrtl.Append(self.popupID8, u"Antonymie") +# menu_cnrtl.Append(self.popupID9, u"Morphologie") +# menu_cnrtl.Append(self.popup_proxe, u"Proxémie") +# menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl) +# menu.AppendSeparator() +# menu.Append(self.popupIDgraph, u"Graphe de la classe") +# menu.Append(self.idseg, u"Segments répétés") +# menu.Append(self.iducecarac, u"UCE caractéristiques") +# menu.Append(self.idexport, 'Partitionner...') +# #menu.Append(self.popupID2, u"Concordancier") +# # menu.Append(self.popupID3, "recharger") +# +# self.PopupMenu(menu) +# menu.Destroy() +# elif 'tableau' in dir(self.Source) : +# if not hasattr(self, "pop1"): +# self.pop1 = wx.NewId() +# self.pop2 = wx.NewId() +# self.pop3 = wx.NewId() +# self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1) +# self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2) +# self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3) +# +# menu = wx.Menu() +# menu.Append(self.pop2, u"Chi2 par classe") +# menu.Append(self.pop3, u"Chi2 modalités de la variable") +# menu.AppendSeparator() +# menu.Append(self.pop1, u"Graph de la classe") +# self.PopupMenu(menu) +# menu.Destroy() +# +# def onexport(self, evt) : +# if 'corpus' in dir(self.Source): +# corpus = self.Source.corpus +# ClasseCHD(self.parent, corpus, self.cl) +# +# def quest_var_mod(self, evt) : +# if 'corpus' in dir(self.Source): +# corpus = self.Source.corpus +# if self.var_mod == {} : +# self.var_mod = treat_var_mod([val for val in corpus.make_etoiles()]) +# else : +# corpus = self.Source.tableau +# if self.var_mod == {} : +# self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups]) +# with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f : +# chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f] +# title = chistable[0] +# title.pop(0) +# chistable.pop(0) +# vchistable = [line[1:] for line in chistable] +# fchistable = [line[0] for line in chistable] +# word = self.getColumnText(self.list.GetFirstSelected(), 6) +# if len(word.split('_')) > 1 : +# var = word.split('_')[0] +# words = [word for word in self.var_mod[var]] +# words.sort() +# tableout = [] +# kwords = [] +# for word in words : +# 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, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE) +# win.addsaveimage(tmpgraph) +# txt = "" % 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() +# dial.ShowModal() +# dial.Destroy() +# +# def quest_simi(self, evt) : +# tableau = self.Source.tableau +# tab = tableau.make_table_from_classe(self.cl, self.la) +# pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl) +# self.filename = os.path.join(pathout,'mat01.csv') +# tableau.printtable(self.filename, tab) +# del tab +# paramsimi = {'coeff' : 0, +# 'layout' : 2, +# 'type' : 1, +# 'arbremax' : 1, +# 'coeff_tv' : 1, +# 'coeff_tv_nb' : 0, +# 'tvprop' : 0, +# 'tvmin' : 5, +# 'tvmax' : 30, +# 'coeff_te' : 1, +# 'coeff_temin' : 1, +# 'coeff_temax' : 10, +# 'label_v': 1, +# 'label_e': 1, +# 'vcex' : 0, +# 'vcexmin' : 10, +# 'vcexmax' : 25, +# 'cex' : 10, +# 'cexfromchi' : True, +# 'sfromchi': False, +# 'seuil_ok' : 0, +# 'seuil' : 1, +# 'cols' : (255,0,0), +# 'cola' : (200,200,200), +# 'width' : 1000, +# 'height' : 1000, +# 'first' : True, +# 'keep_coord' : True, +# 'alpha' : 20, +# 'film': False, +# } +## self.tableau.actives = {} +## self.tableau.lchi = self.lchi +## self.tableau.chi = {} +## for i, val in enumerate(self.la) : +## self.tableau.actives[val] = [self.lfreq[i]] +## self.tableau.chi[val] = [self.lchi[i]] +# +# act = {} +# self.tableau.chi = {} +# self.tableau.lchi = self.lchi +# self.tableau.parametre['fromprof'] = True +# for i, val in enumerate(self.la) : +# act[val] = [self.lfreq[i]] +# self.tableau.chi[val] = [self.lchi[i]] +# DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act) +# +# def onwordgraph(self, evt): +# word = self.getColumnText(self.list.GetFirstSelected(), 6) +# dlg = progressbar(self, 2) +# corpus = self.Source.corpus +# uces = corpus.lc[self.cl-1] +# dlg.Update(1, u'Tableau...') +# #tab = corpus.make_table_with_classe(uces, self.la) +# pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word) +# self.filename = os.path.join(pathout,'mat01.csv') +# dlg.Update(2, u'Ecriture...') +# #corpus.write_tab(tab, self.filename) +# #del tab +# corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename) +# dlg.Destroy() +# paramsimi = {'coeff' : 0, +# 'layout' : 2, +# 'type' : 1, +# 'arbremax' : 0, +# 'coeff_tv' : 1, +# 'coeff_tv_nb' : 0, +# 'tvprop' : 0, +# 'tvmin' : 5, +# 'tvmax' : 30, +# 'coeff_te' : 1, +# 'coeff_temin' : 1, +# 'coeff_temax' : 10, +# 'label_v': 1, +# 'label_e': 0, +# 'vcex' : 1, +# 'vcexmin' : 10, +# 'vcexmax' : 25, +# 'cex' : 10, +# 'seuil_ok' : 1, +# 'seuil' : 1, +# 'cols' : (255,0,0), +# 'cola' : (200,200,200), +# 'width' : 600, +# 'height' : 600, +# 'first' : True, +# 'keep_coord' : True, +# 'alpha' : 20, +# 'film': False, +# } +# self.tableau = Tableau(self.parent, '') +# self.tableau.listactives = self.la +# self.tableau.actives = {} +# for i, val in enumerate(self.la) : +# self.tableau.actives[val] = [self.lfreq[i]] +# DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word) +# +# + def OnPopupOne(self, event): + corpus = self.Source.corpus + #print 'ATTENTION PRINT ET TABLE' + #corpus.make_et_table() + word = self.getColumnText(self.GetFirstSelected(), 6) + lems = corpus.getlems() + uces = corpus.lc[self.cl-1] + rep = [] + #FIXME : donner aussi eff reel a la place de nb uce + for forme in lems[word].formes : + ucef = list(set(corpus.getworduces(forme)).intersection(uces)) + #ucef = [uce for uce in corpus.formes[forme][1] if uce in uces] + if ucef != [] : + nb = len(ucef) + rep.append([corpus.getforme(forme).forme, nb]) + 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) + win.Show(True) +# +# def on_graph(self, evt): +# dlg = progressbar(self, 2) +# corpus = self.Source.corpus +# uces = corpus.lc[self.cl-1] +# dlg.Update(1, u'Tableau...') +# #tab = corpus.make_table_with_classe(uces, self.la) +# pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl) +# self.filename = os.path.join(pathout,'mat01.csv') +# dlg.Update(2, u'Ecriture...') +# #corpus.write_tab(tab, self.filename) +# #del tab +# corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename) +# dlg.Destroy() +# paramsimi = {'coeff' : 0, +# 'layout' : 2, +# 'type' : 1, +# 'arbremax' : 1, +# 'coeff_tv' : 1, +# 'coeff_tv_nb' : 0, +# 'tvprop' : 0, +# 'tvmin' : 5, +# 'tvmax' : 30, +# 'coeff_te' : 1, +# 'coeff_temin' : 1, +# 'coeff_temax' : 10, +# 'label_v': 1, +# 'label_e': 0, +# 'vcex' : 0, +# 'vcexmin' : 10, +# 'vcexmax' : 25, +# 'cex' : 10, +# 'cexfromchi' : True, +# 'sfromchi': False, +# 'seuil_ok' : 0, +# 'seuil' : 1, +# 'cols' : (255,0,0), +# 'cola' : (200,200,200), +# 'width' : 1000, +# 'height' : 1000, +# 'first' : True, +# 'keep_coord' : True, +# 'alpha' : 20, +# 'film': False, +# } +# self.tableau = Tableau(self.parent, '') +# self.tableau.listactives = self.la +# self.tableau.actives = {} +# self.tableau.lchi = self.lchi +# self.tableau.chi = {} +# self.tableau.parametre['fromprof'] = True +# for i, val in enumerate(self.la) : +# self.tableau.actives[val] = [self.lfreq[i]] +# self.tableau.chi[val] = [self.lchi[i]] +# DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout) +# +# def on_segments(self,evt) : +# dlg = progressbar(self, 2) +# corpus = self.Source.corpus +# uces = corpus.lc[self.cl-1] +# l = [] +# dlg.Update(1, u'Segments...') +# for i in range(2,10) : +# li = corpus.find_segments_in_classe(uces, i, 1000) +# if li == [] : +# break +# else : +# l += li +# l.sort(reverse = True) +# d = {} +# dlg.Update(2, 'Tri...') +# for i, line in enumerate(l) : +# d[i] = [line[1],line[0], line[2]] +# first = ['','',''] +# para={'dico': d,'fline':first} +# dlg.Destroy() +# win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500)) +# win.Show(True) +# +# def on_uce_carac(self,evt) : +# dial = PrefUCECarac(self, self.parent) +# dial.CenterOnParent() +# if dial.ShowModal() == wx.ID_OK : +# limite = dial.spin_eff.GetValue() +# atype = dial.radio_type.GetSelection() +# dlg = progressbar(self,maxi = 4) +# corpus = self.Source.corpus +# uces = corpus.lc[self.cl-1] +# tab = corpus.make_table_with_classe(uces, self.la) +# tab.pop(0) +# dlg.Update(2, u'score...') +# if atype == 0 : +# ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab] +# else : +# ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1])/float(sum(line)),2) if sum(line)!=0 else 0 for line in tab] +# ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)] +# del ntab +# ntab2.sort(reverse = True) +# ntab2 = ntab2[:limite] +# nuces = [val[1] for val in ntab2] +# dlg.Update(3, u'concordancier...') +# #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2] +# ucestxt1 = [row for row in corpus.getconcorde(nuces)] +# ucestxt = [] +# ucis_txt = [] +# for uce in ucestxt1 : +# ucetxt = ' '+uce[1]+' ' +# ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '
') +# for lem in self.la : +# listmot = corpus.getlems()[lem].formes +# for id in listmot : +# forme = corpus.getforme(id).forme +# ucetxt = ucetxt.replace(' '+forme+' ', ' ' + forme + ' ') +# ucestxt.append(ucetxt) +# #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt] +# dlg.Update(4, u'texte...') +# #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2] +# win = message(self, -1, u"UCE caractéristiques - Classe %i" % self.cl, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE) +# win.html = '\n' + '

'.join(['
'.join([ucis_txt[i], 'score : ' + str(ntab2[i][0]), ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n' +# win.HtmlPage.SetPage(win.html) +# dlg.Destroy() +# win.Show(True) +# +# def on_tablex(self, evt): +# if 'corpus' in dir(self.Source): +# corpus = self.Source.corpus +# else : +# corpus = self.Source.tableau +# with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f : +# chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f] +# title = chistable[0] +# title.pop(0) +# chistable.pop(0) +# vchistable = [line[1:] for line in chistable] +# fchistable = [line[0] for line in chistable] +# words = [self.getColumnText(self.list.GetFirstSelected(), 6)] +# tableout = [vchistable[fchistable.index(words[0])]] +# last = self.list.GetFirstSelected() +# while self.list.GetNextSelected(last) != -1: +# last = self.list.GetNextSelected(last) +# word = self.getColumnText(last, 6) +# words.append(word) +# tableout.append(vchistable[fchistable.index(word)]) +# tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR) +# nbcl = len(title) +# txt = barplot(tableout, words, 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, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE) +# win.addsaveimage(tmpgraph) +# txt = "" % tmpgraph +# win.HtmlPage.SetPage(txt) +# win.Show(True) +# +# def onlexdendro(self, evt): +# if 'corpus' in dir(self.Source): +# corpus = self.Source.corpus +# else : +# corpus = self.Source.tableau +# with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f : +# chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f] +# title = chistable[0] +# title.pop(0) +# chistable.pop(0) +# vchistable = [line[1:] for line in chistable] +# fchistable = [line[0] for line in chistable] +# words = [self.getColumnText(self.list.GetFirstSelected(), 6)] +# tableout = [vchistable[fchistable.index(words[0])]] +# last = self.list.GetFirstSelected() +# while self.list.GetNextSelected(last) != -1: +# last = self.list.GetNextSelected(last) +# word = self.getColumnText(last, 6) +# words.append(word) +# tableout.append(vchistable[fchistable.index(word)]) +# 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, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE) +# win.addsaveimage(tmpgraph) +# txt = "" % tmpgraph +# win.HtmlPage.SetPage(txt) +# win.Show(True) +# +# +# def make_concord(self, uces, title, color = 'red') : +# corpus = self.Source.corpus +# ListWord = [self.getColumnText(self.list.GetFirstSelected(), 6)] +# last = self.list.GetFirstSelected() +# while self.list.GetNextSelected(last) != -1: +# last = self.list.GetNextSelected(last) +# ListWord.append(self.getColumnText(last, 6)) +# listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes] +# win = message(self, -1, title, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE) +# toshow = ['\n

Concordancier

\n'] +# toshow.append('

' % color + ' '.join(ListWord) + '


') +# duce = {} +# ucef = [] +# for word in ListWord : +# ucef += list(set(corpus.getlemuces(word)).intersection(uces)) +# ucef = list(set(ucef)) +# ucef.sort() +# res = corpus.getconcorde(ucef) +# txt = '
'.join(toshow) +'

' +# for uce in res : +# ucetxt = ' '+uce[1]+' ' +# txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '
' +# for forme in listmot: +# forme = corpus.getforme(forme).forme +# ucetxt = ucetxt.replace(' '+forme+' ', ' ' + forme + ' ') +# txt += ucetxt + '

' +# win.HtmlPage.SetPage(txt) +# return win +# +# def OnPopupTwo(self, event): +# corpus = self.Source.corpus +# uces = corpus.lc[self.cl-1] +# win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl) +# win.Show(True) +# +# def OnPopupThree(self, event): +# corpus = self.Source.corpus +# uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] +# win = self.make_concord(uces, "Concordancier - UCE classées") +# win.Show(True) +# +# def OnPopupFour(self, event): +# corpus = self.Source.corpus +# uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0 +# win = self.make_concord(uces, "Concordancier - Toutes les UCE") +# win.Show(True) +# +# def OnPopupFive(self, event): +# word = self.getColumnText(self.list.GetFirstSelected(), 6) +# lk = "http://www.cnrtl.fr/definition/" + word +# webbrowser.open(lk) +# +# def OnPopupSix(self, event): +# word = self.getColumnText(self.list.GetFirstSelected(), 6) +# lk = "http://www.cnrtl.fr/etymologie/" + word +# webbrowser.open(lk) +# +# def OnPopupSeven(self, event): +# word = self.getColumnText(self.list.GetFirstSelected(), 6) +# lk = "http://www.cnrtl.fr/synonymie/" + word +# webbrowser.open(lk) +# +# def OnPopupHeight(self, event): +# word = self.getColumnText(self.list.GetFirstSelected(), 6) +# lk = "http://www.cnrtl.fr/antonymie/" + word +# webbrowser.open(lk) +# +# def OnPopupNine(self, event): +# word = self.getColumnText(self.list.GetFirstSelected(), 6) +# lk = "http://www.cnrtl.fr/morphologie/" + word +# webbrowser.open(lk) +# +# def onproxe(self, evt) : +# word = self.getColumnText(self.list.GetFirstSelected(), 6) +# lk = "http://www.cnrtl.fr/proxemie/" + word +# webbrowser.open(lk) +# +# def OnSize(self, event): +# w, h = self.GetClientSizeTuple() +# self.list.SetDimensions(0, 0, w, h) +# +# def OnColClick(self, event): +# self.do_greyline() +# +# +#class wliste(wx.Frame): +# def __init__(self, parent, id, title, d, fline, size=(600, 500)): +# wx.Frame.__init__(self, parent, id) +# self.liste = ListForSpec(self, parent, d, fline) +# self.button_1 = wx.Button(self, -1, "Fermer") +# self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1) +# self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) +# self.__do_layout() +# +# def __do_layout(self): +# sizer_1 = wx.BoxSizer(wx.VERTICAL) +# sizer_2 = wx.BoxSizer(wx.VERTICAL) +# sizer_2.Add(self.liste, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) +# sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, 0) +# sizer_1.Add(sizer_2, 1, wx.EXPAND, 0) +# self.SetAutoLayout(True) +# self.SetSizer(sizer_1) +# self.Layout() +# +# def OnCloseMe(self, event): +# self.Close(True) +# +# def OnCloseWindow(self, event): +# self.Destroy() +# class message(wx.Frame): def __init__(self, *args, **kwds): kwds["style"] = wx.DEFAULT_FRAME_STYLE @@ -867,36 +1636,36 @@ class message(wx.Frame): def OnCloseWindow(self, event): self.Destroy() - -def getSmallUpArrowData(): - return \ -'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ -\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ -\x00\x00C\xb0\x89\ -\xd3.\x10\xd1m\xc3\xe5*\xbc.\x80i\xc2\x17.\x8c\xa3y\x81\x01\x00\xa1\x0e\x04e\ -?\x84B\xef\x00\x00\x00\x00IEND\xaeB`\x82" - -def getSmallDnArrowBitmap(): - return wx.BitmapFromImage(getSmallDnArrowImage()) - -def getSmallDnArrowImage(): - stream = cStringIO.StringIO(getSmallDnArrowData()) - return wx.ImageFromStream(stream) +# +#def getSmallUpArrowData(): +# return \ +#'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ +#\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ +#\x00\x00C\xb0\x89\ +#\xd3.\x10\xd1m\xc3\xe5*\xbc.\x80i\xc2\x17.\x8c\xa3y\x81\x01\x00\xa1\x0e\x04e\ +#?\x84B\xef\x00\x00\x00\x00IEND\xaeB`\x82" +# +#def getSmallDnArrowBitmap(): +# return wx.BitmapFromImage(getSmallDnArrowImage()) +# +#def getSmallDnArrowImage(): +# stream = cStringIO.StringIO(getSmallDnArrowData()) +# return wx.ImageFromStream(stream) diff --git a/Rscripts/afc_graph.R b/Rscripts/afc_graph.R index 17f065e..0c47dfa 100644 --- a/Rscripts/afc_graph.R +++ b/Rscripts/afc_graph.R @@ -184,8 +184,10 @@ if (typegraph == 0) { rnames } library(rgl) - rn <- vire.nonascii(rownames(table.in)) + #rn <- vire.nonascii(rownames(table.in)) + rn <- rownames(table.in) rgl.open() + par3d(cex=0.7) #par3d(windowRect = c(100,100,600,600)) rgl.bg(col = c('white', "#99bb99"), front = "lines", box=FALSE, sphere = TRUE) rgl.lines(c(rx), c(0, 0), c(0, 0), col = "#000000") @@ -195,19 +197,21 @@ if (typegraph == 0) { text3d(0,ry[2]+1,0, ylab) text3d(0,0,rz[2]+1, zlab) rain = rainbow(clnb) - colors = rain[classes] - text3d(table.in[,1], table.in[,2], table.in[,3], rn, col='black') - if (tchi) { + if (tchi) { maxchi <- norm.vec(maxchi, tchi.min/100, tchi.max/100) } else if (!is.null(cex.par)) { maxchi <- norm.vec(cex.par, txt.min/100, txt.max/100) } else { maxchi <- 0.1 } + colors = rain[classes] + text3d(table.in[,1], table.in[,2], table.in[,3], rn, col= colors , cex = cex.par) for (i in 1:clnb) { text3d(rx[2],(ry[2]+(0.2*i)),0,paste('classe',i),col=rain[i]) } - rgl.spheres(table.in, col = colors, radius = maxchi, alpha = alpha) + #if (tchi) { + # rgl.spheres(table.in, col = colors, radius = maxchi, alpha = alpha) + #} if (dofilm) { require(tcltk) diff --git a/app.fil b/app.fil index 0202140..43f8e8d 100644 --- a/app.fil +++ b/app.fil @@ -1,37 +1,54 @@ -./checkinstall.py -./aslexico.py +./corpusNG.py +./Liste.py +./analysetxt.py +./KeyFrame.py +./ttparser.py +./tabverges.py +./listlex.py +./textdist.py +./textafcuci.py +./iramuteq.py +./checkversion.py +./tabrsimple.py +./textaslexico.py +./corpus.py +./tabchddist.py +./extract.py +./dialog.py ./openanalyse.py -./listlex2.py -./chdtxt.py -./student.py -./sheet.py -./textstat.py -./guiparam3d.py -./chdtxtNG.py -./chd.py -./OptionAlceste.py -./rchdng.py -./getencoding.py +./tableau.py +./search_tools.py ./PrintRScript.py -./normalize.py -./lancergl.py -./dendro.py +./tabstudent.py +./textstat.py +./guifunct.py ./layout.py -./chi2.py -./afcm.py -./dialog.py -./checkversion.py -./pamtxt.py -./ProfList.py -./frequence.py -./simi.py -./listlex.py -./ooolib.py -./chdquest.py +./usecorpusNG.py +./textsimi.py +./textcheckcorpus.py +./OptionAlceste.py +./tabsimi.py +./iracmd.py +./textclassechd.py +./newsimi.py ./chemins.py +./ProfList.py +./word_stat.py +./tree.py +./textwordcloud.py +./guiparam3d.py +./parse_factiva_xml.py +./textchdalc.py +./colors.py +./parse_factiva_txt2.py ./functions.py -./afcuci.py -./KeyFrame.py -./Liste.py -./guifunct.py -./iramuteq.py +./sheet.py +./profile_segment.py +./checkinstall.py +./parse_factiva_html.py +./search_list.py +./tabchdalc.py +./parse_factiva_txt.py +./tabfrequence.py +./tabchi2.py +./tabafcm.py diff --git a/chemins.py b/chemins.py index ec4ab2d..e448064 100644 --- a/chemins.py +++ b/chemins.py @@ -119,6 +119,8 @@ def ConstructConfigPath(AppliPath, user=True): 'pam' : os.path.join(ConfigPath, 'pam.cfg'), 'history' : os.path.join(ConfigPath, 'history.db'), 'corpus' : os.path.join(ConfigPath, 'corpus.cfg'), + 'stat' : os.path.join(ConfigPath, 'stat.cfg'), + 'simitxt' : os.path.join(ConfigPath, 'simitxt.cfg'), } return DictConfigPath diff --git a/configuration/simitxt.cfg b/configuration/simitxt.cfg new file mode 100644 index 0000000..6b6c6fc --- /dev/null +++ b/configuration/simitxt.cfg @@ -0,0 +1,39 @@ + +[simitxt] +tvprop = False +arbremax = True +coeff_temin = 1 +seuil = 1 +cols = (255, 0, 0, 255) +vcex = True +height = 1000 +alpha = 20 +vcexmax = 25 +film = False +cola = (200, 200, 200, 255) +coeff_tv_nb = 0 +bystar = False +cexfromchi = False +width = 1000 +tvmax = 30 +time = 0h 0m 20s +nbactives = 1833 +vcexmin = 10 +seuil_ok = False +type = simitxt +keep_coord = False +label_e = False +sfromchi = False +lem = 1 +label_v = True +eff_min_forme = 3 +fromprof = True +layout = 2 +tvmin = 5 +cex = 10 +coeff = 0 +coeff_te = True +coeff_temax = 10 +type_graph = 1 +coeff_tv = True +first = False diff --git a/configuration/stat.cfg b/configuration/stat.cfg new file mode 100644 index 0000000..642c876 --- /dev/null +++ b/configuration/stat.cfg @@ -0,0 +1,7 @@ +[stat] +pathout = +name = +encoding = +lem = 1 +corpus = +type = stat diff --git a/corpusNG.py b/corpusNG.py index a950d0f..6a027dc 100644 --- a/corpusNG.py +++ b/corpusNG.py @@ -3,6 +3,9 @@ import codecs import os +import gettext +_ = gettext.gettext +import locale import sys from time import time from functions import decoupercharact, ReadDicoAsDico, DoConf @@ -16,6 +19,7 @@ from uuid import uuid4 from chemins import PathOut from dialog import CorpusPref from functions import ReadLexique, ReadDicoAsDico +from colors import colors import datetime @@ -457,10 +461,10 @@ class Corpus : else : self.lems[lem].act = 2 - def make_actives_limit(self, limit) : + def make_actives_limit(self, limit, key = 1) : if self.idformes is None : self.make_idformes() - return [lem for lem in self.lems if self.getlemeff(lem) >= limit and self.lems[lem].act == 1] + return [lem for lem in self.lems if self.getlemeff(lem) >= limit and self.lems[lem].act == key] def make_actives_nb(self, nbmax, key) : log.info('make_actives_nb : %i - %i' % (nbmax,key)) @@ -520,7 +524,6 @@ class Corpus : except IndexError : det[et[0]] = 1 print det - def make_and_write_profile_et(self, ucecl, fileout) : log.info('etoiles/classes') @@ -528,6 +531,31 @@ class Corpus : with open(fileout, 'w') as f : f.write('\n'.join([';'.join([etoile] + [`len(set(self.getucesfrometoile(etoile)).intersection(classe))` for classe in ucecl]) for etoile in etoiles]).encode(self.parametres['syscoding'])) + def make_colored_corpus(self) : + ucecl = {} + for i, lc in enumerate(self.lc) : + for uce in lc : + ucecl[uce] = i + 1 + for uce in self.lc0 : + ucecl[uce] = 0 + color = ['black'] + colors[len(self.lc) - 1] + txt = ''' + + +''' % sys.getdefaultencoding() + res = self.getalluces() + self.make_iduces() + actuci = '' + actpara = False + for uce in res : + if self.iduces[uce[0]].uci != actuci : + actuci = self.iduces[uce[0]].uci + txt += '

' + ' '.join(self.ucis[self.iduces[uce[0]].uci].etoiles) + '

' + txt += '' % (color[ucecl[uce[0]]]) + uce[1] + '

' + else : + txt += '' % (color[ucecl[uce[0]]]) + uce[1] + '

' + return txt + '\n' + def count_from_list(self, l, d) : for val in l : if val in d : @@ -536,6 +564,15 @@ class Corpus : d[val] = 1 return d + def count_from_list_cl(self, l, d, a, clnb) : + for val in l : + if val in d : + d[val][a] += 1 + else : + d[val] = [0] * clnb + d[val][a] = 1 + return d + def find_segments(self, taille_segment, taille_limite) : d = {} for uce in self.getalluces() : @@ -560,8 +597,18 @@ class Corpus : l = l[-taille_limite:] return l - - + def make_segments_profile(self, fileout, lenmin = 3, lenmax = 10, effmin = 50, lem = False) : + d = {} + for b, classe in enumerate(self.lc) : + for uce in self.getconcorde(classe) : + uce = uce[1].split() + if lem : + uce = [self.formes[forme].lem for forme in uce] + for taille_segment in range(lenmin,lenmax) : + d =self.count_from_list_cl([' '.join(uce[i:i+taille_segment]) for i in range(len(uce)-(taille_segment - 1))], d, b, len(self.lc)) + result = [[seg] + [str(val) for val in d[seg]] for seg in d if sum(d[seg]) >= effmin] + with open(fileout, 'w') as f : + f.write('\n'.join([';'.join(line) for line in result])) def make_ucecl_from_R(self, filein) : with open(filein, 'rU') as f : @@ -689,7 +736,7 @@ def decouperlist(chaine, longueur, longueurOptimale) : Si on trouve un '$', c'est fini. Sinon, on cherche le meilleur candidat. C'est-à-dire le rapport poids/distance le plus important. """ - separateurs = [[u'.', 6.0], [u'?', 6.0], [u'!', 6.0], [u'£', 6.0], [u':', 5.0], [u';', 4.0], [u',', 1.0], [u' ', 0.01]] + separateurs = [[u'.', 6.0], [u'?', 6.0], [u'!', 6.0], [u'£$£', 6.0], [u':', 5.0], [u';', 4.0], [u',', 1.0], [u' ', 0.01]] dsep = dict([[val[0],val[1]] for val in separateurs]) trouve = False # si on a trouvé un bon séparateur iDecoupe = 0 # indice du caractere ou il faut decouper @@ -771,7 +818,7 @@ class BuildCorpus : if self.corpus.parametres['keep_ponct'] : self.ponctuation_espace = [' ', ''] else : - self.ponctuation_espace = [' ','.', u'£', ';', '?', '!', ',', ':',''] + self.ponctuation_espace = [' ','.', u'£$£', ';', '?', '!', ',', ':',''] self.cleans = [] self.tolist = self.corpus.parametres.get('tolist', 0) self.buildcleans() @@ -794,13 +841,18 @@ class BuildCorpus : def dobuild(self) : t1 = time() - self.read_corpus(self.infile) - self.indexdb() - self.corpus.parametres['ira'] = self.corpus.pathout['Corpus.cira'] - self.time = time() - t1 - self.dofinish() - DoConf().makeoptions(['corpus'],[self.corpus.parametres], self.corpus.pathout['Corpus.cira']) - log.info('time : %f' % (time() - t1)) + try : + self.read_corpus(self.infile) + except Warning, args : + log.info('pas kool %s' % args) + raise Warning + else : + self.indexdb() + self.corpus.parametres['ira'] = self.corpus.pathout['Corpus.cira'] + self.time = time() - t1 + self.dofinish() + DoConf().makeoptions(['corpus'],[self.corpus.parametres], self.corpus.pathout['Corpus.cira']) + log.info('time : %f' % (time() - t1)) def connect(self) : self.conn_f = sqlite3.connect(self.corpus.pathout['formes.db']) @@ -854,7 +906,7 @@ class BuildCorpus : self.cleans.append(self.dolower) if self.corpus.parametres.get('firstclean', 1) : self.cleans.append(self.firstclean) - self.rule = self.corpus.parametres.get('keep_caract', u"^a-zA-Z0-9àÀâÂäÄáÁéÉèÈêÊëËìÌîÎïÏòÒôÔöÖùÙûÛüÜçÇßœŒ’ñ.:,;!?*'_-") + self.rule = self.corpus.parametres.get('keep_caract', u"^a-zA-Z0-9àÀâÂäÄáÁéÉèÈêÊëËìÌîÎïÏòÒôÔöÖùÙûÛüÜçÇßœŒ’ñ.:,;!?*'_") self.cleans.append(self.docharact) if self.corpus.parametres.get('expressions', 1) : self.cleans.append(self.make_expression) @@ -886,7 +938,7 @@ class BuildCorpus : def firstclean(self, txt) : txt = txt.replace(u'’',"'") txt = txt.replace(u'œ', u'oe') - return txt.replace('...',u' £ ').replace('?',' ? ').replace('.',' . ').replace('!', ' ! ').replace(',',' , ').replace(';', ' ; ').replace(':',' : ') + return txt.replace('...',u' £$£ ').replace('?',' ? ').replace('.',' . ').replace('!', ' ! ').replace(',',' , ').replace(';', ' ; ').replace(':',' : ').replace(u'…', ' £$£ ') def make_cleans(self, txt) : for clean in self.cleans : @@ -945,28 +997,47 @@ class BuildFromAlceste(BuildCorpus) : iduci = -1 idpara = -1 iduce = -1 - with codecs.open(infile, 'rU', self.encoding) as f : - for line in f : - if self.testuci(line) : - iduci += 1 - if txt != [] : - iduce, idpara = self.treattxt(txt, iduce, idpara, iduci - 1) - txt = [] - self.corpus.ucis.append(Uci(iduci, line)) - else : - self.corpus.ucis.append(Uci(iduci, line)) - elif line.startswith(u'-*') : - if txt != [] : - iduce, idpara = self.treattxt(txt, iduce, idpara, iduci) - txt = [] - idpara += 1 - self.corpus.ucis[-1].paras.append(line.split()[0]) - elif line.strip() != '' and iduci != -1 : - txt.append(line) - if txt != [] : - iduce, idpara = self.treattxt(txt, iduce, idpara, iduci) - del(txt) - self.backup_uce() + linenb = 0 + try : + with codecs.open(infile, 'r', self.encoding) as f : + for line in f : + linenb += 1 + line = line.rstrip('\n\r') + if self.testuci(line) : + iduci += 1 + if txt != [] : + iduce, idpara = self.treattxt(txt, iduce, idpara, iduci - 1) + txt = [] + self.corpus.ucis.append(Uci(iduci, line)) + else : + if iduci > 0 : + if self.corpus.ucis[-1].uces == [] : + log.info('linenb : %i' % linenb) + raise Exception("EmptyText %i" % linenb) + self.corpus.ucis.append(Uci(iduci, line)) + elif line.startswith(u'-*') : + if iduci != -1 : + if txt != [] : + iduce, idpara = self.treattxt(txt, iduce, idpara, iduci) + txt = [] + idpara += 1 + self.corpus.ucis[-1].paras.append(line.split()[0]) + else : + raise Exception('paragrapheOT') + elif line.strip() != '' and iduci != -1 : + txt.append(line) + if txt != [] and iduci != -1 : + iduce, idpara = self.treattxt(txt, iduce, idpara, iduci) + del(txt) + else : + raise Exception("EmptyText") + if iduci != -1 and iduce != -1: + self.backup_uce() + else : + log.info(_(u"No Texte in corpora. Are you sure of the formatting ?")) + raise Exception('TextBeforeTextMark') + except UnicodeDecodeError : + raise Exception("CorpusEncoding") def treattxt(self, txt, iduce, idpara, iduci) : if self.corpus.parametres.get('ucemethod', 0) == 2 and self.corpus.parametres['douce']: @@ -1029,7 +1100,7 @@ class BuildFromAlceste(BuildCorpus) : uce = ' '.join([val for val in texte_uce if val not in self.ponctuation_espace]) if uce != '' : - print 'RESTEE UUCEEEEEEEEEEEEE', uce + #print 'RESTEE UUCEEEEEEEEEEEEE', uce out.append(uce) return out else : diff --git a/dialog.py b/dialog.py index 79ad5f9..44b7dc8 100755 --- a/dialog.py +++ b/dialog.py @@ -19,7 +19,7 @@ wx.HelpProvider_Set(provider) #--------------------------------------------------------------------------- -encodages = [[u'cp1252',u'Windows'], [u'utf-8',u'Linux'], [u'MacRoman',u'MacOs X'], [u'ascii', u'English'], [u'big5', u'Traditional Chinese'], [u'big5hkscs', u'Traditional Chinese'], [u'cp037', u'English'], [u'cp424', u'Hebrew'], [u'cp437', u'English'], [u'cp500', u'Western Europe'], [u'cp737', u'Greek'], [u'cp775', u'Baltic languages'], [u'cp850', u'Western Europe'], [u'cp852', u'Central and Eastern Europe'], [u'cp855', u'Bulg, Byelorus, Mace, Rus, Serb'], [u'cp856', u'Hebrew'], [u'cp857', u'Turkish'], [u'cp860', u'Portuguese'], [u'cp861', u'Icelandic'], [u'cp862', u'Hebrew'], [u'cp863', u'Canadian'], [u'cp864', u'Arabic'], [u'cp865', u'Danish, Norwegian'], [u'cp866', u'Russian'], [u'cp869', u'Greek'], [u'cp874', u'Thai'], [u'cp875', u'Greek'], [u'cp932', u'Japanese'], [u'cp949', u'Korean'], [u'cp950', u'Traditional Chinese'], [u'cp1006', u'Urdu'], [u'cp1026', u'Turkish'], [u'cp1140', u'Western Europe'], [u'cp1250', u'Central and Eastern Europe'], [u'cp1251', u'Bulg, Byelorus, Mace, Rus, Serb'], [u'cp1253', u'Greek'], [u'cp1254', u'Turkish'], [u'cp1255', u'Hebrew'], [u'cp1256', u'Arabic'], [u'cp1257', u'Baltic languages'], [u'cp1258', u'Vietnamese'], [u'euc_jp', u'Japanese'], [u'euc_jis_2004', u'Japanese'], [u'euc_jisx0213', u'Japanese'], [u'euc_kr', u'Korean'], [u'gb2312', u'Simplified Chinese'], [u'gbk', u'Unified Chinese'], [u'gb18030', u'Unified Chinese'], [u'hz', u'Simplified Chinese'], [u'iso2022_jp', u'Japanese'], [u'iso2022_jp_1', u'Japanese'], [u'iso2022_jp_2', u'Jp, K, S C, WE, G'], [u'iso2022_jp_2004', u'Japanese'], [u'iso2022_jp_3', u'Japanese'], [u'iso2022_jp_ext', u'Japanese'], [u'iso2022_kr', u'Korean'], [u'latin_1', u'West Europe'], [u'iso8859_2', u'Central and Eastern Europe'], [u'iso8859_3', u'Esperanto, Maltese'], [u'iso8859_4', u'Baltic languages'], [u'iso8859_5', u'Bulg, Byelorus, Mace, Rus, Serb'], [u'iso8859_6', u'Arabic'], [u'iso8859_7', u'Greek'], [u'iso8859_8', u'Hebrew'], [u'iso8859_9', u'Turkish'], [u'iso8859_10', u'Nordic languages'], [u'iso8859_13', u'Baltic languages'], [u'iso8859_14', u'Celtic languages'], [u'iso8859_15', u'Western Europe'], [u'iso8859_16', u'South-Eastern Europe'], [u'johab', u'Korean'], [u'koi8_r', u'Russian'], [u'koi8_u', u'Ukrainian'], [u'mac_cyrillic', u'Bulg, Byelorus, Mace, Rus, Serb'], [u'mac_greek', u'Greek'], [u'mac_iceland', u'Icelandic'], [u'mac_latin2', u'Central and Eastern Europe'], [u'mac_turkish', u'Turkish'], [u'ptcp154', u'Kazakh'], [u'shift_jis', u'Japanese'], [u'shift_jis_2004', u'Japanese'], [u'shift_jisx0213', u'Japanese'], [u'utf_32', u'all languages'], [u'utf_32_be', u'all languages'], [u'utf_32_le', u'all languages'], [u'utf_16', u'all languages'], [u'utf_16_be', u'all languages (BMP only)'], [u'utf_16_le', u'all languages (BMP only)'], [u'utf_7', u'all languages'], [u'utf_8_sig', u'all languages']] +encodages = [[u'cp1252',u'Western Europe'], [u'utf-8',u'all languages'], [u'MacRoman',u'Western Europe'], [u'ascii', u'English'], [u'big5', u'Traditional Chinese'], [u'big5hkscs', u'Traditional Chinese'], [u'cp037', u'English'], [u'cp424', u'Hebrew'], [u'cp437', u'English'], [u'cp500', u'Western Europe'], [u'cp737', u'Greek'], [u'cp775', u'Baltic languages'], [u'cp850', u'Western Europe'], [u'cp852', u'Central and Eastern Europe'], [u'cp855', u'Bulg, Byelorus, Mace, Rus, Serb'], [u'cp856', u'Hebrew'], [u'cp857', u'Turkish'], [u'cp860', u'Portuguese'], [u'cp861', u'Icelandic'], [u'cp862', u'Hebrew'], [u'cp863', u'Canadian'], [u'cp864', u'Arabic'], [u'cp865', u'Danish, Norwegian'], [u'cp866', u'Russian'], [u'cp869', u'Greek'], [u'cp874', u'Thai'], [u'cp875', u'Greek'], [u'cp932', u'Japanese'], [u'cp949', u'Korean'], [u'cp950', u'Traditional Chinese'], [u'cp1006', u'Urdu'], [u'cp1026', u'Turkish'], [u'cp1140', u'Western Europe'], [u'cp1250', u'Central and Eastern Europe'], [u'cp1251', u'Bulg, Byelorus, Mace, Rus, Serb'], [u'cp1253', u'Greek'], [u'cp1254', u'Turkish'], [u'cp1255', u'Hebrew'], [u'cp1256', u'Arabic'], [u'cp1257', u'Baltic languages'], [u'cp1258', u'Vietnamese'], [u'euc_jp', u'Japanese'], [u'euc_jis_2004', u'Japanese'], [u'euc_jisx0213', u'Japanese'], [u'euc_kr', u'Korean'], [u'gb2312', u'Simplified Chinese'], [u'gbk', u'Unified Chinese'], [u'gb18030', u'Unified Chinese'], [u'hz', u'Simplified Chinese'], [u'iso2022_jp', u'Japanese'], [u'iso2022_jp_1', u'Japanese'], [u'iso2022_jp_2', u'Jp, K, S C, WE, G'], [u'iso2022_jp_2004', u'Japanese'], [u'iso2022_jp_3', u'Japanese'], [u'iso2022_jp_ext', u'Japanese'], [u'iso2022_kr', u'Korean'], [u'latin_1', u'West Europe'], [u'iso8859_2', u'Central and Eastern Europe'], [u'iso8859_3', u'Esperanto, Maltese'], [u'iso8859_4', u'Baltic languages'], [u'iso8859_5', u'Bulg, Byelorus, Mace, Rus, Serb'], [u'iso8859_6', u'Arabic'], [u'iso8859_7', u'Greek'], [u'iso8859_8', u'Hebrew'], [u'iso8859_9', u'Turkish'], [u'iso8859_10', u'Nordic languages'], [u'iso8859_13', u'Baltic languages'], [u'iso8859_14', u'Celtic languages'], [u'iso8859_15', u'Western Europe'], [u'iso8859_16', u'South-Eastern Europe'], [u'johab', u'Korean'], [u'koi8_r', u'Russian'], [u'koi8_u', u'Ukrainian'], [u'mac_cyrillic', u'Bulg, Byelorus, Mace, Rus, Serb'], [u'mac_greek', u'Greek'], [u'mac_iceland', u'Icelandic'], [u'mac_latin2', u'Central and Eastern Europe'], [u'mac_turkish', u'Turkish'], [u'ptcp154', u'Kazakh'], [u'shift_jis', u'Japanese'], [u'shift_jis_2004', u'Japanese'], [u'shift_jisx0213', u'Japanese'], [u'utf_32', u'all languages'], [u'utf_32_be', u'all languages'], [u'utf_32_le', u'all languages'], [u'utf_16', u'all languages'], [u'utf_16_be', u'all languages (BMP only)'], [u'utf_16_le', u'all languages (BMP only)'], [u'utf_7', u'all languages'], [u'utf_8_sig', u'all languages']] class FileOptionDialog(wx.Dialog): def __init__( @@ -1493,7 +1493,7 @@ class PrefSimi ( wx.Dialog ): class SelectColDial ( wx.Dialog ): def __init__( self, parent ): - wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 200,300 ), style = wx.DEFAULT_DIALOG_STYLE ) + wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 400,500 ), style = wx.DEFAULT_DIALOG_STYLE ) self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize ) @@ -2129,11 +2129,11 @@ class FindInCluster(wx.Frame): cl = self.formes[idb][1] - 1 forme = self.formes[idb][0] profile.ProfNB.SetSelection(cl) - UnSelectList(profile.ProfNB.GetPage(cl).list) - datas = dict([[profile.ProfNB.GetPage(cl).getColumnText(i,6),i] for i in range(profile.ProfNB.GetPage(cl).list.GetItemCount())]) - profile.ProfNB.GetPage(cl).list.SetItemState(datas[self.formes[idb][0]], wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED) - profile.ProfNB.GetPage(cl).list.Focus(datas[forme]) - profile.ProfNB.GetPage(cl).list.SetFocus() + UnSelectList(profile.ProfNB.GetPage(cl)) + datas = dict([[profile.ProfNB.GetPage(cl).getColumnText(i,6),i] for i in range(profile.ProfNB.GetPage(cl).GetItemCount())]) + profile.ProfNB.GetPage(cl).SetItemState(datas[self.formes[idb][0]], wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED) + profile.ProfNB.GetPage(cl).Focus(datas[forme]) + profile.ProfNB.GetPage(cl).SetFocus() def OnCloseMe(self, evt) : self.Close(True) @@ -2182,10 +2182,10 @@ class SearchDial ( wx.Dialog ): pass def OnSearch(self, evt): - UnSelectList(self.listctrl.list) + UnSelectList(self.listctrl) search_word = self.search.GetValue() if search_word.strip() != '' : - formes = [self.listctrl.getColumnText(i, self.col) for i in range(self.listctrl.list.GetItemCount())] + formes = [self.listctrl.getColumnText(i, self.col) for i in range(self.listctrl.GetItemCount())] if search_word.endswith(u'*') : search_word = search_word[0:-1] result = [j for j, forme in enumerate(formes) if forme.startswith(search_word)] @@ -2203,15 +2203,15 @@ class SearchDial ( wx.Dialog ): def showitems(self, items) : if len(items) == 1 : - self.listctrl.list.SetItemState(items[0], wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED) - self.listctrl.list.Focus(items[0]) - self.listctrl.list.SetFocus() + self.listctrl.SetItemState(items[0], wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED) + self.listctrl.Focus(items[0]) + self.listctrl.SetFocus() self.Destroy() else : for i in items : - self.listctrl.list.SetItemState(i, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED) - self.listctrl.list.Focus(items[0]) - self.listctrl.list.SetFocus() + self.listctrl.SetItemState(i, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED) + self.listctrl.Focus(items[0]) + self.listctrl.SetFocus() self.forward.Enable(True) self.backward.Enable(False) self.items = items @@ -2229,12 +2229,13 @@ class SearchDial ( wx.Dialog ): first_forme = proflist[0] cl = first_forme[1] - 1 profile.ProfNB.SetSelection(cl) - profile.ProfNB.GetPage(cl).list.SetFocus() - UnSelectList(profile.ProfNB.GetPage(cl).list) - datas = dict([[profile.ProfNB.GetPage(cl).getColumnText(i,6),i] for i in range(profile.ProfNB.GetPage(cl).list.GetItemCount())]) - profile.ProfNB.GetPage(cl).list.SetItemState(datas[first_forme[0]], wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED) - profile.ProfNB.GetPage(cl).list.Focus(datas[first_forme[0]]) - profile.ProfNB.GetPage(cl).list.SetFocus() + profile.ProfNB.GetPage(cl).SetFocus() + print profile.ProfNB.GetPage(cl) + UnSelectList(profile.ProfNB.GetPage(cl)) + datas = dict([[profile.ProfNB.GetPage(cl).getColumnText(i,6),i] for i in range(profile.ProfNB.GetPage(cl).GetItemCount())]) + profile.ProfNB.GetPage(cl).SetItemState(datas[first_forme[0]], wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED) + profile.ProfNB.GetPage(cl).Focus(datas[first_forme[0]]) + profile.ProfNB.GetPage(cl).SetFocus() if len(proflist) == 1 : self.Destroy() else : @@ -2245,8 +2246,8 @@ class SearchDial ( wx.Dialog ): self.noresult() def onforward(self, evt) : - self.listctrl.list.Focus(self.items[self.forwitem]) - self.listctrl.list.SetFocus() + self.listctrl.Focus(self.items[self.forwitem]) + self.listctrl.SetFocus() self.forwitem += 1 if self.forwitem == len(self.items) : self.forward.Enable(False) @@ -2257,8 +2258,8 @@ class SearchDial ( wx.Dialog ): self.backward.Enable(True) def onbackward(self, evt) : - self.listctrl.list.Focus(self.items[self.backitem]) - self.listctrl.list.SetFocus() + self.listctrl.Focus(self.items[self.backitem]) + self.listctrl.SetFocus() self.backitem -= 1 if self.backitem == -1 : self.forwitem -= 1 @@ -2279,6 +2280,7 @@ class SearchDial ( wx.Dialog ): self.search.Clear() def UnSelectList(liste) : + print liste if liste.GetFirstSelected() != -1 : last = liste.GetFirstSelected() liste.Select(liste.GetFirstSelected(), False) @@ -2535,18 +2537,18 @@ class PrefWordCloud ( wx.Dialog ): self.m_staticline4 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) fgSizer1.Add( self.m_staticline4, 0, wx.EXPAND |wx.ALL, 5 ) - #self.m_staticText5 = wx.StaticText( self, wx.ID_ANY, u"Nombre maximum de formes", wx.DefaultPosition, wx.DefaultSize, 0 ) - #self.m_staticText5.Wrap( -1 ) - #fgSizer1.Add( self.m_staticText5, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, 5 ) + self.m_staticText5 = wx.StaticText( self, wx.ID_ANY, u"Nombre maximum de formes", wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticText5.Wrap( -1 ) + fgSizer1.Add( self.m_staticText5, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, 5 ) - #self.spin_maxword = wx.SpinCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.SP_ARROW_KEYS, 0, 10000, 600 ) - #fgSizer1.Add( self.spin_maxword, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) + self.spin_maxword = wx.SpinCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.SP_ARROW_KEYS, 0, 10000, 600 ) + fgSizer1.Add( self.spin_maxword, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) - #self.m_staticline5 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) - #fgSizer1.Add( self.m_staticline5, 0, wx.EXPAND |wx.ALL, 5 ) + self.m_staticline5 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) + fgSizer1.Add( self.m_staticline5, 0, wx.EXPAND |wx.ALL, 5 ) - #self.m_staticline6 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) - #fgSizer1.Add( self.m_staticline6, 0, wx.EXPAND |wx.ALL, 5 ) + self.m_staticline6 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) + fgSizer1.Add( self.m_staticline6, 0, wx.EXPAND |wx.ALL, 5 ) self.m_staticText6 = wx.StaticText( self, wx.ID_ANY, u"Taille du texte", wx.DefaultPosition, wx.DefaultSize, 0 ) self.m_staticText6.Wrap( -1 ) @@ -2767,7 +2769,8 @@ class CorpusPref ( wx.Dialog ): self.parent = parent langues_n = [u'français', u'english', u'german (expérimentale)', u'italian (expérimentale)', u'swedish (exp.)', u'portuguese (exp.)'] self.langues = [u'french', u'english', u'german', 'italian', 'swedish', u'portuguese'] - self.encodages = encodages + self.encodages = [enc[0].lower() for enc in encodages] + ucimark = [u'****', u'0000'] ucemethod = [u'charactères', u'occurrences', u'paragraphe'] @@ -2793,7 +2796,7 @@ class CorpusPref ( wx.Dialog ): self.m_staticText1.Wrap( -1 ) fgSizer1.Add( self.m_staticText1, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, 5 ) - encodage_choicesChoices = [' - '.join(encodage) for encodage in self.encodages] + encodage_choicesChoices = [' - '.join(encodage) for encodage in encodages] self.encodage_choices = wx.Choice( self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, encodage_choicesChoices, 0 ) self.encodage_choices.SetSelection( 0 ) fgSizer1.Add( self.encodage_choices, 0, wx.ALL, 5 ) @@ -2969,7 +2972,11 @@ class CorpusPref ( wx.Dialog ): pass def setparametres(self, parametres) : - self.encodage_choices.SetSelection(0) + if locale.getpreferredencoding().lower() == 'mac-roman' : + enc = self.encodages.index('macroman') + else : + enc = self.encodages.index(locale.getpreferredencoding().lower()) + self.encodage_choices.SetSelection(enc) self.lang_choices.SetSelection(0) self.repout_choices.SetValue(parametres['pathout']) self.ucimark_choices.SetSelection(parametres['ucimark']) @@ -2987,7 +2994,7 @@ class CorpusPref ( wx.Dialog ): def doparametres(self) : parametres = {} - parametres['encoding'] = self.encodages[self.encodage_choices.GetSelection()][0] + parametres['encoding'] = encodages[self.encodage_choices.GetSelection()][0] parametres['lang'] = self.langues[self.lang_choices.GetSelection()] parametres['pathout'] = self.repout_choices.GetValue() parametres['ucimark'] = self.ucimark_choices.GetSelection() diff --git a/functions.py b/functions.py index 0e5edfd..4479eaf 100644 --- a/functions.py +++ b/functions.py @@ -171,7 +171,8 @@ class DoConf : self.conf.write(f) def totext(self, parametres) : - txt = ['Corpus'] + #txt = ['Corpus'] + txt = [] for val in parametres : if isinstance(parametres[val], int) : txt.append(' \t\t: '.join([val, `parametres[val]`])) @@ -316,8 +317,8 @@ def formatExceptionInfo(maxTBlevel=5): cla, exc, trbk = sys.exc_info() excName = cla.__name__ try: - excArgs = exc.__dict__["args"] - except KeyError: + excArgs = exc.args[0] + except : excArgs = "" excTb = traceback.format_tb(trbk, maxTBlevel) return (excName, excArgs, excTb) @@ -330,7 +331,7 @@ def decoupercharact(chaine, longueur, longueurOptimale, separateurs = None) : Si on trouve un '$', c'est fini. Sinon, on cherche le meilleur candidat. C'est-à-dire le rapport poids/distance le plus important. """ - separateurs = [[u'.', 60.0], [u'?', 60.0], [u'!', 60.0], [u'£', 60], [u':', 50.0], [u';', 40.0], [u',', 10.0], [u' ', 0.1]] + separateurs = [[u'.', 60.0], [u'?', 60.0], [u'!', 60.0], [u'£$£', 60], [u':', 50.0], [u';', 40.0], [u',', 10.0], [u' ', 0.1]] trouve = False # si on a trouvé un bon séparateur iDecoupe = 0 # indice du caractere ou il faut decouper @@ -380,28 +381,38 @@ def decoupercharact(chaine, longueur, longueurOptimale, separateurs = None) : # si on a rien trouvé return False, chaine.split(), '' -def BugReport(parent): +def BugReport(parent, error = None): for ch in parent.GetChildren(): if "" == str(type(ch)): ch.Destroy() + excName, exc, excTb = formatExceptionInfo() + if excName == 'Exception' : + txt = 'Message :\n' + else : + txt = u' !== BUG ==! \n' + txt += u'*************************************\n' + txt += '\n'.join(excTb).replace(' ', ' ') + txt += excName + '\n' + txt += exc + dial = BugDialog(parent) - txt = u' !== BUG ==! \n' - txt += u'*************************************\n' - for line in formatExceptionInfo(): - if type(line) == type([]): - for don in line: - txt += don.replace(' ', ' ') - else: - txt += line + '\n' + #for line in formatExceptionInfo(): + # if type(line) == type([]): + # for don in line: + # txt += don.replace(' ', ' ') + # else: + # txt += line + '\n' if 'Rerror' in dir(parent) : txt += parent.Rerror parent.Rerror = '' + #if error is not None : + # txt += '\n%s\n' %error print formatExceptionInfo() log.error(txt) dial.text_ctrl_1.write(txt) dial.CenterOnParent() dial.ShowModal() - raise NameError('Bug') + #raise Exception('Bug') def PlaySound(parent): if parent.pref.getboolean('iramuteq', 'sound') : @@ -514,7 +525,7 @@ def check_Rresult(parent, pid) : except : BugReport(parent) else : - if pid !=0 : + if pid != 0 : try : raise Exception(u'Erreur R') except : diff --git a/guifunct.py b/guifunct.py index 7b1f2fe..f7e6249 100644 --- a/guifunct.py +++ b/guifunct.py @@ -114,36 +114,40 @@ def getCorpus(page) : return None class SelectColumn : - def __init__(self, parent, dictcol, actives, pathout, selected = None) : + def __init__(self, parent, dictcol, actives, pathout, selected = None, dlg = False) : self.ira = parent - dial = dialog.SelectColDial(self.ira) - listcol = ListForSpec(dial, self, dictcol, ['forme', 'eff']) - dial.bSizer2.Add( listcol, 2, wx.ALL|wx.EXPAND, 5 ) - dial.m_sdbSizer2.AddButton( dial.m_sdbSizer2OK ) - dial.m_sdbSizer2.Realize() - dial.bSizer2.Add( dial.m_sdbSizer2, 0, wx.EXPAND, 5 ) - dial.Layout() - if selected is None : - for row in xrange(listcol.list.GetItemCount()): - listcol.list.Select(row) + if dlg : + dial = dialog.SelectColDial(self.ira) + listcol = ListForSpec(dial, self, dictcol, ['forme', 'eff']) + dial.bSizer2.Add( listcol, 2, wx.ALL|wx.EXPAND, 5 ) + dial.m_sdbSizer2.AddButton( dial.m_sdbSizer2OK ) + dial.m_sdbSizer2.Realize() + dial.bSizer2.Add( dial.m_sdbSizer2, 0, wx.EXPAND, 5 ) + dial.Layout() + if selected is None : + for row in xrange(listcol.GetItemCount()): + listcol.Select(row) + else : + orderlex = dict([[listcol.getColumnText(i,0),i] for i in range(0,listcol.GetItemCount())]) + for row in selected : + listcol.Select(orderlex[actives[row]]) + dial.CenterOnParent() + val = dial.ShowModal() + last = listcol.GetFirstSelected() + lastl = [listcol.GetFirstSelected()] + indexes = [listcol.getColumnText(listcol.GetFirstSelected(),0)] + while listcol.GetNextSelected(last) != -1: + last = listcol.GetNextSelected(last) + lastl.append(last) + indexes.append(listcol.getColumnText(last,0)) + dial.Destroy() + column = [actives.index(val) for val in indexes] + column.sort() + with open(pathout, 'w') as f : + f.write('\n'.join([`val` for val in column])) else : - orderlex = dict([[listcol.getColumnText(i,0),i] for i in range(0,listcol.list.GetItemCount())]) - for row in selected : - listcol.list.Select(orderlex[actives[row]]) - dial.CenterOnParent() - val = dial.ShowModal() - last = listcol.list.GetFirstSelected() - lastl = [listcol.list.GetFirstSelected()] - indexes = [listcol.getColumnText(listcol.list.GetFirstSelected(),0)] - while listcol.list.GetNextSelected(last) != -1: - last = listcol.list.GetNextSelected(last) - lastl.append(last) - indexes.append(listcol.getColumnText(last,0)) - dial.Destroy() - column = [actives.index(val) for val in indexes] - column.sort() - with open(pathout, 'w') as f : - f.write('\n'.join([`val` for val in column])) + with open(pathout, 'w') as f : + f.write('\n'.join([`i` for i in range(0,len(actives))])) class PrepSimi : def __init__(self, parent, parametres, indices_simi) : diff --git a/iracmd.py b/iracmd.py index ad31bed..e0fd3da 100644 --- a/iracmd.py +++ b/iracmd.py @@ -35,7 +35,7 @@ log.debug('----------TEST corpusNG-----------------') from analysetxt import Alceste, gramact, gramsup from corpusNG import * - +#cmd = iracmd.CmdLine(args=['-f','/home/pierre/workspace/iramuteq/corpus/lru2.txt','-t','alceste']) AppliPath = os.path.abspath(os.path.dirname(os.path.realpath(sys.argv[0]))) if os.getenv('HOME') != None: @@ -45,10 +45,19 @@ else: UserConfigPath = os.path.abspath(os.path.join(user_home, '.iramuteq')) class CmdLine : - def __init__(self) : + def __init__(self, args = None) : self.DictPath = ConstructDicoPath(AppliPath) self.ConfigPath = ConstructConfigPath(UserConfigPath) self.syscoding = sys.getdefaultencoding() + self.TEMPDIR = tempfile.mkdtemp('iramuteq') + self.RscriptsPath = ConstructRscriptsPath(AppliPath) + self.PathPath = ConfigParser() + self.PathPath.read(self.ConfigPath['path']) + self.RPath = self.PathPath.get('PATHS', 'rpath') + self.pref = RawConfigParser() + self.pref.read(self.ConfigPath['preferences']) + self.history = History(self.ConfigPath['history']) + parser = OptionParser() parser.add_option("-f", "--file", dest="filename", help="chemin du corpus", metavar="FILE", default=False) @@ -58,8 +67,12 @@ class CmdLine : parser.add_option("-e", "--enc", dest="encodage", help="encodage du corpus", metavar="ENC", default=locale.getpreferredencoding()) parser.add_option("-l", "--lang", dest="language", help="langue du corpus", metavar="LANG", default='french') parser.add_option("-r", "--read", dest="read", help="lire un corpus", metavar="READ", default = False) + parser.add_option("-b", "--build", action="store_true", dest="build", help = "construire un corpus", default = False) - (options, args) = parser.parse_args() + if args is None : + (options, args) = parser.parse_args() + else : + (options, args) = parser.parse_args(args) print args print options options.type_analyse @@ -68,19 +81,16 @@ class CmdLine : elif options.filename and options.type_analyse : config = DoConf(self.ConfigPath[options.type_analyse]).getoptions() #self.ConfigPath[options.type_analyse] = os.path.abspath(options.configfile) + elif options.read and options.type_analyse : + config = DoConf(self.ConfigPath[options.type_analyse]).getoptions() elif options.read : pass + elif options.filename and options.build : + pass else : print 'rien a faire' return - self.TEMPDIR = tempfile.mkdtemp('iramuteq') - self.RscriptsPath = ConstructRscriptsPath(AppliPath) - self.PathPath = ConfigParser() - self.PathPath.read(self.ConfigPath['path']) - self.RPath = self.PathPath.get('PATHS', 'rpath') - self.pref = RawConfigParser() - self.pref.read(self.ConfigPath['preferences']) - self.history = History(self.ConfigPath['history']) + #self.history.write() if options.filename or options.read :#or options.build: self.corpus_encodage = options.encodage @@ -101,20 +111,27 @@ class CmdLine : corpus_parametres['encoding'] = self.corpus_encodage corpus_parametres['syscoding'] = locale.getpreferredencoding() corpus_parametres['pathout'] = PathOut(self.filename, 'corpus').mkdirout() - corpus = BuildFromAlceste(self.filename, corpus_parametres, self.lexique, self.expressions).corpus - self.history.add(corpus.parametres) - corpus = copycorpus(corpus) + try : + corpus = BuildFromAlceste(self.filename, corpus_parametres, self.lexique, self.expressions).corpus + except Exception, txt: + log.info('probleme lors de la construction: %s' %txt) + corpus = None + raise + else : + self.history.add(corpus.parametres) + corpus = copycorpus(corpus) #with codecs.open(self.filename, 'r', self.corpus_encodage) as f: elif options.read : corpus = Corpus(self, parametres = DoConf(options.read).getoptions('corpus'), read = options.read) corpus.parametres['path'] = os.path.abspath(options.read) pathout = os.path.dirname(os.path.dirname(os.path.abspath(options.read))) + self.corpus = corpus - - corpus.conn_all() - corpus.make_lems() - corpus.parse_active(gramact, gramsup) + if corpus is not None : + corpus.conn_all() + corpus.make_lems() + corpus.parse_active(gramact, gramsup) # log.warning('ATTENTION gethapaxuces') # MakeUciStat(corpus) # qfqsdf @@ -127,24 +144,24 @@ class CmdLine : # f.write('\n'.join(['\t'.join(val) for val in res])) # self.content = f.read() #self.content = self.content.replace('\r','') - if options.type_analyse == 'alceste' : - log.debug('ATTENTION : ANALYSE NG') - #print corpus.make_etoiles() - #zerzre - #corpus.read_corpus() - #corpus.parse_active(gramact, gramsup) - config['type'] = 'alceste' - Alceste(self, corpus, parametres = config) - # self.Text = AnalyseAlceste(self, cmd = True, big = True) - #self.Text = AnalyseAlceste(self, cmd = True) - elif options.type_analyse == 'pam' : - self.Text = PamTxt(self, cmd = True) - elif options.type_analyse == 'afcuci' : - self.Text = AfcUci(self, cmd = True) - elif options.type_analyse == 'stat' : - self.Text = Stat(self, corpus, config = {'type' : 'stat'}) - elif options.type_analyse == 'spec' : - self.Text = Lexico(self, corpus, config = {'type' : 'spec'}) + if options.type_analyse == 'alceste' : + log.debug('ATTENTION : ANALYSE NG') + #print corpus.make_etoiles() + #zerzre + #corpus.read_corpus() + #corpus.parse_active(gramact, gramsup) + config['type'] = 'alceste' + self.Text = Alceste(self, corpus, parametres = config) + # self.Text = AnalyseAlceste(self, cmd = True, big = True) + #self.Text = AnalyseAlceste(self, cmd = True) + elif options.type_analyse == 'pam' : + self.Text = PamTxt(self, cmd = True) + elif options.type_analyse == 'afcuci' : + self.Text = AfcUci(self, cmd = True) + elif options.type_analyse == 'stat' : + self.Text = Stat(self, corpus, parametres = config) + elif options.type_analyse == 'spec' : + self.Text = Lexico(self, corpus, config = {'type' : 'spec'}) #print self.Text.corpus.hours, 'h', self.Text.corpus.minutes,'min', self.Text.corpus.seconds, 's' # self.Text.corpus.make_colored_corpus('colored.html') diff --git a/iramuteq.py b/iramuteq.py index 01cbcb6..8fa06d6 100644 --- a/iramuteq.py +++ b/iramuteq.py @@ -118,7 +118,7 @@ if os.getenv('HOME') != None: else: user_home = os.getenv('HOMEPATH') UserConfigPath = os.path.abspath(os.path.join(user_home, '.iramuteq')) -#Si pas de fichiers de config utilisateur, on crée le repertoire +#Si pas de fichiers de config utilisateur, on cree le repertoire CreateIraDirectory(UserConfigPath, AppliPath) #fichiers log pour windows (py2exe) print 'PLUS DE LOG !!!!!!!!!!' @@ -177,37 +177,37 @@ class IraFrame(wx.Frame): self.mb = wx.MenuBar() file_menu = wx.Menu() - item = wx.MenuItem(file_menu, ID_OpenData, _(u"Open a questionnaire"), _(u"Open a questionnaire")) + item = wx.MenuItem(file_menu, ID_OpenData, _(u"Open a matrix"), _(u"Open a matrix")) item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN)) file_menu.AppendItem(item) - item = wx.MenuItem(file_menu, ID_OpenText, u"Ouvrir texte", u"Ouvrir un corpus texte") + item = wx.MenuItem(file_menu, ID_OpenText, _(u"Open a text corpora"), _(u"Open a text corpora")) item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN)) file_menu.AppendItem(item) - item = wx.MenuItem(file_menu, ID_OnOpenAnalyse, u"Ouvrir une Analyse", "Ouvrir une Analyse") + item = wx.MenuItem(file_menu, ID_OnOpenAnalyse, _(u"Open an analysis"), _("Open an analysis")) item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN)) file_menu.AppendItem(item) - item1 = wx.MenuItem(file_menu, ID_Import, u"Importer un corpus factiva...", "Importer un corpus factiva...") + item1 = wx.MenuItem(file_menu, ID_Import, _(u"Import a factiva corpora..."), _("Import a factiva corpora...")) item1.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_TIP)) file_menu.AppendItem(item1) #item1.Enable(True) - item = wx.MenuItem(file_menu, ID_SaveTab, u"Enregistrer l\'onglet sous...", u"Enregistrer l\'onglet sous ...") + item = wx.MenuItem(file_menu, ID_SaveTab, _(u"Save tab as..."), _(u"Save tab as...")) item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_SAVE_AS)) #item.Enable(False) file_menu.AppendItem(item) - file_menu.Append(wx.ID_EXIT, u"Exit") + file_menu.Append(wx.ID_EXIT, _(u"Exit")) edit_menu = wx.Menu() - edit_menu.Append(wx.ID_PREFERENCES, '', u'Préférences') + edit_menu.Append(wx.ID_PREFERENCES, '', _(u'Preferences')) view_menu = wx.Menu() - view_menu.Append(ID_ACCEUIL, u"Page d'accueil") - view_menu.Append(ID_VIEWDATA, u"Afficher les données") - view_menu.Append(ID_RESULT, u'Afficher les résultats') + view_menu.Append(ID_ACCEUIL, _(u"Home page")) + view_menu.Append(ID_VIEWDATA, _(u"Show data")) + view_menu.Append(ID_RESULT, _(u'Show results')) #view_menu.AppendSeparator() analyse_menu = wx.Menu() @@ -570,10 +570,13 @@ vous devez signaler le chemin de l'éxecutable de R dans les préférences.""" builder = Builder(self, dlg) if builder.res == wx.ID_OK : - corpus = builder.doanalyse() - self.history.add(corpus.parametres) - self.tree.OnItemAppend(corpus.parametres) - OpenAnalyse(self, corpus.parametres) + try : + corpus = builder.doanalyse() + self.history.add(corpus.parametres) + self.tree.OnItemAppend(corpus.parametres) + OpenAnalyse(self, corpus.parametres) + except : + BugReport(self) #self.content = DoConf().totext(corpus.parametres) # parametres = DoConf(os.path.join(UserConfigPath,'corpus.cfg')).getoptions('corpus') # parametres['originalpath'] = self.filename @@ -590,28 +593,24 @@ vous devez signaler le chemin de l'éxecutable de R dans les préférences.""" # corpus = BuildFromAlceste(self.filename, parametres, self.lexique, self.expressions).corpus #self.corpus_encodage = dial.encodages[dial.list_encodages.GetSelection()][0] #self.corpus_lang = dial.langues[dial.choice_dict.GetSelection()] - count = 1 - keepGoing = dlg.Update(count, u"Lecture du fichier") -# try : -# with codecs.open(self.filename, 'rU', self.corpus_encodage) as f: -# self.content = f.read() -# #self.content = self.content.replace('\r','\n') -# except UnicodeDecodeError : -# msg = u"Ce fichier ne semble pas être encodé en %s" % self.corpus_encodage -# dial = wx.MessageDialog(self, msg, u"Problème d'encodage", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING) -# dial.CenterOnParent() -# res = dial.ShowModal() -# dial.Destroy() -# self.OpenText() - self.ShowMenu(_("View")) - self.ShowMenu(_("Text analysis")) - self.ShowMenu(_(u"Spreadsheet analysis"), False) - self.type = "Texte" - self.DataTxt = False - self.Text = '' - count += 1 - keepGoing = dlg.Update(count, u"Chargement du dictionnaire") - dlg.Destroy() + else : + count = 1 + keepGoing = dlg.Update(count, u"Lecture du fichier") + # msg = u"Ce fichier ne semble pas être encodé en %s" % self.corpus_encodage + # dial = wx.MessageDialog(self, msg, u"Problème d'encodage", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING) + # dial.CenterOnParent() + # res = dial.ShowModal() + # dial.Destroy() + # self.OpenText() + self.ShowMenu(_("View")) + self.ShowMenu(_("Text analysis")) + self.ShowMenu(_(u"Spreadsheet analysis"), False) + self.type = "Texte" + self.DataTxt = False + self.Text = '' + count += 1 + keepGoing = dlg.Update(count, u"Chargement du dictionnaire") + dlg.Destroy() #self.OnViewData(wx.EVT_BUTTON) def OnExit(self, event): @@ -707,7 +706,6 @@ Voulez-vous fermer quand même ?""" remove = True if self.nb.GetPageCount() == 1 and remove and not notebook : self.LastTabClose() - def LastTabClose(self) : if self.nb.GetPageCount() == 1 : @@ -991,7 +989,9 @@ Voulez-vous fermer quand même ?""" class IntroPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent) - #col = randint(0, 100) + #col = randint(0, 255) + #col1 = randint(0,255) + #col2 = randint(0,255) col = 0 bckgrdcolor = wx.Colour(col, col, col) self.SetBackgroundColour(bckgrdcolor) diff --git a/layout.py b/layout.py index 91d5f83..642121c 100644 --- a/layout.py +++ b/layout.py @@ -227,6 +227,7 @@ class OpenCHDS(): self.pathout.basefiles(ChdTxtPathOut) DictPathOut = self.pathout self.DictPathOut = DictPathOut + self.dictpathout = DictPathOut self.parent = parent Profile = DictPathOut['PROFILE_OUT'] @@ -341,7 +342,7 @@ class OpenCHDS(): panel.ProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition) panel.ProfNB.SetArtProvider(aui.ChromeTabArt()) #self.ProfNB.SetTabCtrlHeight(100) - panel.AntiProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition) + #panel.AntiProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition) if os.path.exists(DictPathOut['prof_seg']) : prof_seg = ReadProfileAsDico(self, DictPathOut['prof_seg'], False, self.encoding) self.prof_seg_nb = aui.AuiNotebook(panel, -1, wx.DefaultPosition) @@ -351,9 +352,9 @@ class OpenCHDS(): indpour = ' - '.join([ind, DictProfile[str(i + 1)][0][2]]) print 'construction liste classe %i' % i self.tabprofile = ProfListctrlPanel(self.parent, self, DictProfile[str(i + 1)], Alceste, i + 1) - self.tabantiprofile = ProfListctrlPanel(self.parent, self, DictAnti[str(i + 1)], Alceste, i + 1) + #self.tabantiprofile = ProfListctrlPanel(self.parent, self, DictAnti[str(i + 1)], Alceste, i + 1) panel.ProfNB.AddPage(self.tabprofile, 'classe %s %s(%s%%)' % (str(i + 1), sep, indpour)) - panel.AntiProfNB.AddPage(self.tabantiprofile, 'classe %s' % str(i + 1)) + #panel.AntiProfNB.AddPage(self.tabantiprofile, 'classe %s' % str(i + 1)) if os.path.exists(DictPathOut['prof_seg']) : self.tab_prof_seg = ProfListctrlPanel(self.parent, self, prof_seg[str(i + 1)], False, i + 1) self.prof_seg_nb.AddPage(self.tab_prof_seg, 'classe %i' % (i + 1)) @@ -368,13 +369,13 @@ class OpenCHDS(): if os.path.exists(self.DictPathOut['afc_facteur']) : dictrow, first = ReadList(self.DictPathOut['afc_facteur'], self.encoding) self.TabAFC_facteur = ListForSpec(self.parent, parametres, dictrow, first) - dictrow, first = ReadList(self.DictPathOut['afc_row'], self.encoding) - self.TabAFC_ligne = ListForSpec(self.parent, self.parametres, dictrow, first) - dictrow, first = ReadList(self.DictPathOut['afc_col'], self.encoding) - self.TabAFC_colonne = ListForSpec(parent, self.parametres, dictrow, first) + #dictrow, first = ReadList(self.DictPathOut['afc_row'], self.encoding) + #self.TabAFC_ligne = ListForSpec(self.parent, self.parametres, dictrow, first) + #dictrow, first = ReadList(self.DictPathOut['afc_col'], self.encoding) + #self.TabAFC_colonne = ListForSpec(parent, self.parametres, dictrow, first) self.TabAFC.AddPage(self.TabAFC_facteur, 'Facteurs') - self.TabAFC.AddPage(self.TabAFC_colonne, u'Colonnes') - self.TabAFC.AddPage(self.TabAFC_ligne, u'Lignes') + #self.TabAFC.AddPage(self.TabAFC_colonne, u'Colonnes') + #self.TabAFC.AddPage(self.TabAFC_ligne, u'Lignes') sizer_3 = wx.BoxSizer(wx.VERTICAL) self.parent.nb_panel_2 = wx.Panel(panel.TabChdSim, -1) @@ -387,7 +388,7 @@ class OpenCHDS(): self.parent.Bind(wx.EVT_BUTTON, self.onsimi, self.parent.button_simi) panel.TabChdSim.AddPage(panel.ProfNB, 'Profils') - panel.TabChdSim.AddPage(panel.AntiProfNB, 'Antiprofils') + #panel.TabChdSim.AddPage(panel.AntiProfNB, 'Antiprofils') dlg.Update(4 + self.clnb, 'Affichage...') if clnb > 2 : panel.TabChdSim.AddPage(self.TabAFC, 'AFC') @@ -456,11 +457,13 @@ class OpenCHDS(): dlg.Destroy() def onprofseg(self, event): - try : + #try : + print 'plus de bug profseg' + print self.parametres corpus = self.parent.nb.GetPage(self.parent.nb.GetSelection()).corpus - ProfileSegment(self.parent,corpus) - except : - BugReport(self.parent) + ProfileSegment(self.parent, self.dictpathout, self.parametres, corpus) + #except : + # BugReport(self.parent) def onproftype(self, event): try : diff --git a/listlex.py b/listlex.py index 46d3b54..5d34a66 100644 --- a/listlex.py +++ b/listlex.py @@ -24,19 +24,19 @@ from PrintRScript import barplot from dialog import SearchDial #--------------------------------------------------------------------------- -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 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.Panel, listmix.ColumnSorterMixin): +class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin): def __init__(self, parent,gparent, dlist,first): + 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 - wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) search_id = wx.NewId() self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id) @@ -44,73 +44,65 @@ class ListForSpec(wx.Panel, listmix.ColumnSorterMixin): self.SetAcceleratorTable(self.accel_tbl) self.il = wx.ImageList(16, 16) - - self.sm_up = self.il.Add(getSmallUpArrowBitmap()) - self.sm_dn = self.il.Add(getSmallDnArrowBitmap()) + 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) + exec(s) + self.SetImageList(self.il, wx.IMAGE_LIST_SMALL) tID = wx.NewId() - self.list = List(self, tID, - style=wx.LC_REPORT - | wx.BORDER_NONE - | wx.LC_EDIT_LABELS - | wx.LC_SORT_ASCENDING - ) - - self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL) + self.attr1 = wx.ListItemAttr() + self.attr1.SetBackgroundColour((230, 230, 230)) + self.attr2 = wx.ListItemAttr() + self.attr2.SetBackgroundColour("light blue") self.dlist = dlist - self.PopulateList(dlist,first) - self.Bind(wx.EVT_SIZE, self.OnSize) - self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list) - self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick) + self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self) # for wxMSW - self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick) + self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick) # for wxGTK - self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick) + self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick) self.itemDataMap = dlist + self.itemIndexMap = dlist.keys() + self.SetItemCount(len(dlist)) + + listmix.ListCtrlAutoWidthMixin.__init__(self) listmix.ColumnSorterMixin.__init__(self, len(first)) self.SortListItems(1, False) - self.do_greyline() #----------------------------------------------------------------------------------------- - def PopulateList(self, dlist,first): i=0 for name in first : - self.list.InsertColumn(i,name,wx.LIST_FORMAT_LEFT) + self.InsertColumn(i,name,wx.LIST_FORMAT_LEFT) i+=1 - ct=0 - for key,data in dlist.iteritems() : - ct+=1 - index = self.list.InsertStringItem(sys.maxint, str(data[0])) - i=1 - for val in data[1:]: - self.list.SetStringItem(index, i, str(data[i])) - i+=1 - - self.list.SetItemData(index, key) - self.list.SetColumnWidth(0, wx.LIST_AUTOSIZE) + self.SetColumnWidth(0, 180) + for i in range(1,len(first)-1): - self.list.SetColumnWidth(i, 130) + self.SetColumnWidth(i, len(first[i]) * 10) - def do_greyline(self): - for row in xrange(self.list.GetItemCount()): - if row % 2 : - self.list.SetItemBackgroundColour(row,(230,230,230)) - else : - self.list.SetItemBackgroundColour(row,wx.WHITE) + def OnGetItemText(self, item, col): + index=self.itemIndexMap[item] + s = self.itemDataMap[index][col] + return s + + def OnGetItemAttr(self, item): + if item % 2 : + return self.attr1 + else : + return self.attr2 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py def GetListCtrl(self): - return self.list + return self # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py def GetSortImages(self): @@ -120,17 +112,22 @@ class ListForSpec(wx.Panel, listmix.ColumnSorterMixin): def OnRightDown(self, event): x = event.GetX() y = event.GetY() - item, flags = self.list.HitTest((x, y)) + item, flags = self.HitTest((x, y)) if flags & wx.LIST_HITTEST_ONITEM: - self.list.Select(item) + self.Select(item) event.Skip() def getColumnText(self, index, col): - item = self.list.GetItem(index, col) + item = self.GetItem(index, col) return item.GetText() + def GetItemData(self, item) : + index=self.itemIndexMap[item] + s = self.itemDataMap[index] + return s + def OnItemSelected(self, event): self.currentItem = event.m_itemIndex event.Skip() @@ -170,7 +167,7 @@ class ListForSpec(wx.Panel, listmix.ColumnSorterMixin): activenotebook = self.parent.nb.GetSelection() page = self.parent.nb.GetPage(activenotebook) corpus = page.corpus - word = self.getColumnText(self.list.GetFirstSelected(), 0) + word = self.getColumnText(self.GetFirstSelected(), 0) lems = corpus.getlems() rep = [] for forme in lems[word].formes : @@ -183,7 +180,7 @@ class ListForSpec(wx.Panel, listmix.ColumnSorterMixin): def OnPopupTwo(self, event): activenotebook = self.parent.nb.GetSelection() page = self.parent.nb.GetPage(activenotebook) - item=self.getColumnText(self.list.GetFirstSelected(), 0) + 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 @@ -198,53 +195,17 @@ class ListForSpec(wx.Panel, listmix.ColumnSorterMixin): forme = corpus.getforme(forme).forme ucetxt = ucetxt.replace(' '+forme+' ', ' ' + forme + ' ') txt += ucetxt + '

' -# for uce in uce_ok: -# content = ' '+' '.join(corpus.ucis_paras_uces[uce[0]][uce[1]][uce[2]])+' ' -# for form in listmot : -# sp = '' -# i = 0 -# forme = ' ' + form + ' ' -# while i < len(content): -# coordword = content[i:].find(forme) -# if coordword != -1 and i == 0: -# txt += '
' + ' '.join(corpus.ucis[uce[0]][0]) + '
' -# if coordword < avap: -# sp = ' ' * (avap - coordword) -# deb = i -# else: -# deb = i + coordword - avap -# if len(content) < i + coordword + avap: -# fin = len(content) - 1 -# else: -# fin = i + coordword + avap -# txt += '' + sp + content[deb:fin].replace(forme, '' + forme + '') + '
' -# i += coordword + len(forme) -# sp = '' -# elif coordword != -1 and i != 0 : -# if coordword < avap: -# sp = ' ' * (avap - coordword) -# deb = i -# else: -# deb = i + coordword - avap -# if len(content) < i + coordword + avap: -# fin = len(content) - 1 -# else: -# fin = i + coordword + avap -# txt += '' + sp + content[deb:fin].replace(forme, '' + forme + '') + '
' -# i += coordword + len(forme) -# sp = '' -# else: -# i = len(content) -# sp = '' win.HtmlPage.SetPage(txt) win.Show(True) def OnPopupThree(self, event) : - datas = [self.dlist[self.list.GetItemData(self.list.GetFirstSelected())]] - last = self.list.GetFirstSelected() - while self.list.GetNextSelected(last) != -1: - last = self.list.GetNextSelected(last) - data = self.dlist[self.list.GetItemData(last)] + print self.GetFirstSelected() + datas = [self.GetItemData(self.GetFirstSelected())] + print datas + last = self.GetFirstSelected() + while self.GetNextSelected(last) != -1: + last = self.GetNextSelected(last) + data = self.GetItemData(last) datas += [data] colnames = self.first[1:] table = [[str(val) for val in line[1:]] for line in datas] @@ -298,12 +259,12 @@ class ListForSpec(wx.Panel, listmix.ColumnSorterMixin): win.HtmlPage.SetPage(txt) win.Show(True) - def OnSize(self, event): - w,h = self.GetClientSizeTuple() - self.list.SetDimensions(0, 0, w, h) - - def OnColClick(self,event): - self.do_greyline() + def SortItems(self,sorter=cmp): + items = list(self.itemDataMap.keys()) + items.sort(sorter) + self.itemIndexMap = items + # redraw the list + self.Refresh() class message(wx.Frame): def __init__(self, *args, **kwds): @@ -340,37 +301,3 @@ class message(wx.Frame): def OnCloseWindow(self, event): self.Destroy() - - -def getSmallUpArrowData(): - return \ -'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ -\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ -\x00\x00C\xb0\x89\ -\xd3.\x10\xd1m\xc3\xe5*\xbc.\x80i\xc2\x17.\x8c\xa3y\x81\x01\x00\xa1\x0e\x04e\ -?\x84B\xef\x00\x00\x00\x00IEND\xaeB`\x82" - -def getSmallDnArrowBitmap(): - return wx.BitmapFromImage(getSmallDnArrowImage()) - -def getSmallDnArrowImage(): - stream = cStringIO.StringIO(getSmallDnArrowData()) - return wx.ImageFromStream(stream) diff --git a/messages.pot b/messages.pot index fb7e9f9..7b1034a 100644 --- a/messages.pot +++ b/messages.pot @@ -8,42 +8,78 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-09-16 16:27+0200\n" +"POT-Creation-Date: 2012-11-14 15:17+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" +"Language: \n" "MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" +"Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: iramuteq.py:134 -msgid "&Open a questionnaire\tCtrl+O" +#: iramuteq.py:244 +msgid "Edition" msgstr "" -#: iramuteq.py:184 -msgid "Edition" +#: iramuteq.py:202 +msgid "Exit" msgstr "" -#: iramuteq.py:183 +#: iramuteq.py:243 msgid "File" msgstr "" -#: iramuteq.py:188 +#: iramuteq.py:248 msgid "Help" msgstr "" -#: iramuteq.py:134 -msgid "Open a questionnaire" +#: iramuteq.py:208 +msgid "Home page" +msgstr "" + +#: iramuteq.py:192 +msgid "Import a factiva corpora..." +msgstr "" + +#: iramuteq.py:180 +msgid "Open a matrix" +msgstr "" + +#: iramuteq.py:184 +msgid "Open a text corpora" +msgstr "" + +#: iramuteq.py:188 +msgid "Open an analysis" +msgstr "" + +#: iramuteq.py:205 +msgid "Preferences" +msgstr "" + +#: iramuteq.py:197 +msgid "Save tab as..." +msgstr "" + +#: iramuteq.py:209 +msgid "Show data" +msgstr "" + +#: iramuteq.py:210 +msgid "Show results" msgstr "" -#: iramuteq.py:186 +#: iramuteq.py:246 iramuteq.py:457 iramuteq.py:608 tableau.py:178 msgid "Spreadsheet analysis" msgstr "" -#: iramuteq.py:187 +#: iramuteq.py:247 iramuteq.py:458 iramuteq.py:607 openanalyse.py:94 +#: openanalyse.py:97 openanalyse.py:100 openanalyse.py:103 openanalyse.py:106 +#: openanalyse.py:109 tableau.py:179 msgid "Text analysis" msgstr "" -#: iramuteq.py:185 +#: iramuteq.py:245 iramuteq.py:456 iramuteq.py:535 iramuteq.py:606 +#: tableau.py:177 msgid "View" msgstr "" diff --git a/profile_segment.py b/profile_segment.py index d3b3f46..3def4b8 100644 --- a/profile_segment.py +++ b/profile_segment.py @@ -13,9 +13,11 @@ from dialog import PrefSegProf, PrefProfTypes from time import sleep class ProfileSegment() : - def __init__(self, parent, corpus) : + def __init__(self, parent, pathout, parametres, corpus) : self.parent = parent self.corpus = corpus + self.dictpathout = pathout + self.parametres = parametres dial = PrefSegProf(self.parent) dial.CenterOnParent() if dial.ShowModal() == wx.ID_OK : @@ -37,19 +39,19 @@ class ProfileSegment() : self.dlg.Destroy() def make_table(self) : - self.corpus.make_segments_profile(self.corpus.dictpathout['segments_classes'], lenmin = self.mini, lenmax = self.maxi, effmin = self.eff, lem = self.lem) + self.corpus.make_segments_profile(self.dictpathout['segments_classes'], lenmin = self.mini, lenmax = self.maxi, effmin = self.eff, lem = self.lem) def make_prof(self) : txt = """ load("%s") source("%s") - """ % (self.corpus.dictpathout['RData'], self.parent.RscriptsPath['chdfunct']) + """ % (self.dictpathout['RData'], self.parent.RscriptsPath['chdfunct']) txt += """ dt <- read.csv2("%s", row.names = 1) to <- build.pond.prof(dt) PrintProfile(n1,to[4],NULL,to[5],NULL,clnb,"%s","%s") - """ % (self.corpus.dictpathout['segments_classes'], self.corpus.dictpathout['prof_seg'], self.corpus.dictpathout['antiprof_seg']) + """ % (self.corpus.dictpathout['segments_classes'], self.dictpathout['prof_seg'], self.dictpathout['antiprof_seg']) fo = tempfile.mktemp(dir=self.parent.TEMPDIR) with open(fo, 'w') as f : f.write(txt) @@ -63,7 +65,7 @@ class ProfileSegment() : SelectTab = self.parent.nb.GetSelection() page = self.parent.nb.GetPage(SelectTab).TabChdSim print page - prof_seg = ReadProfileAsDico(self, self.corpus.dictpathout['prof_seg'], True, self.corpus.parametre['syscoding']) + prof_seg = ReadProfileAsDico(self, self.dictpathout['prof_seg'], True, self.parent.syscoding) prof_seg_nb = aui.AuiNotebook(self.parent, -1, wx.DefaultPosition) for i in range(0,len(self.corpus.lc)) : ntab = ProfListctrlPanel(self.parent, self, prof_seg[str(i + 1)], False, i + 1) diff --git a/search_list.py b/search_list.py index 816660c..9502f84 100644 --- a/search_list.py +++ b/search_list.py @@ -23,14 +23,15 @@ from chemins import ffr from PrintRScript import barplot, dendroandbarplot #--------------------------------------------------------------------------- -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 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 SearchList(wx.Panel, listmix.ColumnSorterMixin): +class SearchList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin): #wx.Panel, listmix.ColumnSorterMixin): def __init__(self, parent,gparent, dlist,first, nbactives, nbetoiles, add_dendro=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 @@ -38,7 +39,7 @@ class SearchList(wx.Panel, listmix.ColumnSorterMixin): self.first = ['id','formes'] + first self.nbactives = nbactives self.nbetoiles = nbetoiles - wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) + #wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) self.il = wx.ImageList(16, 16) @@ -48,31 +49,34 @@ class SearchList(wx.Panel, listmix.ColumnSorterMixin): tID = wx.NewId() - self.list = List(self, tID, - style=wx.LC_REPORT - | wx.BORDER_NONE - | wx.LC_EDIT_LABELS - | wx.LC_SORT_ASCENDING - ) + #self.list = List(self, tID, + # style=wx.LC_REPORT + # | wx.BORDER_NONE + # | wx.LC_EDIT_LABELS + # | wx.LC_SORT_ASCENDING + # ) - self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL) + #self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL) self.dlist = dlist - self.PopulateList(dlist,first) self.Bind(wx.EVT_SIZE, self.OnSize) - self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list) + self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self) self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick) # for wxMSW - self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick) + self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick) # for wxGTK - self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick) + self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick) self.itemDataMap = dlist + self.itemIndexMap = dlist.keys() + self.SetItemCount(len(dlist)) listmix.ColumnSorterMixin.__init__(self, len(first)+2) + + self.PopulateList(dlist,first) self.SortListItems(1, False) self.do_greyline() @@ -81,40 +85,40 @@ class SearchList(wx.Panel, listmix.ColumnSorterMixin): def PopulateList(self, dlist,first): first = ['id','formes']+first for i, name in enumerate(first) : - self.list.InsertColumn(i, name, wx.LIST_FORMAT_LEFT) - - for key in dlist : - index = self.list.InsertStringItem(sys.maxint, '%5i' % key) - for i, val in enumerate(dlist[key][1:]) : - self.list.SetStringItem(index, i+1, str(dlist[key][i+1])) - self.list.SetItemData(index, key) + self.InsertColumn(i, name, wx.LIST_FORMAT_LEFT) + + #for key in dlist : + # index = self.list.InsertStringItem(sys.maxint, '%5i' % key) + # for i, val in enumerate(dlist[key][1:]) : + # self.list.SetStringItem(index, i+1, str(dlist[key][i+1])) + # self.list.SetItemData(index, key) - self.list.SetColumnWidth(0, wx.LIST_AUTOSIZE) + self.SetColumnWidth(0, wx.LIST_AUTOSIZE) for i in range(1,len(first)-1): - self.list.SetColumnWidth(i, 130) + self.SetColumnWidth(i, 130) if self.nbactives + self.nbetoiles != len(dlist) : #there is supp data for i in range(self.nbactives, (len(dlist) - self.nbetoiles)) : - item = self.list.GetItem(i) + item = self.GetItem(i) item.SetTextColour(wx.RED) - self.list.SetItem(item) + self.SetItem(item) for i in range((len(dlist) - self.nbetoiles), len(dlist)) : - item = self.list.GetItem(i) + item = self.GetItem(i) item.SetTextColour(wx.BLUE) - self.list.SetItem(item) + self.SetItem(item) def do_greyline(self): - for row in xrange(self.list.GetItemCount()): + for row in xrange(self.GetItemCount()): if row % 2 : - self.list.SetItemBackgroundColour(row,(230,230,230)) + self.SetItemBackgroundColour(row,(230,230,230)) else : - self.list.SetItemBackgroundColour(row,wx.WHITE) + self.SetItemBackgroundColour(row,wx.WHITE) # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py def GetListCtrl(self): - return self.list + return self # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py def GetSortImages(self): @@ -124,18 +128,21 @@ class SearchList(wx.Panel, listmix.ColumnSorterMixin): def OnRightDown(self, event): x = event.GetX() y = event.GetY() - item, flags = self.list.HitTest((x, y)) + item, flags = self.HitTest((x, y)) if flags & wx.LIST_HITTEST_ONITEM: - self.list.Select(item) + self.Select(item) event.Skip() - def getColumnText(self, index, col): - item = self.list.GetItem(index, col) + item = self.GetItem(index, col) return item.GetText() + def OnGetItemText(self, item, col): + index=self.itemIndexMap[item] + s = self.itemDataMap[index][col] + return s def OnItemSelected(self, event): self.currentItem = event.m_itemIndex @@ -173,7 +180,7 @@ class SearchList(wx.Panel, listmix.ColumnSorterMixin): activenotebook = self.parent.nb.GetSelection() page = self.parent.nb.GetPage(activenotebook) corpus = page.corpus - word = self.getColumnText(self.list.GetFirstSelected(), 0) + word = self.getColumnText(self.GetFirstSelected(), 0) lems = corpus.lems rep = [] for forme in lems[word] : @@ -186,7 +193,7 @@ class SearchList(wx.Panel, listmix.ColumnSorterMixin): def OnPopupTwo(self, event): activenotebook = self.parent.nb.GetSelection() page = self.parent.nb.GetPage(activenotebook) - item=self.getColumnText(self.list.GetFirstSelected(), 0) + 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 @@ -236,11 +243,11 @@ class SearchList(wx.Panel, listmix.ColumnSorterMixin): win.Show(True) def OnPopupThree(self, event) : - datas = [self.dlist[self.list.GetItemData(self.list.GetFirstSelected())]] - last = self.list.GetFirstSelected() - while self.list.GetNextSelected(last) != -1: - last = self.list.GetNextSelected(last) - data = self.dlist[self.list.GetItemData(last)] + datas = [self.dlist[self.GetItemData(self.GetFirstSelected())]] + last = self.GetFirstSelected() + while self.GetNextSelected(last) != -1: + last = self.GetNextSelected(last) + data = self.dlist[self.GetItemData(last)] datas += [data] colnames = self.first[2:] rownames = [val[1] for val in datas] @@ -259,11 +266,11 @@ class SearchList(wx.Panel, listmix.ColumnSorterMixin): def ongraphdendro(self, evt) : corpus = self.parent.corpus - datas = [self.dlist[self.list.GetItemData(self.list.GetFirstSelected())]] - last = self.list.GetFirstSelected() - while self.list.GetNextSelected(last) != -1: - last = self.list.GetNextSelected(last) - data = self.dlist[self.list.GetItemData(last)] + datas = [self.dlist[self.GetItemData(self.GetFirstSelected())]] + last = self.GetFirstSelected() + while self.GetNextSelected(last) != -1: + last = self.GetNextSelected(last) + data = self.dlist[self.GetItemData(last)] datas += [data] colnames = self.first[2:] rownames = [val[1] for val in datas] @@ -282,7 +289,7 @@ class SearchList(wx.Panel, listmix.ColumnSorterMixin): def OnSize(self, event): w,h = self.GetClientSizeTuple() - self.list.SetDimensions(0, 0, w, h) + self.SetDimensions(0, 0, w, h) def OnColClick(self,event): self.do_greyline() diff --git a/textsimi.py b/textsimi.py index 18da495..c8d1d62 100644 --- a/textsimi.py +++ b/textsimi.py @@ -31,10 +31,11 @@ class SimiTxt(AnalyseText): #FIXME self.actives = self.corpus.make_actives_limit(3) dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)]) - SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv']) + SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], dlg = self.dlg) self.makefiles() - prep = PrepSimi(self.ira, self.parametres, indices_simi) - self.parametres = prep.parametres + if self.dlg : + prep = PrepSimi(self.ira, self.parametres, indices_simi) + self.parametres = prep.parametres script = PrintSimiScript(self) script.make_script() self.doR(script.scriptout) diff --git a/textwordcloud.py b/textwordcloud.py index 9e35872..01ccf9a 100644 --- a/textwordcloud.py +++ b/textwordcloud.py @@ -26,7 +26,13 @@ class WordCloud(AnalyseText): def doanalyse(self) : self.parametres['type'] = 'wordcloud' #FIXME - self.actives = self.corpus.make_actives_limit(3) + limit = 3 + mode = 'both' + if mode == 'both' : + self.actives = self.corpus.make_actives_limit(limit, 1) + self.actives += self.corpus.make_actives_limit(limit, 2) + elif mode == 'act' : + self.actives = self.corpus.make_actives_limit(limit, 1) dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)]) SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv']) self.make_option() @@ -43,6 +49,7 @@ class WordCloud(AnalyseText): self.parametres['width'] = dial.spin_L.GetValue() self.parametres['height'] = dial.spin_H.GetValue() #maxword = dial.spin_maxword.GetValue() + self.parametres['maxword'] = dial.spin_maxword.GetValue() self.parametres['mincex'] = float(dial.spin_mincex.GetValue())/float(10) self.parametres['maxcex'] = float(dial.spin_maxcex.GetValue())/float(10) self.parametres['col_text'] = dial.color_text.GetColour() diff --git a/tree.py b/tree.py index d856799..5e90eb0 100644 --- a/tree.py +++ b/tree.py @@ -15,6 +15,62 @@ from functions import DoConf log = logging.getLogger('iramuteq.tree') #from agw import customtreectrl as CT +class InfoDialog ( wx.Dialog ): + + def __init__( self, parent, txt, parametres ): + wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Informations", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE ) + + self.SetSizeHintsSz( wx.Size( 400,200 ), wx.DefaultSize ) + + bSizer1 = wx.BoxSizer( wx.VERTICAL ) + + self.m_panel2 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) + bSizer2 = wx.BoxSizer( wx.VERTICAL ) + + self.m_staticText4 = wx.StaticText( self.m_panel2, wx.ID_ANY, txt, wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticText4.Wrap( -1 ) + bSizer2.Add( self.m_staticText4, 0, wx.ALL, 5 ) + + + self.m_panel2.SetSizer( bSizer2 ) + self.m_panel2.Layout() + bSizer2.Fit( self.m_panel2 ) + bSizer1.Add( self.m_panel2, 0, wx.EXPAND |wx.ALL, 5 ) + + self.m_panel1 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) + fgSizer1 = wx.FlexGridSizer( 0, 2, 0, 0 ) + fgSizer1.SetFlexibleDirection( wx.BOTH ) + fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED ) + + for val in parametres : + fgSizer1.Add( wx.StaticText( self.m_panel1, wx.ID_ANY, val[0], wx.DefaultPosition, wx.DefaultSize, 0 ), 0, wx.ALL, 0) + fgSizer1.Add( wx.StaticText( self.m_panel1, wx.ID_ANY, val[1], wx.DefaultPosition, wx.DefaultSize, 0 ), 0, wx.ALL, 0) + fgSizer1.Add( wx.StaticLine( self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ), 0, wx.EXPAND |wx.ALL, 0) + fgSizer1.Add( wx.StaticLine( self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ), 0, wx.EXPAND|wx.ALL, 0) + + self.m_panel1.SetSizer( fgSizer1 ) + self.m_panel1.Layout() + fgSizer1.Fit( self.m_panel1 ) + bSizer1.Add( self.m_panel1, 0, wx.EXPAND |wx.ALL, 3 ) + + m_sdbSizer1 = wx.StdDialogButtonSizer() + self.m_sdbSizer1OK = wx.Button( self, wx.ID_OK ) + m_sdbSizer1.AddButton( self.m_sdbSizer1OK ) + m_sdbSizer1.Realize(); + + bSizer1.Add( m_sdbSizer1, 0, wx.EXPAND, 5 ) + + + self.SetSizer( bSizer1 ) + self.Layout() + bSizer1.Fit( self ) + + self.Centre( wx.BOTH ) + + def __del__( self ): + pass + + class LeftTree(CT.CustomTreeCtrl): def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, @@ -467,11 +523,14 @@ class LeftTree(CT.CustomTreeCtrl): numchildren = str(self.itemdict["children"]) itemtype = self.itemdict["itemtype"] pydata = self.itemdict['pydata'] - if 'analyses' in pydata : - toshow = dict([[val, pydata[val]] for val in pydata if val not in['analyses', 'isload']]) - else : - toshow = pydata - pydata = DoConf().totext(toshow) + #if 'analyses' in pydata : + # toshow = dict([[val, pydata[val]] for val in pydata if val not in['analyses', 'isload']]) + #else : + toshow = pydata['ira'] + toshow = DoConf(toshow).getoptions() + txt = DoConf().totext(toshow) + parametres = [val.split('\t\t:') for val in txt.splitlines()] + parametres.sort() if itemtype == 0: itemtype = "Normal" @@ -480,12 +539,7 @@ class LeftTree(CT.CustomTreeCtrl): else: itemtype = "RadioButton" - strs = "Information On Selected Item:\n\n" + "Text: " + itemtext + "\n" \ - "Number Of Children: " + numchildren + "\n" \ - "Item Type: " + itemtype + "\n" \ - "Item Data Type: " + pydata + "\n" - - dlg = wx.MessageDialog(self, strs, "CustomTreeCtrlDemo Info", wx.OK | wx.ICON_INFORMATION) + dlg = InfoDialog(self, itemtext, parametres) dlg.ShowModal() dlg.Destroy() -- 2.7.4