1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2009 Pierre Ratinaud
8 from KeyFrame import AlcOptFrame
9 from chemins import ConstructConfigPath
10 from functions import DoConf
14 class OptionAlc(wx.Dialog):
15 def __init__(self, parent, parametres, *args, **kwds):
16 kwds['style'] = wx.DEFAULT_DIALOG_STYLE
17 wx.Dialog.__init__(self, parent, *args, **kwds)
19 self.parametres = parametres
20 self.DictPath = parametres['pathout']
21 self.AlcesteConf = parametres
23 self.svdmethod = ['svdR', 'irlba']
24 if self.parent.pref.getboolean('iramuteq','libsvdc') :
25 self.svdmethod.append('svdlibc')
26 #self.label_1 = wx.StaticText(self, -1, u"Lemmatisation")
27 #self.radio_1 = wx.RadioBox(self, -1, u"", choices=['oui', 'non'], majorDimension=0, style=wx.RA_SPECIFY_ROWS)
29 self.label_12 = wx.StaticText(self, -1, u"Classification")
30 self.radio_box_2 = wx.RadioBox(self, -1, u"", choices=[u"double sur UC", u"simple sur UCE", u"simple sur UCI"], majorDimension=0, style=wx.RA_SPECIFY_ROWS) #, u"simple sur UCE (non implemente)"
31 self.label_2 = wx.StaticText(self, -1, u"taille uc 1")
32 self.spin_ctrl_1 = wx.SpinCtrl(self, -1, "formes actives",size = (100,30), min=0, max=100)
33 self.label_3 = wx.StaticText(self, -1, u"taille uc 2")
34 self.spin_ctrl_2 = wx.SpinCtrl(self, -1, "",size = (100,30), min=0, max=100)
35 self.lab_nbcl = wx.StaticText(self, -1, u"nombre de classes terminales de la phase 1")
36 self.spin_nbcl = wx.SpinCtrl(self, -1, "",size = (100,30), min=2, max=100)
37 txt = """Nombre minimum d'uce par classe
39 self.label_7 = wx.StaticText(self, -1, txt)
40 self.spin_ctrl_4 = wx.SpinCtrl(self, -1, "",size = (100,30), min=0, max=1000)
41 txt = u"""Fréquence minimum d'une forme
42 analysée (2 = automatique)"""
43 self.label_8 = wx.StaticText(self, -1, txt)
44 self.spin_ctrl_5 = wx.SpinCtrl(self, -1, "",size = (100,30), min=2, max=1000)
45 self.label_max_actives = wx.StaticText(self, -1, u"Nombre maximum de formes analysées")
46 self.spin_max_actives = wx.SpinCtrl(self, -1, "",size = (100,30), min=20, max=10000)
47 self.label_svd = wx.StaticText(self, -1, u"Méthode pour svd")
48 self.choicesvd = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, self.svdmethod, 0 )
49 self.label_patate = wx.StaticText(self, -1, u"Mode patate (+ rapide, - précis)")
50 self.check_patate = wx.CheckBox( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
51 #self.label_4 = wx.StaticText(self, -1, u"Configuration \ndes clés d'analyse")
52 #self.button_5 = wx.Button(self, wx.ID_PREFERENCES, "")
53 self.button_1 = wx.Button(self, wx.ID_CANCEL, "")
54 self.button_2 = wx.Button(self, wx.ID_DEFAULT, u"Valeurs par défaut")
55 self.button_4 = wx.Button(self, wx.ID_OK, "")
56 self.static_line_1 = wx.StaticLine(self, -1)
58 self.__set_properties()
61 #self.Bind(wx.EVT_BUTTON, self.OnKeyPref, self.button_5)
62 self.Bind(wx.EVT_BUTTON, self.OnDef, self.button_2)
64 def __set_properties(self):
65 self.SetTitle("Options")
66 #lang = self.AlcesteConf.get('ALCESTE', 'lang')
67 #self.choice_dict.SetSelection(self.langues.index(lang))
68 #DefaultLem = self.parametres['lem']
70 # self.radio_1.SetSelection(0)
72 # self.radio_1.SetSelection(1)
73 self.radio_box_2.SetSelection(int(self.parametres['classif_mode']))
74 self.spin_ctrl_1.SetValue(int(self.parametres['tailleuc1']))
75 self.spin_ctrl_2.SetValue(int(self.parametres['tailleuc2']))
76 self.spin_ctrl_4.SetValue(int(self.parametres['mincl']))
77 self.spin_ctrl_5.SetValue(int(self.parametres['minforme']))
78 self.spin_ctrl_5.Disable()
79 self.spin_max_actives.SetValue(int(self.parametres['max_actives']))
80 self.spin_nbcl.SetValue(int(self.parametres['nbcl_p1']))
81 if 'svdmethod' in self.parametres :
82 self.choicesvd.SetSelection(self.svdmethod.index(self.parametres['svdmethod']))
84 self.choicesvd.SetSelection(1)
85 if 'mode.patate' in self.parametres :
86 self.check_patate.SetValue(self.parametres['mode.patate'])
88 self.check_patate.SetValue(False)
91 def __do_layout(self):
92 sizer_1 = wx.BoxSizer(wx.VERTICAL)
93 sizer_2 = wx.BoxSizer(wx.VERTICAL)
94 grid_sizer2 = wx.FlexGridSizer(0, 2, 0, 0)
95 grid_button = wx.FlexGridSizer(1, 3, 0, 0)
97 #grid_sizer2.Add(self.label_dict, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
98 #grid_sizer2.Add(self.choice_dict, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
100 #grid_sizer2.Add(self.label_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
101 #grid_sizer2.Add(self.radio_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
102 #grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
103 #grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
105 grid_sizer2.Add(self.label_12, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
106 grid_sizer2.Add(self.radio_box_2, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
107 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
108 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
110 grid_sizer2.Add(self.label_2, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
111 grid_sizer2.Add(self.spin_ctrl_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
112 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
113 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
115 grid_sizer2.Add(self.label_3, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
116 grid_sizer2.Add(self.spin_ctrl_2, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
117 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
118 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
120 grid_sizer2.Add(self.lab_nbcl, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
121 grid_sizer2.Add(self.spin_nbcl, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
122 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
123 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
125 grid_sizer2.Add(self.label_7, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
126 grid_sizer2.Add(self.spin_ctrl_4, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
127 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
128 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
130 grid_sizer2.Add(self.label_8, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
131 grid_sizer2.Add(self.spin_ctrl_5, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
132 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
133 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
135 grid_sizer2.Add(self.label_max_actives, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
136 grid_sizer2.Add(self.spin_max_actives, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
137 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
138 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
140 grid_sizer2.Add(self.label_svd, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
141 grid_sizer2.Add(self.choicesvd, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
142 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
143 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
145 grid_sizer2.Add(self.label_patate, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
146 grid_sizer2.Add(self.check_patate, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
147 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
148 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
150 grid_button.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
151 grid_button.Add(self.button_2, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
152 grid_button.Add(self.button_4, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
153 sizer_2.Add(grid_sizer2, 3, wx.EXPAND, 0)
154 sizer_2.Add(grid_button, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
155 sizer_1.Add(sizer_2, 0, wx.EXPAND, 0)
156 self.SetSizer(sizer_1)
160 def OnKeyPref(self, event):
162 dial = AlcOptFrame(self.parent, self)
163 dial.CenterOnParent()
164 val = dial.ShowModal()
166 def OnDef(self, event):
167 ConfOri = ConstructConfigPath(self.parent.AppliPath, user=False)
168 ConfUser = ConstructConfigPath(self.parent.UserConfigPath)
169 shutil.copyfile(ConfOri['alceste'], ConfUser['alceste'])
170 corpus = self.parametres['corpus']
171 pathout = self.parametres['pathout']
172 self.parametres = DoConf(self.parent.ConfigPath['alceste']).getoptions('ALCESTE')
173 self.parametres['corpus'] = corpus
174 self.parametres['pathout'] = pathout
175 self.__set_properties()
177 ###################################################################################@
179 class OptionPam(wx.Dialog):
180 def __init__(self, parent, *args, **kwds):
181 kwds['style'] = wx.DEFAULT_DIALOG_STYLE
182 wx.Dialog.__init__(self, *args, **kwds)
184 self.DictPath = parent.DictPath
185 self.pamconf = parent.pamconf
186 self.type = parent.type
189 self.label_1 = wx.StaticText(self, -1, u"Lemmatisation")
190 self.radio_1 = wx.RadioBox(self, -1, u"", choices=['oui', 'non'], majorDimension=0, style=wx.RA_SPECIFY_ROWS)
191 #self.label_exp = wx.StaticText(self, -1, u"Utiliser le dict. des expressions")
192 #self.radio_exp = wx.RadioBox(self, -1, u"", choices=['oui', 'non'], majorDimension=0, style=wx.RA_SPECIFY_ROWS)
193 txt = u"""Methode de construction
194 de la matrice des distances"""
195 self.label_12 = wx.StaticText(self, -1, txt)
196 self.distance = [u"binary", u"euclidean", u"maximum", u'manhattan', u'canberra', u'minkowski']
197 self.choice_1 = wx.Choice(self, -1, (100,50), choices=self.distance)
198 self.label_13 = wx.StaticText(self, -1, u'Analyse')
199 self.cltype = [u'k-means (pam)', u'fuzzy (fanny)']
200 self.radio_box_3 = wx.RadioBox(self, -1, u"", choices=self.cltype, majorDimension=0, style=wx.RA_SPECIFY_ROWS)
201 self.label_classif = wx.StaticText(self, -1, u"Classification")
202 self.radio_box_classif = wx.RadioBox(self, -1, u"", choices=[u"sur UCE", u"sur UCI"], majorDimension=0, style=wx.RA_SPECIFY_ROWS)
203 #self.label_2 = wx.StaticText(self, -1, "taille uc")
204 #self.spin_ctrl_1 = wx.SpinCtrl(self, -1, "formes actives", min=0, max=100)
205 self.label_max_actives = wx.StaticText(self, -1, u"Nombre maximum de formes analysées")
206 self.spin_max_actives = wx.SpinCtrl(self, -1, "",size = (100,30), min=20, max=10000)
207 txt = """Nombre de formes par uce
209 self.label_6 = wx.StaticText(self, -1, txt)
210 self.spin_ctrl_3 = wx.SpinCtrl(self, -1, "", size = (100,30), min=0, max=100000)
211 txt = "Nombre de classes"
212 self.label_7 = wx.StaticText(self, -1, txt)
213 self.spin_ctrl_4 = wx.SpinCtrl(self, -1, "", size = (100,30), min=0, max=1000)
214 self.label_4 = wx.StaticText(self, -1, u"Configuration \ndes clés d'analyse")
215 self.button_5 = wx.Button(self, wx.ID_PREFERENCES, "")
216 self.button_1 = wx.Button(self, wx.ID_CANCEL, "")
217 self.button_2 = wx.Button(self, wx.ID_DEFAULT, u"Valeurs par défaut")
218 self.button_4 = wx.Button(self, wx.ID_OK, "")
219 self.static_line_1 = wx.StaticLine(self, -1)
221 self.__set_properties()
224 self.Bind(wx.EVT_BUTTON, self.OnKeyPref, self.button_5)
225 self.Bind(wx.EVT_BUTTON, self.OnDef, self.button_2)
227 def __set_properties(self):
228 self.SetTitle("Options")
229 DefaultLem = self.pamconf.getboolean('pam', 'lem')
231 self.radio_1.SetSelection(0)
233 self.radio_1.SetSelection(1)
234 expressions = self.pamconf.getboolean('pam', 'expressions')
236 # self.radio_exp.SetSelection(0)
238 # self.radio_exp.SetSelection(1)
239 self.choice_1.SetSelection(self.distance.index(self.pamconf.get('pam', 'method')))
240 if self.pamconf.get('pam', 'cluster_type') == u'pam' :
241 self.radio_box_3.SetSelection(0)
243 self.radio_box_3.SetSelection(1)
244 self.radio_box_classif.SetSelection(int(self.pamconf.get('pam','type')))
245 self.spin_max_actives.SetValue(int(self.pamconf.get('pam','max_actives')))
246 self.spin_ctrl_3.SetValue(int(self.pamconf.get('pam', 'nbforme_uce')))
248 self.spin_ctrl_4.SetValue(int(self.pamconf.get('pam', cle)))
250 def __do_layout(self):
251 sizer_1 = wx.BoxSizer(wx.VERTICAL)
252 sizer_2 = wx.BoxSizer(wx.VERTICAL)
253 grid_sizer2 = wx.FlexGridSizer(11, 2, 2, 2)
254 grid_button = wx.FlexGridSizer(1, 3, 1, 1)
255 grid_sizer2.Add(self.label_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
256 grid_sizer2.Add(self.radio_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
257 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
258 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
260 grid_sizer2.Add(self.label_exp, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
261 grid_sizer2.Add(self.radio_exp, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
262 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
263 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
265 grid_sizer2.Add(self.label_12, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
266 grid_sizer2.Add(self.choice_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
267 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
268 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
270 grid_sizer2.Add(self.label_13, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
271 grid_sizer2.Add(self.radio_box_3, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
272 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
273 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
275 grid_sizer2.Add(self.label_classif, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
276 grid_sizer2.Add(self.radio_box_classif, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
277 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
278 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
280 #grid_sizer2.Add(self.label_2, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
281 #grid_sizer2.Add(self.spin_ctrl_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
282 #grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
283 #grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
285 grid_sizer2.Add(self.label_max_actives, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
286 grid_sizer2.Add(self.spin_max_actives, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
287 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
288 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
290 grid_sizer2.Add(self.label_6, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
291 grid_sizer2.Add(self.spin_ctrl_3, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
292 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
293 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
295 grid_sizer2.Add(self.label_7, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
296 grid_sizer2.Add(self.spin_ctrl_4, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
297 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
298 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
300 grid_sizer2.Add(self.label_4, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
301 grid_sizer2.Add(self.button_5, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
302 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
303 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
305 grid_button.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
306 grid_button.Add(self.button_2, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
307 grid_button.Add(self.button_4, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
308 sizer_2.Add(grid_sizer2, 3, wx.EXPAND, 0)
309 sizer_2.Add(grid_button, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
310 sizer_1.Add(sizer_2, 0, wx.EXPAND, 0)
311 self.SetSizer(sizer_1)
315 def OnKeyPref(self, event):
317 dial = AlcOptFrame(self.parent, self)
318 dial.CenterOnParent()
319 val = dial.ShowModal()
321 def OnDef(self, event):
322 ConfOri = ConstructConfigPath(self.parent.parent.AppliPath, user=False)
323 ConfUser = ConstructConfigPath(self.parent.parent.UserConfigPath)
324 shutil.copyfile(ConfOri['pam'], ConfUser['pam'])
325 self.parent.pamconf.read(self.parent.ConfigPath['pam'])
326 self.__set_properties()