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 cree 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 matrix"), _(u"Open a matrix"))
181 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
182 file_menu.AppendItem(item)
184 item = wx.MenuItem(file_menu, ID_OpenText, _(u"Open a text corpora"), _(u"Open a text corpora"))
185 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
186 file_menu.AppendItem(item)
188 item = wx.MenuItem(file_menu, ID_OnOpenAnalyse, _(u"Open an analysis"), _("Open an analysis"))
189 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
190 file_menu.AppendItem(item)
192 item1 = wx.MenuItem(file_menu, ID_Import, _(u"Import a factiva corpora..."), _("Import a factiva corpora..."))
193 item1.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_TIP))
194 file_menu.AppendItem(item1)
197 item = wx.MenuItem(file_menu, ID_SaveTab, _(u"Save tab as..."), _(u"Save tab as..."))
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'Preferences'))
207 view_menu = wx.Menu()
208 view_menu.Append(ID_ACCEUIL, _(u"Home page"))
209 view_menu.Append(ID_VIEWDATA, _(u"Show data"))
210 view_menu.Append(ID_RESULT, _(u'Show results'))
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 :
574 corpus = builder.doanalyse()
575 self.history.add(corpus.parametres)
576 self.tree.OnItemAppend(corpus.parametres)
577 OpenAnalyse(self, corpus.parametres)
580 #self.content = DoConf().totext(corpus.parametres)
581 # parametres = DoConf(os.path.join(UserConfigPath,'corpus.cfg')).getoptions('corpus')
582 # parametres['originalpath'] = self.filename
584 # parametres['pathout'] = PathOut(self.filename, 'corpus').dirout
585 # dial = CorpusPref(self, parametres)
586 # dial.CenterOnParent()
587 # dial.txtpath.SetLabel(self.filename)
588 # res = dial.ShowModal()
589 # parametres = dial.doparametres()
591 # ReadLexique(self, lang = parametres['lang'])
592 # self.expressions = ReadDicoAsDico(self.DictPath.get(parametres['lang'], 'french_exp'))
593 # corpus = BuildFromAlceste(self.filename, parametres, self.lexique, self.expressions).corpus
594 #self.corpus_encodage = dial.encodages[dial.list_encodages.GetSelection()][0]
595 #self.corpus_lang = dial.langues[dial.choice_dict.GetSelection()]
598 keepGoing = dlg.Update(count, u"Lecture du fichier")
599 # msg = u"Ce fichier ne semble pas être encodé en %s" % self.corpus_encodage
600 # dial = wx.MessageDialog(self, msg, u"Problème d'encodage", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
601 # dial.CenterOnParent()
602 # res = dial.ShowModal()
605 self.ShowMenu(_("View"))
606 self.ShowMenu(_("Text analysis"))
607 self.ShowMenu(_(u"Spreadsheet analysis"), False)
612 keepGoing = dlg.Update(count, u"Chargement du dictionnaire")
614 #self.OnViewData(wx.EVT_BUTTON)
616 def OnExit(self, event):
619 def OnAbout(self, event):
620 info = wx.AboutDialogInfo()
621 info.Name = ConfigGlob.get('DEFAULT', 'name')
622 info.Version = ConfigGlob.get('DEFAULT', 'version')
623 info.Copyright = ConfigGlob.get('DEFAULT', 'copyright')
624 info.Description = u"""
625 Interface de R pour les Analyses Multidimensionnelles
626 de Textes et de Questionnaires
629 construit avec des logiciels libres.
635 info.WebSite = ("http://www.iramuteq.org", u"Site web IRaMuTeQ")
636 dev = ConfigGlob.get('DEFAULT', 'dev').split(';')
637 info.Developers = dev
638 info.License = u"""Iramuteq est un logiciel libre ; vous pouvez le diffuser et/ou le modifier
639 suivant les termes de la Licence Publique Générale GNU telle que publiée
640 par la Free Software Foundation ; soit la version 2 de cette licence,
641 soit (à votre convenance) une version ultérieure.
643 Iramuteq est diffusé dans l'espoir qu'il sera utile,
644 mais SANS AUCUNE GARANTIE ; sans même une garantie implicite
645 de COMMERCIALISATION ou d'ADÉQUATION À UN USAGE PARTICULIER.
646 Voyez la Licence Publique Générale GNU pour plus de détails.
648 Vous devriez avoir reçu une copie de la Licence Publique Générale GNU
649 avec Iramuteq ; sinon, veuillez écrire à la Free Software Foundation,
650 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, États-Unis."""
653 def GetDockArt(self):
654 return self._mgr.GetArtProvider()
659 def OnPageChanged(self, event) :
660 new = event.GetSelection()
661 nobject = event.GetEventObject()
662 parent = nobject.GetParent()
663 if isinstance(parent, IraFrame) :
664 npage = self.nb.GetPage(new)
665 self.tree.GiveFocus(uuid=npage.parametres['uuid'])
667 def OnCloseTab(self, evt):
668 log.info('Closing tab %s' % str(evt.GetEventObject()))
669 ctrl = evt.GetEventObject()
670 if isinstance(ctrl.GetParent(), aui.AuiNotebook) or isinstance(ctrl.GetParent(), wx.Panel):
674 page = self.nb.GetPage(self.nb.GetSelection())
675 if 'parametres' in dir(page) :
676 self.history.rmtab(page.parametres)
677 self.tree.CloseItem(uuid = page.parametres['uuid'])
678 TabTitle = self.nb.GetPageText(self.nb.GetSelection())
679 if self.DictTab != {} :
680 if TabTitle in self.DictTab :
681 ListFile=self.DictTab[TabTitle]
682 if False in ListFile:
684 Certains résultats ne sont pas enregistrer.
685 Voulez-vous fermer quand même ?"""
686 dlg = wx.MessageDialog(self, msg, "Sauvegarde",wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
689 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
694 for f in ListFile[1:] :
699 elif True in ListFile :
702 del self.DictTab[TabTitle]
707 if self.nb.GetPageCount() == 1 and remove and not notebook :
710 def LastTabClose(self) :
711 if self.nb.GetPageCount() == 1 :
712 self.DisEnSaveTabAs(False)
714 self.ShowAPane("Text")
716 self.ShowAPane("Data")
718 self.ShowAPane("Intro_Text")
720 def OnSaveTabAs(self, event):
721 SelectTab = self.nb.GetSelection()
722 TabTitle = self.nb.GetPageText(SelectTab)
723 FileToSave = self.DictTab[TabTitle]
726 self, message="Enregistrer sous...", defaultDir=os.getcwd(),
727 defaultFile="resultat.html", wildcard="Tous les fichiers|*", style=wx.SAVE | wx.OVERWRITE_PROMPT
729 dlg.SetFilterIndex(2)
732 if dlg.ShowModal() == wx.ID_OK:
734 Dirname = os.path.dirname(Path)
735 Filename = dlg.GetFilename()
740 shutil.copyfile(FileToSave[-1], Path)
741 os.remove(FileToSave[len(FileToSave) - 1])
742 NewListFile.append(True)
743 NewListFile.append(Path)
744 for f in FileToSave[1:-1] :
745 Fileout = os.path.join(Dirname, os.path.basename(f))
746 shutil.copyfile(f, Fileout)
747 NewListFile.append(Fileout)
750 self.DictTab[TabText] = NewListFile
751 del self.DictTab[TabTitle]
752 self.nb.SetPageText(SelectTab, TabText)
754 def GetStartPosition(self):
758 pt = self.ClientToScreen(wx.Point(0, 0))
760 return wx.Point(pt.x + x, pt.y + x)
762 def ShowAPane(self, panel):
763 for pane in self._mgr.GetAllPanes() :
764 if not pane.IsToolbar() and pane.name != 'lefttree':
766 self._mgr.GetPane(panel).Show()
769 def OnAcceuil(self, event):
770 self.ShowAPane(u"Intro_Text")
773 # def OnCreateTab(self, event):
774 # if not self._mgr.GetPane("Tab_content").name == "Tab_content":
775 # self._mgr.AddPane(self.CreateTabCtrl(), aui.AuiPaneInfo().
776 # Name("Tab_content").
778 # self._mgr.GetPane("Intro_Text").Hide()
779 # self._mgr.GetPane("Tab_content").Show()
780 # self.ctrl.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnCloseTab)
782 # page = wx.TextCtrl(self, -1, str(text), style=wx.TE_MULTILINE)
783 # self.ctrl.AddPage(page, "qsdqsd")
784 # self.ctrl.SetSelection(self.ctrl.GetPageCount() - 1)
788 def CreateHTMLCtrl(self):
789 ctrl = wx.html.HtmlWindow(self, -1, wx.DefaultPosition, wx.Size(400, 300))
790 if "gtk2" in wx.PlatformInfo:
791 ctrl.SetStandardFonts()
792 ctrl.SetPage(u"text")
795 def ShowTab(self, evt):
796 self.ShowAPane("Tab_content")
798 ################################################################
800 ################################################################
802 def OnFreq(self, event):
808 def OnChi2(self, event):
810 # print('PAS DE DEBUG SUR CHI2')
811 chi = ChiSquare(self)
815 def OnStudent(self, event):
821 def OnRCode(self, event):
827 def OnCHDSIM(self, event):
829 # print 'ATTENTION!!!!'
830 chdsim = ChdCluster(self)
831 if chdsim.val == wx.ID_OK:
836 def OnCHDAlceste(self, event):
838 # print('PLUS DE BUG SUR ALCESTE QUESTIONNAIRE')
839 self.quest = AnalyseQuest(self)
840 if self.quest.val == wx.ID_OK:
845 def OnSimiTxt(self, evt, corpus = None) :
846 print 'PLUS DE BUG SUR SIMITXT'
848 #self.Text = SimiTxt(self)
849 self.Text = SimiTxt(self, corpus, parametres = {'type': 'simitxt'}, dlg = progressbar(self, 3))
850 if self.Text.val == wx.ID_OK :
855 def OnWordCloud(self, evt, corpus = None) :
856 # print 'PLUS DE BUG SUR WORDCLOUD'
858 self.Text = WordCloud(self, corpus, parametres = {'type' : 'wordcloud'}, dlg = progressbar(self, 3))
859 if self.Text.val == wx.ID_OK :
865 def OnAFCM(self, event):
871 def OnCheckcorpus(self, evt):
877 def OnTextStat(self, event, corpus = None):
878 print 'PAS DE BUG SUR TEXT STAT'
880 self.Text = Stat(self, corpus, parametres = {'type': 'stat'}, dlg = progressbar(self, 7))
882 if self.Text.val == wx.ID_OK :
887 def OnTextSpec(self, event, corpus = None):
889 #self.Text = AsLexico(self)
890 print('ATTENTION : PLUS DE BUG SUR LEXICO')
891 self.Text = Lexico(self, corpus, parametres = {'type' : 'spec'}, dlg = progressbar(self, 3))
892 if self.Text.val == wx.ID_OK :
897 def OnTextAfcm(self, event):
904 def import_factiva(self,event):
910 def OnTextAlceste(self, event, corpus = None):
912 print('ATTENTION : PLUS DE BUG SUR ALCESTE')
913 #RunAnalyse(self, corpus, Alceste, OptAlceste)
914 self.Text = Alceste(self, corpus, parametres = {'type': 'alceste'}, dlg = progressbar(self,6))
915 #self.history.addtab(self.Text.parametres)
916 #OpenAnalyse(self, self.Text.parametres['ira'])
917 if self.Text.val == wx.ID_OK:
922 def OnPamSimple(self, event):
924 self.Text = PamTxt(self)
925 if self.Text.val == wx.ID_OK:
930 def OnSimi(self,evt):
932 #print 'ATTENTION !!!! VERGES'
933 self.res = DoSimi(self, param = None)
934 #self.res = Verges(self)
935 if self.res.val == wx.ID_OK :
939 #################################################################
941 def OnHelp(self, event):
942 webbrowser.open('http://www.iramuteq.org/documentation')
944 def OnPref(self, event):
945 dlg = PrefDialog(self)
947 self.val = dlg.ShowModal()
950 if self.check_update:
955 #CheckRPackages(self)
957 def OnOpenFromCmdl(self):
959 if options.filename :
960 if os.path.exists(options.filename):
961 self.filename = os.path.abspath(options.filename)
965 if os.path.exists(os.path.realpath(args[0])):
966 self.filename = os.path.abspath(os.path.realpath(args[0]))
972 if os.path.splitext(self.filename)[1] in ['.csv', '.xls', '.ods']:
973 self.tableau = Tableau(self, self.filename)
974 get_table_param(self, self.filename)
975 self.tableau.make_content()
976 self.tableau.show_tab()
977 #open_data(self, self.filename)
978 elif os.path.splitext(self.filename)[1] == '.txt':
980 elif os.path.splitext(self.filename)[1] == '.ira' :
981 #self.corpus = Corpus(self)
982 #self.Text = OpenAnalyse(self, self.filename)
983 OpenAnalyse(self, self.filename)
985 print 'ce fichier n\'existe pas'
989 class IntroPanel(wx.Panel):
990 def __init__(self, parent):
991 wx.Panel.__init__(self, parent)
992 #col = randint(0, 255)
993 #col1 = randint(0,255)
994 #col2 = randint(0,255)
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=(1100, 800))
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__':