...
[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         try :
426             self.pref.read(self.ConfigPath['preferences'])
427             if IsNew(self) :
428                 UpgradeConf(self)
429                 New = True
430             else :
431                 CopyConf(self)
432                 New = False
433         except :
434             UpgradeConf(self)
435             self.pref.read(self.ConfigPath['preferences'])
436             New = True
437         #configuration des chemins de R
438         self.PathPath = ConfigParser()
439         self.PathPath.read(ConfigPath['path'])
440         BestRPath = False
441         if not CheckRPath(self.PathPath) :
442             if sys.platform == 'win32':
443                 BestRPath = FindRPAthWin32()
444             else:
445                 BestRPath = FindRPathNix()
446             if BestRPath:
447                 self.PathPath.set('PATHS', 'rpath', BestRPath)
448                 with open(ConfigPath['path'], 'w') as f :
449                     self.PathPath.write(f)
450         else:
451             BestRPath = True 
452         if BestRPath :
453             self.RPath = self.PathPath.get('PATHS', 'rpath')
454             if New :
455                 CheckRPackages(self)
456             if not RLibsAreInstalled(self) :
457                 CheckRPackages(self)
458         else :
459             msg = u"""
460 Le chemin de l'executable de R n'a pas Ã©té trouvé.
461 Si R n'est pas installé, vous devez l'installer (http://www.r-project.org/).
462 Si R n'est pas installé dans le répertoire par défaut
463 (souvent C:\Program Files\R\R-2.x.x\R.exe sous windows ou /usr/bin/R sous linux ou Mac Os X)
464 vous devez signaler le chemin de l'éxecutable de R dans les préférences.""" 
465             dlg = wx.MessageDialog(self, msg, u"Problème de configuration", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
466             dlg.CenterOnParent()
467             if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
468                  evt.Veto()
469             dlg.Destroy()
470         self.DataPop = False
471         self.DataTxt = False
472         self.Text = ''
473         self.sound = self.pref.getboolean('iramuteq', 'sound')
474         self.check_update = self.pref.getboolean('iramuteq', 'checkupdate')
475         self.version = ConfigGlob.get('DEFAULT', 'version')
476         self.lexique = None
477         self.corpus = None
478 ##############################################################@
479         self.DisEnSaveTabAs(False)
480         self.ShowMenu(_("View"), False)
481         self.ShowMenu(_("Spreadsheet analysis"), False)
482         self.ShowMenu(_("Text analysis"), False)
483    
484         self._mgr.Update()
485
486     def OnVerif(self, evt) :
487         pack = CheckRPackages(self)
488         if pack :
489             dlg = wx.MessageDialog(self, u"Installation OK", u"Installation", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
490             dlg.CenterOnParent()
491             if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
492                  evt.Veto()
493
494     #FIXME  marche pas sous mac ?
495     def DisEnSaveTabAs(self, DISEN):
496     #Disable SaveTabAs
497         file_menu = self.mb.GetMenu(0)
498         items = file_menu.GetMenuItems()
499         for item in items :
500             if item.GetId() == ID_SaveTab :
501                 item.Enable(DISEN)
502     
503     def ShowMenu(self, menu, Show=True):
504         menu_pos = self.mb.FindMenu(menu)
505         self.mb.EnableTop(menu_pos, Show)
506         self.mb.UpdateMenus()
507
508
509 #--------------------------------------------------------------------
510     def OnClose(self, event):
511         print 'onclose'
512         with open(self.ConfigPath['path'], 'w') as f :
513             self.PathPath.write(f)
514         if self.DictTab != {} :
515             savestates = [self.DictTab[item][0] for item in self.DictTab]
516             if False in savestates :
517                 notsave = [item for item in self.DictTab if self.DictTab[item][0] == False] 
518                 msg = u"""
519  Certains résultats ne sont pas enregistrés.
520  Voulez-vous fermer quand même ?"""
521                 dlg = wx.MessageDialog(self, msg, "Sauvegarde",
522                        wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
523                 dlg.CenterOnParent()
524                 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
525                     event.Veto()
526                     dlg.Destroy()
527                 else:
528                     dlg.Destroy()
529                     for item in notsave :
530                         for tmpfile in self.DictTab[item][1:] :
531                             os.remove(tmpfile)
532                             print 'remove : ' + tmpfile
533                     self._mgr.UnInit()
534                     del self._mgr
535                     self.Destroy()
536             else :
537                 self._mgr.UnInit()
538                 del self._mgr
539                 self.Destroy()
540         else :
541             self._mgr.UnInit()
542             del self._mgr
543             self.Destroy()
544             #if sys.platform == 'win32' :
545             #    os.system("taskkill /im iramuteq.exe /f")
546             #    print 'meurtre de process'
547
548     def OnOpenData(self, event):
549         inputname, self.input_path = OnOpen(self, "Data")
550         if inputname:
551             self.filename = self.input_path[0]
552             self.tableau = Tableau(self,os.path.abspath(self.input_path[0]))
553             get_table_param(self, self.input_path[0])
554             self.tableau.make_content()
555             self.tableau.show_tab()
556
557     def OnOpenAnalyse(self, event):
558         self.AnalysePath = OnOpen(self, "Analyse")
559         OpenAnalyse(self, self.AnalysePath[1][0], True)
560         self.ShowMenu(_("View"))
561
562     def OnOpenText(self, event):
563         inputname, self.input_path = OnOpen(self, "Texte")
564         self.filename = self.input_path[0]
565         if inputname:
566              self.OpenText()
567    
568     def OnViewData(self, event):
569         print self.type
570         print self.DataTxt
571         if self.type == "Data":
572             if not self.DataPop :
573                 self.Sheet.Populate(self.content)
574                 self.DataPop = True
575                 self.DataTxt = False
576             self.ShowAPane(u"Data")
577         elif self.type == "Texte" or self.type == 'Analyse' :
578             if not self.DataTxt :
579                 self.text_ctrl_txt.Clear()
580                 self.text_ctrl_txt.write(self.content)
581                 self.text_ctrl_txt.ShowPosition(0)
582                 self.DataTxt = True
583                 self.DataPop = False
584             self.ShowAPane(u"Text")
585         self._mgr.Update()
586         
587     def OpenText(self):
588         #dial = EncodeDialog(self)
589         dlg = wx.ProgressDialog("Ouverture...",
590                                    "Veuillez patienter...",
591                                    maximum=2,
592                                    parent=self,
593                                    style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
594                                    )
595         
596         builder =  Builder(self, dlg)
597         if builder.res == wx.ID_OK :
598             try :
599                 corpus = builder.doanalyse()
600                 self.history.add(corpus.parametres)
601                 self.tree.OnItemAppend(corpus.parametres)
602                 OpenAnalyse(self, corpus.parametres)
603             except :
604                 BugReport(self)
605         #self.content = DoConf().totext(corpus.parametres)
606 #        parametres = DoConf(os.path.join(UserConfigPath,'corpus.cfg')).getoptions('corpus')
607 #        parametres['originalpath'] = self.filename
608 #        
609 #        parametres['pathout'] = PathOut(self.filename, 'corpus').dirout
610 #        dial = CorpusPref(self, parametres)
611 #        dial.CenterOnParent()
612 #        dial.txtpath.SetLabel(self.filename)
613 #        res = dial.ShowModal()
614 #        parametres = dial.doparametres()
615 #        print parametres
616 #        ReadLexique(self, lang = parametres['lang'])
617 #        self.expressions = ReadDicoAsDico(self.DictPath.get(parametres['lang'], 'french_exp'))
618 #        corpus = BuildFromAlceste(self.filename, parametres, self.lexique, self.expressions).corpus
619         #self.corpus_encodage =  dial.encodages[dial.list_encodages.GetSelection()][0]
620         #self.corpus_lang = dial.langues[dial.choice_dict.GetSelection()]
621             else :
622                 count = 1
623                 keepGoing = dlg.Update(count, u"Lecture du fichier")
624     #            msg = u"Ce fichier ne semble pas Ãªtre encodé en %s" % self.corpus_encodage
625     #            dial = wx.MessageDialog(self, msg, u"Problème d'encodage", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
626     #            dial.CenterOnParent()
627     #            res = dial.ShowModal()
628     #            dial.Destroy()
629     #            self.OpenText()
630                 self.ShowMenu(_("View"))
631                 self.ShowMenu(_("Text analysis"))
632                 self.ShowMenu(_(u"Spreadsheet analysis"), False)
633                 self.type = "Texte"
634                 self.DataTxt = False
635                 self.Text = ''
636                 count += 1
637                 keepGoing = dlg.Update(count, u"Chargement du dictionnaire")
638                 dlg.Destroy()
639         #self.OnViewData(wx.EVT_BUTTON)
640         
641     def OnExit(self, event):
642         self.Close()
643
644     def OnAbout(self, event):
645         info = wx.AboutDialogInfo()
646         info.Name = ConfigGlob.get('DEFAULT', 'name')
647         info.Version = ConfigGlob.get('DEFAULT', 'version')
648         info.Copyright = ConfigGlob.get('DEFAULT', 'copyright')
649         info.Description = u"""
650 Interface de R pour les Analyses Multidimensionnelles 
651 de Textes et de Questionnaires
652
653 Un logiciel libre
654 construit avec des logiciels libres.
655
656 Laboratoire LERASS
657
658 REPERE
659 """
660         info.WebSite = ("http://www.iramuteq.org", u"Site web IRaMuTeQ")
661         dev = ConfigGlob.get('DEFAULT', 'dev').split(';')
662         info.Developers = dev
663         info.License = u"""Iramuteq est un logiciel libre ; vous pouvez le diffuser et/ou le modifier 
664 suivant les termes de la Licence Publique Générale GNU telle que publiée 
665 par la Free Software Foundation ; soit la version 2 de cette licence, 
666 soit (à votre convenance) une version ultérieure.
667
668 Iramuteq est diffusé dans l'espoir qu'il sera utile, 
669 mais SANS AUCUNE GARANTIE ; sans même une garantie implicite 
670 de COMMERCIALISATION ou d'ADÉQUATION Ã€ UN USAGE PARTICULIER. 
671 Voyez la Licence Publique Générale GNU pour plus de détails.
672
673 Vous devriez avoir reçu une copie de la Licence Publique Générale GNU
674 avec Iramuteq ; sinon, veuillez Ã©crire Ã  la Free Software Foundation,
675 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, Ã‰tats-Unis."""
676         wx.AboutBox(info)
677
678     def GetDockArt(self):
679         return self._mgr.GetArtProvider()
680
681     def DoUpdate(self):
682         self._mgr.Update()
683
684     def OnPageChanged(self, event) :
685         new = event.GetSelection()
686         nobject = event.GetEventObject()
687         parent = nobject.GetParent()
688         if isinstance(parent, IraFrame) :
689             npage = self.nb.GetPage(new)
690             self.tree.GiveFocus(uuid=npage.parametres['uuid'])
691
692     def OnCloseTab(self, evt):
693         #log.info('Closing tab %s' % str(evt.GetEventObject()))
694         ctrl = evt.GetEventObject()
695         if isinstance(ctrl.GetParent(), aui.AuiNotebook) or isinstance(ctrl.GetParent(), wx.Panel):
696             notebook = True
697         else :
698             notebook = False
699         page = self.nb.GetPage(self.nb.GetSelection())
700         if 'parametres' in dir(page) and isinstance(ctrl.GetParent(), IraFrame) :
701             self.history.rmtab(page.parametres)
702             self.tree.CloseItem(uuid = page.parametres['uuid'])
703         TabTitle = self.nb.GetPageText(self.nb.GetSelection())
704         if self.DictTab != {} :
705             if TabTitle in self.DictTab :
706                 ListFile=self.DictTab[TabTitle]
707                 if False in ListFile:
708                     msg = u"""
709 Certains résultats ne sont pas enregistrer.
710 Voulez-vous fermer quand même ?"""
711                     dlg = wx.MessageDialog(self, msg, "Sauvegarde",wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
712
713                     dlg.CenterOnParent()
714                     if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
715                         remove = False
716                         evt.Veto()
717                         dlg.Destroy()
718                     else :
719                         for f in ListFile[1:] :
720                             print 'remove', f
721                             os.remove(f)
722                             remove = True
723                         dlg.Destroy()
724                 elif True in ListFile :
725                     remove = True
726                 if remove:
727                    del self.DictTab[TabTitle]
728             else : 
729                 self.LastTabClose()
730         else :
731             remove = True
732         if self.nb.GetPageCount() == 1 and remove and not notebook :
733             self.LastTabClose()
734     
735     def LastTabClose(self) :
736         if self.nb.GetPageCount() == 1 :
737             self.DisEnSaveTabAs(False)
738             if self.DataTxt :
739                 self.ShowAPane("Text")
740             elif self.DataPop :
741                 self.ShowAPane("Data")
742             else :
743                 self.ShowAPane("Intro_Text")
744
745     def OnSaveTabAs(self, event):
746         SelectTab = self.nb.GetSelection()
747         TabTitle = self.nb.GetPageText(SelectTab)
748         FileToSave = self.DictTab[TabTitle]
749         NewListFile = []
750         dlg = wx.FileDialog(
751             self, message="Enregistrer sous...", defaultDir=os.getcwd(),
752             defaultFile="resultat.html", wildcard="Tous les fichiers|*", style=wx.SAVE | wx.OVERWRITE_PROMPT
753             )
754         dlg.SetFilterIndex(2)
755         dlg.CenterOnParent()
756         
757         if dlg.ShowModal() == wx.ID_OK:
758             Path = dlg.GetPath()
759             Dirname = os.path.dirname(Path)
760             Filename = dlg.GetFilename()
761         else :
762             Path = False
763         dlg.Destroy()
764         if Path:
765             shutil.copyfile(FileToSave[-1], Path)
766             os.remove(FileToSave[len(FileToSave) - 1])
767             NewListFile.append(True)
768             NewListFile.append(Path)
769             for f in FileToSave[1:-1] :
770                 Fileout = os.path.join(Dirname, os.path.basename(f))
771                 shutil.copyfile(f, Fileout)
772                 NewListFile.append(Fileout)
773                 os.remove(f)
774             TabText = Filename
775             self.DictTab[TabText] = NewListFile
776             del self.DictTab[TabTitle]
777             self.nb.SetPageText(SelectTab, TabText)
778
779     def GetStartPosition(self):
780
781         self.x = self.x + 20
782         x = self.x
783         pt = self.ClientToScreen(wx.Point(0, 0))
784         
785         return wx.Point(pt.x + x, pt.y + x)
786     
787     def ShowAPane(self, panel):
788         for pane in self._mgr.GetAllPanes() :
789             if not pane.IsToolbar() and pane.name != 'lefttree': 
790                 pane.Hide()
791         self._mgr.GetPane(panel).Show()
792         self._mgr.Update()
793         
794     def OnAcceuil(self, event):
795         self.ShowAPane(u"Intro_Text")
796         event.Skip()
797     
798     def CreateHTMLCtrl(self):
799         ctrl = wx.html.HtmlWindow(self, -1, wx.DefaultPosition, wx.Size(400, 300))
800         if "gtk2" in wx.PlatformInfo:
801             ctrl.SetStandardFonts()
802         ctrl.SetPage(u"text")        
803         return ctrl
804
805     def ShowTab(self, evt):
806         self.ShowAPane("Tab_content")
807
808 ################################################################
809 #debut des analyses
810 ################################################################
811
812     def OnFreq(self, event):
813         try:
814             Frequences(self) 
815         except:
816             BugReport(self)
817             
818     def OnChi2(self, event):
819         try:
820         #    print('PAS DE DEBUG SUR CHI2')
821             chi = ChiSquare(self)
822         except:
823             BugReport(self)
824     
825     def OnStudent(self, event):
826         try:
827             MakeStudent(self) 
828         except:
829             BugReport(self)
830
831     def OnRCode(self, event):
832         try:
833             InputText(self)
834         except:
835             BugReport(self)
836
837     def OnCHDSIM(self, event):
838         try:
839         #    print 'ATTENTION!!!!'
840             chdsim = ChdCluster(self)
841             if chdsim.val == wx.ID_OK:
842                 PlaySound(self)
843         except:
844             BugReport(self)
845  
846     def OnCHDAlceste(self, event):
847         try:
848          #   print('PLUS DE BUG SUR ALCESTE QUESTIONNAIRE')
849             self.quest = AnalyseQuest(self)
850             if self.quest.val == wx.ID_OK:
851                 PlaySound(self)
852         except:
853             BugReport(self)
854
855     def OnSimiTxt(self, evt, corpus = None) :
856         #    print 'PLUS DE BUG SUR SIMITXT'
857         try :
858             #self.Text = SimiTxt(self)
859             if corpus is None :
860                 corpus = self.tree.getcorpus()            
861             self.Text = SimiTxt(self, corpus, parametres = {'type': 'simitxt'}, dlg = progressbar(self, 3))
862             if self.Text.val == wx.ID_OK :
863                 PlaySound(self)
864         except :
865             BugReport(self)
866     
867     def OnWordCloud(self, evt, corpus = None) :
868         #    print 'PLUS DE BUG SUR WORDCLOUD'
869         try :
870             if corpus is None :
871                 corpus = self.tree.getcorpus()            
872             self.Text = WordCloud(self, corpus, parametres = {'type' : 'wordcloud'}, dlg = progressbar(self, 3))
873             if self.Text.val == wx.ID_OK :
874                 PlaySound(self)
875         except :
876             BugReport(self)
877
878
879     def OnAFCM(self, event):
880         try:
881             DoAFCM(self)
882         except:
883             BugReport(self)
884
885     def OnCheckcorpus(self, evt):
886         try :
887             checkcorpus(self)
888         except :
889             BugReport(self)
890
891     def OnTextStat(self, event, corpus = None):
892             print 'PAS DE BUG SUR TEXT STAT'
893         #try:
894             if corpus is None :
895                 corpus = self.tree.getcorpus()
896             self.Text = Stat(self, corpus, parametres = {'type': 'stat'}, dlg = progressbar(self, 7))
897             
898             if self.Text.val == wx.ID_OK :
899                 PlaySound(self)
900         #except:
901         #    BugReport(self)
902         
903     def OnTextSpec(self, event, corpus = None):  
904         #try:
905             #self.Text = AsLexico(self)
906             print('ATTENTION : PLUS DE BUG SUR LEXICO')
907             if corpus is None :
908                 corpus = self.tree.getcorpus()
909             self.Text = Lexico(self, corpus, parametres = {'type' : 'spec'}, dlg = progressbar(self, 3))
910             if self.Text.val == wx.ID_OK :
911                 PlaySound(self)
912         #except:
913         #    BugReport(self)
914     
915     def OnTextAfcm(self, event):
916         try:
917             AfcUci(self)
918             PlaySound(self)
919         except:
920             BugReport(self)
921
922     def import_factiva_xml(self,event):
923         try :
924             ImportFactiva(self, 'xml')
925         except :
926             BugReport(self)
927
928     def import_factiva_mail(self, evt) :
929         try :
930             ImportFactiva(self, 'mail')
931         except :
932             BugReport(self)
933
934     def import_factiva_txt(self, evt) :
935         try :
936             ImportFactiva(self, 'txt')
937         except :
938             BugReport(self)
939
940     def ExtractTools(self, evt) :
941         ID = evt.GetId()
942         if ID == self.ID_splitvar :
943             Extract(self, 'splitvar')
944         else :
945             Extract(self, 'mods')
946
947     def OnTextAlceste(self, event, corpus = None):
948         try:
949             #print('ATTENTION : PLUS DE BUG SUR ALCESTE')
950             #RunAnalyse(self, corpus, Alceste, OptAlceste)
951             if corpus is None :
952                 corpus = self.tree.getcorpus()            
953             self.Text = Alceste(self, corpus, parametres = {'type': 'alceste'}, dlg = progressbar(self,6))
954             if self.Text.val == wx.ID_OK:
955                 PlaySound(self)
956         except:
957             BugReport(self)
958
959     def OnPamSimple(self, event):
960         try:
961             self.Text = PamTxt(self)
962             if self.Text.val == wx.ID_OK:
963                 PlaySound(self)
964         except:
965             BugReport(self)
966     
967     def OnSimi(self,evt):
968         try :
969             #print 'ATTENTION !!!! VERGES'
970             self.res = DoSimi(self, param = None)
971             #self.res = Verges(self)
972             if self.res.val == wx.ID_OK :
973                  PlaySound(self)
974         except :
975             BugReport(self)
976 #################################################################
977
978     def OnHelp(self, event):
979         webbrowser.open('http://www.iramuteq.org/documentation')
980     
981     def OnPref(self, event):
982         dlg = PrefDialog(self)
983         dlg.CenterOnParent()
984         self.val = dlg.ShowModal()
985
986     def Upgrade(self) :
987         if self.check_update:
988             NewVersion(self)
989         else:
990             print 'pas de verif'    
991         #IsNew(self)
992         #CheckRPackages(self)
993
994     def OnOpenFromCmdl(self):
995         truepath = True
996         if options.filename :
997             if os.path.exists(options.filename):
998                 self.filename = os.path.abspath(options.filename)
999             else:
1000                 truepath = False
1001         elif args :
1002             if os.path.exists(os.path.realpath(args[0])):
1003                 self.filename = os.path.abspath(os.path.realpath(args[0]))
1004             else:
1005                 truepath = False
1006         else:
1007             pass
1008         if truepath :
1009             if os.path.splitext(self.filename)[1] in ['.csv', '.xls', '.ods']:
1010                 self.tableau = Tableau(self, self.filename)
1011                 get_table_param(self, self.filename)
1012                 self.tableau.make_content()
1013                 self.tableau.show_tab()
1014                 #open_data(self, self.filename)
1015             elif os.path.splitext(self.filename)[1] == '.txt':
1016                 self.OpenText()
1017             elif os.path.splitext(self.filename)[1] == '.ira' :
1018                 #self.corpus = Corpus(self)
1019                 #self.Text = OpenAnalyse(self, self.filename)
1020                 OpenAnalyse(self, self.filename)
1021         if not truepath:
1022             print 'ce fichier n\'existe pas'
1023             
1024         
1025
1026 class IntroPanel(wx.Panel):
1027     def __init__(self, parent):
1028         wx.Panel.__init__(self, parent)
1029         #col = randint(0, 255)
1030         #col1 = randint(0,255)
1031         #col2 = randint(0,255)
1032         col = 0
1033         bckgrdcolor = wx.Colour(col, col, col)
1034         self.SetBackgroundColour(bckgrdcolor)
1035         txtcolour = wx.Colour(250, 250, 250)
1036         linkcolor = wx.Colour(255, 0, 0)
1037         sizer1 = wx.BoxSizer(wx.VERTICAL)
1038         sizer2 = wx.BoxSizer(wx.VERTICAL)
1039         sizer3 = wx.BoxSizer(wx.HORIZONTAL)
1040         sizer4 = wx.BoxSizer(wx.VERTICAL)
1041         sizer5 = wx.BoxSizer(wx.HORIZONTAL)
1042         grid_sizer_1 = wx.FlexGridSizer(1, 4, 0, 0)
1043         grid_sizer_3 = wx.FlexGridSizer(1, 4, 0, 0)
1044         grid_sizer_2 = wx.FlexGridSizer(1, 3, 0, 0)
1045         PanelPres = wx.Panel(self)
1046         PanelPres.SetBackgroundColour(bckgrdcolor)
1047         label_1 = wx.StaticText(self, -1, u"IRaMuTeQ", size=(-1, -1))
1048         label_1.SetFont(wx.Font(46, wx.TELETYPE, wx.NORMAL, wx.BOLD, 0, "Purisa"))
1049         label_1.SetForegroundColour(wx.RED)
1050         label2 = wx.StaticText(PanelPres, -1 , u'\nVersion ' + ConfigGlob.get('DEFAULT', 'version') + '\n')
1051         label2.SetForegroundColour(txtcolour)
1052         label2.SetBackgroundColour(bckgrdcolor)
1053         #label3 = wx.StaticText(PanelPres, -1 , u'Equipe ')
1054         #label3.SetForegroundColour(txtcolour)
1055         #label3.SetBackgroundColour(bckgrdcolor)
1056         self.hyper2 = hl.HyperLinkCtrl(PanelPres, wx.ID_ANY, u"REPERE", URL="http://repere.no-ip.org/")
1057         self.hyper2.SetColours(linkcolor, linkcolor, "RED")
1058         self.hyper2.SetBackgroundColour(bckgrdcolor)
1059         self.hyper2.EnableRollover(True)
1060         self.hyper2.SetUnderlines(False, False, True)
1061         self.hyper2.SetBold(True)
1062         self.hyper2.UpdateLink()
1063         label_lerass = wx.StaticText(PanelPres, -1, u'Laboratoire ')
1064         label_lerass.SetForegroundColour(txtcolour)
1065         label_lerass.SetBackgroundColour(bckgrdcolor)
1066         self.hyper_lerass = hl.HyperLinkCtrl(PanelPres, -1, u'LERASS', URL="http://www.lerass.com")
1067         self.hyper_lerass.SetColours(linkcolor, linkcolor, "RED")
1068         self.hyper_lerass.SetBackgroundColour(bckgrdcolor)
1069         self.hyper_lerass.EnableRollover(True)
1070         self.hyper_lerass.SetUnderlines(False, False, True)
1071         self.hyper_lerass.SetBold(True)
1072         self.hyper_lerass.UpdateLink()
1073         blank = wx.StaticText(PanelPres, -1, u'\n')
1074         blank1 = wx.StaticText(PanelPres, -1, u'\n')
1075         labellicence = wx.StaticText(PanelPres, -1, u'Licence GNU GPL')
1076         labellicence.SetForegroundColour(txtcolour)
1077         labellicence.SetBackgroundColour(bckgrdcolor)
1078         labelcopy = wx.StaticText(PanelPres, -1, ConfigGlob.get('DEFAULT', 'copyright'))
1079         labelcopy.SetForegroundColour(txtcolour)
1080         labelcopy.SetBackgroundColour(bckgrdcolor)
1081         python_img = wx.Image(os.path.join(ImagePath,'python-logo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1082         r_img = wx.Image(os.path.join(ImagePath,'Rlogo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1083         lexique_img = wx.Image(os.path.join(ImagePath,'LexTexte4.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1084         but_python = wx.BitmapButton(self, -1, python_img)
1085         but_lexique = wx.BitmapButton(self, -1, lexique_img)
1086         but_r = wx.BitmapButton(self, -1, r_img)
1087         self.Bind(wx.EVT_BUTTON, self.OnPython, but_python)
1088         self.Bind(wx.EVT_BUTTON, self.OnLexique, but_lexique)
1089         self.Bind(wx.EVT_BUTTON, self.OnR, but_r)
1090         
1091         
1092         #grid_sizer_1.Add(label3, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1093         grid_sizer_1.Add(self.hyper2, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1094         grid_sizer_3.Add(label_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1095         grid_sizer_3.Add(self.hyper_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1096         sizer4.Add(label_1, 0, wx.ALIGN_CENTER, 5)
1097         sizer2.Add(label2, 0, wx.ALIGN_CENTER, 5)
1098         #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1099         sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1100         sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1101         sizer2.Add(grid_sizer_3, 0, wx.ALIGN_CENTER, 5)
1102         sizer2.Add(wx.StaticText(PanelPres, -1, u' '), 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(grid_sizer_1, 0, wx.ALIGN_CENTER, 5)
1106         sizer2.Add(labellicence, 0, wx.ALIGN_CENTER, 5)
1107         sizer2.Add(labelcopy, 0, wx.ALIGN_CENTER, 5)
1108         sizer1.Add(sizer4, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1109         PanelPres.SetSizer(sizer2)
1110         sizer5.Add(blank, 1, wx.EXPAND | wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 2)
1111         sizer5.Add(PanelPres, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1112         sizer5.Add(blank1, 1, wx.ALIGN_CENTER_HORIZONTAL,2)
1113         grid_sizer_2.Add(but_python, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1114         grid_sizer_2.Add(but_lexique, 1,wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1115         grid_sizer_2.Add(but_r, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1116         
1117         sizer1.Add(sizer5, 3, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 1)
1118         sizer1.Add(grid_sizer_2, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
1119         self.SetSizer(sizer1)
1120         sizer1.Fit(self)
1121     
1122     def OnPython(self,evt):
1123         webbrowser.open('http://www.python.org')
1124     
1125     def OnLexique(self,evt):
1126         webbrowser.open('http://www.lexique.org')
1127         
1128     def OnR(self,evt):
1129         webbrowser.open('http://www.r-project.org')
1130
1131 class MySplashScreen(wx.SplashScreen):
1132     def __init__(self):
1133         bmp = wx.Image(os.path.join(ImagePath, 'splash.png')).ConvertToBitmap()
1134         wx.SplashScreen.__init__(self, bmp,
1135                                  wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
1136                                  2000, None, -1)
1137         self.Bind(wx.EVT_CLOSE, self.OnClose)
1138         self.fc = wx.FutureCall(1, self.ShowMain)
1139
1140     def OnClose(self, evt):
1141         evt.Skip()
1142         self.Hide()
1143         
1144         if self.fc.IsRunning():
1145             self.fc.Stop()
1146             self.ShowMain()
1147
1148     def ShowMain(self):
1149         frame = IraFrame(None, -1, "IRaMuTeQ " + ConfigGlob.get('DEFAULT', 'version'), size=(1100, 800))
1150         frame.Show()
1151         frame.Upgrade()
1152         frame.OnOpenFromCmdl()
1153 #        if self.fc.IsRunning():
1154 #            self.Raise()
1155         #wx.CallAfter(frame.ShowTip)
1156         
1157 class MyApp(wx.App):
1158     def OnInit(self):
1159         """
1160         Create and show the splash screen.  It will then create and show
1161         the main frame when it is time to do so.
1162         """
1163         wx.SystemOptions.SetOptionInt("mac.window-plain-transition", 1)
1164         self.SetAppName("Iramuteq")       
1165         splash = MySplashScreen()
1166         splash.Show()
1167         return True
1168
1169 def main():
1170     app = MyApp(False)
1171     app.MainLoop()
1172
1173 if __name__ == '__main__':
1174     __name__ = 'Main'
1175     main()