X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=blobdiff_plain;f=guifunct.py;h=e97c04b7d5314a74f10e32b5987e61e0d3356c64;hp=92537891d6f90f3a76d5a51a2d4660baf0daa7b3;hb=3414a4710a5bdf52e2172e08f6da20465ca92e4a;hpb=2537abe111160f6c8ed2052665e24a79c1865101;ds=inline diff --git a/guifunct.py b/guifunct.py index 9253789..e97c04b 100644 --- a/guifunct.py +++ b/guifunct.py @@ -7,9 +7,15 @@ import wx import os import sys from copy import copy -import dialog +from dialog import FileOptionDialog, SelectColDial, OptLexi, PrefSimpleFile from listlex import * -from functions import treat_var_mod +from vitemspicker import VItemsPicker, EVT_IP_SELECTION_CHANGED, IP_SORT_CHOICES, IP_SORT_SELECTED, IP_REMOVE_FROM_CHOICES +from functions import treat_var_mod, print_liste, exec_rcode, check_Rresult, DoConf, read_list_file, indices_simi +import codecs +import wx.lib.hyperlink as hl +from webexport import WebExport +from PrintRScript import PrintSimiScript +#from wx import GetTopLevelWindows def OnOpen(self, type): @@ -40,49 +46,44 @@ def OnOpen(self, type): elif type == "Texte": return False, [False] elif type == "Analyse": - return [False] + return False def getfileextension(file) : return os.path.splitext(file)[1] def get_table_param(self, filename) : if getfileextension(filename) == '.csv': - dlg = dialog.FileOptionDialog(self, -1, _(u"File format").decode('utf8'), sep=True, size=(350, 200), + dlg = FileOptionDialog(self, -1, _(u"File format").decode('utf8'), sep=True, size=(350, 200), style=wx.DEFAULT_DIALOG_STYLE) dlg.CenterOnParent() val = dlg.ShowModal() if val == wx.ID_OK: - self.tableau.parametre['colsep'] = dlg.colsep[dlg.choice3.GetSelection()] - self.tableau.parametre['txtsep'] = dlg.txtsep[dlg.choice4.GetSelection()] - if self.tableau.parametre['colsep'] == 'tabulation' : - self.tableau.parametre['colsep'] = '\t' - self.tableau.parametre['filetype'] = 'csv' - else : - dlg.Destroy() + self.tableau.parametres['colsep'] = dlg.colsep[dlg.choice3.GetSelection()] + self.tableau.parametres['txtsep'] = dlg.txtsep[dlg.choice4.GetSelection()] + if self.tableau.parametres['colsep'] == 'tabulation' : + self.tableau.parametres['colsep'] = '\t' + self.tableau.parametres['filetype'] = 'csv' + self.tableau.parametres['encodage'] = dlg.le[dlg.list_encodages.GetSelection()] elif getfileextension(filename) == '.xls' : - dlg = dialog.FileOptionDialog(self, -1, _(u"File format").decode('utf8'), sep=False, sheet = True, size=(350, 200), + dlg = FileOptionDialog(self, -1, _(u"File format").decode('utf8'), sep=False, sheet = True, size=(350, 200), style=wx.DEFAULT_DIALOG_STYLE) dlg.CenterOnParent() val = dlg.ShowModal() if val == wx.ID_OK: - self.tableau.parametre['colsep'] = ';' - self.tableau.parametre['txtsep'] = '\"' - self.tableau.parametre['encodage'] = sys.getdefaultencoding() - self.tableau.parametre['sheetnb'] = dlg.spin1.GetValue() - self.tableau.parametre['filetype'] = 'xls' - else : - dlg.Destroy() + self.tableau.parametres['colsep'] = ';' + self.tableau.parametres['txtsep'] = '\"' + self.tableau.parametres['encodage'] = sys.getdefaultencoding() + self.tableau.parametres['sheetnb'] = dlg.spin1.GetValue() + self.tableau.parametres['filetype'] = 'xls' elif getfileextension(filename) == '.ods': - dlg = dialog.FileOptionDialog(self, -1, _(u"File format").decode('utf8'), sep=False, size=(350, 200), + dlg = FileOptionDialog(self, -1, _(u"File format").decode('utf8'), sep=False, size=(350, 200), style=wx.DEFAULT_DIALOG_STYLE) dlg.CenterOnParent() val = dlg.ShowModal() if val == wx.ID_OK: - self.tableau.parametre['colsep'] = ';' - self.tableau.parametre['txtsep'] = '\"' - self.tableau.parametre['filetype'] = 'ods' - else : - dlg.Destroy() + self.tableau.parametres['colsep'] = ';' + self.tableau.parametres['txtsep'] = '\"' + self.tableau.parametres['filetype'] = 'ods' else : val = False if val == wx.ID_OK: @@ -94,7 +95,8 @@ def get_table_param(self, filename) : self.tableau.firstcolisrownames = True else: self.tableau.firstcolisrownames = False - dlg.Destroy() + dlg.Destroy() + return val def getPage(ira) : if '_mgr' in dir(ira) : @@ -118,8 +120,8 @@ class SelectColumn : def __init__(self, parent, dictcol, actives, pathout, selected = None, dlg = False) : self.ira = parent if dlg : - dial = dialog.SelectColDial(self.ira) - listcol = ListForSpec(dial, self, dictcol, ['forme', 'eff']) + dial = SelectColDial(self.ira) + listcol = ListForSpec(dial, self, dictcol, ['eff']) dial.bSizer2.Add( listcol, 2, wx.ALL|wx.EXPAND, 5 ) dial.m_sdbSizer2.AddButton( dial.m_sdbSizer2OK ) dial.m_sdbSizer2.AddButton( dial.butok) @@ -152,6 +154,7 @@ class SelectColumn : else : self.ok = False else : + self.ok = True if selected is None : selected = [i for i in range(0, len(actives))] with open(pathout, 'w') as f : @@ -171,9 +174,18 @@ class PrefSimi ( wx.Dialog ): bSizer16 = wx.BoxSizer( wx.HORIZONTAL ) if wordlist is not None : - self.listcol = ListForSpec(self, self, wordlist, ['forme', 'eff']) + self.listcol = ListForSpec(self, self, wordlist, ['eff']) self.listcol.SetMinSize( wx.Size( 270,-1 ) ) - bSizer16.Add( self.listcol, 0, wx.ALL|wx.EXPAND, 5 ) + listsizer = wx.BoxSizer( wx.VERTICAL ) + countsizer = wx.BoxSizer( wx.HORIZONTAL ) + self.butcount = wx.Button(self, -1, _(u"count").decode('utf8')) + self.textcount = wx.TextCtrl(self, -1, "", wx.DefaultPosition, wx.Size( 100,-1 ), wx.TE_READONLY ) + countsizer.Add(self.butcount, 0, wx.ALL, 5) + countsizer.Add(self.textcount, 0, wx.ALL, 5 ) + listsizer.Add(countsizer, 0, wx.ALL, 5) + listsizer.Add(self.listcol, 2, wx.ALL|wx.EXPAND, 5 ) + #bSizer16.Add( self.listcol, 0, wx.ALL|wx.EXPAND, 5 ) + bSizer16.Add( listsizer, 0, wx.ALL|wx.EXPAND, 5) if selected is None : for row in xrange(self.listcol.GetItemCount()): self.listcol.Select(row) @@ -240,7 +252,7 @@ class PrefSimi ( wx.Dialog ): self.m_staticline295 = wx.StaticLine( self.m_panel2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) fgSizer3.Add( self.m_staticline295, 0, wx.EXPAND, 5 ) - self.m_staticText5 = wx.StaticText( self.m_panel2, wx.ID_ANY, _(u"Graphical type").decode('utf8'), wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticText5 = wx.StaticText( self.m_panel2, wx.ID_ANY, _(u"Graphic type").decode('utf8'), wx.DefaultPosition, wx.DefaultSize, 0 ) self.m_staticText5.Wrap( -1 ) fgSizer3.Add( self.m_staticText5, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) @@ -317,6 +329,19 @@ class PrefSimi ( wx.Dialog ): self.check_elab = wx.CheckBox( self.m_panel2, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 ) fgSizer3.Add( self.check_elab, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) + self.m_staticline39 = wx.StaticLine( self.m_panel2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) + fgSizer3.Add( self.m_staticline39, 0, wx.EXPAND |wx.ALL, 5 ) + + self.m_staticline40 = wx.StaticLine( self.m_panel2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) + fgSizer3.Add( self.m_staticline40, 0, wx.EXPAND |wx.ALL, 5 ) + + self.m_staticText321 = wx.StaticText( self.m_panel2, wx.ID_ANY, _(u"Edge curved").decode('utf8'), wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticText321.Wrap( -1 ) + fgSizer3.Add( self.m_staticText321, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) + + self.check_curved = wx.CheckBox( self.m_panel2, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 ) + fgSizer3.Add( self.check_curved, 0, wx.ALL, 5 ) + self.m_staticline2914 = wx.StaticLine( self.m_panel2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) fgSizer3.Add( self.m_staticline2914, 0, wx.EXPAND, 5 ) @@ -603,7 +628,7 @@ class PrefSimi ( wx.Dialog ): self.m_staticText21.Wrap( -1 ) bSizer5.Add( self.m_staticText21, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) - self.cols = wx.ColourPickerCtrl( self.m_panel3, wx.ID_ANY, wx.Colour( 255, 0, 0 ), wx.DefaultPosition, wx.Size( 10,10 ), wx.CLRP_DEFAULT_STYLE ) + self.cols = wx.ColourPickerCtrl( self.m_panel3, wx.ID_ANY, wx.Colour( 255, 0, 0 ), wx.DefaultPosition, wx.DefaultSize, wx.CLRP_DEFAULT_STYLE ) bSizer5.Add( self.cols, 0, wx.ALL, 5 ) @@ -709,16 +734,6 @@ class PrefSimi ( wx.Dialog ): self.__set_properties() # Connect Events - # if not self.paramsimi['first'] : - # self.check_coord.Bind( wx.EVT_CHECKBOX, self.OnKeepCoords ) - # self.choice3.Bind( wx.EVT_CHOICE, self.OnChangeType ) - # self.check2.Bind( wx.EVT_CHECKBOX, self.OnCheck2 ) - # self.checki.Bind( wx.EVT_CHECKBOX, self.OnChecki ) - # self.check_vcex.Bind( wx.EVT_CHECKBOX, self.OnCheck_vcex ) - # self.checkit.Bind( wx.EVT_CHECKBOX, self.OnCheckit ) - # self.check_s_size.Bind( wx.EVT_CHECKBOX, self.OnCheck_s_size ) - - # Connect Events if not self.paramsimi['first'] : self.check_coord.Bind( wx.EVT_CHECKBOX, self.OnKeepCoords ) self.choice3.Bind( wx.EVT_CHOICE, self.OnChangeType ) @@ -729,6 +744,11 @@ class PrefSimi ( wx.Dialog ): self.checki.Bind( wx.EVT_CHECKBOX, self.OnChecki ) self.check_vcex.Bind( wx.EVT_CHECKBOX, self.OnCheck_vcex ) self.check_s_size.Bind( wx.EVT_CHECKBOX, self.OnCheck_s_size ) + self.listcol.Bind( wx.EVT_LIST_ITEM_SELECTED, self.ChangeCount) + self.listcol.Bind( wx.EVT_LIST_ITEM_DESELECTED, self.ChangeCount) + self.butcount.Bind( wx.EVT_BUTTON, self.ChangeCount) + self.ChangeCount(wx.EVT_BUTTON) + def __set_properties(self): self.choice1.SetSelection(self.paramsimi['coeff']) @@ -776,6 +796,10 @@ class PrefSimi ( wx.Dialog ): self.comcheck.SetValue(self.paramsimi['com']) self.choix_com.SetSelection(self.paramsimi['communities']) self.halo.SetValue(self.paramsimi['halo']) + self.check_curved.SetValue(self.paramsimi.get('edgecurved', True)) + + def ChangeCount(self, evt) : + self.textcount.SetValue('%i' % self.listcol.GetSelectedItemCount()) def OnCheck_s_size(self, evt): if self.check_s_size.GetValue() : @@ -877,7 +901,7 @@ class PrepSimi : if 'bystar' in self.parametres : if self.dial.check_bystar.GetValue() : variables = treat_var_mod(self.parametres['stars']) - vardial = dialog.OptLexi(parent, force_chi = True) + vardial = OptLexi(parent, force_chi = True) vardial.listet = self.parametres['stars'] vardial.variables = [v for v in variables] for et in vardial.variables : @@ -895,19 +919,22 @@ class PrepSimi : self.parametres['listet'] = self.etline else: vardial.Destroy() - last = self.dial.listcol.GetFirstSelected() - lastl = [self.dial.listcol.GetFirstSelected()] - indexes = [self.dial.listcol.getColumnText(self.dial.listcol.GetFirstSelected(),0)] - while self.dial.listcol.GetNextSelected(last) != -1: - last = self.dial.listcol.GetNextSelected(last) - lastl.append(last) - indexes.append(self.dial.listcol.getColumnText(last,0)) - 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])) - self.make_param() - self.dial.Destroy() + self.val = False + self.dial.Destroy() + if self.val : + last = self.dial.listcol.GetFirstSelected() + lastl = [self.dial.listcol.GetFirstSelected()] + indexes = [self.dial.listcol.getColumnText(self.dial.listcol.GetFirstSelected(),0)] + while self.dial.listcol.GetNextSelected(last) != -1: + last = self.dial.listcol.GetNextSelected(last) + lastl.append(last) + indexes.append(self.dial.listcol.getColumnText(last,0)) + 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])) + self.make_param() + self.dial.Destroy() else : self.dial.Destroy() @@ -949,16 +976,365 @@ class PrepSimi : 'com' :self.dial.comcheck.GetValue(), 'communities' : self.dial.choix_com.GetSelection(), 'halo' : self.dial.halo.GetValue(), + 'edgecurved' : self.dial.check_curved.GetValue(), } if 'cexfromchi' in self.parametres : param['cexfromchi'] = self.dial.checkit.GetValue() if 'sfromchi' in self.parametres : param['sfromchi'] = self.dial.checki.GetValue() - print param if 'vlabcolor' in self.parametres : param['vlabcolor'] = self.parametres['vlabcolor'] if 'check_bystar' in dir(self.dial) : param['bystar'] = self.dial.check_bystar.GetValue() - param['stars'] = self.parametres['stars'] + param['stars'] = self.parametres.get('stars', 0) self.parametres.update(param) +class CreateTgenDialog ( wx.Frame ): + + def __init__( self, parent, lemlist, tgen = None, tgens = None ): + wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = _(u'Tgen Creator').decode('utf8'), pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP ) + self.ira = wx.GetApp().GetTopWindow() + self.SetIcon(self.ira._icon) + self.tgens = tgens + self.edit = False + self.parent = parent + + self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize ) + + bSizer2 = wx.BoxSizer( wx.VERTICAL ) + + namepan = wx.Panel(self, -1) + + fgSizer3 = wx.FlexGridSizer( 0, 2, 0, 0 ) + fgSizer3.SetFlexibleDirection( wx.BOTH ) + fgSizer3.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED ) + + self.m_staticText3 = wx.StaticText( namepan, wx.ID_ANY, _(u"Name").decode('utf8'), wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticText3.Wrap( -1 ) + + fgSizer3.Add( self.m_staticText3, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, 5 ) + + self.m_textCtrl1 = wx.TextCtrl( namepan, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_textCtrl1.SetMinSize( wx.Size( 250,-1 ) ) + + fgSizer3.Add( self.m_textCtrl1, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) + + namepan.SetSizer( fgSizer3 ) + + bSizer2.Add( namepan, 1, wx.EXPAND, 5 ) + + self.ip = VItemsPicker(self,-1, lemlist, _(u'Forms').decode('utf8'), _('Selection').decode('utf8')) + self.ip._source.SetMinSize( wx.Size( 350, 400 ) ) + + bSizer2.Add( self.ip, 0, wx.ALL, 5 ) + + butpanel = wx.Panel(self, -1) + + m_sdbSizer3 = wx.StdDialogButtonSizer() + self.m_sdbSizer3OK = wx.Button( butpanel, wx.ID_OK ) + m_sdbSizer3.AddButton( self.m_sdbSizer3OK ) + self.m_sdbSizer3Cancel = wx.Button( butpanel, wx.ID_CANCEL ) + m_sdbSizer3.AddButton( self.m_sdbSizer3Cancel ) + m_sdbSizer3.Realize(); + + butpanel.SetSizer( m_sdbSizer3 ) + + bSizer2.Add( butpanel, 1, wx.EXPAND, 5 ) + + + self.SetSizer( bSizer2 ) + self.Layout() + bSizer2.Fit( self ) + + self.Centre( wx.BOTH ) + + self.m_textCtrl1.Bind( wx.EVT_TEXT, self.OnTextEnter ) + self.ip.Bind(EVT_IP_SELECTION_CHANGED, self.OnSelectionChange) + self.m_sdbSizer3OK.Bind(wx.EVT_BUTTON, self.OnClose) + self.m_sdbSizer3Cancel.Bind(wx.EVT_BUTTON, self.OnCancel) + + #self.ip.SetItems(lemlist) + self.m_sdbSizer3OK.Enable(False) + + if tgen is not None : + self.m_textCtrl1.SetValue(tgen) + self.ip._destData = dict([[i,[word,'']] for i, word in enumerate(tgens[tgen])]) + self.ip._SetDestItems() + #self.ip.SetSelections(tgens[tgen]) + self.m_sdbSizer3OK.Enable(True) + self.edit = True + else : + self.edit = False + + def __del__( self ): + pass + + def OnTextEnter(self, evt): + if self.m_textCtrl1.GetValue() != '' and self.m_textCtrl1.GetValue() not in self.tgens and self.ip.GetSelections() != []: + self.m_sdbSizer3OK.Enable(True) + else : + self.m_sdbSizer3OK.Enable(False) + if self.m_textCtrl1.GetValue() != '' and self.ip.GetSelections() and self.edit: + self.m_sdbSizer3OK.Enable(True) + + def OnSelectionChange(self, evt): + if self.ip.GetSelections() != [] and self.m_textCtrl1.GetValue() != '' and self.m_textCtrl1.GetValue() not in self.tgens : + self.m_sdbSizer3OK.Enable(True) + else : + self.m_sdbSizer3OK.Enable(False) + if self.m_textCtrl1.GetValue() != '' and self.ip.GetSelections() and self.edit: + self.m_sdbSizer3OK.Enable(True) + + def OnClose(self, evt): + self.Close() + + def OnCancel(self, evt): + self.Destroy() + +class TGenFrame ( wx.Frame ): + + def __init__( self, parent, corpus, Tgen ): + wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Tgen", pos = wx.DefaultPosition, size = wx.Size( -1, -1 ), style = wx.CLOSE_BOX|wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL|wx.STAY_ON_TOP ) + self.ira = wx.GetApp().GetTopWindow() + self.SetIcon(self.ira._icon) + self.Tgen = Tgen + self.parent = parent + self.corpus = corpus + self.activetgen = None + self.panel = wx.Panel(self, wx.ID_ANY) + + #self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize ) + + panelsizer = wx.BoxSizer( wx.VERTICAL ) + + bSizer1 = wx.BoxSizer( wx.VERTICAL ) + + fgSizer1 = wx.FlexGridSizer( 0, 2, 0, 0 ) + fgSizer1.SetFlexibleDirection( wx.BOTH ) + fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED ) + + self.m_staticText1 = wx.StaticText( self.panel, wx.ID_ANY, u"Tgen", wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticText1.Wrap( -1 ) + fgSizer1.Add( self.m_staticText1, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) + + self.m_staticText2 = wx.StaticText( self.panel, wx.ID_ANY, _(u"Content").decode('utf8'), wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticText2.Wrap( -1 ) + fgSizer1.Add( self.m_staticText2, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) + + tgensChoices = Tgen.tgen.keys() + self.tgens = wx.ListBox( self.panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, tgensChoices, 0 ) + self.tgens.SetMinSize( wx.Size( 250,350 ) ) + + fgSizer1.Add( self.tgens, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND, 5 ) + + tgencontentChoices = [] + self.tgencontent = wx.ListBox( self.panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, tgencontentChoices, 0|wx.VSCROLL ) + self.tgencontent.SetMinSize( wx.Size( 250,350 ) ) + + fgSizer1.Add( self.tgencontent, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND, 5 ) + + fgSizer2 = wx.FlexGridSizer( 0, 2, 0, 0 ) + fgSizer2.SetFlexibleDirection( wx.BOTH ) + fgSizer2.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED ) + + self.but_new = wx.Button( self.panel, wx.ID_ANY, _(u"New...").decode('utf8'), wx.DefaultPosition, wx.DefaultSize, 0 ) + fgSizer2.Add( self.but_new, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) + + self.but_del = wx.Button( self.panel, wx.ID_ANY, _(u"Delete").decode('utf8'), wx.DefaultPosition, wx.DefaultSize, 0 ) + fgSizer2.Add( self.but_del, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) + + + fgSizer1.Add( fgSizer2, 0, wx.EXPAND, 0 ) + + fgSizer3 = wx.FlexGridSizer( 0, 2, 0, 0 ) + fgSizer3.SetFlexibleDirection( wx.BOTH ) + fgSizer3.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED ) + self.but_edit = wx.Button( self.panel, wx.ID_ANY, _(u"Edit").decode('utf8'), wx.DefaultPosition, wx.DefaultSize, 0 ) + fgSizer3.Add( self.but_edit, 1, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) + + self.but_compute = wx.Button( self.panel, wx.ID_ANY, _(u"Compute").decode('utf8'), wx.DefaultPosition, wx.DefaultSize, 0 ) + fgSizer3.Add( self.but_compute, 1, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) + + fgSizer1.Add( fgSizer3, 0, wx.EXPAND, 0 ) + + bSizer1.Add( fgSizer1, 1, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND, 5 ) + + + m_sdbSizer2 = wx.StdDialogButtonSizer() + self.m_sdbSizer2OK = wx.Button( self.panel, wx.ID_OK ) + m_sdbSizer2.AddButton( self.m_sdbSizer2OK ) + #self.m_sdbSizer2Cancel = wx.Button( self, wx.ID_CANCEL ) + #m_sdbSizer2.AddButton( self.m_sdbSizer2Cancel ) + m_sdbSizer2.Realize(); + + bSizer1.Add( m_sdbSizer2, 0, wx.EXPAND, 5 ) + + #panelsizer.Add(bSizer1, 0, wx.EXPAND, 5 ) + + #panel.SetSizer( panelsizer ) + self.panel.SetSizer( bSizer1 ) + self.panel.Layout() + bSizer1.Fit( self ) + + self.Centre( wx.BOTH ) + + # Connect Events + self.tgens.Bind( wx.EVT_LISTBOX, self.GetContent ) + self.but_new.Bind( wx.EVT_BUTTON, self.OnNewTgen ) + self.but_del.Bind( wx.EVT_BUTTON, self.OnDeleteTgen ) + self.but_edit.Bind( wx.EVT_BUTTON, self.OnEditTgen ) + self.but_compute.Bind(wx.EVT_BUTTON, self.OnCompute) + self.m_sdbSizer2OK.Bind( wx.EVT_BUTTON, self.OnOK ) + + def __del__( self ): + pass + + def GetContent( self, event ): + tgen = event.GetString() + if tgen != '' : + self.tgencontent.Clear() + for word in self.Tgen[tgen] : + self.tgencontent.Append(word) + + def OnNewTgen( self, event, tgen = None ): + if tgen is None : + self.dial = CreateTgenDialog(self, dict([[i, [lem, self.corpus.lems[lem].freq, self.corpus.lems[lem].gram]] for i, lem in enumerate(self.corpus.lems.keys())]), tgens = self.Tgen.tgen) + else : + self.dial = CreateTgenDialog(self, dict([[i, [lem, self.corpus.lems[lem].freq, self.corpus.lems[lem].gram]] for i, lem in enumerate(self.corpus.lems.keys())]), tgen = tgen, tgens = self.Tgen.tgen) + self.dial.ip._source.selected = dict(zip(self.Tgen.tgen[tgen], self.Tgen.tgen[tgen])) + self.activetgen = tgen + self.dial.Show() + self.dial.Bind(wx.EVT_CLOSE, self.OnDialClose) + + def OnDeleteTgen( self, event ): + if self.tgens.GetSelection() != -1 : + tgens = self.tgens.GetItems() + del self.Tgen.tgen[tgens[self.tgens.GetSelection()]] + self.Tgen.write() + self.tgens.Clear() + self.tgencontent.Clear() + for val in self.Tgen.tgen : + self.tgens.Append(val) + event.Skip() + + def OnEditTgen( self, event ): + if self.tgens.GetSelection() != -1 : + tgens = self.tgens.GetItems() + tgen = tgens[self.tgens.GetSelection()] + self.activetgen = tgen + self.dial = CreateTgenDialog(self, dict([[i, [lem, self.corpus.lems[lem].freq, self.corpus.lems[lem].gram]] for i, lem in enumerate(self.corpus.lems.keys())]), tgen = tgen, tgens = self.Tgen.tgen) + self.dial.Bind(wx.EVT_CLOSE, self.OnDialClose) + self.dial.m_textCtrl1.Enable(False) + self.dial.ip._source.selected = dict(zip(self.Tgen.tgen[tgen], self.Tgen.tgen[tgen])) + self.dial.Show() + event.Skip() + + def OnCompute(self, evt): + ira = wx.GetApp().GetTopWindow() + ira.tree.OnTgenCompute(evt) + + def OnOK(self, evt): + self.Destroy() + + def OnDialClose(self, evt): + if self.dial.edit : + del self.Tgen.tgen[self.activetgen] + self.tgens.Clear() + self.tgencontent.Clear() + for val in self.Tgen.tgen : + self.tgens.Append(val) + self.Tgen.tgen[self.dial.m_textCtrl1.GetValue()] = self.dial.ip.GetSelections() + self.Tgen.write() + self.tgens.Append(self.dial.m_textCtrl1.GetValue()) + self.dial.Destroy() + evt.Skip() + +class ExportMetaTable : + def __init__(self, parent, corpus): + self.ira = parent + dial = PrefSimpleFile(self, self.ira, **{'mask' : '*.csv', 'title': _(u"metadata table").decode('utf8')}) + dial.fbb.SetValue(corpus.pathout['metadata.csv']) + dial.CenterOnParent() + res = dial.ShowModal() + if res == wx.ID_OK : + fileout = dial.fbb.GetValue() + dial.Destroy() + corpus.export_meta_table(fileout) + dlg = wx.MessageDialog(self.ira, _("Done !").decode('utf8'), _(u"Export metadata").decode('utf8'), wx.OK | wx.ICON_INFORMATION) + dlg.CenterOnParent() + dlg.ShowModal() + dlg.Destroy() + else : + dial.Destroy() + + +def redosimi(self, evt) : + with open(self.pathout['selected.csv'],'r') as f : + selected = f.read() + selected = [int(val) for val in selected.splitlines()] + if self.actives is None : + with codecs.open(self.pathout['actives.csv'], 'r', self.parametres['encoding']) as f : + self.actives = f.read() + self.actives = self.actives.splitlines()#[act for act in self.actives.splitlines()] + if os.path.exists(self.pathout['actives_nb.csv']) : + with open(self.pathout['actives_nb.csv'], 'r') as f : + act_nb = f.read() + act_nb = act_nb.splitlines() + dictcol = dict([[i, [self.actives[i], int(act_nb[i])]] for i, val in enumerate(self.actives)]) + else : + dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)]) + #res = SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], selected = selected, dlg = True) + #if res.ok : + if evt is not None : + prep = PrepSimi(self.ira, self, self.parametres,self.pathout['selected.csv'], self.actives, indices_simi, wordlist = dictcol, selected = selected) + else : + class EmptyBase(object): pass + prep = EmptyBase() + prep.val = wx.ID_OK + prep.parametres = self.parametres + order_actives = [[i, act, self.corpus.getlemeff(act)] for i, act in enumerate(self.actives)] + order_actives = sorted(order_actives, key=itemgetter(2), reverse = True) + with open(self.pathout['selected.csv'], 'w') as f : + f.write('\n'.join([`order_actives[val][0]` for val in self.parametres['selected']])) + if prep.val == wx.ID_OK or evt is None: + self.parametres = prep.parametres + + script = PrintSimiScript(self) + script.make_script() + pid = exec_rcode(self.ira.RPath, script.scriptout, wait = True) + check_Rresult(self.ira, pid) + if self.parametres['type_graph'] in [1,3] : + if self.parametres['svg'] : + filename, ext = os.path.splitext(script.filename) + fileout = filename + '.svg' + elif self.parametres['type_graph'] == 3 : + fileout = script.filename + parametres = {'gexffile' : fileout, + 'dirout' : os.path.dirname(fileout), + 'titre': 'Le titre', + #'nodemin': self.param['txt_min'], + #'nodemax': self.param['txt_max'], + #'bargraphw' : 60*int(self.param['clnb']), + } + web = WebExport(self.ira, parametres) + fileout = web.exportsimi() + else : + fileout = script.filename + if os.path.exists(self.pathout['liste_graph']): + graph_simi = read_list_file(self.pathout['liste_graph']) + graph_simi.append([os.path.basename(fileout), script.txtgraph]) + else : + graph_simi = [[os.path.basename(fileout), script.txtgraph]] + self.fileout = fileout + print_liste(self.pathout['liste_graph'], graph_simi) + DoConf().makeoptions([self.parametres['type']], [self.parametres], self.pathout['Analyse.ira']) + if evt is not None : + if self.parametres['type_graph'] in [1,3] : + if self.parametres['svg'] or self.parametres['type_graph'] == 3 : + self.graphpan.sizer_3.Add(hl.HyperLinkCtrl(self.graphpan.panel_1, -1, fileout, URL = fileout), 0, wx.ALIGN_CENTER_HORIZONTAL, 0) + else : + self.graphpan.sizer_3.Add(wx.StaticBitmap(self.graphpan.panel_1, -1, wx.Bitmap(fileout, wx.BITMAP_TYPE_ANY)), 0, wx.ALIGN_CENTER_HORIZONTAL, 0) + self.graphpan.sizer_3.Add(wx.StaticText(self.graphpan.panel_1,-1, script.txtgraph), 0, wx.ALIGN_CENTER_HORIZONTAL, 0) + self.graphpan.sizer_3.Fit(self.graphpan.panel_1) + self.graphpan.Layout() + self.graphpan.panel_1.Scroll(0,self.graphpan.panel_1.GetScrollRange(wx.VERTICAL)) \ No newline at end of file