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