# -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Author: Pierre Ratinaud
#
#comes from ListCtrl.py from the demo tool of wxPython:
# Author: Robin Dunn & Gary Dumer
#
# Created:
# Copyright: (c) 1998 by Total Control Software
# Licence: wxWindows license
#----------------------------------------------------------------------------
import os
import sys
import wx
import wx.lib.mixins.listctrl as listmix
import cStringIO
import tempfile
from functions import exec_rcode, MessageImage
from chemins import ffr
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 ListForSpec(wx.Panel, listmix.ColumnSorterMixin):
def __init__(self, parent,gparent, dlist,first):
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)
self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id)])
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())
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.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)
# 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 = dlist
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)
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)
for i in range(1,len(first)-1):
self.list.SetColumnWidth(i, 130)
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, 0, True)
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 not hasattr(self, "popupID1"):
self.popupID1 = wx.NewId()
self.popupID2 = wx.NewId()
self.popupID3 = wx.NewId()
self.popup_Tgen_glob = wx.NewId()
self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
self.Bind(wx.EVT_MENU, self.OnTgen_glob, id=self.popup_Tgen_glob)
# make a menu
menu = wx.Menu()
# add some items
menu.Append(self.popupID1, u"Formes associƩes")
menu.Append(self.popupID2, u"Concordancier")
menu.Append(self.popupID3, "Graphique")
#menu.Append(self.popup_Tgen_glob, "Tgen global")
self.PopupMenu(menu)
menu.Destroy()
def OnPopupOne(self, event):
activenotebook = self.parent.nb.GetSelection()
page = self.parent.nb.GetPage(activenotebook)
corpus = page.corpus
word = self.getColumnText(self.list.GetFirstSelected(), 0)
lems = corpus.getlems()
rep = []
for forme in lems[word].formes :
rep.append([corpus.getforme(forme).forme, corpus.getforme(forme).freq])
win = message(self, -1, u"Formes associƩes", size=(300, 200), style=wx.DEFAULT_FRAME_STYLE)
win.html = '\n' + '
'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n'
win.HtmlPage.SetPage(win.html)
win.Show(True)
def OnPopupTwo(self, event):
activenotebook = self.parent.nb.GetSelection()
page = self.parent.nb.GetPage(activenotebook)
item=self.getColumnText(self.list.GetFirstSelected(), 0)
corpus = page.corpus
win = message(self, -1, u"Concordancier", size=(600, 200),style = wx.DEFAULT_FRAME_STYLE)
avap=60
listmot = corpus.getlems()[item].formes
uce_ok = corpus.getlemuces(item)
txt = '