2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2008-2012, Pierre Ratinaud
7 from optparse import OptionParser
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()
24 from random import randint
25 from ConfigParser import *
29 #------------------------------------
32 #import wx.lib.agw.aui as aui
36 import wx.lib.hyperlink as hl
37 #from wx.lib.wordwrap import wordwrap
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
60 from textwordcloud import WordCloud
61 from profile_segment import ProfileSegment
62 from textcheckcorpus import checkcorpus
63 from openanalyse import OpenAnalyse
64 from corpusNG import BuildFromAlceste, Builder
65 from sheet import MySheet
66 from checkinstall import CreateIraDirectory, CheckRPath, FindRPAthWin32, FindRPathNix, CheckRapp, CheckRPackages, IsNew, UpgradeConf, CopyConf, RLibsAreInstalled
67 from chemins import ConstructRscriptsPath, ConstructConfigPath, ConstructDicoPath, ConstructGlobalPath, PathOut
68 from parse_factiva_xml import ImportFactiva
69 from tree import LeftTree
70 ##########################################################
71 ID_OpenData = wx.NewId()
72 ID_Import = wx.NewId()
73 ID_OpenText = wx.NewId()
74 ID_OnOpenAnalyse = wx.NewId()
77 ID_Student = wx.NewId()
78 ID_CHDSIM = wx.NewId()
79 ID_CHDAlceste = wx.NewId()
80 ID_TEXTAFCM = wx.NewId()
81 ID_TEXTSTAT = wx.NewId()
83 ID_TEXTALCESTE = wx.NewId()
84 ID_TEXTPAM = wx.NewId()
85 ID_CHECKCORPUS = wx.NewId()
86 ID_Tabcontent = wx.NewId()
89 ID_CloseTab = wx.NewId()
90 ID_SaveTab = wx.NewId()
91 ID_CreateText = wx.NewId()
92 ID_ACCEUIL = wx.NewId()
93 ID_RESULT = wx.NewId()
94 ID_VIEWDATA = wx.NewId()
95 ID_HTMLcontent = wx.NewId()
96 ID_SimiTxt = wx.NewId()
97 ##########################################################
98 #elements de configuration
99 ##########################################################
101 if sys.platform == 'darwin' :
102 sys.setdefaultencoding('utf-8')
103 wx.SetDefaultPyEncoding('utf-8')
105 sys.setdefaultencoding(locale.getpreferredencoding())
106 #chemin de l'application
108 AppliPath = os.path.abspath(os.path.dirname(os.path.realpath(sys.argv[0])))
110 ImagePath = os.path.join(AppliPath, 'images')
111 #configuration generale
112 DictConfigPath = ConstructGlobalPath(AppliPath)
113 ConfigGlob = ConfigParser()
114 ConfigGlob.read(DictConfigPath['global'])
115 #repertoire de l'utilisateur
116 if os.getenv('HOME') != None:
117 user_home = os.getenv('HOME')
119 user_home = os.getenv('HOMEPATH')
120 UserConfigPath = os.path.abspath(os.path.join(user_home, '.iramuteq'))
121 #Si pas de fichiers de config utilisateur, on crée le repertoire
122 CreateIraDirectory(UserConfigPath, AppliPath)
123 #fichiers log pour windows (py2exe)
124 print 'PLUS DE LOG !!!!!!!!!!'
126 log = logging.getLogger('iramuteq')
127 fh = logging.FileHandler(os.path.join(UserConfigPath,'stdout.log'))
128 ch = logging.StreamHandler()
129 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
130 ch.setFormatter(formatter)
131 fh.setFormatter(formatter)
134 log.setLevel(logging.INFO)
137 # if sys.platform == 'win32' or sys.platform == 'darwin':
138 # sys.stdout = open(os.path.join(UserConfigPath,'stdout.log'), 'w')
139 # sys.stderr = open(os.path.join(UserConfigPath,'stderr.log'), 'w')
140 #chemin des fichiers de configuration utilisateur
142 ConfigPath = ConstructConfigPath(UserConfigPath)
143 #####################################################################
145 class IraFrame(wx.Frame):
146 def __init__(self, parent, id= -1, title="", pos=wx.DefaultPosition,
147 size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE |
150 log.info('Starting...')
151 wx.Frame.__init__(self, parent, id, title, pos, size, style)
153 self.AppliPath = AppliPath
154 self.images_path = os.path.join(AppliPath,'images')
155 self.UserConfigPath = UserConfigPath
156 self.RscriptsPath = ConstructRscriptsPath(AppliPath)
157 self.DictPath = ConstructDicoPath(AppliPath)
158 self.ConfigGlob = ConfigGlob
159 self.ConfigPath = ConstructConfigPath(UserConfigPath)
160 self.pref = RawConfigParser()
162 mylocale = wx.Locale(wx.LANGUAGE_FRENCH)
163 mylocale.AddCatalogLookupPathPrefix(os.path.join(AppliPath,'locale'))
164 mylocale.AddCatalog('iramuteq')
165 presLan_en = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['en'])
166 presLan_fr = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['fr_FR'])
170 # tell FrameManager to manage this frame
171 #self._mgr = wx.aui.AuiManager()
172 self._mgr = aui.AuiManager()
173 self._mgr.SetManagedWindow(self)
176 #--------------------------------------------------------------------------------
177 self.mb = wx.MenuBar()
179 file_menu = wx.Menu()
180 item = wx.MenuItem(file_menu, ID_OpenData, _(u"Open a questionnaire"), _(u"Open a questionnaire"))
181 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
182 file_menu.AppendItem(item)
184 item = wx.MenuItem(file_menu, ID_OpenText, u"Ouvrir texte", u"Ouvrir un corpus texte")
185 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
186 file_menu.AppendItem(item)
188 item = wx.MenuItem(file_menu, ID_OnOpenAnalyse, u"Ouvrir une Analyse", "Ouvrir une Analyse")
189 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
190 file_menu.AppendItem(item)
192 item1 = wx.MenuItem(file_menu, ID_Import, u"Importer un corpus factiva...", "Importer un corpus factiva...")
193 item1.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_TIP))
194 file_menu.AppendItem(item1)
197 item = wx.MenuItem(file_menu, ID_SaveTab, u"Enregistrer l\'onglet sous...", u"Enregistrer l\'onglet sous ...")
198 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_SAVE_AS))
200 file_menu.AppendItem(item)
202 file_menu.Append(wx.ID_EXIT, u"Exit")
204 edit_menu = wx.Menu()
205 edit_menu.Append(wx.ID_PREFERENCES, '', u'Préférences')
207 view_menu = wx.Menu()
208 view_menu.Append(ID_ACCEUIL, u"Page d'accueil")
209 view_menu.Append(ID_VIEWDATA, u"Afficher les données")
210 view_menu.Append(ID_RESULT, u'Afficher les résultats')
211 #view_menu.AppendSeparator()
213 analyse_menu = wx.Menu()
214 analyse_menu.Append(ID_Freq, u"Fréquences")
215 analyse_menu.Append(ID_Chi2, u"Chi2")
216 #analyse_menu.Append(ID_Student, u"t de Student")
217 menu_classif = wx.Menu()
218 menu_classif.Append(ID_CHDAlceste, u"Méthode Alceste")
219 menu_classif.Append(ID_CHDSIM, u"Par matrice des distances")
220 analyse_menu.AppendMenu(-1, u"Classification", menu_classif)
221 analyse_menu.Append(ID_AFCM, u"AFCM")
222 analyse_menu.Append(ID_SIMI, u"Analyse de similitudes")
223 ID_RCODE = wx.NewId()
224 analyse_menu.Append(ID_RCODE, u"Code R...")
226 text_menu = wx.Menu()
227 text_menu.Append(ID_CHECKCORPUS, u"Vérifier le corpus")
228 text_menu.Append(ID_TEXTSTAT, u"Statistiques textuelles")
229 text_menu.Append(ID_ASLEX, u"Spécificités et AFC")
230 #text_menu.Append(ID_TEXTAFCM, u"AFC sur UCI / Vocabulaire")
231 menu_classiftxt = wx.Menu()
232 menu_classiftxt.Append(ID_TEXTALCESTE, u"Méthode Alceste")
233 menu_classiftxt.Append(ID_TEXTPAM, u"Par matrice des distances")
234 text_menu.AppendMenu(-1, u"Classification", menu_classiftxt)
235 text_menu.Append(ID_SimiTxt, u'Analyse de similitude')
237 text_menu.Append(ID_WC, u'Nuage de mots')
239 help_menu = wx.Menu()
240 help_menu.Append(wx.ID_ABOUT, u'À propos...')
241 help_menu.Append(wx.ID_HELP, u'Aide en ligne')
243 self.mb.Append(file_menu, _(u"File"))
244 self.mb.Append(edit_menu, _(u"Edition"))
245 self.mb.Append(view_menu, _(u"View"))
246 self.mb.Append(analyse_menu, _("Spreadsheet analysis"))
247 self.mb.Append(text_menu, _(u"Text analysis"))
248 self.mb.Append(help_menu, _(u"Help"))
250 self.SetMenuBar(self.mb)
251 #--------------------------------------------------------------------
252 self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
253 self.statusbar.SetStatusWidths([-2, -3])
254 self.statusbar.SetStatusText(u"Prêt", 0)
255 self.statusbar.SetStatusText(u"Bienvenue", 1)
257 # min size for the frame itself isn't completely done.
258 # see the end up FrameManager::Update() for the test
259 # code. For now, just hard code a frame minimum size
260 self.SetMinSize(wx.Size(400, 400))
262 # create some toolbars
263 tb1 = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
264 wx.TB_FLAT | wx.TB_NODIVIDER)
265 tb1.SetToolBitmapSize(wx.Size(16, 16))
266 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")
268 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")
272 #------------------------------------------------------------------------------------------------
274 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)
276 #self._mgr.AddPane(self.text_ctrl_txt, wx.aui.AuiPaneInfo().
277 # Name("Text").CenterPane())
278 self._mgr.AddPane(self.text_ctrl_txt, aui.AuiPaneInfo().
279 Name("Text").CenterPane())
280 #self._mgr.AddPane(IntroPanel(self), wx.aui.AuiPaneInfo().Name("Intro_Text").
282 self._mgr.AddPane(IntroPanel(self), aui.AuiPaneInfo().Name("Intro_Text").
284 if not os.path.exists(os.path.join(UserConfigPath, 'history.db')) :
285 with open(os.path.join(UserConfigPath, 'history.db'), 'w') as f :
287 self.history = History(os.path.join(UserConfigPath, 'history.db'))
288 self.tree = LeftTree(self)
289 self._mgr.AddPane(self.tree, aui.AuiPaneInfo().Name("lefttree").Caption("Navigateur").
290 Left().MinSize(wx.Size(200,500)).Layer(1).Position(1).CloseButton(False).MaximizeButton(True).
291 MinimizeButton(True))
293 #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)
294 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)
295 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
296 self.nb.SetAGWWindowStyleFlag(notebook_flags)
297 self.nb.SetArtProvider(aui.ChromeTabArt())
298 #self.nb.SetArtProvider(aui.VC8TabArt())
299 #self.nb.parent = self
300 #self._notebook_style = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.NO_BORDER
301 #self._mgr.AddPane(self.nb, wx.aui.AuiPaneInfo().
302 # Name("Tab_content").
304 self._mgr.AddPane(self.nb, aui.AuiPaneInfo().
307 self.Sheet = MySheet(self)
308 #self._mgr.AddPane(self.Sheet, wx.aui.AuiPaneInfo().Name("Data").CenterPane())
309 self._mgr.AddPane(self.Sheet, aui.AuiPaneInfo().Name("Data").CenterPane())
310 #self.nb.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnCloseTab)
311 self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnCloseTab)
312 self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
313 # add the toolbars to the manager
315 #self._mgr.AddPane(tb1, wx.aui.AuiPaneInfo().
316 # Name("tb1").Caption("Fichiers").
317 # ToolbarPane().Top().
318 # LeftDockable(False).RightDockable(False))
319 self._mgr.AddPane(tb1, aui.AuiPaneInfo().
320 Name("tb1").Caption("Fichiers").
322 LeftDockable(True).RightDockable(False))
324 self.ShowAPane("Intro_Text")
325 self._mgr.GetPane("lefttree").Show()
326 self._mgr.GetPane("classif_tb").Hide()
327 # "commit" all changes made to FrameManager
330 # Show How To Use The Closing Panes Event
331 ##################################################################
332 self.Bind(wx.EVT_MENU, self.OnAcceuil, id=ID_ACCEUIL)
333 self.Bind(wx.EVT_MENU, self.OnViewData, id=ID_VIEWDATA)
334 self.Bind(wx.EVT_MENU, self.ShowTab, id=ID_RESULT)
335 self.Bind(wx.EVT_MENU, self.OnOpenData, id=ID_OpenData)
336 self.Bind(wx.EVT_MENU, self.OnOpenText, id=ID_OpenText)
337 self.Bind(wx.EVT_MENU, self.OnOpenAnalyse, id=ID_OnOpenAnalyse)
338 self.Bind(wx.EVT_MENU, self.import_factiva, id= ID_Import)
339 self.Bind(wx.EVT_MENU, self.OnFreq, id=ID_Freq)
340 self.Bind(wx.EVT_MENU, self.OnChi2, id=ID_Chi2)
341 self.Bind(wx.EVT_MENU, self.OnStudent, id=ID_Student)
342 self.Bind(wx.EVT_MENU, self.OnCHDSIM, id=ID_CHDSIM)
343 self.Bind(wx.EVT_MENU, self.OnCHDAlceste, id=ID_CHDAlceste)
344 self.Bind(wx.EVT_MENU, self.OnAFCM, id=ID_AFCM)
345 self.Bind(wx.EVT_MENU, self.OnRCode, id=ID_RCODE)
346 self.Bind(wx.EVT_MENU, self.OnCheckcorpus, id = ID_CHECKCORPUS)
347 self.Bind(wx.EVT_MENU, self.OnTextStat, id=ID_TEXTSTAT)
348 self.Bind(wx.EVT_MENU, self.OnTextSpec, id=ID_ASLEX)
349 self.Bind(wx.EVT_MENU, self.OnTextAfcm, id=ID_TEXTAFCM)
350 self.Bind(wx.EVT_MENU, self.OnTextAlceste, id=ID_TEXTALCESTE)
351 self.Bind(wx.EVT_MENU, self.OnPamSimple, id=ID_TEXTPAM)
352 self.Bind(wx.EVT_MENU, self.OnSimiTxt, id=ID_SimiTxt)
353 self.Bind(wx.EVT_MENU, self.OnWordCloud, id=ID_WC)
354 self.Bind(wx.EVT_MENU, self.OnSimi, id=ID_SIMI)
355 self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
356 self.Bind(wx.EVT_MENU, self.OnSaveTabAs, id=ID_SaveTab)
357 self.Bind(wx.EVT_MENU, self.OnAbout, id=wx.ID_ABOUT)
358 self.Bind(wx.EVT_MENU, self.OnHelp, id=wx.ID_HELP)
359 self.Bind(wx.EVT_MENU, self.OnPref, id=wx.ID_PREFERENCES)
360 self.Bind(wx.EVT_CLOSE, self.OnClose)
361 ##################################################################
362 flags = self._mgr.GetAGWFlags()
363 #flags &= ~wx.aui.AUI_MGR_TRANSPARENT_HINT
364 #flags &= ~wx.aui.AUI_MGR_VENETIAN_BLINDS_HINT
365 #flags &= ~wx.aui.AUI_MGR_RECTANGLE_HINT
366 flags &= ~(aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING)
367 self._mgr.SetAGWFlags(self._mgr.GetAGWFlags() ^ (aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING))
368 self._mgr.GetArtProvider().SetMetric(aui.AUI_DOCKART_GRADIENT_TYPE, aui.AUI_GRADIENT_HORIZONTAL)
369 self.GetDockArt().SetColor(aui.AUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR, "#00FFF9")
372 self._icon = wx.Icon(os.path.join(ImagePath, "iraicone.ico"), wx.BITMAP_TYPE_ICO)
373 self.SetIcon(self._icon)
374 ##########################
376 self.input_path = [False]
377 self.TEMPDIR = tempfile.mkdtemp('iramuteq')
378 self.FileTabList = []
384 self.g_header = False
391 self.SysEncoding = sys.getdefaultencoding()
392 self.syscoding = sys.getdefaultencoding()
393 #print 'SysEncoding',self.SysEncoding
394 if self.SysEncoding == 'mac-roman' : self.SysEncoding = 'MacRoman'
398 self.pref.read(self.ConfigPath['preferences'])
407 self.pref.read(self.ConfigPath['preferences'])
409 #configuration des chemins de R
410 self.PathPath = ConfigParser()
411 self.PathPath.read(ConfigPath['path'])
413 if not CheckRPath(self.PathPath) :
414 if sys.platform == 'win32':
415 BestRPath = FindRPAthWin32()
417 BestRPath = FindRPathNix()
419 self.PathPath.set('PATHS', 'rpath', BestRPath)
420 with open(ConfigPath['path'], 'w') as f :
421 self.PathPath.write(f)
425 self.RPath = self.PathPath.get('PATHS', 'rpath')
428 if not RLibsAreInstalled(self) :
432 Le chemin de l'executable de R n'a pas été trouvé.
433 Si R n'est pas installé, vous devez l'installer (http://www.r-project.org/).
434 Si R n'est pas installé dans le répertoire par défaut
435 (C:\Program Files\R\R-2.x.x\R.exe sous windows ou /usr/bin/R sous linux ou Mac Os X)
436 vous devez signaler le chemin de l'éxecutable de R dans les préférences."""
437 dlg = wx.MessageDialog(self, msg, u"Problème de configuration", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
439 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
443 if sys.platform == 'darwin':
444 self.Rapp = self.PathPath.get('PATHS', 'rapp')
445 RappOk = CheckRapp(self.Rapp)
449 self.sound = self.pref.getboolean('iramuteq', 'sound')
450 self.check_update = self.pref.getboolean('iramuteq', 'checkupdate')
451 self.version = ConfigGlob.get('DEFAULT', 'version')
454 ##############################################################@
455 self.DisEnSaveTabAs(False)
456 self.ShowMenu(_("View"), False)
457 self.ShowMenu(_("Spreadsheet analysis"), False)
458 self.ShowMenu(_("Text analysis"), False)
462 def OnVerif(self, evt) :
463 pack = CheckRPackages(self)
465 dlg = wx.MessageDialog(self, u"Installation OK", u"Installation", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
467 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
470 #FIXME marche pas sous mac ?
471 def DisEnSaveTabAs(self, DISEN):
473 file_menu = self.mb.GetMenu(0)
474 items = file_menu.GetMenuItems()
475 items[4].Enable(DISEN)
477 def ShowMenu(self, menu, Show=True):
478 menu_pos = self.mb.FindMenu(menu)
479 self.mb.EnableTop(menu_pos, Show)
480 self.mb.UpdateMenus()
483 #--------------------------------------------------------------------
484 def OnClose(self, event):
486 with open(self.ConfigPath['path'], 'w') as f :
487 self.PathPath.write(f)
488 if self.DictTab != {} :
489 savestates = [self.DictTab[item][0] for item in self.DictTab]
490 if False in savestates :
491 notsave = [item for item in self.DictTab if self.DictTab[item][0] == False]
493 Certains résultats ne sont pas enregistrés.
494 Voulez-vous fermer quand même ?"""
495 dlg = wx.MessageDialog(self, msg, "Sauvegarde",
496 wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
498 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
503 for item in notsave :
504 for tmpfile in self.DictTab[item][1:] :
506 print 'remove : ' + tmpfile
519 #if sys.platform == 'win32' :
520 # os.system("taskkill /im iramuteq.exe /f")
521 # print 'meurtre de process'
523 def OnOpenData(self, event):
524 inputname, self.input_path = OnOpen(self, "Data")
526 self.filename = self.input_path[0]
527 self.tableau = Tableau(self,os.path.abspath(self.input_path[0]))
528 get_table_param(self, self.input_path[0])
529 self.tableau.make_content()
530 self.tableau.show_tab()
532 def OnOpenAnalyse(self, event):
533 self.AnalysePath = OnOpen(self, "Analyse")
534 OpenAnalyse(self, self.AnalysePath[1][0], True)
535 self.ShowMenu(_("View"))
537 def OnOpenText(self, event):
538 inputname, self.input_path = OnOpen(self, "Texte")
539 self.filename = self.input_path[0]
543 def OnViewData(self, event):
546 if self.type == "Data":
547 if not self.DataPop :
548 self.Sheet.Populate(self.content)
551 self.ShowAPane(u"Data")
552 elif self.type == "Texte" or self.type == 'Analyse' :
553 if not self.DataTxt :
554 self.text_ctrl_txt.Clear()
555 self.text_ctrl_txt.write(self.content)
556 self.text_ctrl_txt.ShowPosition(0)
559 self.ShowAPane(u"Text")
563 #dial = EncodeDialog(self)
564 dlg = wx.ProgressDialog("Ouverture...",
565 "Veuillez patienter...",
568 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
571 builder = Builder(self, dlg)
572 if builder.res == wx.ID_OK :
573 corpus = builder.doanalyse()
574 self.history.add(corpus.parametres)
575 self.tree.OnItemAppend(corpus.parametres)
576 OpenAnalyse(self, corpus.parametres)
577 #self.content = DoConf().totext(corpus.parametres)
578 # parametres = DoConf(os.path.join(UserConfigPath,'corpus.cfg')).getoptions('corpus')
579 # parametres['originalpath'] = self.filename
581 # parametres['pathout'] = PathOut(self.filename, 'corpus').dirout
582 # dial = CorpusPref(self, parametres)
583 # dial.CenterOnParent()
584 # dial.txtpath.SetLabel(self.filename)
585 # res = dial.ShowModal()
586 # parametres = dial.doparametres()
588 # ReadLexique(self, lang = parametres['lang'])
589 # self.expressions = ReadDicoAsDico(self.DictPath.get(parametres['lang'], 'french_exp'))
590 # corpus = BuildFromAlceste(self.filename, parametres, self.lexique, self.expressions).corpus
591 #self.corpus_encodage = dial.encodages[dial.list_encodages.GetSelection()][0]
592 #self.corpus_lang = dial.langues[dial.choice_dict.GetSelection()]
594 keepGoing = dlg.Update(count, u"Lecture du fichier")
596 # with codecs.open(self.filename, 'rU', self.corpus_encodage) as f:
597 # self.content = f.read()
598 # #self.content = self.content.replace('\r','\n')
599 # except UnicodeDecodeError :
600 # msg = u"Ce fichier ne semble pas être encodé en %s" % self.corpus_encodage
601 # dial = wx.MessageDialog(self, msg, u"Problème d'encodage", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
602 # dial.CenterOnParent()
603 # res = dial.ShowModal()
606 self.ShowMenu(_("View"))
607 self.ShowMenu(_("Text analysis"))
608 self.ShowMenu(_(u"Spreadsheet analysis"), False)
613 keepGoing = dlg.Update(count, u"Chargement du dictionnaire")
615 #self.OnViewData(wx.EVT_BUTTON)
617 def OnExit(self, event):
620 def OnAbout(self, event):
621 info = wx.AboutDialogInfo()
622 info.Name = ConfigGlob.get('DEFAULT', 'name')
623 info.Version = ConfigGlob.get('DEFAULT', 'version')
624 info.Copyright = ConfigGlob.get('DEFAULT', 'copyright')
625 info.Description = u"""
626 Interface de R pour les Analyses Multidimensionnelles
627 de Textes et de Questionnaires
630 construit avec des logiciels libres.
636 info.WebSite = ("http://www.iramuteq.org", u"Site web IRaMuTeQ")
637 dev = ConfigGlob.get('DEFAULT', 'dev').split(';')
638 info.Developers = dev
639 info.License = u"""Iramuteq est un logiciel libre ; vous pouvez le diffuser et/ou le modifier
640 suivant les termes de la Licence Publique Générale GNU telle que publiée
641 par la Free Software Foundation ; soit la version 2 de cette licence,
642 soit (à votre convenance) une version ultérieure.
644 Iramuteq est diffusé dans l'espoir qu'il sera utile,
645 mais SANS AUCUNE GARANTIE ; sans même une garantie implicite
646 de COMMERCIALISATION ou d'ADÉQUATION À UN USAGE PARTICULIER.
647 Voyez la Licence Publique Générale GNU pour plus de détails.
649 Vous devriez avoir reçu une copie de la Licence Publique Générale GNU
650 avec Iramuteq ; sinon, veuillez écrire à la Free Software Foundation,
651 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, États-Unis."""
654 def GetDockArt(self):
655 return self._mgr.GetArtProvider()
660 def OnPageChanged(self, event) :
661 new = event.GetSelection()
662 nobject = event.GetEventObject()
663 parent = nobject.GetParent()
664 if isinstance(parent, IraFrame) :
665 npage = self.nb.GetPage(new)
666 self.tree.GiveFocus(uuid=npage.parametres['uuid'])
668 def OnCloseTab(self, evt):
669 log.info('Closing tab %s' % str(evt.GetEventObject()))
670 ctrl = evt.GetEventObject()
671 if isinstance(ctrl.GetParent(), aui.AuiNotebook) or isinstance(ctrl.GetParent(), wx.Panel):
675 page = self.nb.GetPage(self.nb.GetSelection())
676 if 'parametres' in dir(page) :
677 self.history.rmtab(page.parametres)
678 self.tree.CloseItem(uuid = page.parametres['uuid'])
679 TabTitle = self.nb.GetPageText(self.nb.GetSelection())
680 if self.DictTab != {} :
681 if TabTitle in self.DictTab :
682 ListFile=self.DictTab[TabTitle]
683 if False in ListFile:
685 Certains résultats ne sont pas enregistrer.
686 Voulez-vous fermer quand même ?"""
687 dlg = wx.MessageDialog(self, msg, "Sauvegarde",wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
690 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
695 for f in ListFile[1:] :
700 elif True in ListFile :
703 del self.DictTab[TabTitle]
708 if self.nb.GetPageCount() == 1 and remove and not notebook :
712 def LastTabClose(self) :
713 if self.nb.GetPageCount() == 1 :
714 self.DisEnSaveTabAs(False)
716 self.ShowAPane("Text")
718 self.ShowAPane("Data")
720 self.ShowAPane("Intro_Text")
722 def OnSaveTabAs(self, event):
723 SelectTab = self.nb.GetSelection()
724 TabTitle = self.nb.GetPageText(SelectTab)
725 FileToSave = self.DictTab[TabTitle]
728 self, message="Enregistrer sous...", defaultDir=os.getcwd(),
729 defaultFile="resultat.html", wildcard="Tous les fichiers|*", style=wx.SAVE | wx.OVERWRITE_PROMPT
731 dlg.SetFilterIndex(2)
734 if dlg.ShowModal() == wx.ID_OK:
736 Dirname = os.path.dirname(Path)
737 Filename = dlg.GetFilename()
742 shutil.copyfile(FileToSave[-1], Path)
743 os.remove(FileToSave[len(FileToSave) - 1])
744 NewListFile.append(True)
745 NewListFile.append(Path)
746 for f in FileToSave[1:-1] :
747 Fileout = os.path.join(Dirname, os.path.basename(f))
748 shutil.copyfile(f, Fileout)
749 NewListFile.append(Fileout)
752 self.DictTab[TabText] = NewListFile
753 del self.DictTab[TabTitle]
754 self.nb.SetPageText(SelectTab, TabText)
756 def GetStartPosition(self):
760 pt = self.ClientToScreen(wx.Point(0, 0))
762 return wx.Point(pt.x + x, pt.y + x)
764 def ShowAPane(self, panel):
765 for pane in self._mgr.GetAllPanes() :
766 if not pane.IsToolbar() and pane.name != 'lefttree':
768 self._mgr.GetPane(panel).Show()
771 def OnAcceuil(self, event):
772 self.ShowAPane(u"Intro_Text")
775 # def OnCreateTab(self, event):
776 # if not self._mgr.GetPane("Tab_content").name == "Tab_content":
777 # self._mgr.AddPane(self.CreateTabCtrl(), aui.AuiPaneInfo().
778 # Name("Tab_content").
780 # self._mgr.GetPane("Intro_Text").Hide()
781 # self._mgr.GetPane("Tab_content").Show()
782 # self.ctrl.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnCloseTab)
784 # page = wx.TextCtrl(self, -1, str(text), style=wx.TE_MULTILINE)
785 # self.ctrl.AddPage(page, "qsdqsd")
786 # self.ctrl.SetSelection(self.ctrl.GetPageCount() - 1)
790 def CreateHTMLCtrl(self):
791 ctrl = wx.html.HtmlWindow(self, -1, wx.DefaultPosition, wx.Size(400, 300))
792 if "gtk2" in wx.PlatformInfo:
793 ctrl.SetStandardFonts()
794 ctrl.SetPage(u"text")
797 def ShowTab(self, evt):
798 self.ShowAPane("Tab_content")
800 ################################################################
802 ################################################################
804 def OnFreq(self, event):
810 def OnChi2(self, event):
812 # print('PAS DE DEBUG SUR CHI2')
813 chi = ChiSquare(self)
817 def OnStudent(self, event):
823 def OnRCode(self, event):
829 def OnCHDSIM(self, event):
831 # print 'ATTENTION!!!!'
832 chdsim = ChdCluster(self)
833 if chdsim.val == wx.ID_OK:
838 def OnCHDAlceste(self, event):
840 # print('PLUS DE BUG SUR ALCESTE QUESTIONNAIRE')
841 self.quest = AnalyseQuest(self)
842 if self.quest.val == wx.ID_OK:
847 def OnSimiTxt(self, evt, corpus = None) :
848 print 'PLUS DE BUG SUR SIMITXT'
850 #self.Text = SimiTxt(self)
851 self.Text = SimiTxt(self, corpus, parametres = {'type': 'simitxt'}, dlg = progressbar(self, 3))
852 if self.Text.val == wx.ID_OK :
857 def OnWordCloud(self, evt, corpus = None) :
858 # print 'PLUS DE BUG SUR WORDCLOUD'
860 self.Text = WordCloud(self, corpus, parametres = {'type' : 'wordcloud'}, dlg = progressbar(self, 3))
861 if self.Text.val == wx.ID_OK :
867 def OnAFCM(self, event):
873 def OnCheckcorpus(self, evt):
879 def OnTextStat(self, event, corpus = None):
880 print 'PAS DE BUG SUR TEXT STAT'
882 self.Text = Stat(self, corpus, parametres = {'type': 'stat'}, dlg = progressbar(self, 7))
884 if self.Text.val == wx.ID_OK :
889 def OnTextSpec(self, event, corpus = None):
891 #self.Text = AsLexico(self)
892 print('ATTENTION : PLUS DE BUG SUR LEXICO')
893 self.Text = Lexico(self, corpus, parametres = {'type' : 'spec'}, dlg = progressbar(self, 3))
894 if self.Text.val == wx.ID_OK :
899 def OnTextAfcm(self, event):
906 def import_factiva(self,event):
912 def OnTextAlceste(self, event, corpus = None):
914 print('ATTENTION : PLUS DE BUG SUR ALCESTE')
915 #RunAnalyse(self, corpus, Alceste, OptAlceste)
916 self.Text = Alceste(self, corpus, parametres = {'type': 'alceste'}, dlg = progressbar(self,6))
917 #self.history.addtab(self.Text.parametres)
918 #OpenAnalyse(self, self.Text.parametres['ira'])
919 if self.Text.val == wx.ID_OK:
924 def OnPamSimple(self, event):
926 self.Text = PamTxt(self)
927 if self.Text.val == wx.ID_OK:
932 def OnSimi(self,evt):
934 #print 'ATTENTION !!!! VERGES'
935 self.res = DoSimi(self, param = None)
936 #self.res = Verges(self)
937 if self.res.val == wx.ID_OK :
941 #################################################################
943 def OnHelp(self, event):
944 webbrowser.open('http://www.iramuteq.org/documentation')
946 def OnPref(self, event):
947 dlg = PrefDialog(self)
949 self.val = dlg.ShowModal()
952 if self.check_update:
957 #CheckRPackages(self)
959 def OnOpenFromCmdl(self):
961 if options.filename :
962 if os.path.exists(options.filename):
963 self.filename = os.path.abspath(options.filename)
967 if os.path.exists(os.path.realpath(args[0])):
968 self.filename = os.path.abspath(os.path.realpath(args[0]))
974 if os.path.splitext(self.filename)[1] in ['.csv', '.xls', '.ods']:
975 self.tableau = Tableau(self, self.filename)
976 get_table_param(self, self.filename)
977 self.tableau.make_content()
978 self.tableau.show_tab()
979 #open_data(self, self.filename)
980 elif os.path.splitext(self.filename)[1] == '.txt':
982 elif os.path.splitext(self.filename)[1] == '.ira' :
983 #self.corpus = Corpus(self)
984 #self.Text = OpenAnalyse(self, self.filename)
985 OpenAnalyse(self, self.filename)
987 print 'ce fichier n\'existe pas'
991 class IntroPanel(wx.Panel):
992 def __init__(self, parent):
993 wx.Panel.__init__(self, parent)
994 #col = randint(0, 100)
996 bckgrdcolor = wx.Colour(col, col, col)
997 self.SetBackgroundColour(bckgrdcolor)
998 txtcolour = wx.Colour(250, 250, 250)
999 linkcolor = wx.Colour(255, 0, 0)
1000 sizer1 = wx.BoxSizer(wx.VERTICAL)
1001 sizer2 = wx.BoxSizer(wx.VERTICAL)
1002 sizer3 = wx.BoxSizer(wx.HORIZONTAL)
1003 sizer4 = wx.BoxSizer(wx.VERTICAL)
1004 sizer5 = wx.BoxSizer(wx.HORIZONTAL)
1005 grid_sizer_1 = wx.FlexGridSizer(1, 4, 0, 0)
1006 grid_sizer_3 = wx.FlexGridSizer(1, 4, 0, 0)
1007 grid_sizer_2 = wx.FlexGridSizer(1, 3, 0, 0)
1008 PanelPres = wx.Panel(self)
1009 PanelPres.SetBackgroundColour(bckgrdcolor)
1010 label_1 = wx.StaticText(self, -1, u"IRaMuTeQ", size=(-1, -1))
1011 label_1.SetFont(wx.Font(46, wx.TELETYPE, wx.NORMAL, wx.BOLD, 0, "Purisa"))
1012 label_1.SetForegroundColour(wx.RED)
1013 label2 = wx.StaticText(PanelPres, -1 , u'\nVersion ' + ConfigGlob.get('DEFAULT', 'version') + '\n')
1014 label2.SetForegroundColour(txtcolour)
1015 label2.SetBackgroundColour(bckgrdcolor)
1016 #label3 = wx.StaticText(PanelPres, -1 , u'Equipe ')
1017 #label3.SetForegroundColour(txtcolour)
1018 #label3.SetBackgroundColour(bckgrdcolor)
1019 self.hyper2 = hl.HyperLinkCtrl(PanelPres, wx.ID_ANY, u"REPERE", URL="http://repere.no-ip.org/")
1020 self.hyper2.SetColours(linkcolor, linkcolor, "RED")
1021 self.hyper2.SetBackgroundColour(bckgrdcolor)
1022 self.hyper2.EnableRollover(True)
1023 self.hyper2.SetUnderlines(False, False, True)
1024 self.hyper2.SetBold(True)
1025 self.hyper2.UpdateLink()
1026 label_lerass = wx.StaticText(PanelPres, -1, u'Laboratoire ')
1027 label_lerass.SetForegroundColour(txtcolour)
1028 label_lerass.SetBackgroundColour(bckgrdcolor)
1029 self.hyper_lerass = hl.HyperLinkCtrl(PanelPres, -1, u'LERASS', URL="http://www.lerass.com")
1030 self.hyper_lerass.SetColours(linkcolor, linkcolor, "RED")
1031 self.hyper_lerass.SetBackgroundColour(bckgrdcolor)
1032 self.hyper_lerass.EnableRollover(True)
1033 self.hyper_lerass.SetUnderlines(False, False, True)
1034 self.hyper_lerass.SetBold(True)
1035 self.hyper_lerass.UpdateLink()
1036 blank = wx.StaticText(PanelPres, -1, u'\n')
1037 blank1 = wx.StaticText(PanelPres, -1, u'\n')
1038 labellicence = wx.StaticText(PanelPres, -1, u'Licence GNU GPL')
1039 labellicence.SetForegroundColour(txtcolour)
1040 labellicence.SetBackgroundColour(bckgrdcolor)
1041 labelcopy = wx.StaticText(PanelPres, -1, ConfigGlob.get('DEFAULT', 'copyright'))
1042 labelcopy.SetForegroundColour(txtcolour)
1043 labelcopy.SetBackgroundColour(bckgrdcolor)
1044 python_img = wx.Image(os.path.join(ImagePath,'python-logo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1045 r_img = wx.Image(os.path.join(ImagePath,'Rlogo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1046 lexique_img = wx.Image(os.path.join(ImagePath,'LexTexte4.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1047 but_python = wx.BitmapButton(self, -1, python_img)
1048 but_lexique = wx.BitmapButton(self, -1, lexique_img)
1049 but_r = wx.BitmapButton(self, -1, r_img)
1050 self.Bind(wx.EVT_BUTTON, self.OnPython, but_python)
1051 self.Bind(wx.EVT_BUTTON, self.OnLexique, but_lexique)
1052 self.Bind(wx.EVT_BUTTON, self.OnR, but_r)
1055 #grid_sizer_1.Add(label3, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1056 grid_sizer_1.Add(self.hyper2, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1057 grid_sizer_3.Add(label_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1058 grid_sizer_3.Add(self.hyper_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1059 sizer4.Add(label_1, 0, wx.ALIGN_CENTER, 5)
1060 sizer2.Add(label2, 0, wx.ALIGN_CENTER, 5)
1061 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1062 sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1063 sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1064 sizer2.Add(grid_sizer_3, 0, wx.ALIGN_CENTER, 5)
1065 sizer2.Add(wx.StaticText(PanelPres, -1, u' '), 0, wx.ALIGN_CENTER, 5)
1066 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1067 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1068 sizer2.Add(grid_sizer_1, 0, wx.ALIGN_CENTER, 5)
1069 sizer2.Add(labellicence, 0, wx.ALIGN_CENTER, 5)
1070 sizer2.Add(labelcopy, 0, wx.ALIGN_CENTER, 5)
1071 sizer1.Add(sizer4, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1072 PanelPres.SetSizer(sizer2)
1073 sizer5.Add(blank, 1, wx.EXPAND | wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 2)
1074 sizer5.Add(PanelPres, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1075 sizer5.Add(blank1, 1, wx.ALIGN_CENTER_HORIZONTAL,2)
1076 grid_sizer_2.Add(but_python, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1077 grid_sizer_2.Add(but_lexique, 1,wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1078 grid_sizer_2.Add(but_r, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1080 sizer1.Add(sizer5, 3, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 1)
1081 sizer1.Add(grid_sizer_2, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
1082 self.SetSizer(sizer1)
1085 def OnPython(self,evt):
1086 webbrowser.open('http://www.python.org')
1088 def OnLexique(self,evt):
1089 webbrowser.open('http://www.lexique.org')
1092 webbrowser.open('http://www.r-project.org')
1094 class MySplashScreen(wx.SplashScreen):
1096 bmp = wx.Image(os.path.join(ImagePath, 'splash.png')).ConvertToBitmap()
1097 wx.SplashScreen.__init__(self, bmp,
1098 wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
1100 self.Bind(wx.EVT_CLOSE, self.OnClose)
1101 self.fc = wx.FutureCall(1500, self.ShowMain)
1103 def OnClose(self, evt):
1107 if self.fc.IsRunning():
1112 frame = IraFrame(None, -1, "IRaMuTeQ " + ConfigGlob.get('DEFAULT', 'version'), size=(950, 650))
1115 frame.OnOpenFromCmdl()
1116 # if self.fc.IsRunning():
1118 #wx.CallAfter(frame.ShowTip)
1120 class MyApp(wx.App):
1123 Create and show the splash screen. It will then create and show
1124 the main frame when it is time to do so.
1127 wx.SystemOptions.SetOptionInt("mac.window-plain-transition", 1)
1128 self.SetAppName("Iramuteq")
1129 splash = MySplashScreen()
1137 if __name__ == '__main__':