1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2011 Pierre Ratinaud
12 from functions import treat_var_mod
15 def OnOpen(self, type):
17 wildcard = u"Fichiers supportés|*.ods;*.xls;*.csv;*.txt|Openoffice Clac|*.ods|Fichier excel|*.xls|Fichier csv|*.csv|Fichier texte|*.txt|Tous les fichiers|*"
19 wildcard = "Fichier texte|*.txt|Tous les fichiers|*"
20 elif type == "Analyse":
21 wildcard = "Fichier analyse/Corpus|*.ira;*.cira"
22 defaultDir = self.PathPath.get('PATHS', 'lastpath')
23 if defaultDir.strip() == '':
24 defaultDir = self.UserConfigPath.replace('.iramuteq','')
26 self, message="Choisissez un fichier", defaultDir=defaultDir,
27 defaultFile="", wildcard=wildcard, style=wx.OPEN | wx.CHANGE_DIR)
29 if dlg.ShowModal() == wx.ID_OK :
30 fileName = dlg.GetFilename()
33 self.PathPath.set('PATHS', 'lastpath', os.path.dirname(path[0]))
42 elif type == "Analyse":
45 def getfileextension(file) :
46 return os.path.splitext(file)[1]
48 def get_table_param(self, filename) :
49 if getfileextension(filename) == '.csv':
50 dlg = dialog.FileOptionDialog(self, -1, u"Format du fichier", sep=True, size=(350, 200),
51 style=wx.DEFAULT_DIALOG_STYLE)
55 self.tableau.parametre['colsep'] = dlg.colsep[dlg.choice3.GetSelection()]
56 self.tableau.parametre['txtsep'] = dlg.txtsep[dlg.choice4.GetSelection()]
57 if self.tableau.parametre['colsep'] == 'tabulation' :
58 self.tableau.parametre['colsep'] = '\t'
59 self.tableau.parametre['filetype'] = 'csv'
62 elif getfileextension(filename) == '.xls' :
63 dlg = dialog.FileOptionDialog(self, -1, u"Format du fichier", sep=False, sheet = True, size=(350, 200),
64 style=wx.DEFAULT_DIALOG_STYLE)
68 self.tableau.parametre['colsep'] = ';'
69 self.tableau.parametre['txtsep'] = '\"'
70 self.tableau.parametre['encodage'] = sys.getdefaultencoding()
71 self.tableau.parametre['sheetnb'] = dlg.spin1.GetValue()
72 self.tableau.parametre['filetype'] = 'xls'
75 elif getfileextension(filename) == '.ods':
76 dlg = dialog.FileOptionDialog(self, -1, u"Format du fichier", sep=False, size=(350, 200),
77 style=wx.DEFAULT_DIALOG_STYLE)
81 self.tableau.parametre['colsep'] = ';'
82 self.tableau.parametre['txtsep'] = '\"'
83 self.tableau.parametre['filetype'] = 'ods'
89 if dlg.radio_box_1.GetSelection() == 0:
90 self.tableau.firstrowiscolnames = True
92 self.tableau.firstrowiscolnames = False
93 if dlg.radio_box_2.GetSelection() == 0:
94 self.tableau.firstcolisrownames = True
96 self.tableau.firstcolisrownames = False
100 if '_mgr' in dir(ira) :
101 if not ira._mgr.GetPane('Text').IsShown() :
102 if ira.nb.GetPageCount() >= 1:
103 return ira.nb.GetPage(ira.nb.GetSelection())
111 def getCorpus(page) :
112 if 'corpus' in page.__dict__:
113 return copy(page.corpus)
118 def __init__(self, parent, dictcol, actives, pathout, selected = None, dlg = False) :
121 dial = dialog.SelectColDial(self.ira)
122 listcol = ListForSpec(dial, self, dictcol, ['forme', 'eff'])
123 dial.bSizer2.Add( listcol, 2, wx.ALL|wx.EXPAND, 5 )
124 dial.m_sdbSizer2.AddButton( dial.m_sdbSizer2OK )
125 dial.m_sdbSizer2.Realize()
126 dial.bSizer2.Add( dial.m_sdbSizer2, 0, wx.EXPAND, 5 )
128 if selected is None :
129 for row in xrange(listcol.GetItemCount()):
132 orderlex = dict([[listcol.getColumnText(i,0),i] for i in range(0,listcol.GetItemCount())])
133 for row in selected :
134 listcol.Select(orderlex[actives[row]])
135 dial.CenterOnParent()
136 val = dial.ShowModal()
137 last = listcol.GetFirstSelected()
138 lastl = [listcol.GetFirstSelected()]
139 indexes = [listcol.getColumnText(listcol.GetFirstSelected(),0)]
140 while listcol.GetNextSelected(last) != -1:
141 last = listcol.GetNextSelected(last)
143 indexes.append(listcol.getColumnText(last,0))
145 column = [actives.index(val) for val in indexes]
147 with open(pathout, 'w') as f :
148 f.write('\n'.join([`val` for val in column]))
150 with open(pathout, 'w') as f :
151 f.write('\n'.join([`i` for i in range(0,len(actives))]))
154 def __init__(self, parent, parametres, indices_simi) :
155 self.parametres = parametres
156 self.dial = dialog.PrefSimi(parent, -1, self.parametres, indices_simi)
157 self.dial.CenterOnParent()
158 self.val = self.dial.ShowModal()
159 if self.val == wx.ID_OK :
160 if self.dial.check_bystar.GetValue() :
161 variables = treat_var_mod(self.parametres['stars'])
162 vardial = dialog.OptLexi(parent)
163 vardial.listet = self.parametres['stars']
164 vardial.variables = [v for v in variables]
165 for et in vardial.variables :
166 vardial.list_box_1.Append(et)
167 nval = vardial.ShowModal()
168 if nval == wx.ID_OK :
169 if vardial.choice.GetSelection() == 1 :
170 listet = [vardial.listet[i] for i in dial.list_box_1.GetSelections()]
172 listet = variables[vardial.variables[dial.list_box_1.GetSelections()[0]]]
174 self.tableau.etline = self.Source.corpus.make_etline(listet)
177 def make_param(self) :
178 self.select = self.dial.check_colch.GetValue()
179 if self.parametres.get('first', True) :
182 keep_coord = self.dial.check_coord.GetValue()
183 param = {'coeff' : self.dial.choice1.GetSelection(),
184 'layout' : self.dial.choice2.GetSelection(),
185 'type_graph' : self.dial.choice3.GetSelection(),
186 'arbremax' : self.dial.check1.GetValue(),
187 'coeff_tv' : self.dial.check_s_size.GetValue(),
188 'coeff_tv_nb' : self.dial.spin_tv.GetValue(),
189 'tvprop' : self.dial.check2.GetValue(),
190 'tvmin' : self.dial.spin_tvmin.GetValue(),
191 'tvmax' : self.dial.spin_tvmax.GetValue(),
192 'coeff_te' : self.dial.check3.GetValue(),
193 'coeff_temin' : self.dial.spin_temin.GetValue(),
194 'coeff_temax' : self.dial.spin_temax.GetValue(),
195 'label_e' : self.dial.check_elab.GetValue(),
196 'label_v' : self.dial.check_vlab.GetValue(),
197 'vcex' : self.dial.check_vcex.GetValue(),
198 'vcexmin' : self.dial.spin_vcexmin.GetValue(),
199 'vcexmax' : self.dial.spin_vcexmax.GetValue(),
200 'cex' : self.dial.spin_cex.GetValue(),
201 'seuil_ok' : self.dial.check_seuil.GetValue(),
202 'seuil' : self.dial.spin_seuil.GetValue(),
203 'cols' : self.dial.cols.GetColour(),
204 'cola' : self.dial.cola.GetColour(),
205 'width' : self.dial.spin_width.GetValue(),
206 'height' : self.dial.spin_height.GetValue(),
208 'keep_coord' : keep_coord,
209 'alpha' : self.dial.slider_sphere.GetValue(),
210 'film' : self.dial.film.GetValue()
212 if 'cexfromchi' in self.parametres :
213 param['cexfromchi'] = self.dial.checkit.GetValue()
214 if 'sfromchi' in self.parametres :
215 param['sfromchi'] = self.dial.checki.GetValue()
216 if 'vlabcolor' in self.parametres :
217 param['vlabcolor'] = self.parametres['vlabcolor']
218 if 'check_bystar' in dir(self.dial) :
219 param['bystar'] = self.dial.check_bystar.GetValue()
220 param['stars'] = self.parametres['stars']
221 self.parametres.update(param)