multisplit
[iramuteq] / search_tools.py
1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2020 Pierre Ratinaud
4 #modification pour python 3 : Laurent Mérat, 6x7 - mai 2020
5 #License: GNU/GPL
6
7 #------------------------------------
8 # import des modules python
9 #------------------------------------
10 import codecs
11
12 #------------------------------------
13 # import des modules wx
14 #------------------------------------
15 import wx
16
17 #------------------------------------
18 # import des fichiers du projet
19 #------------------------------------
20 from search_list import SearchList
21 from dialog import SearchDial
22
23
24 class SearchFrame(wx.Frame):
25
26     def __init__(self, parent, id, title, corpus, size=(800, 900)):
27         # begin wxGlade: MyFrame.__init__
28         #kwds["style"] = wx.DEFAULT_FRAME_STYLE
29         wx.Frame.__init__(self, parent, id, size = size, style = wx.CLOSE_BOX|wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL)
30         self.parent = parent
31         self.ira = wx.GetApp().GetTopWindow()
32         self.SetIcon(self.ira._icon)
33         search_id = wx.NewId()
34         self.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
35         self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id)])
36         self.SetAcceleratorTable(self.accel_tbl)
37         self.corpus = corpus
38         dlg = wx.ProgressDialog("Traitements", "lecture du tableau...", maximum = 4, parent=self, style = wx.PD_APP_MODAL|wx.PD_AUTO_HIDE|wx.PD_ELAPSED_TIME)
39         dlg.Center()
40         dlg.Update(1)
41         with open(corpus.dictpathout['chisqtable'], 'r', encoding='utf8') as f :
42             chisqtable = [line.replace('\n','').replace('"','').replace(',','.').split(';') for line in f]
43         first = chisqtable[0]
44         first.pop(0)
45         chisqtable.pop(0)
46         dlg.Update(2)
47         self.dchisqtable = dict([[i, [i, line[0]] + [float(val) for val in line[1:]]] for i, line in enumerate(chisqtable)])
48         self.dindex = dict([[line[0], i] for i,line in enumerate(chisqtable)]) 
49         #self.text_ctrl_1 = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE)
50         #nbactives = len(self.corpus.actives)
51         dlg.Update(3)
52         with open(corpus.dictpathout['ContEtOut'], 'r', encoding='utf8') as f :
53             nbetoiles = len(f.readlines())
54         with open(corpus.dictpathout['Contout'], 'r', encoding='utf8') as f :
55             nbactives = len(f.readlines())
56         dlg.Update(4, "Ouverture...")
57         self.liste = SearchList(self, parent, self.dchisqtable, first, nbactives, nbetoiles) 
58         dlg.Destroy()
59         #self.HtmlPage = wx.html.HtmlWindow(self, -1)
60         #if "gtk2" in wx.PlatformInfo:
61         #    self.HtmlPage.SetStandardFonts()
62         #self.HtmlPage.SetFonts('Courier', 'Courier')
63         self.button_1 = wx.Button(self, -1, "Fermer")
64         self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
65         self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
66         self.SetTitle('Navigation')
67         self.SetSize(wx.Size(900,700))
68         self.__do_layout()
69         # end wxGlade
70
71     def __do_layout(self):
72         # begin wxGlade: MyFrame.__do_layout
73         sizer_1 = wx.BoxSizer(wx.VERTICAL)
74         sizer_2 = wx.BoxSizer(wx.VERTICAL)
75         sizer_2.Add(self.liste, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
76         #sizer_2.Add(self.HtmlPage, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
77         sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, 0)
78         sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
79         self.SetAutoLayout(True)
80         self.SetSizer(sizer_1)
81         self.Layout()
82         # end wxGlade
83
84     def OnCloseMe(self, event):
85         self.Show(False)
86
87     def OnCloseWindow(self, event):
88         self.Show(False)
89
90     def onsearch(self, evt) :
91         if evt is not None :
92             self.dial = SearchDial(self, self.liste, 1, True)
93             self.dial.Show()
94             #self.dial.Destroy()
95         else :
96             self.dial = SearchDial(self, self.liste, 1, False)