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()
23 from random import randint
24 from ConfigParser import *
28 #------------------------------------
31 #import wx.lib.agw.aui as aui
35 import wx.lib.hyperlink as hl
36 #------------------------------------
37 from functions import BugReport, PlaySound, ReadLexique, History, DoConf, ReadDicoAsDico, progressbar
38 from checkversion import NewVersion
39 from guifunct import *
40 from tableau import Tableau
41 from dialog import PrefDialog, EncodeDialog, CorpusPref
42 from tabfrequence import Frequences
43 from tabchi2 import ChiSquare
44 #from tabstudent import MakeStudent
45 from tabchddist import ChdCluster
46 from tabafcm import DoAFCM
47 from tabchdalc import AnalyseQuest
48 from tabsimi import DoSimi
49 from tabrsimple import InputText
50 from tabverges import Verges
51 #from textafcuci import AfcUci
52 #from textchdalc import AnalyseAlceste
53 from analysetxt import Alceste
54 from textdist import PamTxt
55 from textstat import Stat
56 from textaslexico import Lexico
57 from textsimi import SimiTxt, SimiFromCluster
58 from textwordcloud import WordCloud
59 from profile_segment import ProfileSegment
60 from textcheckcorpus import checkcorpus
61 from openanalyse import OpenAnalyse
62 from corpusNG import BuildFromAlceste, Builder
63 from sheet import MySheet
64 from checkinstall import CreateIraDirectory, CheckRPath, FindRPAthWin32, FindRPathNix, CheckRPackages, IsNew, UpgradeConf, CopyConf, RLibsAreInstalled
65 from chemins import ConstructRscriptsPath, ConstructConfigPath, ConstructDicoPath, ConstructGlobalPath, PathOut
66 from parse_factiva_xml import ImportFactiva
68 from tree import LeftTree
69 ##########################################################
70 ID_OpenData = wx.NewId()
71 ID_Import = wx.NewId()
72 ID_OpenText = wx.NewId()
73 ID_OnOpenAnalyse = wx.NewId()
76 ID_Student = wx.NewId()
77 ID_CHDSIM = wx.NewId()
78 ID_CHDAlceste = wx.NewId()
79 ID_TEXTAFCM = wx.NewId()
80 ID_TEXTSTAT = wx.NewId()
82 ID_TEXTALCESTE = wx.NewId()
83 ID_TEXTPAM = wx.NewId()
84 ID_CHECKCORPUS = wx.NewId()
85 ID_Tabcontent = wx.NewId()
88 ID_CloseTab = wx.NewId()
89 ID_SaveTab = wx.NewId()
90 ID_CreateText = wx.NewId()
91 ID_ACCEUIL = wx.NewId()
92 ID_RESULT = wx.NewId()
93 ID_VIEWDATA = wx.NewId()
94 ID_HTMLcontent = wx.NewId()
95 ID_SimiTxt = wx.NewId()
96 ##########################################################
97 #elements de configuration
98 ##########################################################
100 if sys.platform == 'darwin' :
101 sys.setdefaultencoding('utf-8')
102 wx.SetDefaultPyEncoding('utf-8')
104 sys.setdefaultencoding(locale.getpreferredencoding())
105 #chemin de l'application
106 AppliPath = os.path.abspath(os.path.dirname(os.path.realpath(sys.argv[0])))
108 ImagePath = os.path.join(AppliPath, 'images')
109 #configuration generale
110 DictConfigPath = ConstructGlobalPath(AppliPath)
111 ConfigGlob = ConfigParser()
112 ConfigGlob.read(DictConfigPath['global'])
113 #repertoire de l'utilisateur
114 if os.getenv('HOME') != None:
115 user_home = os.getenv('HOME')
117 user_home = os.getenv('HOMEPATH')
118 UserConfigPath = os.path.abspath(os.path.join(user_home, '.iramuteq'))
119 #Si pas de fichiers de config utilisateur, on cree le repertoire
120 CreateIraDirectory(UserConfigPath, AppliPath)
121 #fichiers log pour windows (py2exe)
122 log = logging.getLogger('iramuteq')
123 fh = logging.FileHandler(os.path.join(UserConfigPath,'stdout.log'))
124 ch = logging.StreamHandler()
125 formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
126 ch.setFormatter(formatter)
127 fh.setFormatter(formatter)
130 log.setLevel(logging.INFO)
133 class writer(object):
134 def write(self, data):
135 if data.strip() != '' :
136 log.info('BUG : %s' % data)
137 sys.stderr = writer()
138 ConfigPath = ConstructConfigPath(UserConfigPath)
139 #####################################################################
141 class IraFrame(wx.Frame):
142 def __init__(self, parent, id= -1, title="", pos=wx.DefaultPosition,
143 size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE |
146 log.info('Starting...')
147 wx.Frame.__init__(self, parent, id, title, pos, size, style)
149 self.AppliPath = AppliPath
150 self.images_path = os.path.join(AppliPath,'images')
151 self.UserConfigPath = UserConfigPath
152 self.RscriptsPath = ConstructRscriptsPath(AppliPath)
153 #self.DictPath = ConstructDicoPath(AppliPath)
154 self.DictPath = ConstructDicoPath(UserConfigPath)
155 self.ConfigGlob = ConfigGlob
156 self.ConfigPath = ConstructConfigPath(UserConfigPath)
157 self.pref = RawConfigParser()
158 #workaround for import problem
159 self.SimiFromCluster = SimiFromCluster
161 mylocale = wx.Locale(wx.LANGUAGE_FRENCH)
162 mylocale.AddCatalogLookupPathPrefix(os.path.join(AppliPath,'locale'))
163 mylocale.AddCatalog('iramuteq')
164 presLan_en = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['en'])
165 presLan_fr = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['fr_FR'])
169 # tell FrameManager to manage this frame
170 #self._mgr = wx.aui.AuiManager()
171 self._mgr = aui.AuiManager()
172 self._mgr.SetManagedWindow(self)
175 #--------------------------------------------------------------------------------
176 self.mb = wx.MenuBar()
178 file_menu = wx.Menu()
179 item = wx.MenuItem(file_menu, ID_OpenData, _(u"Open a matrix"), _(u"Open a matrix"))
180 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
181 file_menu.AppendItem(item)
183 item = wx.MenuItem(file_menu, ID_OpenText, _(u"Open a text corpora"), _(u"Open a text corpora"))
184 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
185 file_menu.AppendItem(item)
187 item = wx.MenuItem(file_menu, ID_OnOpenAnalyse, _(u"Open an analysis"), _("Open an analysis"))
188 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
189 file_menu.AppendItem(item)
192 menuFactiva = wx.Menu()
193 fact_from_xml = wx.MenuItem(menuFactiva, wx.ID_ANY, _(u"from xml"))
194 fact_from_mail = wx.MenuItem(menuFactiva, wx.ID_ANY, _(u"from mail"))
195 fact_from_txt = wx.MenuItem(menuFactiva, wx.ID_ANY, _(u"from copy/paste"))
196 menuFactiva.AppendItem(fact_from_xml)
197 menuFactiva.AppendItem(fact_from_mail)
198 menuFactiva.AppendItem(fact_from_txt)
200 file_menu.AppendMenu(-1, _(u"Import from factiva"), menuFactiva)
203 item = wx.MenuItem(file_menu, ID_SaveTab, _(u"Save tab as..."), _(u"Save tab as..."))
204 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_SAVE_AS))
206 file_menu.AppendItem(item)
208 file_menu.Append(wx.ID_EXIT, _(u"Exit"))
210 edit_menu = wx.Menu()
211 edit_menu.Append(wx.ID_PREFERENCES, '', _(u'Preferences'))
213 view_menu = wx.Menu()
214 view_menu.Append(ID_ACCEUIL, _(u"Home page"))
215 view_menu.Append(ID_VIEWDATA, _(u"Show data"))
216 view_menu.Append(ID_RESULT, _(u'Show results'))
217 #view_menu.AppendSeparator()
219 analyse_menu = wx.Menu()
220 analyse_menu.Append(ID_Freq, u"Fréquences")
221 analyse_menu.Append(ID_Chi2, u"Chi2")
222 #analyse_menu.Append(ID_Student, u"t de Student")
223 menu_classif = wx.Menu()
224 menu_classif.Append(ID_CHDAlceste, u"Méthode Alceste")
225 menu_classif.Append(ID_CHDSIM, u"Par matrice des distances")
226 analyse_menu.AppendMenu(-1, u"Classification", menu_classif)
227 analyse_menu.Append(ID_AFCM, u"AFCM")
228 analyse_menu.Append(ID_SIMI, u"Analyse de similitudes")
229 ID_RCODE = wx.NewId()
230 analyse_menu.Append(ID_RCODE, u"Code R...")
232 text_menu = wx.Menu()
233 text_menu.Append(ID_CHECKCORPUS, u"Vérifier le corpus")
234 text_menu.Append(ID_TEXTSTAT, u"Statistiques textuelles")
235 text_menu.Append(ID_ASLEX, u"Spécificités et AFC")
236 #text_menu.Append(ID_TEXTAFCM, u"AFC sur UCI / Vocabulaire")
237 menu_classiftxt = wx.Menu()
238 menu_classiftxt.Append(ID_TEXTALCESTE, u"Méthode Alceste")
239 menu_classiftxt.Append(ID_TEXTPAM, u"Par matrice des distances")
240 text_menu.AppendMenu(-1, u"Classification", menu_classiftxt)
241 text_menu.Append(ID_SimiTxt, u'Analyse de similitude')
243 text_menu.Append(ID_WC, u'Nuage de mots')
245 help_menu = wx.Menu()
246 help_menu.Append(wx.ID_ABOUT, u'À propos...')
247 help_menu.Append(wx.ID_HELP, u'Aide en ligne')
249 self.mb.Append(file_menu, _(u"File"))
250 self.mb.Append(edit_menu, _(u"Edition"))
251 self.mb.Append(view_menu, _(u"View"))
252 self.mb.Append(analyse_menu, _("Spreadsheet analysis"))
253 self.mb.Append(text_menu, _(u"Text analysis"))
254 self.mb.Append(help_menu, _(u"Help"))
256 self.SetMenuBar(self.mb)
257 #--------------------------------------------------------------------
258 self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
259 self.statusbar.SetStatusWidths([-2, -3])
260 self.statusbar.SetStatusText(u"Prêt", 0)
261 self.statusbar.SetStatusText(u"Bienvenue", 1)
263 # min size for the frame itself isn't completely done.
264 # see the end up FrameManager::Update() for the test
265 # code. For now, just hard code a frame minimum size
266 self.SetMinSize(wx.Size(400, 400))
268 # create some toolbars
269 tb1 = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
270 wx.TB_FLAT | wx.TB_NODIVIDER)
271 tb1.SetToolBitmapSize(wx.Size(16, 16))
272 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")
274 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")
278 #------------------------------------------------------------------------------------------------
280 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)
282 #self._mgr.AddPane(self.text_ctrl_txt, wx.aui.AuiPaneInfo().
283 # Name("Text").CenterPane())
284 self._mgr.AddPane(self.text_ctrl_txt, aui.AuiPaneInfo().
285 Name("Text").CenterPane())
286 #self._mgr.AddPane(IntroPanel(self), wx.aui.AuiPaneInfo().Name("Intro_Text").
288 self._mgr.AddPane(IntroPanel(self), aui.AuiPaneInfo().Name("Intro_Text").
290 #if not os.path.exists(os.path.join(UserConfigPath, 'history.db')) :
291 # with open(os.path.join(UserConfigPath, 'history.db'), 'w') as f :
293 self.history = History(os.path.join(UserConfigPath, 'history.db'))
294 self.tree = LeftTree(self)
295 self._mgr.AddPane(self.tree, aui.AuiPaneInfo().Name("lefttree").Caption("Navigateur").
296 Left().MinSize(wx.Size(200,500)).Layer(1).Position(1).CloseButton(False).MaximizeButton(True).
297 MinimizeButton(True))
299 #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)
300 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)
301 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
302 self.nb.SetAGWWindowStyleFlag(notebook_flags)
303 self.nb.SetArtProvider(aui.ChromeTabArt())
304 #self.nb.SetArtProvider(aui.VC8TabArt())
305 #self.nb.parent = self
306 #self._notebook_style = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.NO_BORDER
307 #self._mgr.AddPane(self.nb, wx.aui.AuiPaneInfo().
308 # Name("Tab_content").
310 self._mgr.AddPane(self.nb, aui.AuiPaneInfo().
313 self.Sheet = MySheet(self)
314 #self._mgr.AddPane(self.Sheet, wx.aui.AuiPaneInfo().Name("Data").CenterPane())
315 self._mgr.AddPane(self.Sheet, aui.AuiPaneInfo().Name("Data").CenterPane())
316 self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnCloseTab)
317 self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
318 # add the toolbars to the manager
320 #self._mgr.AddPane(tb1, wx.aui.AuiPaneInfo().
321 # Name("tb1").Caption("Fichiers").
322 # ToolbarPane().Top().
323 # LeftDockable(False).RightDockable(False))
324 self._mgr.AddPane(tb1, aui.AuiPaneInfo().
325 Name("tb1").Caption("Fichiers").
327 LeftDockable(True).RightDockable(False))
329 self.ShowAPane("Intro_Text")
330 self._mgr.GetPane("lefttree").Show()
331 self._mgr.GetPane("classif_tb").Hide()
332 # "commit" all changes made to FrameManager
335 # Show How To Use The Closing Panes Event
336 ##################################################################
337 self.Bind(wx.EVT_MENU, self.OnAcceuil, id=ID_ACCEUIL)
338 self.Bind(wx.EVT_MENU, self.OnViewData, id=ID_VIEWDATA)
339 self.Bind(wx.EVT_MENU, self.ShowTab, id=ID_RESULT)
340 self.Bind(wx.EVT_MENU, self.OnOpenData, id=ID_OpenData)
341 self.Bind(wx.EVT_MENU, self.OnOpenText, id=ID_OpenText)
342 self.Bind(wx.EVT_MENU, self.OnOpenAnalyse, id=ID_OnOpenAnalyse)
343 self.Bind(wx.EVT_MENU, self.import_factiva_xml, fact_from_xml)
344 self.Bind(wx.EVT_MENU, self.import_factiva_mail, fact_from_mail)
345 self.Bind(wx.EVT_MENU, self.import_factiva_txt, fact_from_txt)
346 self.Bind(wx.EVT_MENU, self.OnFreq, id=ID_Freq)
347 self.Bind(wx.EVT_MENU, self.OnChi2, id=ID_Chi2)
348 self.Bind(wx.EVT_MENU, self.OnStudent, id=ID_Student)
349 self.Bind(wx.EVT_MENU, self.OnCHDSIM, id=ID_CHDSIM)
350 self.Bind(wx.EVT_MENU, self.OnCHDAlceste, id=ID_CHDAlceste)
351 self.Bind(wx.EVT_MENU, self.OnAFCM, id=ID_AFCM)
352 self.Bind(wx.EVT_MENU, self.OnRCode, id=ID_RCODE)
353 self.Bind(wx.EVT_MENU, self.OnCheckcorpus, id = ID_CHECKCORPUS)
354 self.Bind(wx.EVT_MENU, self.OnTextStat, id=ID_TEXTSTAT)
355 self.Bind(wx.EVT_MENU, self.OnTextSpec, id=ID_ASLEX)
356 self.Bind(wx.EVT_MENU, self.OnTextAfcm, id=ID_TEXTAFCM)
357 self.Bind(wx.EVT_MENU, self.OnTextAlceste, id=ID_TEXTALCESTE)
358 self.Bind(wx.EVT_MENU, self.OnPamSimple, id=ID_TEXTPAM)
359 self.Bind(wx.EVT_MENU, self.OnSimiTxt, id=ID_SimiTxt)
360 self.Bind(wx.EVT_MENU, self.OnWordCloud, id=ID_WC)
361 self.Bind(wx.EVT_MENU, self.OnSimi, id=ID_SIMI)
362 self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
363 self.Bind(wx.EVT_MENU, self.OnSaveTabAs, id=ID_SaveTab)
364 self.Bind(wx.EVT_MENU, self.OnAbout, id=wx.ID_ABOUT)
365 self.Bind(wx.EVT_MENU, self.OnHelp, id=wx.ID_HELP)
366 self.Bind(wx.EVT_MENU, self.OnPref, id=wx.ID_PREFERENCES)
367 self.Bind(wx.EVT_CLOSE, self.OnClose)
368 ##################################################################
369 flags = self._mgr.GetAGWFlags()
370 #flags &= ~wx.aui.AUI_MGR_TRANSPARENT_HINT
371 #flags &= ~wx.aui.AUI_MGR_VENETIAN_BLINDS_HINT
372 #flags &= ~wx.aui.AUI_MGR_RECTANGLE_HINT
373 flags &= ~(aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING)
374 self._mgr.SetAGWFlags(self._mgr.GetAGWFlags() ^ (aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING))
375 self._mgr.GetArtProvider().SetMetric(aui.AUI_DOCKART_GRADIENT_TYPE, aui.AUI_GRADIENT_HORIZONTAL)
376 self.GetDockArt().SetColor(aui.AUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR, "#00FFF9")
379 self._icon = wx.Icon(os.path.join(ImagePath, "iraicone.ico"), wx.BITMAP_TYPE_ICO)
380 self.SetIcon(self._icon)
381 ##########################
383 self.input_path = [False]
384 self.TEMPDIR = tempfile.mkdtemp('iramuteq')
385 self.FileTabList = []
391 self.g_header = False
398 self.SysEncoding = sys.getdefaultencoding()
399 self.syscoding = sys.getdefaultencoding()
400 #print 'SysEncoding',self.SysEncoding
401 if self.SysEncoding == 'mac-roman' : self.SysEncoding = 'MacRoman'
405 self.pref.read(self.ConfigPath['preferences'])
414 self.pref.read(self.ConfigPath['preferences'])
416 #configuration des chemins de R
417 self.PathPath = ConfigParser()
418 self.PathPath.read(ConfigPath['path'])
420 if not CheckRPath(self.PathPath) :
421 if sys.platform == 'win32':
422 BestRPath = FindRPAthWin32()
424 BestRPath = FindRPathNix()
426 self.PathPath.set('PATHS', 'rpath', BestRPath)
427 with open(ConfigPath['path'], 'w') as f :
428 self.PathPath.write(f)
432 self.RPath = self.PathPath.get('PATHS', 'rpath')
435 if not RLibsAreInstalled(self) :
439 Le chemin de l'executable de R n'a pas été trouvé.
440 Si R n'est pas installé, vous devez l'installer (http://www.r-project.org/).
441 Si R n'est pas installé dans le répertoire par défaut
442 (souvent C:\Program Files\R\R-2.x.x\R.exe sous windows ou /usr/bin/R sous linux ou Mac Os X)
443 vous devez signaler le chemin de l'éxecutable de R dans les préférences."""
444 dlg = wx.MessageDialog(self, msg, u"Problème de configuration", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
446 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
452 self.sound = self.pref.getboolean('iramuteq', 'sound')
453 self.check_update = self.pref.getboolean('iramuteq', 'checkupdate')
454 self.version = ConfigGlob.get('DEFAULT', 'version')
457 ##############################################################@
458 self.DisEnSaveTabAs(False)
459 self.ShowMenu(_("View"), False)
460 self.ShowMenu(_("Spreadsheet analysis"), False)
461 self.ShowMenu(_("Text analysis"), False)
465 def OnVerif(self, evt) :
466 pack = CheckRPackages(self)
468 dlg = wx.MessageDialog(self, u"Installation OK", u"Installation", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
470 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
473 #FIXME marche pas sous mac ?
474 def DisEnSaveTabAs(self, DISEN):
476 file_menu = self.mb.GetMenu(0)
477 items = file_menu.GetMenuItems()
478 items[4].Enable(DISEN)
480 def ShowMenu(self, menu, Show=True):
481 menu_pos = self.mb.FindMenu(menu)
482 self.mb.EnableTop(menu_pos, Show)
483 self.mb.UpdateMenus()
486 #--------------------------------------------------------------------
487 def OnClose(self, event):
489 with open(self.ConfigPath['path'], 'w') as f :
490 self.PathPath.write(f)
491 if self.DictTab != {} :
492 savestates = [self.DictTab[item][0] for item in self.DictTab]
493 if False in savestates :
494 notsave = [item for item in self.DictTab if self.DictTab[item][0] == False]
496 Certains résultats ne sont pas enregistrés.
497 Voulez-vous fermer quand même ?"""
498 dlg = wx.MessageDialog(self, msg, "Sauvegarde",
499 wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
501 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
506 for item in notsave :
507 for tmpfile in self.DictTab[item][1:] :
509 print 'remove : ' + tmpfile
521 #if sys.platform == 'win32' :
522 # os.system("taskkill /im iramuteq.exe /f")
523 # print 'meurtre de process'
525 def OnOpenData(self, event):
526 inputname, self.input_path = OnOpen(self, "Data")
528 self.filename = self.input_path[0]
529 self.tableau = Tableau(self,os.path.abspath(self.input_path[0]))
530 get_table_param(self, self.input_path[0])
531 self.tableau.make_content()
532 self.tableau.show_tab()
534 def OnOpenAnalyse(self, event):
535 self.AnalysePath = OnOpen(self, "Analyse")
536 OpenAnalyse(self, self.AnalysePath[1][0], True)
537 self.ShowMenu(_("View"))
539 def OnOpenText(self, event):
540 inputname, self.input_path = OnOpen(self, "Texte")
541 self.filename = self.input_path[0]
545 def OnViewData(self, event):
548 if self.type == "Data":
549 if not self.DataPop :
550 self.Sheet.Populate(self.content)
553 self.ShowAPane(u"Data")
554 elif self.type == "Texte" or self.type == 'Analyse' :
555 if not self.DataTxt :
556 self.text_ctrl_txt.Clear()
557 self.text_ctrl_txt.write(self.content)
558 self.text_ctrl_txt.ShowPosition(0)
561 self.ShowAPane(u"Text")
565 #dial = EncodeDialog(self)
566 dlg = wx.ProgressDialog("Ouverture...",
567 "Veuillez patienter...",
570 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
573 builder = Builder(self, dlg)
574 if builder.res == wx.ID_OK :
576 corpus = builder.doanalyse()
577 self.history.add(corpus.parametres)
578 self.tree.OnItemAppend(corpus.parametres)
579 OpenAnalyse(self, corpus.parametres)
582 #self.content = DoConf().totext(corpus.parametres)
583 # parametres = DoConf(os.path.join(UserConfigPath,'corpus.cfg')).getoptions('corpus')
584 # parametres['originalpath'] = self.filename
586 # parametres['pathout'] = PathOut(self.filename, 'corpus').dirout
587 # dial = CorpusPref(self, parametres)
588 # dial.CenterOnParent()
589 # dial.txtpath.SetLabel(self.filename)
590 # res = dial.ShowModal()
591 # parametres = dial.doparametres()
593 # ReadLexique(self, lang = parametres['lang'])
594 # self.expressions = ReadDicoAsDico(self.DictPath.get(parametres['lang'], 'french_exp'))
595 # corpus = BuildFromAlceste(self.filename, parametres, self.lexique, self.expressions).corpus
596 #self.corpus_encodage = dial.encodages[dial.list_encodages.GetSelection()][0]
597 #self.corpus_lang = dial.langues[dial.choice_dict.GetSelection()]
600 keepGoing = dlg.Update(count, u"Lecture du fichier")
601 # msg = u"Ce fichier ne semble pas être encodé en %s" % self.corpus_encodage
602 # dial = wx.MessageDialog(self, msg, u"Problème d'encodage", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
603 # dial.CenterOnParent()
604 # res = dial.ShowModal()
607 self.ShowMenu(_("View"))
608 self.ShowMenu(_("Text analysis"))
609 self.ShowMenu(_(u"Spreadsheet analysis"), False)
614 keepGoing = dlg.Update(count, u"Chargement du dictionnaire")
616 #self.OnViewData(wx.EVT_BUTTON)
618 def OnExit(self, event):
621 def OnAbout(self, event):
622 info = wx.AboutDialogInfo()
623 info.Name = ConfigGlob.get('DEFAULT', 'name')
624 info.Version = ConfigGlob.get('DEFAULT', 'version')
625 info.Copyright = ConfigGlob.get('DEFAULT', 'copyright')
626 info.Description = u"""
627 Interface de R pour les Analyses Multidimensionnelles
628 de Textes et de Questionnaires
631 construit avec des logiciels libres.
637 info.WebSite = ("http://www.iramuteq.org", u"Site web IRaMuTeQ")
638 dev = ConfigGlob.get('DEFAULT', 'dev').split(';')
639 info.Developers = dev
640 info.License = u"""Iramuteq est un logiciel libre ; vous pouvez le diffuser et/ou le modifier
641 suivant les termes de la Licence Publique Générale GNU telle que publiée
642 par la Free Software Foundation ; soit la version 2 de cette licence,
643 soit (à votre convenance) une version ultérieure.
645 Iramuteq est diffusé dans l'espoir qu'il sera utile,
646 mais SANS AUCUNE GARANTIE ; sans même une garantie implicite
647 de COMMERCIALISATION ou d'ADÉQUATION À UN USAGE PARTICULIER.
648 Voyez la Licence Publique Générale GNU pour plus de détails.
650 Vous devriez avoir reçu une copie de la Licence Publique Générale GNU
651 avec Iramuteq ; sinon, veuillez écrire à la Free Software Foundation,
652 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, États-Unis."""
655 def GetDockArt(self):
656 return self._mgr.GetArtProvider()
661 def OnPageChanged(self, event) :
662 new = event.GetSelection()
663 nobject = event.GetEventObject()
664 parent = nobject.GetParent()
665 if isinstance(parent, IraFrame) :
666 npage = self.nb.GetPage(new)
667 self.tree.GiveFocus(uuid=npage.parametres['uuid'])
669 def OnCloseTab(self, evt):
670 #log.info('Closing tab %s' % str(evt.GetEventObject()))
671 ctrl = evt.GetEventObject()
672 if isinstance(ctrl.GetParent(), aui.AuiNotebook) or isinstance(ctrl.GetParent(), wx.Panel):
676 page = self.nb.GetPage(self.nb.GetSelection())
677 if 'parametres' in dir(page) and isinstance(ctrl.GetParent(), IraFrame) :
678 self.history.rmtab(page.parametres)
679 self.tree.CloseItem(uuid = page.parametres['uuid'])
680 TabTitle = self.nb.GetPageText(self.nb.GetSelection())
681 if self.DictTab != {} :
682 if TabTitle in self.DictTab :
683 ListFile=self.DictTab[TabTitle]
684 if False in ListFile:
686 Certains résultats ne sont pas enregistrer.
687 Voulez-vous fermer quand même ?"""
688 dlg = wx.MessageDialog(self, msg, "Sauvegarde",wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
691 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
696 for f in ListFile[1:] :
701 elif True in ListFile :
704 del self.DictTab[TabTitle]
709 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 CreateHTMLCtrl(self):
776 ctrl = wx.html.HtmlWindow(self, -1, wx.DefaultPosition, wx.Size(400, 300))
777 if "gtk2" in wx.PlatformInfo:
778 ctrl.SetStandardFonts()
779 ctrl.SetPage(u"text")
782 def ShowTab(self, evt):
783 self.ShowAPane("Tab_content")
785 ################################################################
787 ################################################################
789 def OnFreq(self, event):
795 def OnChi2(self, event):
797 # print('PAS DE DEBUG SUR CHI2')
798 chi = ChiSquare(self)
802 def OnStudent(self, event):
808 def OnRCode(self, event):
814 def OnCHDSIM(self, event):
816 # print 'ATTENTION!!!!'
817 chdsim = ChdCluster(self)
818 if chdsim.val == wx.ID_OK:
823 def OnCHDAlceste(self, event):
825 # print('PLUS DE BUG SUR ALCESTE QUESTIONNAIRE')
826 self.quest = AnalyseQuest(self)
827 if self.quest.val == wx.ID_OK:
832 def OnSimiTxt(self, evt, corpus = None) :
833 # print 'PLUS DE BUG SUR SIMITXT'
835 #self.Text = SimiTxt(self)
837 corpus = self.tree.getcorpus()
838 self.Text = SimiTxt(self, corpus, parametres = {'type': 'simitxt'}, dlg = progressbar(self, 3))
839 if self.Text.val == wx.ID_OK :
844 def OnWordCloud(self, evt, corpus = None) :
845 # print 'PLUS DE BUG SUR WORDCLOUD'
848 corpus = self.tree.getcorpus()
849 self.Text = WordCloud(self, corpus, parametres = {'type' : 'wordcloud'}, dlg = progressbar(self, 3))
850 if self.Text.val == wx.ID_OK :
856 def OnAFCM(self, event):
862 def OnCheckcorpus(self, evt):
868 def OnTextStat(self, event, corpus = None):
869 print 'PAS DE BUG SUR TEXT STAT'
872 corpus = self.tree.getcorpus()
873 self.Text = Stat(self, corpus, parametres = {'type': 'stat'}, dlg = progressbar(self, 7))
875 if self.Text.val == wx.ID_OK :
880 def OnTextSpec(self, event, corpus = None):
882 #self.Text = AsLexico(self)
883 print('ATTENTION : PLUS DE BUG SUR LEXICO')
885 corpus = self.tree.getcorpus()
886 self.Text = Lexico(self, corpus, parametres = {'type' : 'spec'}, dlg = progressbar(self, 3))
887 if self.Text.val == wx.ID_OK :
892 def OnTextAfcm(self, event):
899 def import_factiva_xml(self,event):
901 ImportFactiva(self, 'xml')
905 def import_factiva_mail(self, evt) :
907 ImportFactiva(self, 'mail')
911 def import_factiva_txt(self, evt) :
913 ImportFactiva(self, 'txt')
917 def OnTextAlceste(self, event, corpus = None):
919 #print('ATTENTION : PLUS DE BUG SUR ALCESTE')
920 #RunAnalyse(self, corpus, Alceste, OptAlceste)
922 corpus = self.tree.getcorpus()
923 self.Text = Alceste(self, corpus, parametres = {'type': 'alceste'}, dlg = progressbar(self,6))
924 if self.Text.val == wx.ID_OK:
929 def OnPamSimple(self, event):
931 self.Text = PamTxt(self)
932 if self.Text.val == wx.ID_OK:
937 def OnSimi(self,evt):
939 #print 'ATTENTION !!!! VERGES'
940 self.res = DoSimi(self, param = None)
941 #self.res = Verges(self)
942 if self.res.val == wx.ID_OK :
946 #################################################################
948 def OnHelp(self, event):
949 webbrowser.open('http://www.iramuteq.org/documentation')
951 def OnPref(self, event):
952 dlg = PrefDialog(self)
954 self.val = dlg.ShowModal()
957 if self.check_update:
962 #CheckRPackages(self)
964 def OnOpenFromCmdl(self):
966 if options.filename :
967 if os.path.exists(options.filename):
968 self.filename = os.path.abspath(options.filename)
972 if os.path.exists(os.path.realpath(args[0])):
973 self.filename = os.path.abspath(os.path.realpath(args[0]))
979 if os.path.splitext(self.filename)[1] in ['.csv', '.xls', '.ods']:
980 self.tableau = Tableau(self, self.filename)
981 get_table_param(self, self.filename)
982 self.tableau.make_content()
983 self.tableau.show_tab()
984 #open_data(self, self.filename)
985 elif os.path.splitext(self.filename)[1] == '.txt':
987 elif os.path.splitext(self.filename)[1] == '.ira' :
988 #self.corpus = Corpus(self)
989 #self.Text = OpenAnalyse(self, self.filename)
990 OpenAnalyse(self, self.filename)
992 print 'ce fichier n\'existe pas'
996 class IntroPanel(wx.Panel):
997 def __init__(self, parent):
998 wx.Panel.__init__(self, parent)
999 #col = randint(0, 255)
1000 #col1 = randint(0,255)
1001 #col2 = randint(0,255)
1003 bckgrdcolor = wx.Colour(col, col, col)
1004 self.SetBackgroundColour(bckgrdcolor)
1005 txtcolour = wx.Colour(250, 250, 250)
1006 linkcolor = wx.Colour(255, 0, 0)
1007 sizer1 = wx.BoxSizer(wx.VERTICAL)
1008 sizer2 = wx.BoxSizer(wx.VERTICAL)
1009 sizer3 = wx.BoxSizer(wx.HORIZONTAL)
1010 sizer4 = wx.BoxSizer(wx.VERTICAL)
1011 sizer5 = wx.BoxSizer(wx.HORIZONTAL)
1012 grid_sizer_1 = wx.FlexGridSizer(1, 4, 0, 0)
1013 grid_sizer_3 = wx.FlexGridSizer(1, 4, 0, 0)
1014 grid_sizer_2 = wx.FlexGridSizer(1, 3, 0, 0)
1015 PanelPres = wx.Panel(self)
1016 PanelPres.SetBackgroundColour(bckgrdcolor)
1017 label_1 = wx.StaticText(self, -1, u"IRaMuTeQ", size=(-1, -1))
1018 label_1.SetFont(wx.Font(46, wx.TELETYPE, wx.NORMAL, wx.BOLD, 0, "Purisa"))
1019 label_1.SetForegroundColour(wx.RED)
1020 label2 = wx.StaticText(PanelPres, -1 , u'\nVersion ' + ConfigGlob.get('DEFAULT', 'version') + '\n')
1021 label2.SetForegroundColour(txtcolour)
1022 label2.SetBackgroundColour(bckgrdcolor)
1023 #label3 = wx.StaticText(PanelPres, -1 , u'Equipe ')
1024 #label3.SetForegroundColour(txtcolour)
1025 #label3.SetBackgroundColour(bckgrdcolor)
1026 self.hyper2 = hl.HyperLinkCtrl(PanelPres, wx.ID_ANY, u"REPERE", URL="http://repere.no-ip.org/")
1027 self.hyper2.SetColours(linkcolor, linkcolor, "RED")
1028 self.hyper2.SetBackgroundColour(bckgrdcolor)
1029 self.hyper2.EnableRollover(True)
1030 self.hyper2.SetUnderlines(False, False, True)
1031 self.hyper2.SetBold(True)
1032 self.hyper2.UpdateLink()
1033 label_lerass = wx.StaticText(PanelPres, -1, u'Laboratoire ')
1034 label_lerass.SetForegroundColour(txtcolour)
1035 label_lerass.SetBackgroundColour(bckgrdcolor)
1036 self.hyper_lerass = hl.HyperLinkCtrl(PanelPres, -1, u'LERASS', URL="http://www.lerass.com")
1037 self.hyper_lerass.SetColours(linkcolor, linkcolor, "RED")
1038 self.hyper_lerass.SetBackgroundColour(bckgrdcolor)
1039 self.hyper_lerass.EnableRollover(True)
1040 self.hyper_lerass.SetUnderlines(False, False, True)
1041 self.hyper_lerass.SetBold(True)
1042 self.hyper_lerass.UpdateLink()
1043 blank = wx.StaticText(PanelPres, -1, u'\n')
1044 blank1 = wx.StaticText(PanelPres, -1, u'\n')
1045 labellicence = wx.StaticText(PanelPres, -1, u'Licence GNU GPL')
1046 labellicence.SetForegroundColour(txtcolour)
1047 labellicence.SetBackgroundColour(bckgrdcolor)
1048 labelcopy = wx.StaticText(PanelPres, -1, ConfigGlob.get('DEFAULT', 'copyright'))
1049 labelcopy.SetForegroundColour(txtcolour)
1050 labelcopy.SetBackgroundColour(bckgrdcolor)
1051 python_img = wx.Image(os.path.join(ImagePath,'python-logo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1052 r_img = wx.Image(os.path.join(ImagePath,'Rlogo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1053 lexique_img = wx.Image(os.path.join(ImagePath,'LexTexte4.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1054 but_python = wx.BitmapButton(self, -1, python_img)
1055 but_lexique = wx.BitmapButton(self, -1, lexique_img)
1056 but_r = wx.BitmapButton(self, -1, r_img)
1057 self.Bind(wx.EVT_BUTTON, self.OnPython, but_python)
1058 self.Bind(wx.EVT_BUTTON, self.OnLexique, but_lexique)
1059 self.Bind(wx.EVT_BUTTON, self.OnR, but_r)
1062 #grid_sizer_1.Add(label3, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1063 grid_sizer_1.Add(self.hyper2, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1064 grid_sizer_3.Add(label_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1065 grid_sizer_3.Add(self.hyper_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1066 sizer4.Add(label_1, 0, wx.ALIGN_CENTER, 5)
1067 sizer2.Add(label2, 0, wx.ALIGN_CENTER, 5)
1068 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1069 sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1070 sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1071 sizer2.Add(grid_sizer_3, 0, wx.ALIGN_CENTER, 5)
1072 sizer2.Add(wx.StaticText(PanelPres, -1, u' '), 0, wx.ALIGN_CENTER, 5)
1073 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1074 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1075 sizer2.Add(grid_sizer_1, 0, wx.ALIGN_CENTER, 5)
1076 sizer2.Add(labellicence, 0, wx.ALIGN_CENTER, 5)
1077 sizer2.Add(labelcopy, 0, wx.ALIGN_CENTER, 5)
1078 sizer1.Add(sizer4, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1079 PanelPres.SetSizer(sizer2)
1080 sizer5.Add(blank, 1, wx.EXPAND | wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 2)
1081 sizer5.Add(PanelPres, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1082 sizer5.Add(blank1, 1, wx.ALIGN_CENTER_HORIZONTAL,2)
1083 grid_sizer_2.Add(but_python, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1084 grid_sizer_2.Add(but_lexique, 1,wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1085 grid_sizer_2.Add(but_r, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1087 sizer1.Add(sizer5, 3, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 1)
1088 sizer1.Add(grid_sizer_2, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
1089 self.SetSizer(sizer1)
1092 def OnPython(self,evt):
1093 webbrowser.open('http://www.python.org')
1095 def OnLexique(self,evt):
1096 webbrowser.open('http://www.lexique.org')
1099 webbrowser.open('http://www.r-project.org')
1101 class MySplashScreen(wx.SplashScreen):
1103 bmp = wx.Image(os.path.join(ImagePath, 'splash.png')).ConvertToBitmap()
1104 wx.SplashScreen.__init__(self, bmp,
1105 wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
1107 self.Bind(wx.EVT_CLOSE, self.OnClose)
1108 self.fc = wx.FutureCall(1, self.ShowMain)
1110 def OnClose(self, evt):
1114 if self.fc.IsRunning():
1119 frame = IraFrame(None, -1, "IRaMuTeQ " + ConfigGlob.get('DEFAULT', 'version'), size=(1100, 800))
1122 frame.OnOpenFromCmdl()
1123 # if self.fc.IsRunning():
1125 #wx.CallAfter(frame.ShowTip)
1127 class MyApp(wx.App):
1130 Create and show the splash screen. It will then create and show
1131 the main frame when it is time to do so.
1133 wx.SystemOptions.SetOptionInt("mac.window-plain-transition", 1)
1134 self.SetAppName("Iramuteq")
1135 splash = MySplashScreen()
1143 if __name__ == '__main__':