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