copycorpus
[iramuteq] / iramuteq.py
1 #!/bin/env python
2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2008-2012, Pierre Ratinaud
5 #Lisense: 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 #print args
15 #print options
16 import sys
17 reload(sys)
18 import locale
19 import tempfile
20 import codecs
21 import os
22 import shutil
23 from random import randint
24 from ConfigParser import *
25 import webbrowser
26 import gettext
27 import logging
28 #------------------------------------
29 import wx
30 #import wx.aui
31 if wx.__version__ >= '2.11' :
32     import wx.lib.agw.aui as aui
33 else :
34     import aui
35 import wx.html
36 import wx.grid
37 import wx.lib.hyperlink as hl
38 #------------------------------------
39 from functions import BugReport, PlaySound, ReadLexique, History, DoConf, ReadDicoAsDico, progressbar
40 from checkversion import NewVersion
41 from guifunct import *
42 from tableau import Tableau
43 from dialog import PrefDialog, EncodeDialog, CorpusPref
44 from tabfrequence import Frequences
45 from tabchi2 import ChiSquare
46 #from tabstudent import MakeStudent
47 from tabchddist import ChdCluster
48 from tabafcm import DoAFCM
49 from tabchdalc import AnalyseQuest
50 from tabsimi import DoSimi
51 from tabrsimple import InputText
52 from tabverges import Verges
53 #from textafcuci import AfcUci
54 #from textchdalc import AnalyseAlceste
55 from analysetxt import Alceste
56 from textdist import PamTxt
57 from textstat import Stat
58 from textaslexico import Lexico
59 from textsimi import SimiTxt, SimiFromCluster
60 from textwordcloud import WordCloud
61 from profile_segment import ProfileSegment
62 from textcheckcorpus import checkcorpus
63 from openanalyse import OpenAnalyse
64 from corpus import BuildFromAlceste, Builder
65 from sheet import MySheet
66 from checkinstall import CreateIraDirectory, CheckRPath, FindRPAthWin32, FindRPathNix, CheckRPackages, IsNew, UpgradeConf, CopyConf, RLibsAreInstalled
67 from chemins import ConstructRscriptsPath, ConstructConfigPath, ConstructDicoPath, ConstructGlobalPath, PathOut
68 from parse_factiva_xml import ImportFactiva
69 from tools import Extract
70
71 from tree import LeftTree
72 ##########################################################
73 ID_OpenData = wx.NewId()
74 ID_Import = wx.NewId()
75 ID_OpenText = wx.NewId()
76 ID_OnOpenAnalyse = wx.NewId()
77 ID_Freq = wx.NewId()
78 ID_Chi2 = wx.NewId()
79 ID_Student = wx.NewId()
80 ID_CHDSIM = wx.NewId()
81 ID_CHDAlceste = wx.NewId()
82 ID_TEXTAFCM = wx.NewId()
83 ID_TEXTSTAT = wx.NewId()
84 ID_ASLEX = wx.NewId()
85 ID_TEXTALCESTE = wx.NewId()
86 ID_TEXTPAM = wx.NewId()
87 ID_CHECKCORPUS = wx.NewId()
88 ID_Tabcontent = wx.NewId()
89 ID_AFCM = wx.NewId()
90 ID_SIMI = wx.NewId()
91 ID_CloseTab = wx.NewId()
92 ID_SaveTab = wx.NewId()
93 ID_CreateText = wx.NewId()
94 ID_ACCEUIL = wx.NewId()
95 ID_RESULT = wx.NewId()
96 ID_VIEWDATA = wx.NewId()
97 ID_HTMLcontent = wx.NewId()
98 ID_SimiTxt = wx.NewId()
99 ##########################################################
100 #elements de configuration
101 ##########################################################
102 #encodage
103 if sys.platform == 'darwin' :
104     sys.setdefaultencoding('utf-8')
105     wx.SetDefaultPyEncoding('utf-8')
106 else :
107     sys.setdefaultencoding(locale.getpreferredencoding())
108 #chemin de l'application
109 AppliPath = os.path.abspath(os.path.dirname(os.path.realpath(sys.argv[0])))
110 #chemin des images
111 ImagePath = os.path.join(AppliPath, 'images')
112 #configuration generale
113 DictConfigPath = ConstructGlobalPath(AppliPath)
114 ConfigGlob = ConfigParser()
115 ConfigGlob.read(DictConfigPath['global'])
116 #repertoire de l'utilisateur
117 if os.getenv('HOME') != None:
118     user_home = os.getenv('HOME')
119 else:
120     user_home = os.getenv('HOMEPATH')
121 UserConfigPath = os.path.abspath(os.path.join(user_home, '.iramuteq'))
122 #Si pas de fichiers de config utilisateur, on cree le repertoire
123 CreateIraDirectory(UserConfigPath, AppliPath)
124 #fichiers log pour windows (py2exe)
125 log = logging.getLogger('iramuteq')
126 fh = logging.FileHandler(os.path.join(UserConfigPath,'stdout.log'))
127 ch = logging.StreamHandler()
128 formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
129 ch.setFormatter(formatter)
130 fh.setFormatter(formatter)
131 log.addHandler(fh)
132 if sys.platform != 'win32' or sys.platform != 'darwin':
133     log.addHandler(ch)
134 log.setLevel(logging.INFO)
135
136
137 class writer(object):
138     def write(self, data):
139         if data.strip() != '' :
140             log.info('ERROR : %s' % data)
141
142 class printer(object) :
143     def write(self, data) :
144         if data.strip() != '' :
145             log.info('Print : %s' % data)
146
147 sys.stderr = writer()
148 sys.stdout = printer()
149
150 ConfigPath = ConstructConfigPath(UserConfigPath)
151 #####################################################################
152
153 class IraFrame(wx.Frame):
154     def __init__(self, parent, id= -1, title="", pos=wx.DefaultPosition,
155                  size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE | 
156                                             wx.SUNKEN_BORDER | 
157                                             wx.CLIP_CHILDREN):
158         log.info('Starting...')
159         wx.Frame.__init__(self, parent, id, title, pos, size, style)
160         #configuration
161         self.AppliPath = AppliPath
162         self.images_path = os.path.join(AppliPath,'images')
163         self.UserConfigPath = UserConfigPath
164         self.RscriptsPath = ConstructRscriptsPath(AppliPath)
165         #self.DictPath = ConstructDicoPath(AppliPath)
166         self.DictPath = ConstructDicoPath(UserConfigPath)
167         self.ConfigGlob = ConfigGlob
168         self.ConfigPath = ConstructConfigPath(UserConfigPath)
169         self.pref = RawConfigParser()
170         #workaround for import problem
171         self.SimiFromCluster = SimiFromCluster
172         #langues
173         mylocale = wx.Locale(wx.LANGUAGE_FRENCH)
174         mylocale.AddCatalogLookupPathPrefix(os.path.join(AppliPath,'locale'))
175         mylocale.AddCatalog('iramuteq')
176         presLan_en = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['en'])
177         presLan_fr = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['fr_FR'])
178         presLan_fr.install()
179
180
181         # tell FrameManager to manage this frame        
182         #self._mgr = wx.aui.AuiManager()
183         self._mgr = aui.AuiManager()
184         self._mgr.SetManagedWindow(self)
185         self.x = 0
186         # create menu
187 #--------------------------------------------------------------------------------
188         self.mb = wx.MenuBar()
189
190         file_menu = wx.Menu()
191         item = wx.MenuItem(file_menu, ID_OpenData, _(u"Open a matrix"), _(u"Open a matrix"))
192         item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
193         file_menu.AppendItem(item)
194         
195         item = wx.MenuItem(file_menu, ID_OpenText, _(u"Open a text corpora"), _(u"Open a text corpora"))
196         item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
197         file_menu.AppendItem(item)
198         
199         item = wx.MenuItem(file_menu, ID_OnOpenAnalyse, _(u"Open an analysis"), _("Open an analysis"))
200         item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
201         file_menu.AppendItem(item)
202
203         
204         menuFactiva = wx.Menu()
205         fact_from_xml = wx.MenuItem(menuFactiva, wx.ID_ANY, _(u"from xml"))
206         fact_from_mail = wx.MenuItem(menuFactiva, wx.ID_ANY, _(u"from mail"))
207         fact_from_txt = wx.MenuItem(menuFactiva, wx.ID_ANY, _(u"from copy/paste"))
208         menuFactiva.AppendItem(fact_from_xml)
209         menuFactiva.AppendItem(fact_from_mail)
210         menuFactiva.AppendItem(fact_from_txt)
211         file_menu.AppendMenu(-1, _(u"Import from factiva"), menuFactiva)
212
213         menuTools = wx.Menu()
214         splitvar = wx.MenuItem(menuTools, wx.ID_ANY, _(u"Split from variable"))
215         extractmod = wx.MenuItem(menuTools, wx.ID_ANY, _(u"Extract mods"))
216         menuTools.AppendItem(splitvar)
217         menuTools.AppendItem(extractmod)
218         self.ID_splitvar = splitvar.GetId()
219         self.ID_extractmod = extractmod.GetId()
220         file_menu.AppendMenu(-1, _(u"Tools"), menuTools)
221
222                
223         item = wx.MenuItem(file_menu, ID_SaveTab, _(u"Save tab as..."), _(u"Save tab as..."))
224         item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_SAVE_AS))
225         file_menu.AppendItem(item)
226         
227         file_menu.Append(wx.ID_EXIT, _(u"Exit"))
228         
229         edit_menu = wx.Menu()
230         edit_menu.Append(wx.ID_PREFERENCES, '', _(u'Preferences'))
231         
232         view_menu = wx.Menu()
233         view_menu.Append(ID_ACCEUIL, _(u"Home page"))
234         view_menu.Append(ID_VIEWDATA, _(u"Show data"))
235         view_menu.Append(ID_RESULT, _(u'Show results'))
236         #view_menu.AppendSeparator()
237
238         analyse_menu = wx.Menu()
239         analyse_menu.Append(ID_Freq, u"Fréquences")
240         analyse_menu.Append(ID_Chi2, u"Chi2")
241         #analyse_menu.Append(ID_Student, u"t de Student")
242         menu_classif = wx.Menu()
243         menu_classif.Append(ID_CHDAlceste, u"Méthode Alceste")
244         menu_classif.Append(ID_CHDSIM, u"Par matrice des distances")
245         analyse_menu.AppendMenu(-1, u"Classification", menu_classif)
246         analyse_menu.Append(ID_AFCM, u"AFCM")
247         analyse_menu.Append(ID_SIMI, u"Analyse de similitudes")
248         ID_RCODE = wx.NewId()
249         analyse_menu.Append(ID_RCODE, u"Code R...")
250
251         text_menu = wx.Menu()
252         text_menu.Append(ID_CHECKCORPUS, u"Vérifier le corpus")
253         text_menu.Append(ID_TEXTSTAT, u"Statistiques textuelles")
254         text_menu.Append(ID_ASLEX, u"Spécificités et AFC")
255         #text_menu.Append(ID_TEXTAFCM, u"AFC sur UCI / Vocabulaire")
256         menu_classiftxt = wx.Menu()
257         menu_classiftxt.Append(ID_TEXTALCESTE, u"Méthode Alceste")
258         menu_classiftxt.Append(ID_TEXTPAM, u"Par matrice des distances")
259         text_menu.AppendMenu(-1, u"Classification", menu_classiftxt)
260         text_menu.Append(ID_SimiTxt, u'Analyse de similitude') 
261         ID_WC = wx.NewId()
262         text_menu.Append(ID_WC, u'Nuage de mots')
263         
264         help_menu = wx.Menu()
265         help_menu.Append(wx.ID_ABOUT, u'À propos...')
266         help_menu.Append(wx.ID_HELP, u'Aide en ligne')
267         
268         self.mb.Append(file_menu, _(u"File"))
269         self.mb.Append(edit_menu, _(u"Edition"))
270         self.mb.Append(view_menu, _(u"View"))
271         self.mb.Append(analyse_menu, _("Spreadsheet analysis"))
272         self.mb.Append(text_menu, _(u"Text analysis"))
273         self.mb.Append(help_menu, _(u"Help"))
274         
275         self.SetMenuBar(self.mb)
276 #--------------------------------------------------------------------
277         self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
278         self.statusbar.SetStatusWidths([-2, -3])
279         self.statusbar.SetStatusText(u"Prêt", 0)
280         self.statusbar.SetStatusText(u"Bienvenue", 1)
281
282         # min size for the frame itself isn't completely done.
283         # see the end up FrameManager::Update() for the test
284         # code. For now, just hard code a frame minimum size
285         self.SetMinSize(wx.Size(400, 400))
286
287         # create some toolbars
288         tb1 = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
289                          wx.TB_FLAT | wx.TB_NODIVIDER)
290         tb1.SetToolBitmapSize(wx.Size(16, 16))
291         tb1.AddLabelTool(ID_OpenData, "OpenData", wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, wx.Size(16, 16)), shortHelp="Questionnaire", longHelp="Ouvrir un questionnaire")
292         tb1.AddSeparator()
293         tb1.AddLabelTool(ID_OpenText, "OpenText", wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, wx.Size(16, 16)), shortHelp="Texte", longHelp="Ouvrir un corpus texte")
294
295         tb1.Realize()
296         
297 #------------------------------------------------------------------------------------------------
298
299         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)
300                       
301         #self._mgr.AddPane(self.text_ctrl_txt, wx.aui.AuiPaneInfo().
302         #                  Name("Text").CenterPane())                      
303         self._mgr.AddPane(self.text_ctrl_txt, aui.AuiPaneInfo().
304                           Name("Text").CenterPane())
305         #self._mgr.AddPane(IntroPanel(self), wx.aui.AuiPaneInfo().Name("Intro_Text").
306         #                  CenterPane())
307         self._mgr.AddPane(IntroPanel(self), aui.AuiPaneInfo().Name("Intro_Text").
308                           CenterPane())
309         #if not os.path.exists(os.path.join(UserConfigPath, 'history.db')) :
310         #    with open(os.path.join(UserConfigPath, 'history.db'), 'w') as f :
311         #        f.write('')
312         self.history = History(os.path.join(UserConfigPath, 'history.db'))
313         self.tree = LeftTree(self)
314         self._mgr.AddPane(self.tree, aui.AuiPaneInfo().Name("lefttree").Caption("Navigateur").
315                           Left().MinSize(wx.Size(200,500)).Layer(1).Position(1).CloseButton(False).MaximizeButton(True).
316                           MinimizeButton(True))
317         
318         #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)
319         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)
320         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
321         self.nb.SetAGWWindowStyleFlag(notebook_flags)
322         self.nb.SetArtProvider(aui.ChromeTabArt())
323         #self.nb.SetArtProvider(aui.VC8TabArt())
324         #self.nb.parent = self
325         #self._notebook_style = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.NO_BORDER
326         #self._mgr.AddPane(self.nb, wx.aui.AuiPaneInfo().
327         #                      Name("Tab_content").
328         #                      CenterPane())
329         self._mgr.AddPane(self.nb, aui.AuiPaneInfo().
330                               Name("Tab_content").
331                               CenterPane())        
332         self.Sheet = MySheet(self)
333         #self._mgr.AddPane(self.Sheet, wx.aui.AuiPaneInfo().Name("Data").CenterPane())
334         self._mgr.AddPane(self.Sheet, aui.AuiPaneInfo().Name("Data").CenterPane())
335         self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnCloseTab)
336         self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
337         # add the toolbars to the manager
338                         
339         #self._mgr.AddPane(tb1, wx.aui.AuiPaneInfo().
340         #                  Name("tb1").Caption("Fichiers").
341         #                  ToolbarPane().Top().
342         #                  LeftDockable(False).RightDockable(False))
343         self._mgr.AddPane(tb1, aui.AuiPaneInfo().
344                           Name("tb1").Caption("Fichiers").
345                           ToolbarPane().Top().
346                           LeftDockable(True).RightDockable(False))        
347         
348         self.ShowAPane("Intro_Text")
349         self._mgr.GetPane("lefttree").Show()
350         self._mgr.GetPane("classif_tb").Hide()
351         # "commit" all changes made to FrameManager   
352         self._mgr.Update()
353
354         # Show How To Use The Closing Panes Event
355 ##################################################################        
356         self.Bind(wx.EVT_MENU, self.OnAcceuil, id=ID_ACCEUIL)
357         self.Bind(wx.EVT_MENU, self.OnViewData, id=ID_VIEWDATA)
358         self.Bind(wx.EVT_MENU, self.ShowTab, id=ID_RESULT)
359         self.Bind(wx.EVT_MENU, self.OnOpenData, id=ID_OpenData)
360         self.Bind(wx.EVT_MENU, self.OnOpenText, id=ID_OpenText)
361         self.Bind(wx.EVT_MENU, self.OnOpenAnalyse, id=ID_OnOpenAnalyse)
362         self.Bind(wx.EVT_MENU, self.import_factiva_xml, fact_from_xml)
363         self.Bind(wx.EVT_MENU, self.import_factiva_mail, fact_from_mail)
364         self.Bind(wx.EVT_MENU, self.import_factiva_txt, fact_from_txt)
365         self.Bind(wx.EVT_MENU, self.ExtractTools, splitvar)
366         self.Bind(wx.EVT_MENU, self.ExtractTools, extractmod)
367         self.Bind(wx.EVT_MENU, self.OnFreq, id=ID_Freq)
368         self.Bind(wx.EVT_MENU, self.OnChi2, id=ID_Chi2)
369         self.Bind(wx.EVT_MENU, self.OnStudent, id=ID_Student)
370         self.Bind(wx.EVT_MENU, self.OnCHDSIM, id=ID_CHDSIM)
371         self.Bind(wx.EVT_MENU, self.OnCHDAlceste, id=ID_CHDAlceste)
372         self.Bind(wx.EVT_MENU, self.OnAFCM, id=ID_AFCM)
373         self.Bind(wx.EVT_MENU, self.OnRCode, id=ID_RCODE)
374         self.Bind(wx.EVT_MENU, self.OnCheckcorpus, id = ID_CHECKCORPUS)
375         self.Bind(wx.EVT_MENU, self.OnTextStat, id=ID_TEXTSTAT)
376         self.Bind(wx.EVT_MENU, self.OnTextSpec, id=ID_ASLEX)
377         self.Bind(wx.EVT_MENU, self.OnTextAfcm, id=ID_TEXTAFCM)
378         self.Bind(wx.EVT_MENU, self.OnTextAlceste, id=ID_TEXTALCESTE)
379         self.Bind(wx.EVT_MENU, self.OnPamSimple, id=ID_TEXTPAM)
380         self.Bind(wx.EVT_MENU, self.OnSimiTxt, id=ID_SimiTxt)
381         self.Bind(wx.EVT_MENU, self.OnWordCloud, id=ID_WC)
382         self.Bind(wx.EVT_MENU, self.OnSimi, id=ID_SIMI)
383         self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
384         self.Bind(wx.EVT_MENU, self.OnSaveTabAs, id=ID_SaveTab)
385         self.Bind(wx.EVT_MENU, self.OnAbout, id=wx.ID_ABOUT)
386         self.Bind(wx.EVT_MENU, self.OnHelp, id=wx.ID_HELP)
387         self.Bind(wx.EVT_MENU, self.OnPref, id=wx.ID_PREFERENCES)
388         self.Bind(wx.EVT_CLOSE, self.OnClose)
389 ##################################################################
390         flags = self._mgr.GetAGWFlags()
391         #flags &= ~wx.aui.AUI_MGR_TRANSPARENT_HINT
392         #flags &= ~wx.aui.AUI_MGR_VENETIAN_BLINDS_HINT
393         #flags &= ~wx.aui.AUI_MGR_RECTANGLE_HINT
394         flags &= ~(aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING)
395         self._mgr.SetAGWFlags(self._mgr.GetAGWFlags() ^ (aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING))
396         self._mgr.GetArtProvider().SetMetric(aui.AUI_DOCKART_GRADIENT_TYPE, aui.AUI_GRADIENT_HORIZONTAL)
397         self.GetDockArt().SetColor(aui.AUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR, "#00FFF9")
398         self.DoUpdate()
399
400         self._icon = wx.Icon(os.path.join(ImagePath, "iraicone.ico"), wx.BITMAP_TYPE_ICO)
401         self.SetIcon(self._icon)
402 ##########################
403         self.ctrl = ""
404         self.input_path = [False]
405         self.TEMPDIR = tempfile.mkdtemp('iramuteq')
406         self.FileTabList = []
407         self.listbar=[]
408         self.DictTab = {}
409         self.FreqNum = 0
410         self.colsep = ''
411         self.txtsep = ''
412         self.g_header = False
413         self.g_id = False
414         self.table = ''
415         self.fileforR = ''
416         self.filename = ''
417         self.nastrings = ''
418         self.encode = ''
419         self.SysEncoding = sys.getdefaultencoding()
420         self.syscoding = sys.getdefaultencoding()
421         #print 'SysEncoding',self.SysEncoding
422         if self.SysEncoding == 'mac-roman' : self.SysEncoding = 'MacRoman'
423         self.type = ''
424
425 ##############################################################@
426         self.DisEnSaveTabAs(False)
427         self.ShowMenu(_("View"), False)
428         self.ShowMenu(_("Spreadsheet analysis"), False)
429         self.ShowMenu(_("Text analysis"), False)
430    
431         self._mgr.Update()
432
433         self.DataPop = False
434         self.DataTxt = False
435         self.Text = ''
436
437         self.lexique = None
438         self.corpus = None
439
440     def finish_init(self) :
441         try :
442             self.pref.read(self.ConfigPath['preferences'])
443             if IsNew(self) :
444                 UpgradeConf(self)
445                 New = True
446             else :
447                 CopyConf(self)
448                 New = False
449         except :
450             UpgradeConf(self)
451             self.pref.read(self.ConfigPath['preferences'])
452             New = True
453         self.sound = self.pref.getboolean('iramuteq', 'sound')
454         self.check_update = self.pref.getboolean('iramuteq', 'checkupdate')
455         self.version = ConfigGlob.get('DEFAULT', 'version')
456         #configuration des chemins de R
457         self.PathPath = ConfigParser()
458         self.PathPath.read(ConfigPath['path'])
459         BestRPath = False
460         if not CheckRPath(self.PathPath) :
461             if sys.platform == 'win32':
462                 BestRPath = FindRPAthWin32()
463             else:
464                 BestRPath = FindRPathNix()
465             if BestRPath:
466                 self.PathPath.set('PATHS', 'rpath', BestRPath)
467                 with open(ConfigPath['path'], 'w') as f :
468                     self.PathPath.write(f)
469         else:
470             BestRPath = True 
471         if BestRPath :
472             self.RPath = self.PathPath.get('PATHS', 'rpath')
473             if New :
474                 CheckRPackages(self)
475             if not RLibsAreInstalled(self) :
476                 CheckRPackages(self)
477         else :
478             msg = u"""
479 Le chemin de l'executable de R n'a pas Ã©té trouvé.
480 Si R n'est pas installé, vous devez l'installer (http://www.r-project.org/).
481 Si R n'est pas installé dans le répertoire par défaut
482 (souvent C:\Program Files\R\R-2.x.x\R.exe sous windows ou /usr/bin/R sous linux ou Mac Os X)
483 vous devez signaler le chemin de l'éxecutable de R dans les préférences.""" 
484             dlg = wx.MessageDialog(self, msg, u"Problème de configuration", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
485             dlg.CenterOnParent()
486             if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
487                  evt.Veto()
488             dlg.Destroy()
489
490
491     def OnVerif(self, evt) :
492         pack = CheckRPackages(self)
493         if pack :
494             dlg = wx.MessageDialog(self, u"Installation OK", u"Installation", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
495             dlg.CenterOnParent()
496             if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
497                  evt.Veto()
498
499     #FIXME  marche pas sous mac ?
500     def DisEnSaveTabAs(self, DISEN):
501     #Disable SaveTabAs
502         file_menu = self.mb.GetMenu(0)
503         items = file_menu.GetMenuItems()
504         for item in items :
505             if item.GetId() == ID_SaveTab :
506                 item.Enable(DISEN)
507     
508     def ShowMenu(self, menu, Show=True):
509         menu_pos = self.mb.FindMenu(menu)
510         self.mb.EnableTop(menu_pos, Show)
511         self.mb.UpdateMenus()
512
513
514 #--------------------------------------------------------------------
515     def OnClose(self, event):
516         print 'onclose'
517         with open(self.ConfigPath['path'], 'w') as f :
518             self.PathPath.write(f)
519         if self.DictTab != {} :
520             savestates = [self.DictTab[item][0] for item in self.DictTab]
521             if False in savestates :
522                 notsave = [item for item in self.DictTab if self.DictTab[item][0] == False] 
523                 msg = u"""
524  Certains résultats ne sont pas enregistrés.
525  Voulez-vous fermer quand même ?"""
526                 dlg = wx.MessageDialog(self, msg, "Sauvegarde",
527                        wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
528                 dlg.CenterOnParent()
529                 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
530                     event.Veto()
531                     dlg.Destroy()
532                 else:
533                     dlg.Destroy()
534                     for item in notsave :
535                         for tmpfile in self.DictTab[item][1:] :
536                             os.remove(tmpfile)
537                             print 'remove : ' + tmpfile
538                     self._mgr.UnInit()
539                     del self._mgr
540                     self.Destroy()
541             else :
542                 self._mgr.UnInit()
543                 del self._mgr
544                 self.Destroy()
545         else :
546             self._mgr.UnInit()
547             del self._mgr
548             self.Destroy()
549             #if sys.platform == 'win32' :
550             #    os.system("taskkill /im iramuteq.exe /f")
551             #    print 'meurtre de process'
552
553     def OnOpenData(self, event):
554         inputname, self.input_path = OnOpen(self, "Data")
555         if inputname:
556             self.filename = self.input_path[0]
557             self.tableau = Tableau(self,os.path.abspath(self.input_path[0]))
558             get_table_param(self, self.input_path[0])
559             self.tableau.make_content()
560             self.tableau.show_tab()
561
562     def OnOpenAnalyse(self, event):
563         self.AnalysePath = OnOpen(self, "Analyse")
564         OpenAnalyse(self, self.AnalysePath[1][0], True)
565         self.ShowMenu(_("View"))
566
567     def OnOpenText(self, event):
568         inputname, self.input_path = OnOpen(self, "Texte")
569         self.filename = self.input_path[0]
570         if inputname:
571              self.OpenText()
572    
573     def OnViewData(self, event):
574         print self.type
575         print self.DataTxt
576         if self.type == "Data":
577             if not self.DataPop :
578                 self.Sheet.Populate(self.content)
579                 self.DataPop = True
580                 self.DataTxt = False
581             self.ShowAPane(u"Data")
582         elif self.type == "Texte" or self.type == 'Analyse' :
583             if not self.DataTxt :
584                 self.text_ctrl_txt.Clear()
585                 self.text_ctrl_txt.write(self.content)
586                 self.text_ctrl_txt.ShowPosition(0)
587                 self.DataTxt = True
588                 self.DataPop = False
589             self.ShowAPane(u"Text")
590         self._mgr.Update()
591         
592     def OpenText(self):
593         #dial = EncodeDialog(self)
594         dlg = wx.ProgressDialog("Ouverture...",
595                                    "Veuillez patienter...",
596                                    maximum=2,
597                                    parent=self,
598                                    style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
599                                    )
600         
601         builder =  Builder(self, dlg)
602         if builder.res == wx.ID_OK :
603             try :
604                 corpus = builder.doanalyse()
605                 self.history.add(corpus.parametres)
606                 self.tree.OnItemAppend(corpus.parametres)
607                 OpenAnalyse(self, corpus.parametres)
608             except :
609                 BugReport(self)
610         #self.content = DoConf().totext(corpus.parametres)
611 #        parametres = DoConf(os.path.join(UserConfigPath,'corpus.cfg')).getoptions('corpus')
612 #        parametres['originalpath'] = self.filename
613 #        
614 #        parametres['pathout'] = PathOut(self.filename, 'corpus').dirout
615 #        dial = CorpusPref(self, parametres)
616 #        dial.CenterOnParent()
617 #        dial.txtpath.SetLabel(self.filename)
618 #        res = dial.ShowModal()
619 #        parametres = dial.doparametres()
620 #        print parametres
621 #        ReadLexique(self, lang = parametres['lang'])
622 #        self.expressions = ReadDicoAsDico(self.DictPath.get(parametres['lang'], 'french_exp'))
623 #        corpus = BuildFromAlceste(self.filename, parametres, self.lexique, self.expressions).corpus
624         #self.corpus_encodage =  dial.encodages[dial.list_encodages.GetSelection()][0]
625         #self.corpus_lang = dial.langues[dial.choice_dict.GetSelection()]
626             else :
627                 count = 1
628                 keepGoing = dlg.Update(count, u"Lecture du fichier")
629     #            msg = u"Ce fichier ne semble pas Ãªtre encodé en %s" % self.corpus_encodage
630     #            dial = wx.MessageDialog(self, msg, u"Problème d'encodage", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
631     #            dial.CenterOnParent()
632     #            res = dial.ShowModal()
633     #            dial.Destroy()
634     #            self.OpenText()
635                 self.ShowMenu(_("View"))
636                 self.ShowMenu(_("Text analysis"))
637                 self.ShowMenu(_(u"Spreadsheet analysis"), False)
638                 self.type = "Texte"
639                 self.DataTxt = False
640                 self.Text = ''
641                 count += 1
642                 keepGoing = dlg.Update(count, u"Chargement du dictionnaire")
643                 dlg.Destroy()
644         #self.OnViewData(wx.EVT_BUTTON)
645         
646     def OnExit(self, event):
647         self.Close()
648
649     def OnAbout(self, event):
650         info = wx.AboutDialogInfo()
651         info.Name = ConfigGlob.get('DEFAULT', 'name')
652         info.Version = ConfigGlob.get('DEFAULT', 'version')
653         info.Copyright = ConfigGlob.get('DEFAULT', 'copyright')
654         info.Description = u"""
655 Interface de R pour les Analyses Multidimensionnelles 
656 de Textes et de Questionnaires
657
658 Un logiciel libre
659 construit avec des logiciels libres.
660
661 Laboratoire LERASS
662
663 REPERE
664 """
665         info.WebSite = ("http://www.iramuteq.org", u"Site web IRaMuTeQ")
666         dev = ConfigGlob.get('DEFAULT', 'dev').split(';')
667         info.Developers = dev
668         info.License = u"""Iramuteq est un logiciel libre ; vous pouvez le diffuser et/ou le modifier 
669 suivant les termes de la Licence Publique Générale GNU telle que publiée 
670 par la Free Software Foundation ; soit la version 2 de cette licence, 
671 soit (à votre convenance) une version ultérieure.
672
673 Iramuteq est diffusé dans l'espoir qu'il sera utile, 
674 mais SANS AUCUNE GARANTIE ; sans même une garantie implicite 
675 de COMMERCIALISATION ou d'ADÉQUATION Ã€ UN USAGE PARTICULIER. 
676 Voyez la Licence Publique Générale GNU pour plus de détails.
677
678 Vous devriez avoir reçu une copie de la Licence Publique Générale GNU
679 avec Iramuteq ; sinon, veuillez Ã©crire Ã  la Free Software Foundation,
680 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, Ã‰tats-Unis."""
681         wx.AboutBox(info)
682
683     def GetDockArt(self):
684         return self._mgr.GetArtProvider()
685
686     def DoUpdate(self):
687         self._mgr.Update()
688
689     def OnPageChanged(self, event) :
690         new = event.GetSelection()
691         nobject = event.GetEventObject()
692         parent = nobject.GetParent()
693         if isinstance(parent, IraFrame) :
694             npage = self.nb.GetPage(new)
695             self.tree.GiveFocus(uuid=npage.parametres['uuid'])
696
697     def OnCloseTab(self, evt):
698         #log.info('Closing tab %s' % str(evt.GetEventObject()))
699         ctrl = evt.GetEventObject()
700         if isinstance(ctrl.GetParent(), aui.AuiNotebook) or isinstance(ctrl.GetParent(), wx.Panel):
701             notebook = True
702         else :
703             notebook = False
704         page = self.nb.GetPage(self.nb.GetSelection())
705         if 'parametres' in dir(page) and isinstance(ctrl.GetParent(), IraFrame) :
706             self.history.rmtab(page.parametres)
707             self.tree.CloseItem(uuid = page.parametres['uuid'])
708         TabTitle = self.nb.GetPageText(self.nb.GetSelection())
709         if self.DictTab != {} :
710             if TabTitle in self.DictTab :
711                 ListFile=self.DictTab[TabTitle]
712                 if False in ListFile:
713                     msg = u"""
714 Certains résultats ne sont pas enregistrer.
715 Voulez-vous fermer quand même ?"""
716                     dlg = wx.MessageDialog(self, msg, "Sauvegarde",wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
717
718                     dlg.CenterOnParent()
719                     if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
720                         remove = False
721                         evt.Veto()
722                         dlg.Destroy()
723                     else :
724                         for f in ListFile[1:] :
725                             print 'remove', f
726                             os.remove(f)
727                             remove = True
728                         dlg.Destroy()
729                 elif True in ListFile :
730                     remove = True
731                 if remove:
732                    del self.DictTab[TabTitle]
733             else : 
734                 self.LastTabClose()
735         else :
736             remove = True
737         if self.nb.GetPageCount() == 1 and remove and not notebook :
738             self.LastTabClose()
739     
740     def LastTabClose(self) :
741         if self.nb.GetPageCount() == 1 :
742             self.DisEnSaveTabAs(False)
743             if self.DataTxt :
744                 self.ShowAPane("Text")
745             elif self.DataPop :
746                 self.ShowAPane("Data")
747             else :
748                 self.ShowAPane("Intro_Text")
749
750     def OnSaveTabAs(self, event):
751         SelectTab = self.nb.GetSelection()
752         TabTitle = self.nb.GetPageText(SelectTab)
753         FileToSave = self.DictTab[TabTitle]
754         NewListFile = []
755         dlg = wx.FileDialog(
756             self, message="Enregistrer sous...", defaultDir=os.getcwd(),
757             defaultFile="resultat.html", wildcard="Tous les fichiers|*", style=wx.SAVE | wx.OVERWRITE_PROMPT
758             )
759         dlg.SetFilterIndex(2)
760         dlg.CenterOnParent()
761         
762         if dlg.ShowModal() == wx.ID_OK:
763             Path = dlg.GetPath()
764             Dirname = os.path.dirname(Path)
765             Filename = dlg.GetFilename()
766         else :
767             Path = False
768         dlg.Destroy()
769         if Path:
770             shutil.copyfile(FileToSave[-1], Path)
771             os.remove(FileToSave[len(FileToSave) - 1])
772             NewListFile.append(True)
773             NewListFile.append(Path)
774             for f in FileToSave[1:-1] :
775                 Fileout = os.path.join(Dirname, os.path.basename(f))
776                 shutil.copyfile(f, Fileout)
777                 NewListFile.append(Fileout)
778                 os.remove(f)
779             TabText = Filename
780             self.DictTab[TabText] = NewListFile
781             del self.DictTab[TabTitle]
782             self.nb.SetPageText(SelectTab, TabText)
783
784     def GetStartPosition(self):
785
786         self.x = self.x + 20
787         x = self.x
788         pt = self.ClientToScreen(wx.Point(0, 0))
789         
790         return wx.Point(pt.x + x, pt.y + x)
791     
792     def ShowAPane(self, panel):
793         for pane in self._mgr.GetAllPanes() :
794             if not pane.IsToolbar() and pane.name != 'lefttree': 
795                 pane.Hide()
796         self._mgr.GetPane(panel).Show()
797         self._mgr.Update()
798         
799     def OnAcceuil(self, event):
800         self.ShowAPane(u"Intro_Text")
801         event.Skip()
802     
803     def CreateHTMLCtrl(self):
804         ctrl = wx.html.HtmlWindow(self, -1, wx.DefaultPosition, wx.Size(400, 300))
805         if "gtk2" in wx.PlatformInfo:
806             ctrl.SetStandardFonts()
807         ctrl.SetPage(u"text")        
808         return ctrl
809
810     def ShowTab(self, evt):
811         self.ShowAPane("Tab_content")
812
813 ################################################################
814 #debut des analyses
815 ################################################################
816
817     def OnFreq(self, event):
818         try:
819             Frequences(self) 
820         except:
821             BugReport(self)
822             
823     def OnChi2(self, event):
824         try:
825         #    print('PAS DE DEBUG SUR CHI2')
826             chi = ChiSquare(self)
827         except:
828             BugReport(self)
829     
830     def OnStudent(self, event):
831         try:
832             MakeStudent(self) 
833         except:
834             BugReport(self)
835
836     def OnRCode(self, event):
837         try:
838             InputText(self)
839         except:
840             BugReport(self)
841
842     def OnCHDSIM(self, event):
843         try:
844         #    print 'ATTENTION!!!!'
845             chdsim = ChdCluster(self)
846             if chdsim.val == wx.ID_OK:
847                 PlaySound(self)
848         except:
849             BugReport(self)
850  
851     def OnCHDAlceste(self, event):
852         try:
853          #   print('PLUS DE BUG SUR ALCESTE QUESTIONNAIRE')
854             self.quest = AnalyseQuest(self)
855             if self.quest.val == wx.ID_OK:
856                 PlaySound(self)
857         except:
858             BugReport(self)
859
860     def OnSimiTxt(self, evt, corpus = None) :
861         #    print 'PLUS DE BUG SUR SIMITXT'
862         try :
863             #self.Text = SimiTxt(self)
864             if corpus is None :
865                 corpus = self.tree.getcorpus()            
866             self.Text = SimiTxt(self, corpus, parametres = {'type': 'simitxt'}, dlg = progressbar(self, 3))
867             if self.Text.val == wx.ID_OK :
868                 PlaySound(self)
869         except :
870             BugReport(self)
871     
872     def OnWordCloud(self, evt, corpus = None) :
873         #    print 'PLUS DE BUG SUR WORDCLOUD'
874         try :
875             if corpus is None :
876                 corpus = self.tree.getcorpus()            
877             self.Text = WordCloud(self, corpus, parametres = {'type' : 'wordcloud'}, dlg = progressbar(self, 3))
878             if self.Text.val == wx.ID_OK :
879                 PlaySound(self)
880         except :
881             BugReport(self)
882
883
884     def OnAFCM(self, event):
885         try:
886             DoAFCM(self)
887         except:
888             BugReport(self)
889
890     def OnCheckcorpus(self, evt):
891         try :
892             checkcorpus(self)
893         except :
894             BugReport(self)
895
896     def OnTextStat(self, event, corpus = None):
897             print 'PAS DE BUG SUR TEXT STAT'
898         #try:
899             if corpus is None :
900                 corpus = self.tree.getcorpus()
901             self.Text = Stat(self, corpus, parametres = {'type': 'stat'}, dlg = progressbar(self, 7))
902             
903             if self.Text.val == wx.ID_OK :
904                 PlaySound(self)
905         #except:
906         #    BugReport(self)
907         
908     def OnTextSpec(self, event, corpus = None):  
909         #try:
910             #self.Text = AsLexico(self)
911             print('ATTENTION : PLUS DE BUG SUR LEXICO')
912             if corpus is None :
913                 corpus = self.tree.getcorpus()
914             self.Text = Lexico(self, corpus, parametres = {'type' : 'spec'}, dlg = progressbar(self, 3))
915             if self.Text.val == wx.ID_OK :
916                 PlaySound(self)
917         #except:
918         #    BugReport(self)
919     
920     def OnTextAfcm(self, event):
921         try:
922             AfcUci(self)
923             PlaySound(self)
924         except:
925             BugReport(self)
926
927     def import_factiva_xml(self,event):
928         try :
929             ImportFactiva(self, 'xml')
930         except :
931             BugReport(self)
932
933     def import_factiva_mail(self, evt) :
934         try :
935             ImportFactiva(self, 'mail')
936         except :
937             BugReport(self)
938
939     def import_factiva_txt(self, evt) :
940         try :
941             ImportFactiva(self, 'txt')
942         except :
943             BugReport(self)
944
945     def ExtractTools(self, evt) :
946         ID = evt.GetId()
947         if ID == self.ID_splitvar :
948             Extract(self, 'splitvar')
949         else :
950             Extract(self, 'mods')
951
952     def OnTextAlceste(self, event, corpus = None):
953         try:
954             #print('ATTENTION : PLUS DE BUG SUR ALCESTE')
955             #RunAnalyse(self, corpus, Alceste, OptAlceste)
956             if corpus is None :
957                 corpus = self.tree.getcorpus()            
958             self.Text = Alceste(self, corpus, parametres = {'type': 'alceste'}, dlg = progressbar(self,6))
959             if self.Text.val == wx.ID_OK:
960                 PlaySound(self)
961         except:
962             BugReport(self)
963
964     def OnPamSimple(self, event):
965         try:
966             self.Text = PamTxt(self)
967             if self.Text.val == wx.ID_OK:
968                 PlaySound(self)
969         except:
970             BugReport(self)
971     
972     def OnSimi(self,evt):
973         try :
974             #print 'ATTENTION !!!! VERGES'
975             self.res = DoSimi(self, param = None)
976             #self.res = Verges(self)
977             if self.res.val == wx.ID_OK :
978                  PlaySound(self)
979         except :
980             BugReport(self)
981 #################################################################
982
983     def OnHelp(self, event):
984         webbrowser.open('http://www.iramuteq.org/documentation')
985     
986     def OnPref(self, event):
987         dlg = PrefDialog(self)
988         dlg.CenterOnParent()
989         self.val = dlg.ShowModal()
990
991     def Upgrade(self) :
992         if self.check_update:
993             NewVersion(self)
994         else:
995             print 'pas de verif'    
996         #IsNew(self)
997         #CheckRPackages(self)
998
999     def OnOpenFromCmdl(self):
1000         truepath = True
1001         if options.filename :
1002             if os.path.exists(options.filename):
1003                 self.filename = os.path.abspath(options.filename)
1004             else:
1005                 truepath = False
1006         elif args :
1007             if os.path.exists(os.path.realpath(args[0])):
1008                 self.filename = os.path.abspath(os.path.realpath(args[0]))
1009             else:
1010                 truepath = False
1011         else:
1012             pass
1013         if truepath :
1014             if os.path.splitext(self.filename)[1] in ['.csv', '.xls', '.ods']:
1015                 self.tableau = Tableau(self, self.filename)
1016                 get_table_param(self, self.filename)
1017                 self.tableau.make_content()
1018                 self.tableau.show_tab()
1019                 #open_data(self, self.filename)
1020             elif os.path.splitext(self.filename)[1] == '.txt':
1021                 self.OpenText()
1022             elif os.path.splitext(self.filename)[1] == '.ira' :
1023                 #self.corpus = Corpus(self)
1024                 #self.Text = OpenAnalyse(self, self.filename)
1025                 OpenAnalyse(self, self.filename)
1026         if not truepath:
1027             print 'ce fichier n\'existe pas'
1028             
1029         
1030
1031 class IntroPanel(wx.Panel):
1032     def __init__(self, parent):
1033         wx.Panel.__init__(self, parent)
1034         #col = randint(0, 255)
1035         #col1 = randint(0,255)
1036         #col2 = randint(0,255)
1037         col = 0
1038         bckgrdcolor = wx.Colour(col, col, col)
1039         self.SetBackgroundColour(bckgrdcolor)
1040         txtcolour = wx.Colour(250, 250, 250)
1041         linkcolor = wx.Colour(255, 0, 0)
1042         sizer1 = wx.BoxSizer(wx.VERTICAL)
1043         sizer2 = wx.BoxSizer(wx.VERTICAL)
1044         sizer3 = wx.BoxSizer(wx.HORIZONTAL)
1045         sizer4 = wx.BoxSizer(wx.VERTICAL)
1046         sizer5 = wx.BoxSizer(wx.HORIZONTAL)
1047         grid_sizer_1 = wx.FlexGridSizer(1, 4, 0, 0)
1048         grid_sizer_3 = wx.FlexGridSizer(1, 4, 0, 0)
1049         grid_sizer_2 = wx.FlexGridSizer(1, 3, 0, 0)
1050         PanelPres = wx.Panel(self)
1051         PanelPres.SetBackgroundColour(bckgrdcolor)
1052         label_1 = wx.StaticText(self, -1, u"IRaMuTeQ", size=(-1, -1))
1053         label_1.SetFont(wx.Font(46, wx.TELETYPE, wx.NORMAL, wx.BOLD, 0, "Purisa"))
1054         label_1.SetForegroundColour(wx.RED)
1055         label2 = wx.StaticText(PanelPres, -1 , u'\nVersion ' + ConfigGlob.get('DEFAULT', 'version') + '\n')
1056         label2.SetForegroundColour(txtcolour)
1057         label2.SetBackgroundColour(bckgrdcolor)
1058         #label3 = wx.StaticText(PanelPres, -1 , u'Equipe ')
1059         #label3.SetForegroundColour(txtcolour)
1060         #label3.SetBackgroundColour(bckgrdcolor)
1061         self.hyper2 = hl.HyperLinkCtrl(PanelPres, wx.ID_ANY, u"REPERE", URL="http://repere.no-ip.org/")
1062         self.hyper2.SetColours(linkcolor, linkcolor, "RED")
1063         self.hyper2.SetBackgroundColour(bckgrdcolor)
1064         self.hyper2.EnableRollover(True)
1065         self.hyper2.SetUnderlines(False, False, True)
1066         self.hyper2.SetBold(True)
1067         self.hyper2.UpdateLink()
1068         label_lerass = wx.StaticText(PanelPres, -1, u'Laboratoire ')
1069         label_lerass.SetForegroundColour(txtcolour)
1070         label_lerass.SetBackgroundColour(bckgrdcolor)
1071         self.hyper_lerass = hl.HyperLinkCtrl(PanelPres, -1, u'LERASS', URL="http://www.lerass.com")
1072         self.hyper_lerass.SetColours(linkcolor, linkcolor, "RED")
1073         self.hyper_lerass.SetBackgroundColour(bckgrdcolor)
1074         self.hyper_lerass.EnableRollover(True)
1075         self.hyper_lerass.SetUnderlines(False, False, True)
1076         self.hyper_lerass.SetBold(True)
1077         self.hyper_lerass.UpdateLink()
1078         blank = wx.StaticText(PanelPres, -1, u'\n')
1079         blank1 = wx.StaticText(PanelPres, -1, u'\n')
1080         labellicence = wx.StaticText(PanelPres, -1, u'Licence GNU GPL')
1081         labellicence.SetForegroundColour(txtcolour)
1082         labellicence.SetBackgroundColour(bckgrdcolor)
1083         labelcopy = wx.StaticText(PanelPres, -1, ConfigGlob.get('DEFAULT', 'copyright'))
1084         labelcopy.SetForegroundColour(txtcolour)
1085         labelcopy.SetBackgroundColour(bckgrdcolor)
1086         python_img = wx.Image(os.path.join(ImagePath,'python-logo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1087         r_img = wx.Image(os.path.join(ImagePath,'Rlogo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1088         lexique_img = wx.Image(os.path.join(ImagePath,'LexTexte4.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1089         but_python = wx.BitmapButton(self, -1, python_img)
1090         but_lexique = wx.BitmapButton(self, -1, lexique_img)
1091         but_r = wx.BitmapButton(self, -1, r_img)
1092         self.Bind(wx.EVT_BUTTON, self.OnPython, but_python)
1093         self.Bind(wx.EVT_BUTTON, self.OnLexique, but_lexique)
1094         self.Bind(wx.EVT_BUTTON, self.OnR, but_r)
1095         
1096         
1097         #grid_sizer_1.Add(label3, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1098         grid_sizer_1.Add(self.hyper2, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1099         grid_sizer_3.Add(label_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1100         grid_sizer_3.Add(self.hyper_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1101         sizer4.Add(label_1, 0, wx.ALIGN_CENTER, 5)
1102         sizer2.Add(label2, 0, wx.ALIGN_CENTER, 5)
1103         #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1104         sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1105         sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1106         sizer2.Add(grid_sizer_3, 0, wx.ALIGN_CENTER, 5)
1107         sizer2.Add(wx.StaticText(PanelPres, -1, u' '), 0, wx.ALIGN_CENTER, 5)
1108         #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1109         #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1110         sizer2.Add(grid_sizer_1, 0, wx.ALIGN_CENTER, 5)
1111         sizer2.Add(labellicence, 0, wx.ALIGN_CENTER, 5)
1112         sizer2.Add(labelcopy, 0, wx.ALIGN_CENTER, 5)
1113         sizer1.Add(sizer4, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1114         PanelPres.SetSizer(sizer2)
1115         sizer5.Add(blank, 1, wx.EXPAND | wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 2)
1116         sizer5.Add(PanelPres, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1117         sizer5.Add(blank1, 1, wx.ALIGN_CENTER_HORIZONTAL,2)
1118         grid_sizer_2.Add(but_python, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1119         grid_sizer_2.Add(but_lexique, 1,wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1120         grid_sizer_2.Add(but_r, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1121         
1122         sizer1.Add(sizer5, 3, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 1)
1123         sizer1.Add(grid_sizer_2, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
1124         self.SetSizer(sizer1)
1125         sizer1.Fit(self)
1126     
1127     def OnPython(self,evt):
1128         webbrowser.open('http://www.python.org')
1129     
1130     def OnLexique(self,evt):
1131         webbrowser.open('http://www.lexique.org')
1132         
1133     def OnR(self,evt):
1134         webbrowser.open('http://www.r-project.org')
1135
1136 class MySplashScreen(wx.SplashScreen):
1137     def __init__(self):
1138         bmp = wx.Image(os.path.join(ImagePath, 'splash.png')).ConvertToBitmap()
1139         wx.SplashScreen.__init__(self, bmp,
1140                                  wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
1141                                  2000, None, -1)
1142         self.Bind(wx.EVT_CLOSE, self.OnClose)
1143         self.fc = wx.FutureCall(1, self.ShowMain)
1144
1145     def OnClose(self, evt):
1146         evt.Skip()
1147         self.Hide()
1148         
1149         if self.fc.IsRunning():
1150             self.fc.Stop()
1151             self.ShowMain()
1152
1153     def ShowMain(self):
1154         frame = IraFrame(None, -1, "IRaMuTeQ " + ConfigGlob.get('DEFAULT', 'version'), size=(1100, 800))
1155         frame.Show()
1156         frame.finish_init()
1157         frame.Upgrade()
1158         frame.OnOpenFromCmdl()
1159 #        if self.fc.IsRunning():
1160 #            self.Raise()
1161         #wx.CallAfter(frame.ShowTip)
1162         
1163 class MyApp(wx.App):
1164     def OnInit(self):
1165         """
1166         Create and show the splash screen.  It will then create and show
1167         the main frame when it is time to do so.
1168         """
1169         wx.SystemOptions.SetOptionInt("mac.window-plain-transition", 1)
1170         self.SetAppName("Iramuteq")       
1171         splash = MySplashScreen()
1172         splash.Show()
1173         return True
1174
1175 def main():
1176     app = MyApp(False)
1177     app.MainLoop()
1178
1179 if __name__ == '__main__':
1180     __name__ = 'Main'
1181     main()