correction labbé
[iramuteq] / iramuteq.py
1 #!/bin/env python
2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2008-2020, Pierre Ratinaud
5 #License: GNU GPL
6 #test
7
8 from optparse import OptionParser
9
10 parser = OptionParser()
11 parser.add_option("-f", "--file", dest="filename",
12                   help="open FILE", metavar="FILE", default=False)
13 (options, args) = parser.parse_args()
14
15 import sys
16 reload(sys)
17 #sys.path.insert(0, '/usr/lib/python2.7/dist-packages/wxPython-4.0.1-py2.7-linux-amd64.egg')
18 import locale
19 import tempfile
20 import codecs
21 import os
22 from random import randint
23 from ConfigParser import ConfigParser, RawConfigParser
24 import webbrowser
25 import gettext
26 import logging
27 #------------------------------------
28 import wx
29 import wx.lib.agw.aui as aui
30 import wx.html
31 import wx.grid
32 import wx.lib.hyperlink as hl
33 #import wx.lib.agw.hyperlink as hl
34 #------------------------------------
35 from functions import BugReport, PlaySound, History, progressbar
36 from checkversion import NewVersion
37 from guifunct import *
38 from tableau import Tableau
39 from dialog import PrefDialog
40 from tabfrequence import Frequences, FreqMultiple
41 from tabchi2 import ChiSquare
42 from tabchi2mcnemar import McNemar
43 #from tabstudent import MakeStudent
44 from tabchddist import ChdCluster
45 from tabafcm import DoAFCM
46 from tabchdalc import AnalyseQuest
47 from tabsimi import DoSimi
48 from tabrsimple import InputText
49 from tabverges import Prototypical
50 from tabsplitvar import SplitMatrixFromVar
51 #frog textdist import AnalysePam
52 from textstat import Stat
53 from textaslexico import Lexico
54 from textlabbe import DistLabbe
55 from textsimi import SimiTxt, SimiFromCluster
56 from textwordcloud import WordCloud, ClusterCloud
57 from textreinert import Reinert#, ReDoReinert
58 #from textcheckcorpus import checkcorpus
59 from openanalyse import OpenAnalyse
60 from corpus import Builder, SubBuilder, MergeClusters
61 from checkinstall import CreateIraDirectory, CheckRPath, FindRPAthWin32, FindRPathNix, CheckRPackages, IsNew, UpgradeConf, CopyConf, RLibsAreInstalled
62 from chemins import RscriptsPath, ConstructConfigPath, ConstructDicoPath, ConstructGlobalPath, PathOut
63 from parse_factiva_xml import ImportFactiva
64 from parse_dmi import ImportDMI
65 from tools import Extract
66 from analyse_merge import AnalyseMerge
67
68 from tree import LeftTree
69 ##########################################################
70 ID_OpenData = wx.NewId()
71 ID_Import = wx.NewId()
72 ID_OpenText = wx.NewId()
73 ID_OnOpenAnalyse = wx.NewId()
74 ID_Freq = wx.NewId()
75 ID_Chi2 = wx.NewId()
76 ID_Chi2mc = wx.NewId()
77 ID_Student = wx.NewId()
78 ID_CHDSIM = wx.NewId()
79 ID_CHDReinert = wx.NewId()
80 ID_TEXTAFCM = wx.NewId()
81 ID_TEXTSTAT = wx.NewId()
82 ID_ASLEX = wx.NewId()
83 ID_TEXTREINERT = wx.NewId()
84 ID_TEXTPAM = wx.NewId()
85 ID_CHECKCORPUS = wx.NewId()
86 ID_Tabcontent = wx.NewId()
87 ID_AFCM = wx.NewId()
88 ID_SIMI = wx.NewId()
89 ID_CloseTab = wx.NewId()
90 ID_SaveTab = wx.NewId()
91 ID_CreateText = wx.NewId()
92 ID_ACCEUIL = wx.NewId()
93 ID_RESULT = wx.NewId()
94 ID_HTMLcontent = wx.NewId()
95 ID_SimiTxt = wx.NewId()
96 ID_proto = wx.NewId()
97 ID_ImportTXM = wx.NewId()
98 ID_FreqMulti = wx.NewId()
99 ID_Splitfromvar = wx.NewId()
100 ID_Subtxtfrommeta = wx.NewId()
101 ID_Subtxtfromthem = wx.NewId()
102 ID_WC = wx.NewId()
103 ID_ImportEuro = wx.NewId()
104 ID_Fact_xml = wx.NewId()
105 ID_Fact_mail = wx.NewId()
106 ID_Fact_copy = wx.NewId()
107 ID_exportmeta = wx.NewId()
108 ID_importdmi = wx.NewId()
109 ID_merge = wx.NewId()
110 ID_merge_clusters = wx.NewId()
111 ID_labbe = wx.NewId()
112 ##########################################################
113 #elements de configuration
114 ##########################################################
115 #encodage
116 if sys.platform == 'darwin' :
117     sys.setdefaultencoding('UTF-8')
118     wx.SetDefaultPyEncoding('UTF-8')
119 else :
120     sys.setdefaultencoding(locale.getpreferredencoding())
121
122 #chemin de l'application
123 AppliPath = os.path.abspath(os.path.dirname(os.path.realpath(sys.argv[0])))
124 #chemin des images
125 ImagePath = os.path.join(AppliPath, 'images')
126 #configuration generale
127 DictConfigPath = ConstructGlobalPath(AppliPath)
128 ConfigGlob = ConfigParser()
129 ConfigGlob.read(DictConfigPath['global'])
130 DefaultConf = ConfigParser()
131 DefaultConf.read(DictConfigPath['preferences'])
132 #repertoire de l'utilisateur
133 user_home = os.getenv('HOME')
134 if user_home is None :
135     user_home = os.path.expanduser('~')
136
137 UserConfigPath = os.path.abspath(os.path.join(user_home, '.iramuteq-%s' % ConfigGlob.get('DEFAULT', 'version_nb')))
138 #Si pas de fichiers de config utilisateur, on cree le repertoire
139 CreateIraDirectory(UserConfigPath, AppliPath)
140 #fichiers log pour windows (py2exe)
141 log = logging.getLogger('iramuteq')
142 fh = logging.FileHandler(os.path.join(UserConfigPath,'stdout.log'))
143 formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
144 fh.setFormatter(formatter)
145 log.addHandler(fh)
146 if sys.platform != 'win32' and sys.platform != 'darwin':
147     ch = logging.StreamHandler()
148     ch.setFormatter(formatter)
149     log.addHandler(ch)
150 log.setLevel(logging.INFO)
151
152 class writer(object):
153     def write(self, data):
154         if data.strip() != '' :
155             log.info('ERROR : %s' % data)
156
157 class printer(object) :
158     def write(self, data) :
159         if data.strip() != '' :
160             log.info('Print : %s' % data)
161
162 sys.stderr = writer()
163 sys.stdout = printer()
164
165 ConfigPath = ConstructConfigPath(UserConfigPath)
166
167 langues = {'french' : wx.LANGUAGE_FRENCH,
168            'english' : wx.LANGUAGE_ENGLISH,
169            'portuguese' : wx.LANGUAGE_PORTUGUESE,
170            'italian' : wx.LANGUAGE_ITALIAN,
171            'spanish' : wx.LANGUAGE_SPANISH
172            }
173
174 code_langues = {'french' : 'fr_FR',
175                 'english' : 'en',
176                 'portuguese' : 'pt_PT',
177                 'italian' : 'it_IT',
178                 'spanish' : 'es_ES'
179                }
180
181 images_analyses = {
182         'textroot' : 'textroot.png',
183         'alceste' : 'reinert.png',
184         'reinert' : 'reinert.png',
185         'corpus' : 'textcorpus.png',
186         'wordcloud' :'wordcloud.png',
187         'stat' :'stats.png',
188         'simitxt' : 'simitxt.png',
189         'clustersimitxt' :'clustersimitxt.png',
190         'clustercloud' : 'clustercloud.png',
191         'spec' : 'spec.png',
192         'matroot' : 'matroot.png',
193         'matrix' : 'matrix.png',
194         'freq' : 'frequences.png',
195         'freqmulti' : 'frequences.png',
196         'chi2' : 'chi2.png',
197         'chi2mcnemar' : 'chi2.png',
198         'reinertmatrix' : 'reinertmatrix.png',
199         'simimatrix' : 'simimatrix.png',
200         'simiclustermatrix' : 'simimatrix.png',
201         'proto' : 'proto.png',
202         'TXM' : 'TXM.png',
203         'europress' : 'europress.png',
204         'factiva_xml' : 'factiva_xml.png',
205         'factiva_copy' : 'factiva_copy.png',
206         'factiva_mail': 'factiva_mail.png',
207         'iramuteq' : 'iraicone.png',
208         'subcorpusmeta' : 'subcorpusmeta.png',
209         'subcorpusthema' : 'subcorpusthema.png',
210         'preferences' : 'preferences.png',
211         'exportmetatable' : 'exportmetatable.png',
212         'importdmi' : 'twitter.png',
213         'labbe' : 'spec.png'
214          }
215 #####################################################################
216
217 class IraFrame(wx.Frame):
218     def __init__(self, parent, id= -1, title="", pos=wx.DefaultPosition,
219                  size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE |
220                                             wx.SUNKEN_BORDER |
221                                             wx.CLIP_CHILDREN):
222         log.info('Starting... ' )
223         log.info('version : %s' % ConfigGlob.get('DEFAULT', 'version'))
224         wx.Frame.__init__(self, parent, id, title, pos, size, style)
225         #configuration
226         self.AppliPath = AppliPath
227         self.images_path = os.path.join(AppliPath,'images')
228         self.UserConfigPath = UserConfigPath
229         #self.RscriptsPath = ConstructRscriptsPath(AppliPath)
230         self.RscriptsPath = PathOut(dirout=os.path.join(AppliPath, 'Rscripts'))
231         self.RscriptsPath.basefiles(RscriptsPath)
232         #self.DictPath = ConstructDicoPath(AppliPath)
233         self.DictPath = ConstructDicoPath(UserConfigPath)
234         self.ConfigGlob = ConfigGlob
235         self.ConfigPath = ConstructConfigPath(UserConfigPath)
236         self.pref = RawConfigParser()
237         #workaround for import problem
238         self.SimiFromCluster = SimiFromCluster
239         #langues
240         gettext.install('iramuteq',  os.path.join(AppliPath,'locale'), unicode=True)
241         #langues = ['fr_FR', 'en', 'pt_PT']
242         #for l in langues :
243         #    pass
244         self.preslangue = {}
245         for langue in code_langues :
246             self.preslangue[langue] = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=[code_langues[langue]])
247         self.setlangue()
248         #self.presLan_fr = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['fr_FR'])
249         #self.presLan_en = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['en'])
250         # tell FrameManager to manage this frame
251         #self._mgr = wx.aui.AuiManager()
252         self._mgr = aui.AuiManager()
253         self._mgr.SetManagedWindow(self)
254         self.x = 0
255         # create menu
256 #--------------------------------------------------------------------------------
257         self.images_analyses = images_analyses
258         for img in images_analyses :
259             self.images_analyses[img] = wx.Image(os.path.join(self.images_path, self.images_analyses[img]), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap()
260         self.mb = wx.MenuBar()
261
262         file_menu = wx.Menu()
263         item = wx.MenuItem(file_menu, ID_OpenData, _(u"Open a matrix").decode('utf8'), _(u"Open a matrix").decode('utf8'))
264         #item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
265         item.SetBitmap(self.images_analyses['matroot'])
266         file_menu.AppendItem(item)
267
268         item = wx.MenuItem(file_menu, ID_OpenText, _(u"Open a text corpus").decode('utf8'), _(u"Open a text corpus").decode('utf8'))
269         item.SetBitmap(self.images_analyses['textroot'])
270         file_menu.AppendItem(item)
271
272         item = wx.MenuItem(file_menu, ID_OnOpenAnalyse, _(u"Open an analysis").decode('utf8'), _(u"Open an analysis").decode('utf8'))
273         item.SetBitmap(self.images_analyses['iramuteq'])
274         file_menu.AppendItem(item)
275
276         item = wx.MenuItem(file_menu, ID_ImportTXM, _(u"Import from TXM").decode('utf8'), _(u"Import from TXM").decode('utf8'))
277         item.SetBitmap(self.images_analyses['TXM'])
278         file_menu.AppendItem(item)
279
280         item = wx.MenuItem(file_menu, ID_ImportEuro, _(u"Import from Europress").decode('utf8'), _(u"Import from Europress").decode('utf8'))
281         item.SetBitmap(self.images_analyses['europress'])
282         file_menu.AppendItem(item)
283
284         item = wx.MenuItem(file_menu, ID_importdmi, _(u"Import from DMI-TCAT (exp.)").decode('utf8'), _(u"Import from DMI-TCAT (exp.)").decode('utf8'))
285         item.SetBitmap(self.images_analyses['importdmi'])
286         file_menu.AppendItem(item)
287
288         item = wx.MenuItem(file_menu, ID_merge, _(u'Merge graphs').decode('utf8'), _(u'Merge graphs').decode('utf8'))
289         file_menu.AppendItem(item)
290
291         item = wx.MenuItem(file_menu, ID_merge_clusters, _(u'Corpus from merge clusters').decode('utf8'), _(u'Corpus from merge clusters').decode('utf8'))
292         file_menu.AppendItem(item)
293
294         menuFactiva = wx.Menu()
295         fact_from_xml = wx.MenuItem(menuFactiva, ID_Fact_xml, _(u"from xml").decode('utf8'))
296         fact_from_xml.SetBitmap(self.images_analyses['factiva_xml'])
297         fact_from_mail = wx.MenuItem(menuFactiva, ID_Fact_mail, _(u"from mail").decode('utf8'))
298         fact_from_mail.SetBitmap(self.images_analyses['factiva_mail'])
299         fact_from_txt = wx.MenuItem(menuFactiva, ID_Fact_copy, _(u"from copy/paste").decode('utf8'))
300         fact_from_txt.SetBitmap(self.images_analyses['factiva_copy'])
301         menuFactiva.AppendItem(fact_from_xml)
302         menuFactiva.AppendItem(fact_from_mail)
303         menuFactiva.AppendItem(fact_from_txt)
304         file_menu.AppendMenu(-1, _(u"Import from factiva").decode('utf8'), menuFactiva)
305
306         menuTools = wx.Menu()
307         splitvar = wx.MenuItem(menuTools, wx.ID_ANY, _(u"Split from variable").decode('utf8'))
308         extractmod = wx.MenuItem(menuTools, wx.ID_ANY, _(u"Extract mods").decode('utf8'))
309         extractthem = wx.MenuItem(menuTools, wx.ID_ANY, _(u"Extract thematics").decode('utf8'))
310         menuTools.AppendItem(splitvar)
311         menuTools.AppendItem(extractmod)
312         menuTools.AppendItem(extractthem)
313         self.ID_splitvar = splitvar.GetId()
314         self.ID_extractmod = extractmod.GetId()
315         self.ID_extractthem = extractthem.GetId()
316         file_menu.AppendMenu(-1, _(u"Tools").decode('utf8'), menuTools)
317
318
319         #item = wx.MenuItem(file_menu, ID_SaveTab, _(u"Save tab as...").decode('utf8'), _(u"Save tab as...").decode('utf8'))
320         #item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_SAVE_AS))
321         #file_menu.AppendItem(item)
322
323         file_menu.Append(wx.ID_EXIT, _(u"Exit").decode('utf8'))
324
325         edit_menu = wx.Menu()
326         pref = wx.MenuItem(edit_menu, wx.ID_PREFERENCES, _(u'Preferences').decode('utf8'))
327         pref.SetBitmap(self.images_analyses['preferences'])
328         edit_menu.AppendItem(pref)
329         #edit_menu.Append(wx.ID_PREFERENCES, _(u'Preferences').decode('utf8'))
330
331         view_menu = wx.Menu()
332         home = wx.MenuItem(view_menu, ID_ACCEUIL, _(u"Home page").decode('utf8'))
333         home.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_GO_HOME, size = (16,16)))
334         view_menu.AppendItem(home)
335         #view_menu.Append(ID_ACCEUIL, _(u"Home page").decode('utf8'))
336         results = wx.MenuItem(view_menu, ID_RESULT, _(u'Show results').decode('utf8'))
337         results.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_LIST_VIEW, size = (16,16)))
338         view_menu.AppendItem(results)
339         #view_menu.Append(ID_RESULT, _(u'Show results').decode('utf8'))
340         #view_menu.AppendSeparator()
341         matrix_menu = wx.Menu()
342         matanalyses = [[ID_Freq, _(u"Frequencies").decode('utf8'), 'freq'],
343                        [ID_FreqMulti, _(u"Multiple  Frequencies").decode('utf8'), 'freqmulti'],
344                        [ID_Chi2, _(u"Chi2").decode('utf8'), 'chi2'],
345                        [ID_Chi2mc, _(u"Chi2 McNemar").decode('utf8'), 'chi2mcnemar'],
346                        {'name' : _(u"Clustering").decode('utf8'),
347                         'content' : [[ID_CHDReinert, _(u"Reinert's Method").decode('utf8'), 'reinertmatrix']]},
348                        [ID_SIMI, _(u"Similarities Analysis").decode('utf8'), 'simimatrix'],
349                        [ID_proto, _(u"Prototypical Analysis").decode('utf8'), 'proto'],
350                        [ID_Splitfromvar, _(u"Split from variable").decode('utf8'), 'subcorpusmeta'],
351                         ]
352
353         for analyse in matanalyses :
354             if not isinstance(analyse, dict) :
355                 item = wx.MenuItem(matrix_menu, analyse[0], analyse[1])
356                 item.SetBitmap(self.images_analyses.get(analyse[2], wx.EmptyBitmap(16,16)))
357                 matrix_menu.AppendItem(item)
358             else :
359                 nmenu = wx.Menu()
360                 for subana in analyse['content'] :
361                     item = wx.MenuItem(nmenu, subana[0], subana[1])
362                     item.SetBitmap(self.images_analyses.get(subana[2], wx.EmptyBitmap(16,16)))
363                     nmenu.AppendItem(item)
364                 matrix_menu.AppendMenu(-1, analyse['name'], nmenu)
365         #item = wx.MenuItem(matrix_menu, ID_Freq, _(u"Frequencies").decode('utf8'))
366         #item.SetBitmap(self.images_analyses['freq'])
367         #matrix_menu.AppendItem(item)
368         #matrix_menu.Append(ID_Freq, _(u"Frequencies").decode('utf8'))
369         #item = wx.MenuItem(matrix_menu, ID_Freq, _(u"Multiple  Frequencies").decode('utf8'))
370         #item.SetBitmap(self.images_analyses['freqmulti'])
371         #matrix_menu.Append(ID_FreqMulti, _(u'Multiple frequencies').decode('utf8'))
372         #matrix_menu.AppendItem(item)
373         #matrix_menu.Append(ID_Chi2, _(u"Chi2").decode('utf8'))
374         #matrix_menu.Append(ID_Student, u"t de Student")
375         #menu_classif = wx.Menu()
376         #menu_classif.Append(ID_CHDReinert, _(u"Reinert's Method").decode('utf8'))
377         #menu_classif.Append(ID_CHDSIM, u"Par matrice des distances")
378         #matrix_menu.AppendMenu(-1, _(u"Clustering").decode('utf8'), menu_classif)
379         #matrix_menu.Append(ID_AFCM, u"AFCM")
380         #matrix_menu.Append(ID_SIMI, _(u"Similarities Analysis").decode('utf8'))
381         #matrix_menu.Append(ID_proto, _(u"Prototypical Analysis").decode('utf8'))
382         ID_RCODE = wx.NewId()
383         #matrix_menu.Append(ID_RCODE, u"Code R...")
384         #menu_splittab = wx.Menu()
385         #ID_SPLITVAR = wx.NewId()
386         #splitvar = wx.MenuItem(menu_splittab, ID_SPLITVAR, _(u"Split from variable").decode('utf8'))
387         #menu_splittab.AppendItem(splitvar)
388         #matrix_menu.AppendMenu(-1, _(u"Split matrix").decode('utf8'), menu_splittab)
389         self.matrix_menu = matrix_menu
390
391         text_menu = wx.Menu()
392         analyses_text = [[ID_TEXTSTAT, _(u"Statistics").decode('utf8'), 'stat'],
393                          [ID_ASLEX, _(u"Specificities and CA").decode('utf8'), 'spec'],
394                          [ID_labbe, _(u"Labbe Distance").decode('utf8'),'labbe'],
395                          {'name' : _(u"Clustering").decode('utf8'),
396                           'content' : [[ID_TEXTREINERT, _(u"Reinert's Method").decode('utf8'), 'alceste']]},
397                          [ID_SimiTxt, _(u"Similarities Analysis").decode('utf8'), 'simitxt'],
398                          [ID_WC, _(u"WordCloud").decode('utf8'), 'wordcloud'],
399                          {'name' : _(u"Sub corpus").decode('utf8'),
400                           'content' : [[ID_Subtxtfrommeta, _(u'Sub corpus from metadata').decode('utf8'), 'subcorpusmeta'],
401                                        [ID_Subtxtfromthem, _(u'Sub corpus from thematic').decode('utf8'), 'subcorpusthema']]},
402                          [ID_exportmeta, _(u"Export metadata table").decode('utf8'), 'exportmetatable'],
403                          ]
404
405         for analyse in analyses_text :
406             if not isinstance(analyse, dict) :
407                 item = wx.MenuItem(text_menu, analyse[0], analyse[1])
408                 item.SetBitmap(self.images_analyses.get(analyse[2], wx.EmptyBitmap(16,16)))
409                 text_menu.AppendItem(item)
410             else :
411                 nmenu = wx.Menu()
412                 for subana in analyse['content'] :
413                     item = wx.MenuItem(nmenu, subana[0], subana[1])
414                     item.SetBitmap(self.images_analyses.get(subana[2], wx.EmptyBitmap(16,16)))
415                     nmenu.AppendItem(item)
416                 text_menu.AppendMenu(-1, analyse['name'], nmenu)
417         #text_menu.Append(ID_CHECKCORPUS, u"VĂ©rifier le corpus")
418 #         text_menu.Append(ID_TEXTSTAT, _(u"Statistics").decode('utf8'))
419 #         text_menu.Append(ID_ASLEX, _(u"Specificities and CA").decode('utf8'))
420 #         #text_menu.Append(ID_TEXTAFCM, u"AFC sur UCI / Vocabulaire")
421 #         menu_classiftxt = wx.Menu()
422 #         menu_classiftxt.Append(ID_TEXTREINERT, _(u"Reinert's Method").decode('utf8'))
423 #         #menu_classiftxt.Append(ID_TEXTPAM, u"Par matrice des distances")
424 #         text_menu.AppendMenu(-1, _(u"Clustering").decode('utf8'), menu_classiftxt)
425 #         text_menu.Append(ID_SimiTxt, _(u"Similarities Analysis").decode('utf8'))
426 #
427 #         text_menu.Append(ID_WC, _(u"WordCloud").decode('utf8'))
428         self.text_menu = text_menu
429
430         help_menu = wx.Menu()
431         about = wx.MenuItem(help_menu, wx.ID_ABOUT, _(u"About...").decode('utf8'))
432         about.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_INFORMATION, size = (16,16)))
433         help_menu.AppendItem(about)
434         #help_menu.Append(wx.ID_ABOUT, _(u"About...").decode('utf8'))
435         help = wx.MenuItem(help_menu, wx.ID_HELP, _(u"Online help...").decode('utf8'))
436         help.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_HELP, size = (16,16)))
437         help_menu.AppendItem(help)
438         #help_menu.Append(wx.ID_HELP, _(u"Online help...").decode('utf8'))
439
440         self.mb.Append(file_menu, _(u"File").decode('utf8'))
441         self.mb.Append(edit_menu, _(u"Edition").decode('utf8'))
442         self.mb.Append(view_menu, _(u"View").decode('utf8'))
443         self.mb.Append(matrix_menu, _(u"Matrix analysis").decode('utf8'))
444         self.mb.Append(text_menu, _(u"Text analysis").decode('utf8'))
445         self.mb.Append(help_menu, _(u"Help").decode('utf8'))
446
447         self.SetMenuBar(self.mb)
448 #--------------------------------------------------------------------
449         self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
450         self.statusbar.SetStatusWidths([-2, -3])
451         self.statusbar.SetStatusText(_(u"Ready").decode('utf8'), 0)
452         self.statusbar.SetStatusText(_(u"Welcome").decode('utf8'), 1)
453
454         # min size for the frame itself isn't completely done.
455         # see the end up FrameManager::Update() for the test
456         # code. For now, just hard code a frame minimum size
457         self.SetMinSize(wx.Size(400, 400))
458
459         # create some toolbars
460         tb1 = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
461                          wx.TB_FLAT | wx.TB_NODIVIDER)
462         tb1.SetToolBitmapSize(wx.Size(16, 16))
463         tb1.AddLabelTool(ID_OpenData, "OpenData", self.images_analyses['matroot'], shortHelp=_(u"Matrix").decode('utf8'), longHelp=_(u"Open a matrix").decode('utf8'))
464         tb1.AddSeparator()
465         tb1.AddLabelTool(ID_OpenText, "OpenText", self.images_analyses['textroot'], shortHelp=_(u"Text").decode('utf8'), longHelp=_(u"Open a text corpus").decode('utf8'))
466         tb1.AddSeparator()
467         tb1.AddLabelTool(ID_OnOpenAnalyse, "OpenAnalyse", self.images_analyses['iramuteq'], shortHelp= _(u"Open an analysis").decode('utf8'), longHelp=_(u"Open an analysis").decode('utf8'))
468         tb1.AddSeparator()
469         tb1.AddLabelTool(ID_ImportTXM, "ImportTXM", self.images_analyses['TXM'], shortHelp= _(u"Import from TXM").decode('utf8'), longHelp=_(u"Import from TXM").decode('utf8'))
470         tb1.AddSeparator()
471         tb1.AddLabelTool(ID_ImportEuro, "ImportEuro", self.images_analyses['europress'], shortHelp= _(u"Import from Europress").decode('utf8'), longHelp=_(u"Import from Europress").decode('utf8'))
472         tb1.AddSeparator()
473         tb1.AddLabelTool(ID_importdmi, "ImportDMI", self.images_analyses['importdmi'], shortHelp= _(u"Import from DMI-TCAT (exp.)").decode('utf8'), longHelp=_(u"Import from DMI-TCAT (exp.)").decode('utf8'))
474         tb1.AddSeparator()
475         tb1.AddLabelTool(ID_Fact_xml, "ImportFactxml", self.images_analyses['factiva_xml'], shortHelp= _(u"Factiva from xml").decode('utf8'), longHelp=_(u"Factiva from xml").decode('utf8'))
476         tb1.AddLabelTool(ID_Fact_mail, "ImportFactmail", self.images_analyses['factiva_mail'], shortHelp= _(u"Factiva from mail").decode('utf8'), longHelp=_(u"Factiva from mail").decode('utf8'))
477         tb1.AddLabelTool(ID_Fact_copy, "ImportFactcopy", self.images_analyses['factiva_copy'], shortHelp= _(u"Factiva from copy/paste").decode('utf8'), longHelp=_(u"Factiva from copy/paste").decode('utf8'))
478         tb1.AddSeparator()
479         tb1.AddLabelTool(wx.ID_PREFERENCES, "Preferences", self.images_analyses['preferences'], shortHelp= _(u"Preferences").decode('utf8'), longHelp=_(u"Preferences").decode('utf8'))
480         tb1.AddSeparator()
481         tb1.AddLabelTool(ID_ACCEUIL, "Home", wx.ArtProvider_GetBitmap(wx.ART_GO_HOME, size = (16,16)), shortHelp= _(u"Home page").decode('utf8'), longHelp=_(u"Home page").decode('utf8'))
482         tb1.AddLabelTool(ID_RESULT, "Results", wx.ArtProvider_GetBitmap(wx.ART_LIST_VIEW, size = (16,16)), shortHelp= _(u'Show results').decode('utf8'), longHelp=_(u'Show results').decode('utf8'))
483         tb1.Realize()
484
485         tb_text = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
486                          wx.TB_FLAT | wx.TB_NODIVIDER)
487         for analyse in analyses_text :
488             if not isinstance(analyse, dict) :
489                 tb_text.AddLabelTool(analyse[0], analyse[1], self.images_analyses.get(analyse[2], wx.EmptyBitmap(16,16)), shortHelp = analyse[1], longHelp = analyse[1])
490             else :
491                 for subana in analyse['content'] :
492                     tb_text.AddLabelTool(subana[0], subana[1], self.images_analyses.get(subana[2], wx.EmptyBitmap(16,16)), shortHelp = subana[1], longHelp = subana[1])
493         tb_text.Realize()
494
495         tb_mat = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
496                          wx.TB_FLAT | wx.TB_NODIVIDER)
497         for analyse in matanalyses :
498             if not isinstance(analyse, dict) :
499                 tb_mat.AddLabelTool(analyse[0], analyse[1], self.images_analyses.get(analyse[2], wx.EmptyBitmap(16,16)), shortHelp = analyse[1], longHelp = analyse[1])
500             else :
501                 for subana in analyse['content'] :
502                     tb_mat.AddLabelTool(subana[0], subana[1], self.images_analyses.get(subana[2], wx.EmptyBitmap(16,16)), shortHelp = subana[1], longHelp = subana[1])
503         tb_mat.Realize()
504
505         tb_help = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
506                          wx.TB_FLAT | wx.TB_NODIVIDER)
507         tb_help.AddLabelTool(wx.ID_ABOUT, "About", wx.ArtProvider_GetBitmap(wx.ART_INFORMATION, size=(16,16)), shortHelp=_(u"About...").decode('utf8'), longHelp=_(u"About...").decode('utf8'))
508         tb_help.AddLabelTool(wx.ID_HELP, "Help", wx.ArtProvider_GetBitmap(wx.ART_HELP, size=(16,16)), shortHelp=_(u"Online help...").decode('utf8'), longHelp=_(u"Online help...").decode('utf8'))
509         tb_help.Realize()
510 #------------------------------------------------------------------------------------------------
511
512         self.text_ctrl_txt = wx.TextCtrl(self, -1, "", wx.Point(0, 0), wx.Size(200, 200), wx.NO_BORDER | wx.TE_MULTILINE | wx.TE_RICH2 | wx.TE_READONLY)
513
514         #self._mgr.AddPane(self.text_ctrl_txt, wx.aui.AuiPaneInfo().
515         #                  Name("Text").CenterPane())
516         self._mgr.AddPane(self.text_ctrl_txt, aui.AuiPaneInfo().
517                           Name("Text").CenterPane())
518         #self._mgr.AddPane(IntroPanel(self), wx.aui.AuiPaneInfo().Name("Intro_Text").
519         #                  CenterPane())
520         self._mgr.AddPane(IntroPanel(self), aui.AuiPaneInfo().Name("Intro_Text").
521                           CenterPane())
522         #if not os.path.exists(os.path.join(UserConfigPath, 'history.db')) :
523         #    with open(os.path.join(UserConfigPath, 'history.db'), 'w') as f :
524         #        f.write('')
525         self.history = History(os.path.join(UserConfigPath, 'history.db'))
526         #self.history.dostat()
527         self.tree = LeftTree(self)
528         self._mgr.AddPane(self.tree, aui.AuiPaneInfo().Name("lefttree").Caption(_(u"Historic").decode('utf8')).
529                           Left().MinSize(wx.Size(200,500)).Layer(1).Position(1).CloseButton(False).MaximizeButton(True).
530                           MinimizeButton(True))
531
532         #self.nb = wx.aui.AuiNotebook(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.aui.AUI_NB_DEFAULT_STYLE | wx.aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.aui.AUI_NB_TAB_MOVE | wx.aui.AUI_NB_TAB_FLOAT| wx.NO_BORDER)
533         self.nb = aui.AuiNotebook(self, -1, wx.DefaultPosition, wx.DefaultSize, aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | aui.AUI_NB_TAB_MOVE | aui.AUI_NB_TAB_FLOAT| wx.NO_BORDER)
534         notebook_flags =  aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | aui.AUI_NB_TAB_MOVE | aui.AUI_NB_TAB_FLOAT| wx.NO_BORDER
535         self.nb.SetAGWWindowStyleFlag(notebook_flags)
536         self.nb.SetArtProvider(aui.ChromeTabArt())
537         #self.nb.SetArtProvider(aui.VC8TabArt())
538         #self.nb.parent = self
539         #self._notebook_style = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.NO_BORDER
540         #self._mgr.AddPane(self.nb, wx.aui.AuiPaneInfo().
541         #                      Name("Tab_content").
542         #                      CenterPane())
543         self._mgr.AddPane(self.nb, aui.AuiPaneInfo().
544                               Name("Tab_content").
545                               CenterPane())
546
547         #self._mgr.AddPane(self.Sheet, wx.aui.AuiPaneInfo().Name("Data").CenterPane())
548         #self._mgr.AddPane(self.Sheet, aui.AuiPaneInfo().Name("Data").CenterPane())
549         self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnCloseTab)
550         self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
551         # add the toolbars to the manager
552
553         #self._mgr.AddPane(tb1, wx.aui.AuiPaneInfo().
554         #                  Name("tb1").Caption("Fichiers").
555         #                  ToolbarPane().Top().
556         #                  LeftDockable(False).RightDockable(False))
557         self._mgr.AddPane(tb1, aui.AuiPaneInfo().
558                           Name("tb1").Caption("Fichiers").
559                           ToolbarPane().Top().
560                           LeftDockable(True).RightDockable(False))
561
562         self._mgr.AddPane(tb_text, aui.AuiPaneInfo().
563                           Name("tb_text").Caption("analyse_text").
564                           ToolbarPane().Top().
565                           LeftDockable(True).RightDockable(False))
566
567         self._mgr.AddPane(tb_mat, aui.AuiPaneInfo().
568                           Name("tb_mat").Caption("analyse_matrix").
569                           ToolbarPane().Top().
570                           LeftDockable(True).RightDockable(False))
571
572         self._mgr.AddPane(tb_help, aui.AuiPaneInfo().
573                           Name("tb_help").Caption("help").
574                           ToolbarPane().Top().
575                           LeftDockable(True).RightDockable(False))
576
577         self._mgr.GetPane('tb_text').Hide()
578         self._mgr.GetPane('tb_mat').Hide()
579
580         self.ShowAPane("Intro_Text")
581         self._mgr.GetPane("lefttree").Show()
582         self._mgr.GetPane("classif_tb").Hide()
583         # "commit" all changes made to FrameManager
584         self._mgr.Update()
585
586         # Show How To Use The Closing Panes Event
587 ##################################################################
588         self.Bind(wx.EVT_MENU, self.OnAcceuil, id=ID_ACCEUIL)
589         self.Bind(wx.EVT_MENU, self.ShowTab, id=ID_RESULT)
590         self.Bind(wx.EVT_MENU, self.OnOpenData, id=ID_OpenData)
591         self.Bind(wx.EVT_MENU, self.OnOpenText, id=ID_OpenText)
592         self.Bind(wx.EVT_MENU, self.OnOpenAnalyse, id=ID_OnOpenAnalyse)
593         self.Bind(wx.EVT_MENU, self.import_factiva_xml, fact_from_xml)
594         self.Bind(wx.EVT_MENU, self.import_factiva_mail, fact_from_mail)
595         self.Bind(wx.EVT_MENU, self.import_factiva_txt, fact_from_txt)
596         self.Bind(wx.EVT_MENU, self.ExtractTools, splitvar)
597         self.Bind(wx.EVT_MENU, self.ExtractTools, extractmod)
598         self.Bind(wx.EVT_MENU, self.ExtractTools, extractthem)
599         self.Bind(wx.EVT_MENU, self.OnFreq, id=ID_Freq)
600         self.Bind(wx.EVT_MENU, self.OnFreqMulti, id=ID_FreqMulti)
601         self.Bind(wx.EVT_MENU, self.OnChi2, id=ID_Chi2)
602         self.Bind(wx.EVT_MENU, self.OnChi2McNemar, id=ID_Chi2mc)
603         self.Bind(wx.EVT_MENU, self.OnStudent, id=ID_Student)
604         self.Bind(wx.EVT_MENU, self.OnCHDSIM, id=ID_CHDSIM)
605         self.Bind(wx.EVT_MENU, self.OnCHDReinert, id=ID_CHDReinert)
606         self.Bind(wx.EVT_MENU, self.OnAFCM, id=ID_AFCM)
607         self.Bind(wx.EVT_MENU, self.OnProto, id=ID_proto)
608         self.Bind(wx.EVT_MENU, self.OnSplitVar, id = ID_Splitfromvar)
609         #self.Bind(wx.EVT_MENU, self.OnRCode, id=ID_RCODE)
610         #self.Bind(wx.EVT_MENU, self.OnSplitVar, id=ID_SPLITVAR)
611         #self.Bind(wx.EVT_MENU, self.OnCheckcorpus, id = ID_CHECKCORPUS)
612         self.Bind(wx.EVT_MENU, self.OnTextStat, id=ID_TEXTSTAT)
613         self.Bind(wx.EVT_MENU, self.OnTextSpec, id=ID_ASLEX)
614         self.Bind(wx.EVT_MENU, self.OnTextLabbe, id=ID_labbe)
615         self.Bind(wx.EVT_MENU, self.OnTextAfcm, id=ID_TEXTAFCM)
616         self.Bind(wx.EVT_MENU, self.OnTextReinert, id=ID_TEXTREINERT)
617         self.Bind(wx.EVT_MENU, self.OnPamSimple, id=ID_TEXTPAM)
618         self.Bind(wx.EVT_MENU, self.OnSimiTxt, id=ID_SimiTxt)
619         self.Bind(wx.EVT_MENU, self.OnWordCloud, id=ID_WC)
620         self.Bind(wx.EVT_MENU, self.OnSubText, id = ID_Subtxtfrommeta)
621         self.Bind(wx.EVT_MENU, self.OnSubText, id = ID_Subtxtfromthem)
622         self.Bind(wx.EVT_MENU, self.OnSimiTab, id=ID_SIMI)
623         self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
624         #self.Bind(wx.EVT_MENU, self.OnSaveTabAs, id=ID_SaveTab)
625         self.Bind(wx.EVT_MENU, self.OnAbout, id=wx.ID_ABOUT)
626         self.Bind(wx.EVT_MENU, self.OnHelp, id=wx.ID_HELP)
627         self.Bind(wx.EVT_MENU, self.OnPref, id=wx.ID_PREFERENCES)
628         self.Bind(wx.EVT_MENU, self.OnImportTXM, id=ID_ImportTXM)
629         self.Bind(wx.EVT_MENU, self.OnImportEuropress, id=ID_ImportEuro)
630         self.Bind(wx.EVT_MENU, self.OnImportDMI, id=ID_importdmi)
631         self.Bind(wx.EVT_MENU, self.OnExportMeta, id=ID_exportmeta)
632         self.Bind(wx.EVT_MENU, self.OnMergeGraph, id = ID_merge)
633         self.Bind(wx.EVT_MENU, self.OnMergeClusters, id = ID_merge_clusters)
634         self.Bind(wx.EVT_CLOSE, self.OnClose)
635 ##################################################################
636         flags = self._mgr.GetAGWFlags()
637         #flags &= ~wx.aui.AUI_MGR_TRANSPARENT_HINT
638         #flags &= ~wx.aui.AUI_MGR_VENETIAN_BLINDS_HINT
639         #flags &= ~wx.aui.AUI_MGR_RECTANGLE_HINT
640         flags &= ~(aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING)
641         self._mgr.SetAGWFlags(self._mgr.GetAGWFlags() ^ (aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING))
642         self._mgr.GetArtProvider().SetMetric(aui.AUI_DOCKART_GRADIENT_TYPE, aui.AUI_GRADIENT_HORIZONTAL)
643         self.GetDockArt().SetColor(aui.AUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR, "#00FFF9")
644         self.DoUpdate()
645
646         self._icon = wx.Icon(os.path.join(ImagePath, "iraicone.ico"), wx.BITMAP_TYPE_ICO)
647         self.SetIcon(self._icon)
648 ##########################
649         self.ctrl = ""
650         self.input_path = [False]
651         self.TEMPDIR = tempfile.mkdtemp('iramuteq')
652         self.FileTabList = []
653         self.listbar=[]
654         self.DictTab = {}
655         self.FreqNum = 0
656         self.colsep = ''
657         self.txtsep = ''
658         self.g_header = False
659         self.g_id = False
660         self.table = ''
661         self.fileforR = ''
662         self.filename = ''
663         self.nastrings = ''
664         self.encode = ''
665         self.SysEncoding = sys.getdefaultencoding()
666         self.syscoding = sys.getdefaultencoding()
667         #print 'SysEncoding',self.SysEncoding
668         if self.SysEncoding == 'mac-roman' : self.SysEncoding = 'MacRoman'
669         self.type = ''
670
671 ##############################################################@
672         self.ShowMenu('view', True)
673         self.ShowMenu('matrix', False)
674         self.ShowMenu('text', False)
675
676         self._mgr.Update()
677
678         self.DataPop = False
679         self.DataTxt = False
680         self.Text = ''
681
682         self.lexique = None
683         self.corpus = None
684
685     def finish_init(self) :
686         try :
687             self.pref.read(self.ConfigPath['preferences'])
688             if IsNew(self) :
689                 UpgradeConf(self)
690                 self.pref.read(self.ConfigPath['preferences'])
691                 New = True
692             else :
693                 CopyConf(self)
694                 New = False
695         except :
696             UpgradeConf(self)
697             self.pref.read(self.ConfigPath['preferences'])
698             New = True
699         self.sound = self.pref.getboolean('iramuteq', 'sound')
700         self.check_update = self.pref.getboolean('iramuteq', 'checkupdate')
701         self.version = ConfigGlob.get('DEFAULT', 'version')
702         #configuration des chemins de R
703         self.PathPath = ConfigParser()
704         self.PathPath.read(ConfigPath['path'])
705         BestRPath = False
706         if not CheckRPath(self.PathPath) :
707             if sys.platform == 'win32':
708                 BestRPath = FindRPAthWin32()
709             else:
710                 BestRPath = FindRPathNix()
711             if BestRPath:
712                 self.PathPath.set('PATHS', 'rpath', BestRPath)
713                 with open(ConfigPath['path'], 'w') as f :
714                     self.PathPath.write(f)
715         else:
716             BestRPath = True
717         if BestRPath :
718             self.RPath = self.PathPath.get('PATHS', 'rpath')
719             if New :
720                 CheckRPackages(self)
721             if not RLibsAreInstalled(self) :
722                 CheckRPackages(self)
723         else :
724             msg = '\n'.join([_(u"Can't find R executable").decode('utf8'), _(u"If R is not installed, get it from http://www.r-project.org.").decode('utf8'),
725                              _(u"If R is installed, report its path in Preferences.").decode('utf8'),
726                              _(u"IRaMuTeQ does not work without R.").decode('utf8')])
727             dlg = wx.MessageDialog(self, msg, _(u"Problem").decode('utf8'), wx.OK | wx.ICON_WARNING)
728             dlg.CenterOnParent()
729             if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
730                 pass
731             dlg.Destroy()
732
733     def setlangue(self) :
734         self.pref.read(self.ConfigPath['preferences'])
735         try :
736             guilangue = self.pref.get('iramuteq', 'guilanguage')
737         except :
738             guilangue = DefaultConf.get('iramuteq', 'guilanguage')
739         self.preslangue.get(guilangue, 'english').install()
740
741     def OnVerif(self, evt) :
742         pack = CheckRPackages(self)
743         if pack :
744             dlg = wx.MessageDialog(self, _(u"Installation OK").decode('utf8'), _(u"Installation").decode('utf8'), wx.OK | wx.ICON_INFORMATION | wx.STAY_ON_TOP)
745             dlg.CenterOnParent()
746             if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
747                 evt.Veto()
748
749     def ShowMenu(self, menu, Show=True):
750         if menu == 'text' :
751             menu_pos = 4
752             if Show :
753                 self._mgr.GetPane('tb_text').Show()
754             else :
755                 self._mgr.GetPane('tb_text').Hide()
756         elif menu == 'matrix' :
757             menu_pos = 3
758             if Show :
759                 self._mgr.GetPane('tb_mat').Show()
760             else :
761                 self._mgr.GetPane('tb_mat').Hide()
762         elif menu == 'view' :
763             menu_pos = 2
764         else :
765             menu_pos = None
766
767         #menu_pos = self.mb.FindMenu(menu)
768         if not menu_pos is None :
769             self.mb.EnableTop(menu_pos, Show)
770             self.mb.UpdateMenus()
771         self._mgr.Update()
772
773 #--------------------------------------------------------------------
774     def OnClose(self, event):
775         print 'onclose'
776         with open(self.ConfigPath['path'], 'w') as f :
777             self.PathPath.write(f)
778         self._mgr.UnInit()
779         del self._mgr
780         self.Destroy()
781
782     def OnOpenData(self, event):
783         inputname, self.input_path = OnOpen(self, "Data")
784         if inputname:
785             #filename = self.input_path[0]
786             self.tableau = Tableau(self,os.path.abspath(self.input_path[0]))
787             val = get_table_param(self, self.input_path[0])
788             if val == wx.ID_OK :
789                 busy = wx.BusyInfo(_("Please wait...").decode('utf8'), self)
790                 wx.SafeYield()
791                 try :
792                     self.tableau.make_content()
793                     OpenAnalyse(self, self.tableau.parametres)
794                     self.tree.OnItemAppend(self.tableau.parametres)
795                     del busy
796                 except :
797                     del busy
798                     BugReport(self)
799                 #self.tableau.show_tab()
800
801     def OnOpenAnalyse(self, event):
802         self.AnalysePath = OnOpen(self, "Analyse")
803         if self.AnalysePath :
804             OpenAnalyse(self, self.AnalysePath[1][0], True)
805             self.ShowMenu('view')
806
807     def OnOpenText(self, event):
808         inputname, self.input_path = OnOpen(self, "Texte")
809         self.filename = self.input_path[0]
810         if inputname:
811             self.OpenText()
812
813     def OnSubText(self, evt, corpus = None, parametres = None):
814         if corpus is None :
815             corpus = self.tree.getcorpus()
816         if evt.GetId() == ID_Subtxtfrommeta :
817             parametres = {'frommeta' : True}
818         elif evt.GetId() == ID_Subtxtfromthem :
819             parametres = {'fromtheme' : True}
820         builder = SubBuilder(self, corpus, parametres)
821         if builder.res == wx.ID_OK :
822             busy = wx.BusyInfo(_("Please wait...").decode('utf8'), self)
823             wx.SafeYield()
824             corpus = builder.doanalyse()
825             self.history.add(corpus.parametres)
826             OpenAnalyse(self, corpus.parametres)
827             self.tree.OnItemAppend(corpus.parametres)
828             del busy
829
830     def OpenText(self):
831         builder =  Builder(self, 5)
832         if builder.res == wx.ID_OK :
833             try :
834                 corpus = builder.doanalyse()
835                 self.history.add(corpus.parametres)
836                 self.tree.OnItemAppend(corpus.parametres)
837                 OpenAnalyse(self, corpus.parametres)
838             except :
839                 builder.dlg.Destroy()
840                 BugReport(self)
841             else :
842                 count = 1
843                 keepGoing = builder.dlg.Update(count, u"Lecture du fichier")
844                 self.ShowMenu('view')
845                 self.ShowMenu('text')
846                 self.ShowMenu('matrix', False)
847                 self.type = "Texte"
848                 self.DataTxt = False
849                 self.Text = ''
850                 count += 1
851                 keepGoing = builder.dlg.Update(count, u"Chargement du dictionnaire")
852                 builder.dlg.Destroy()
853
854     def OnExit(self, event):
855         self.Close()
856
857     def OnAbout(self, event):
858         info = wx.AboutDialogInfo()
859         info.Name = ConfigGlob.get('DEFAULT', 'name')
860         info.Version = ConfigGlob.get('DEFAULT', 'version')
861         info.Copyright = ConfigGlob.get('DEFAULT', 'copyright')
862         info.Translators = ConfigGlob.get('DEFAULT', 'translators').decode('utf8').split(';')
863         info.Description = u"""
864 Interface de R pour les Analyses Multidimensionnelles
865 de Textes et de Questionnaires
866
867 Un logiciel libre
868 construit avec des logiciels libres.
869
870 Laboratoire LERASS
871
872 REPERE
873 """
874         info.WebSite = ("http://www.iramuteq.org", u"Site web IRaMuTeQ")
875         dev = ConfigGlob.get('DEFAULT', 'dev').decode('utf8').split(';')
876         info.Developers = dev
877         info.License = u"""Iramuteq est un logiciel libre ; vous pouvez le diffuser et/ou le modifier
878 suivant les termes de la Licence Publique GĂ©nĂ©rale GNU telle que publiĂ©e 
879 par la Free Software Foundation ; soit la version 2 de cette licence, 
880 soit (Ă  votre convenance) une version ultĂ©rieure.
881
882 Iramuteq est diffusĂ© dans l'espoir qu'il sera utile, 
883 mais SANS AUCUNE GARANTIE ; sans mĂŞme une garantie implicite 
884 de COMMERCIALISATION ou d'ADÉQUATION Ă€ UN USAGE PARTICULIER. 
885 Voyez la Licence Publique GĂ©nĂ©rale GNU pour plus de dĂ©tails.
886
887 Vous devriez avoir reçu une copie de la Licence Publique GĂ©nĂ©rale GNU
888 avec Iramuteq ; sinon, veuillez Ă©crire Ă  la Free Software Foundation,
889 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, Ă‰tats-Unis."""
890         wx.AboutBox(info)
891
892     def GetDockArt(self):
893         return self._mgr.GetArtProvider()
894
895     def DoUpdate(self):
896         self._mgr.Update()
897
898     def OnPageChanged(self, event) :
899         new = event.GetSelection()
900         nobject = event.GetEventObject()
901         parent = nobject.GetParent()
902         if isinstance(parent, IraFrame) :
903             npage = self.nb.GetPage(new)
904             if 'parametres' in dir(npage) :
905                 self.tree.GiveFocus(uuid=npage.parametres['uuid'])
906                 if npage.parametres.get('matrix', False) :
907                     self.ShowMenu('text', False)
908                     self.ShowMenu('matrix', True)
909                 elif npage.parametres.get('corpus', False) :
910                     self.ShowMenu('text')
911                     self.ShowMenu('matrix', False)
912
913     def OnCloseTab(self, evt):
914         #log.info('Closing tab %s' % str(evt.GetEventObject()))
915         ctrl = evt.GetEventObject()
916         if isinstance(ctrl.GetParent(), aui.AuiNotebook) or isinstance(ctrl.GetParent(), wx.Panel):
917             notebook = True
918         else :
919             notebook = False
920         page = self.nb.GetPage(self.nb.GetSelection())
921         if 'parametres' in dir(page) and isinstance(ctrl.GetParent(), IraFrame) :
922             self.history.rmtab(page.parametres)
923             self.tree.CloseItem(uuid = page.parametres['uuid'])
924         TabTitle = self.nb.GetPageText(self.nb.GetSelection())
925
926         if self.nb.GetPageCount() == 1 and not notebook :
927             self.LastTabClose()
928
929     def LastTabClose(self) :
930         if self.nb.GetPageCount() == 1 :
931             if self.DataTxt :
932                 self.ShowAPane("Text")
933             elif self.DataPop :
934                 self.ShowAPane("Data")
935             else :
936                 self.ShowAPane("Intro_Text")
937
938     def GetStartPosition(self):
939
940         self.x = self.x + 20
941         x = self.x
942         pt = self.ClientToScreen(wx.Point(0, 0))
943
944         return wx.Point(pt.x + x, pt.y + x)
945
946     def ShowAPane(self, panel):
947         for pane in self._mgr.GetAllPanes() :
948             if not pane.IsToolbar() and pane.name != 'lefttree':
949                 pane.Hide()
950         self._mgr.GetPane(panel).Show()
951         self._mgr.Update()
952
953     def OnAcceuil(self, event):
954         self.ShowAPane(u"Intro_Text")
955         event.Skip()
956
957     def CreateHTMLCtrl(self):
958         ctrl = wx.html.HtmlWindow(self, -1, wx.DefaultPosition, wx.Size(400, 300))
959         if "gtk2" in wx.PlatformInfo:
960             ctrl.SetStandardFonts()
961         ctrl.SetPage(u"text")
962         return ctrl
963
964     def ShowTab(self, evt):
965         self.ShowAPane("Tab_content")
966
967 ################################################################
968 #debut des analyses
969 ################################################################
970     def analyse_matrix(self, analyse, analyse_type = '', matrix = None, parametres = None, dlgnb = 1):
971         if matrix is None :
972             matrix = self.tree.getmatrix()
973         if parametres is not None :
974             parametres['type'] = analyse_type
975         else :
976             parametres = {'type' : analyse_type}
977         try :
978         #print 'plus de bug@@@@@@@@@@@@@@@@@@@@@@'
979             analyse(self, matrix, parametres = parametres, dlg = dlgnb)
980         except:
981             BugReport(self)
982
983     def OnFreq(self, event, matrix = None):
984         self.analyse_matrix(Frequences, analyse_type = 'freq', matrix = matrix, dlgnb = 3)
985
986     def OnFreqMulti(self, event, matrix = None):
987         self.analyse_matrix(FreqMultiple, analyse_type = 'freqmulti', matrix = matrix, dlgnb = 3)
988
989     def OnChi2(self, event, matrix = None):
990         self.analyse_matrix(ChiSquare, matrix = matrix, analyse_type = 'chi2', dlgnb = 3)
991
992     def OnChi2McNemar(self, event, matrix = None):
993         self.analyse_matrix(McNemar, matrix = matrix, analyse_type = 'chi2mcnemar', dlgnb = 3)
994
995     def OnSimiTab(self, event, matrix = None):
996         self.analyse_matrix(DoSimi, matrix = matrix, analyse_type = 'simimatrix', dlgnb = 5)
997
998     def OnCHDReinert(self, event, matrix = None):
999         #if matrix is None :
1000         #    matrix = self.tree.getmatrix()
1001         #AnalyseQuest(self, matrix, parametres = {'type' : 'reinertmatrix'}, dlg = 3)
1002         self.analyse_matrix(AnalyseQuest, matrix = matrix, analyse_type = 'reinertmatrix', dlgnb = 5)
1003
1004     def OnStudent(self, event):
1005         try:
1006             MakeStudent(self)
1007         except:
1008             BugReport(self)
1009
1010     def OnRCode(self, event):
1011         try:
1012             InputText(self)
1013         except:
1014             BugReport(self)
1015
1016     def OnCHDSIM(self, event):
1017         try:
1018         #    print 'ATTENTION!!!!'
1019             chdsim = ChdCluster(self)
1020             if chdsim.val == wx.ID_OK:
1021                 PlaySound(self)
1022         except:
1023             BugReport(self)
1024
1025 #     def OnCHDReinert(self, event):
1026 #         try:
1027 #          #   print('PLUS DE BUG SUR ALCESTE QUESTIONNAIRE')
1028 #             self.quest = AnalyseQuest(self)
1029 #             if self.quest.val == wx.ID_OK:
1030 #                 PlaySound(self)
1031 #         except:
1032 #             BugReport(self)
1033     def OnMergeGraph(self, evt):
1034         #FIXME
1035         AnalyseMerge(self, {'type': 'merge', 'fileout' : '/tmp/test.txt'}, dlg = 5)
1036
1037     def OnEliminate(self, corpus, parametres) :
1038         print parametres
1039
1040     def OnMergeClusters(self, evt) :
1041         builder = MergeClusters(self, {})
1042         if builder.res == wx.ID_OK :
1043             busy = wx.BusyInfo(_("Please wait...").decode('utf8'), self)
1044             wx.SafeYield()
1045             corpus = builder.doanalyse()
1046             self.history.add(corpus.parametres)
1047             OpenAnalyse(self, corpus.parametres)
1048             self.tree.OnItemAppend(corpus.parametres)
1049             del busy
1050
1051     def OnProto(self, evt, matrix = None) :
1052         self.analyse_matrix(Prototypical, matrix = matrix, analyse_type = 'proto', dlgnb = 3) 
1053         #Prototypical(self, {'type' : 'proto'})
1054
1055     def OnSplitVar(self, evt, matrix = None):
1056         if matrix is None :
1057             matrix = self.tree.getmatrix()
1058         self.analyse_matrix(SplitMatrixFromVar, matrix = matrix, analyse_type = 'splitvar', parametres = {'pathout': matrix.pathout.dirout}, dlgnb = 3)
1059         #matrix = self.tree.getmatrix()
1060
1061
1062     def OnSimiTxt(self, evt, corpus = None) :
1063         #    print 'PLUS DE BUG SUR SIMITXT'
1064         try :
1065             #self.Text = SimiTxt(self)
1066             if corpus is None :
1067                 corpus = self.tree.getcorpus()
1068             self.Text = SimiTxt(self, corpus, parametres = {'type': 'simitxt'}, dlg = 3)
1069             if self.Text.val == wx.ID_OK :
1070                 PlaySound(self)
1071         except :
1072             BugReport(self)
1073
1074     def OnWordCloud(self, evt, corpus = None) :
1075         #    print 'PLUS DE BUG SUR WORDCLOUD'
1076         try :
1077             if corpus is None :
1078                 corpus = self.tree.getcorpus()
1079             self.Text = WordCloud(self, corpus, parametres = {'type' : 'wordcloud'}, dlg = 3)
1080             if self.Text.val == wx.ID_OK :
1081                 PlaySound(self)
1082         except :
1083             BugReport(self)
1084
1085     def OnClusterCloud(self, corpus, parametres = None) :
1086         self.Text = ClusterCloud(self, corpus, parametres = parametres, dlg = 3)
1087
1088     def OnAFCM(self, event):
1089         try:
1090             DoAFCM(self)
1091         except:
1092             BugReport(self)
1093
1094     def OnTextStat(self, event, corpus = None):
1095             #print 'PAS DE BUG SUR TEXT STAT'
1096         try:
1097             if corpus is None :
1098                 corpus = self.tree.getcorpus()
1099             self.Text = Stat(self, corpus, parametres = {'type': 'stat'}, dlg = 7)
1100
1101             if self.Text.val == wx.ID_OK :
1102                 PlaySound(self)
1103         except:
1104             BugReport(self)
1105
1106     def OnTextSpec(self, event, corpus = None):
1107         try:
1108             #self.Text = AsLexico(self)
1109             #print('ATTENTION : PLUS DE BUG SUR LEXICO')
1110             if corpus is None :
1111                 corpus = self.tree.getcorpus()
1112             self.Text = Lexico(self, corpus, parametres = {'type' : 'spec'}, dlg = 3)
1113             if self.Text.val == wx.ID_OK :
1114                 PlaySound(self)
1115         except:
1116             BugReport(self)
1117
1118     def OnTextLabbe(self, event, corpus = None):
1119         try:
1120             if corpus is None :
1121                 corpus = self.tree.getcorpus()
1122             self.Text = DistLabbe(self, corpus, parametres = {'type' : 'labbe'}, dlg = 3)
1123             if self.Text.val == wx.ID_OK :
1124                 PlaySound(self)
1125         except:
1126             BugReport(self)
1127
1128
1129     def OnTextAfcm(self, event):
1130         try:
1131             AfcUci(self)
1132             PlaySound(self)
1133         except:
1134             BugReport(self)
1135
1136     def import_factiva_xml(self,event):
1137         try :
1138             ImportFactiva(self, 'xml')
1139         except :
1140             BugReport(self)
1141
1142     def import_factiva_mail(self, evt) :
1143         try :
1144             ImportFactiva(self, 'mail')
1145         except :
1146             BugReport(self)
1147
1148     def import_factiva_txt(self, evt) :
1149         try :
1150             ImportFactiva(self, 'txt')
1151         except :
1152             BugReport(self)
1153
1154     def OnImportTXM(self, evt) :
1155         try :
1156             ImportFactiva(self, 'txm')
1157         except :
1158             BugReport(self)
1159
1160     def OnImportEuropress(self, evt) :
1161         try :
1162             ImportFactiva(self, 'euro')
1163         except :
1164             BugReport(self)
1165
1166     def OnImportDMI(self, evt):
1167         ImportDMI(self, {})
1168
1169     def OnExportMeta(self, evt, corpus = None):
1170         if corpus is None :
1171             corpus = self.tree.getcorpus()
1172         try :
1173             ExportMetaTable(self, corpus)
1174         except :
1175             BugReport(self)
1176
1177     def ExtractTools(self, evt) :
1178         ID = evt.GetId()
1179         if ID == self.ID_splitvar :
1180             Extract(self, 'splitvar')
1181         elif ID == self.ID_extractmod :
1182             Extract(self, 'mods')
1183         elif ID == self.ID_extractthem :
1184             Extract(self, 'them')
1185
1186     def OnTextReinert(self, event, corpus = None):
1187         try:
1188             #print('ATTENTION : PLUS DE BUG SUR ALCESTE')
1189             #RunAnalyse(self, corpus, Alceste, OptAlceste)
1190             if corpus is None :
1191                 corpus = self.tree.getcorpus()
1192             self.Text = Reinert(self, corpus, parametres = {'type': 'alceste'}, dlg = 6)
1193             if self.Text.val == wx.ID_OK:
1194                 PlaySound(self)
1195         except:
1196             BugReport(self)
1197
1198     def OnPamSimple(self, event, corpus = None):
1199         try:
1200             if corpus is None :
1201                 corpus = self.tree.getcorpus()
1202             self.Text = AnalysePam(self, corpus, parametres = {'type' : 'pamtxt'}, dlg = 6)
1203             if self.Text.val == wx.ID_OK:
1204                 PlaySound(self)
1205         except:
1206             BugReport(self)
1207
1208     def SimiCluster(self, parametres = {}, fromprof = False, tableau = None) :
1209         self.analyse_matrix(DoSimi, parametres = parametres, analyse_type = 'simiclustermatrix', matrix = tableau, dlgnb = 5)
1210
1211 #    def OnSimi(self,evt):
1212 #        try :
1213             #print 'ATTENTION !!!! VERGES'
1214             #print 'PLUS DE BUG SUR SIMI'
1215 #            self.res = DoSimi(self, param = None)
1216             #self.res = Verges(self)
1217 #            if self.res.val == wx.ID_OK :
1218 #                PlaySound(self)
1219 #        except :
1220 #            BugReport(self)
1221 #################################################################
1222
1223     def OnHelp(self, event):
1224         webbrowser.open('http://www.iramuteq.org/documentation')
1225
1226     def OnPref(self, event):
1227         dlg = PrefDialog(self)
1228         dlg.CenterOnParent()
1229         self.val = dlg.ShowModal()
1230         dlg.Destroy()
1231
1232     def Upgrade(self) :
1233         if self.check_update:
1234             NewVersion(self)
1235         else:
1236             print 'pas de verif'
1237         #IsNew(self)
1238         #CheckRPackages(self)
1239
1240     def OnOpenFromCmdl(self):
1241         truepath = True
1242         if options.filename :
1243             if os.path.exists(options.filename):
1244                 self.filename = os.path.abspath(options.filename)
1245             else:
1246                 truepath = False
1247         elif args :
1248             if os.path.exists(os.path.realpath(args[0])):
1249                 self.filename = os.path.abspath(os.path.realpath(args[0]))
1250             else:
1251                 truepath = False
1252         else:
1253             return
1254         if truepath :
1255             if os.path.splitext(self.filename)[1] in ['.csv', '.xls', '.ods']:
1256                 self.tableau = Tableau(self, self.filename)
1257                 val = get_table_param(self, self.filename)
1258                 if val == wx.ID_OK :
1259                     self.tableau.make_content()
1260                     OpenAnalyse(self, self.tableau.parametres)
1261                     self.tree.OnItemAppend(self.tableau.parametres)
1262                 #get_table_param(self, self.filename)
1263                 #self.tableau.make_content()
1264                 #self.tableau.show_tab()
1265                 #open_data(self, self.filename)
1266             elif os.path.splitext(self.filename)[1] == '.txt':
1267                 self.OpenText()
1268             elif os.path.splitext(self.filename)[1] == '.ira' :
1269                 #self.corpus = Corpus(self)
1270                 #self.Text = OpenAnalyse(self, self.filename)
1271                 OpenAnalyse(self, self.filename)
1272         if not truepath:
1273             print 'This file does not exist'
1274
1275
1276 class IntroPanel(wx.Panel):
1277     def __init__(self, parent):
1278         wx.Panel.__init__(self, parent)
1279         #col = randint(0, 255)
1280         #col1 = randint(0,255)
1281         #col2 = randint(0,255)
1282         #col = 57
1283         col = 161
1284         col1 = 198
1285         col2 = 224
1286         bckgrdcolor = wx.Colour(col, col1, col2)
1287         self.SetBackgroundColour(bckgrdcolor)
1288         txtcolour = wx.Colour(250, 250, 250)
1289         linkcolor = wx.Colour(255, 0, 0)
1290         sizer1 = wx.BoxSizer(wx.VERTICAL)
1291         sizer2 = wx.BoxSizer(wx.VERTICAL)
1292         sizer4 = wx.BoxSizer(wx.HORIZONTAL)
1293         grid_sizer_1 = wx.FlexGridSizer(1, 4, 0, 0)
1294         grid_sizer_3 = wx.FlexGridSizer(1, 4, 0, 0)
1295         grid_sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
1296
1297         iralink = hl.HyperLinkCtrl(self, wx.ID_ANY, u"http://www.iramuteq.org", URL="http://www.iramuteq.org")
1298         iralink.SetColours(linkcolor, linkcolor, "RED")
1299         iralink.SetBackgroundColour(bckgrdcolor)
1300         iralink.EnableRollover(True)
1301         iralink.SetUnderlines(False, False, True)
1302         iralink.SetBold(True)
1303         iralink.UpdateLink()
1304
1305         PanelPres = wx.Panel(self)
1306         bckgrdcolor = wx.Colour(randint(0, 255), randint(0, 255), randint(0, 255))
1307         PanelPres.SetBackgroundColour(bckgrdcolor)
1308
1309         label_1 = wx.StaticText(self, -1, u"IRaMuTeQ", size=(-1, -1))
1310         label_1.SetFont(wx.Font(46, wx.TELETYPE, wx.NORMAL, wx.BOLD, 0, "Purisa"))
1311         label_1.SetForegroundColour(wx.RED)
1312
1313         iraicone = wx.Image(os.path.join(ImagePath,'iraicone100x100.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1314         but_ira = wx.StaticBitmap(self, -1, bitmap = iraicone)
1315
1316
1317         label2 = wx.StaticText(PanelPres, -1 , u'\nVersion ' + ConfigGlob.get('DEFAULT', 'version') + '\n')
1318         label2.SetForegroundColour(txtcolour)
1319         label2.SetBackgroundColour(bckgrdcolor)
1320         self.hyper2 = hl.HyperLinkCtrl(PanelPres, wx.ID_ANY, u"REPERE", URL="http://repere.no-ip.org/")
1321         self.hyper2.SetColours(linkcolor, linkcolor, "RED")
1322         self.hyper2.SetBackgroundColour(bckgrdcolor)
1323         self.hyper2.EnableRollover(True)
1324         self.hyper2.SetUnderlines(False, False, True)
1325         self.hyper2.SetBold(True)
1326         self.hyper2.UpdateLink()
1327
1328         label_lerass = wx.StaticText(PanelPres, -1, u'Laboratoire ')
1329         label_lerass.SetForegroundColour(txtcolour)
1330         label_lerass.SetBackgroundColour(bckgrdcolor)
1331
1332         self.hyper_lerass = hl.HyperLinkCtrl(PanelPres, -1, u'LERASS', URL="http://www.lerass.com")
1333         self.hyper_lerass.SetColours(linkcolor, linkcolor, "RED")
1334         self.hyper_lerass.SetBackgroundColour(bckgrdcolor)
1335         self.hyper_lerass.EnableRollover(True)
1336         self.hyper_lerass.SetUnderlines(False, False, True)
1337         self.hyper_lerass.SetBold(True)
1338         self.hyper_lerass.UpdateLink()
1339
1340         blank = wx.StaticText(PanelPres, -1, u'\n')
1341         blank1 = wx.StaticText(PanelPres, -1, u'\n')
1342
1343         labellicence = wx.StaticText(PanelPres, -1, _(u"License GNU GPL").decode('utf8'))
1344         labellicence.SetForegroundColour(txtcolour)
1345         labellicence.SetBackgroundColour(bckgrdcolor)
1346
1347         labelcopy = wx.StaticText(PanelPres, -1, ConfigGlob.get('DEFAULT', 'copyright'))
1348         labelcopy.SetForegroundColour(txtcolour)
1349         labelcopy.SetBackgroundColour(bckgrdcolor)
1350
1351         python_img = wx.Image(os.path.join(ImagePath,'python-logo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1352         r_img = wx.Image(os.path.join(ImagePath,'Rlogo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1353         lexique_img = wx.Image(os.path.join(ImagePath,'LexTexte4.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1354         but_python = wx.BitmapButton(self, -1, python_img)
1355         but_lexique = wx.BitmapButton(self, -1, lexique_img)
1356         but_r = wx.BitmapButton(self, -1, r_img)
1357         self.Bind(wx.EVT_BUTTON, self.OnPython, but_python)
1358         self.Bind(wx.EVT_BUTTON, self.OnLexique, but_lexique)
1359         self.Bind(wx.EVT_BUTTON, self.OnR, but_r)
1360
1361         grid_sizer_1.Add(self.hyper2, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1362         grid_sizer_3.Add(label_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1363         grid_sizer_3.Add(self.hyper_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1364         sizer4.Add(label_1, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5)
1365
1366         sizer2.Add(label2, 0, wx.ALIGN_CENTER, 5)
1367         sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1368         sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1369         sizer2.Add(grid_sizer_3, 0, wx.ALIGN_CENTER, 5)
1370         sizer2.Add(wx.StaticText(PanelPres, -1, u' '), 0, wx.ALIGN_CENTER, 5)
1371         sizer2.Add(grid_sizer_1, 0, wx.ALIGN_CENTER, 5)
1372         sizer2.Add(labellicence, 0, wx.ALIGN_CENTER, 5)
1373         sizer2.Add(labelcopy, 0, wx.ALIGN_CENTER, 5)
1374         sizer1.Add(sizer4, 2, wx.ALIGN_CENTER_HORIZONTAL, 0)
1375         sizer1.Add(but_ira, 1, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5)
1376         sizer1.Add(iralink, 1, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_TOP, 5)
1377         sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 10)
1378         PanelPres.SetSizer(sizer2)
1379         grid_sizer_2.Add(but_python, 1, wx.ALIGN_BOTTOM)
1380         grid_sizer_2.Add(but_lexique, 1, wx.ALIGN_BOTTOM)
1381         grid_sizer_2.Add(but_r, 1,  wx.ALIGN_BOTTOM)
1382
1383         sizer1.Add(PanelPres, 0, wx.EXPAND |wx.ALL, 10)
1384         sizer1.Add(grid_sizer_2, 2, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 1)
1385         self.SetSizer(sizer1)
1386         sizer1.Fit(self)
1387
1388     def OnPython(self,evt):
1389         webbrowser.open('http://www.python.org')
1390
1391     def OnLexique(self,evt):
1392         webbrowser.open('http://www.lexique.org')
1393
1394     def OnR(self,evt):
1395         webbrowser.open('http://www.r-project.org')
1396
1397 class MySplashScreen(wx.SplashScreen):
1398     def __init__(self):
1399         bmp = wx.Image(os.path.join(ImagePath, 'splash.png')).ConvertToBitmap()
1400         wx.SplashScreen.__init__(self, bmp,
1401                                  wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
1402                                  1000, None, -1)
1403         self.Bind(wx.EVT_CLOSE, self.OnClose)
1404         self.fc = wx.FutureCall(1, self.ShowMain)
1405
1406     def OnClose(self, evt):
1407         evt.Skip()
1408         self.Hide()
1409
1410         if self.fc.IsRunning():
1411             self.fc.Stop()
1412             self.ShowMain()
1413
1414     def ShowMain(self):
1415         displaySize = wx.DisplaySize()
1416         w = displaySize[0]/1.2
1417         h = displaySize[1]/1.2
1418         frame = IraFrame(None, -1, "IRaMuTeQ " + ConfigGlob.get('DEFAULT', 'version'), size=(w, h))
1419         frame.Show()
1420         frame.finish_init()
1421         frame.Upgrade()
1422         frame.OnOpenFromCmdl()
1423 #        if self.fc.IsRunning():
1424 #            self.Raise()
1425         #wx.CallAfter(frame.ShowTip)
1426
1427 class MyApp(wx.App):
1428     def OnInit(self):
1429         """
1430         Create and show the splash screen.  It will then create and show
1431         the main frame when it is time to do so.
1432         """
1433         wx.SystemOptions.SetOptionInt("mac.window-plain-transition", 1)
1434         self.SetAppName("Iramuteq")
1435         splash = MySplashScreen()
1436         splash.Show()
1437         return True
1438
1439 def main():
1440     app = MyApp(False)
1441     app.MainLoop()
1442
1443 if __name__ == '__main__':
1444     __name__ = 'Main'
1445     main()