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