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
67 from tree import LeftTree
68 ##########################################################
69 ID_OpenData = wx.NewId()
70 ID_Import = wx.NewId()
71 ID_OpenText = wx.NewId()
72 ID_OnOpenAnalyse = wx.NewId()
75 ID_Student = wx.NewId()
76 ID_CHDSIM = wx.NewId()
77 ID_CHDAlceste = wx.NewId()
78 ID_TEXTAFCM = wx.NewId()
79 ID_TEXTSTAT = wx.NewId()
81 ID_TEXTALCESTE = wx.NewId()
82 ID_TEXTPAM = wx.NewId()
83 ID_CHECKCORPUS = wx.NewId()
84 ID_Tabcontent = wx.NewId()
87 ID_CloseTab = wx.NewId()
88 ID_SaveTab = wx.NewId()
89 ID_CreateText = wx.NewId()
90 ID_ACCEUIL = wx.NewId()
91 ID_RESULT = wx.NewId()
92 ID_VIEWDATA = wx.NewId()
93 ID_HTMLcontent = wx.NewId()
94 ID_SimiTxt = wx.NewId()
95 ##########################################################
96 #elements de configuration
97 ##########################################################
99 if sys.platform == 'darwin' :
100 sys.setdefaultencoding('utf-8')
101 wx.SetDefaultPyEncoding('utf-8')
103 sys.setdefaultencoding(locale.getpreferredencoding())
104 #chemin de l'application
105 AppliPath = os.path.abspath(os.path.dirname(os.path.realpath(sys.argv[0])))
107 ImagePath = os.path.join(AppliPath, 'images')
108 #configuration generale
109 DictConfigPath = ConstructGlobalPath(AppliPath)
110 ConfigGlob = ConfigParser()
111 ConfigGlob.read(DictConfigPath['global'])
112 #repertoire de l'utilisateur
113 if os.getenv('HOME') != None:
114 user_home = os.getenv('HOME')
116 user_home = os.getenv('HOMEPATH')
117 UserConfigPath = os.path.abspath(os.path.join(user_home, '.iramuteq'))
118 #Si pas de fichiers de config utilisateur, on cree le repertoire
119 CreateIraDirectory(UserConfigPath, AppliPath)
120 #fichiers log pour windows (py2exe)
121 log = logging.getLogger('iramuteq')
122 fh = logging.FileHandler(os.path.join(UserConfigPath,'stdout.log'))
123 ch = logging.StreamHandler()
124 formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
125 ch.setFormatter(formatter)
126 fh.setFormatter(formatter)
129 log.setLevel(logging.INFO)
132 class writer(object):
133 def write(self, data):
134 if data.strip() != '' :
135 log.info('BUG : %s' % data)
136 sys.stderr = writer()
137 ConfigPath = ConstructConfigPath(UserConfigPath)
138 #####################################################################
140 class IraFrame(wx.Frame):
141 def __init__(self, parent, id= -1, title="", pos=wx.DefaultPosition,
142 size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE |
145 log.info('Starting...')
146 wx.Frame.__init__(self, parent, id, title, pos, size, style)
148 self.AppliPath = AppliPath
149 self.images_path = os.path.join(AppliPath,'images')
150 self.UserConfigPath = UserConfigPath
151 self.RscriptsPath = ConstructRscriptsPath(AppliPath)
152 #self.DictPath = ConstructDicoPath(AppliPath)
153 self.DictPath = ConstructDicoPath(UserConfigPath)
154 self.ConfigGlob = ConfigGlob
155 self.ConfigPath = ConstructConfigPath(UserConfigPath)
156 self.pref = RawConfigParser()
157 #workaround for import problem
158 self.SimiFromCluster = SimiFromCluster
160 mylocale = wx.Locale(wx.LANGUAGE_FRENCH)
161 mylocale.AddCatalogLookupPathPrefix(os.path.join(AppliPath,'locale'))
162 mylocale.AddCatalog('iramuteq')
163 presLan_en = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['en'])
164 presLan_fr = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['fr_FR'])
168 # tell FrameManager to manage this frame
169 #self._mgr = wx.aui.AuiManager()
170 self._mgr = aui.AuiManager()
171 self._mgr.SetManagedWindow(self)
174 #--------------------------------------------------------------------------------
175 self.mb = wx.MenuBar()
177 file_menu = wx.Menu()
178 item = wx.MenuItem(file_menu, ID_OpenData, _(u"Open a matrix"), _(u"Open a matrix"))
179 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
180 file_menu.AppendItem(item)
182 item = wx.MenuItem(file_menu, ID_OpenText, _(u"Open a text corpora"), _(u"Open a text corpora"))
183 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
184 file_menu.AppendItem(item)
186 item = wx.MenuItem(file_menu, ID_OnOpenAnalyse, _(u"Open an analysis"), _("Open an analysis"))
187 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
188 file_menu.AppendItem(item)
190 item1 = wx.MenuItem(file_menu, ID_Import, _(u"Import a factiva corpora..."), _("Import a factiva corpora..."))
191 item1.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_TIP))
192 file_menu.AppendItem(item1)
195 item = wx.MenuItem(file_menu, ID_SaveTab, _(u"Save tab as..."), _(u"Save tab as..."))
196 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_SAVE_AS))
198 file_menu.AppendItem(item)
200 file_menu.Append(wx.ID_EXIT, _(u"Exit"))
202 edit_menu = wx.Menu()
203 edit_menu.Append(wx.ID_PREFERENCES, '', _(u'Preferences'))
205 view_menu = wx.Menu()
206 view_menu.Append(ID_ACCEUIL, _(u"Home page"))
207 view_menu.Append(ID_VIEWDATA, _(u"Show data"))
208 view_menu.Append(ID_RESULT, _(u'Show results'))
209 #view_menu.AppendSeparator()
211 analyse_menu = wx.Menu()
212 analyse_menu.Append(ID_Freq, u"Fréquences")
213 analyse_menu.Append(ID_Chi2, u"Chi2")
214 #analyse_menu.Append(ID_Student, u"t de Student")
215 menu_classif = wx.Menu()
216 menu_classif.Append(ID_CHDAlceste, u"Méthode Alceste")
217 menu_classif.Append(ID_CHDSIM, u"Par matrice des distances")
218 analyse_menu.AppendMenu(-1, u"Classification", menu_classif)
219 analyse_menu.Append(ID_AFCM, u"AFCM")
220 analyse_menu.Append(ID_SIMI, u"Analyse de similitudes")
221 ID_RCODE = wx.NewId()
222 analyse_menu.Append(ID_RCODE, u"Code R...")
224 text_menu = wx.Menu()
225 text_menu.Append(ID_CHECKCORPUS, u"Vérifier le corpus")
226 text_menu.Append(ID_TEXTSTAT, u"Statistiques textuelles")
227 text_menu.Append(ID_ASLEX, u"Spécificités et AFC")
228 #text_menu.Append(ID_TEXTAFCM, u"AFC sur UCI / Vocabulaire")
229 menu_classiftxt = wx.Menu()
230 menu_classiftxt.Append(ID_TEXTALCESTE, u"Méthode Alceste")
231 menu_classiftxt.Append(ID_TEXTPAM, u"Par matrice des distances")
232 text_menu.AppendMenu(-1, u"Classification", menu_classiftxt)
233 text_menu.Append(ID_SimiTxt, u'Analyse de similitude')
235 text_menu.Append(ID_WC, u'Nuage de mots')
237 help_menu = wx.Menu()
238 help_menu.Append(wx.ID_ABOUT, u'À propos...')
239 help_menu.Append(wx.ID_HELP, u'Aide en ligne')
241 self.mb.Append(file_menu, _(u"File"))
242 self.mb.Append(edit_menu, _(u"Edition"))
243 self.mb.Append(view_menu, _(u"View"))
244 self.mb.Append(analyse_menu, _("Spreadsheet analysis"))
245 self.mb.Append(text_menu, _(u"Text analysis"))
246 self.mb.Append(help_menu, _(u"Help"))
248 self.SetMenuBar(self.mb)
249 #--------------------------------------------------------------------
250 self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
251 self.statusbar.SetStatusWidths([-2, -3])
252 self.statusbar.SetStatusText(u"Prêt", 0)
253 self.statusbar.SetStatusText(u"Bienvenue", 1)
255 # min size for the frame itself isn't completely done.
256 # see the end up FrameManager::Update() for the test
257 # code. For now, just hard code a frame minimum size
258 self.SetMinSize(wx.Size(400, 400))
260 # create some toolbars
261 tb1 = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
262 wx.TB_FLAT | wx.TB_NODIVIDER)
263 tb1.SetToolBitmapSize(wx.Size(16, 16))
264 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")
266 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")
270 #------------------------------------------------------------------------------------------------
272 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)
274 #self._mgr.AddPane(self.text_ctrl_txt, wx.aui.AuiPaneInfo().
275 # Name("Text").CenterPane())
276 self._mgr.AddPane(self.text_ctrl_txt, aui.AuiPaneInfo().
277 Name("Text").CenterPane())
278 #self._mgr.AddPane(IntroPanel(self), wx.aui.AuiPaneInfo().Name("Intro_Text").
280 self._mgr.AddPane(IntroPanel(self), aui.AuiPaneInfo().Name("Intro_Text").
282 #if not os.path.exists(os.path.join(UserConfigPath, 'history.db')) :
283 # with open(os.path.join(UserConfigPath, 'history.db'), 'w') as f :
285 self.history = History(os.path.join(UserConfigPath, 'history.db'))
286 self.tree = LeftTree(self)
287 self._mgr.AddPane(self.tree, aui.AuiPaneInfo().Name("lefttree").Caption("Navigateur").
288 Left().MinSize(wx.Size(200,500)).Layer(1).Position(1).CloseButton(False).MaximizeButton(True).
289 MinimizeButton(True))
291 #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)
292 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)
293 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
294 self.nb.SetAGWWindowStyleFlag(notebook_flags)
295 self.nb.SetArtProvider(aui.ChromeTabArt())
296 #self.nb.SetArtProvider(aui.VC8TabArt())
297 #self.nb.parent = self
298 #self._notebook_style = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.NO_BORDER
299 #self._mgr.AddPane(self.nb, wx.aui.AuiPaneInfo().
300 # Name("Tab_content").
302 self._mgr.AddPane(self.nb, aui.AuiPaneInfo().
305 self.Sheet = MySheet(self)
306 #self._mgr.AddPane(self.Sheet, wx.aui.AuiPaneInfo().Name("Data").CenterPane())
307 self._mgr.AddPane(self.Sheet, aui.AuiPaneInfo().Name("Data").CenterPane())
308 self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnCloseTab)
309 self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
310 # add the toolbars to the manager
312 #self._mgr.AddPane(tb1, wx.aui.AuiPaneInfo().
313 # Name("tb1").Caption("Fichiers").
314 # ToolbarPane().Top().
315 # LeftDockable(False).RightDockable(False))
316 self._mgr.AddPane(tb1, aui.AuiPaneInfo().
317 Name("tb1").Caption("Fichiers").
319 LeftDockable(True).RightDockable(False))
321 self.ShowAPane("Intro_Text")
322 self._mgr.GetPane("lefttree").Show()
323 self._mgr.GetPane("classif_tb").Hide()
324 # "commit" all changes made to FrameManager
327 # Show How To Use The Closing Panes Event
328 ##################################################################
329 self.Bind(wx.EVT_MENU, self.OnAcceuil, id=ID_ACCEUIL)
330 self.Bind(wx.EVT_MENU, self.OnViewData, id=ID_VIEWDATA)
331 self.Bind(wx.EVT_MENU, self.ShowTab, id=ID_RESULT)
332 self.Bind(wx.EVT_MENU, self.OnOpenData, id=ID_OpenData)
333 self.Bind(wx.EVT_MENU, self.OnOpenText, id=ID_OpenText)
334 self.Bind(wx.EVT_MENU, self.OnOpenAnalyse, id=ID_OnOpenAnalyse)
335 self.Bind(wx.EVT_MENU, self.import_factiva, id= ID_Import)
336 self.Bind(wx.EVT_MENU, self.OnFreq, id=ID_Freq)
337 self.Bind(wx.EVT_MENU, self.OnChi2, id=ID_Chi2)
338 self.Bind(wx.EVT_MENU, self.OnStudent, id=ID_Student)
339 self.Bind(wx.EVT_MENU, self.OnCHDSIM, id=ID_CHDSIM)
340 self.Bind(wx.EVT_MENU, self.OnCHDAlceste, id=ID_CHDAlceste)
341 self.Bind(wx.EVT_MENU, self.OnAFCM, id=ID_AFCM)
342 self.Bind(wx.EVT_MENU, self.OnRCode, id=ID_RCODE)
343 self.Bind(wx.EVT_MENU, self.OnCheckcorpus, id = ID_CHECKCORPUS)
344 self.Bind(wx.EVT_MENU, self.OnTextStat, id=ID_TEXTSTAT)
345 self.Bind(wx.EVT_MENU, self.OnTextSpec, id=ID_ASLEX)
346 self.Bind(wx.EVT_MENU, self.OnTextAfcm, id=ID_TEXTAFCM)
347 self.Bind(wx.EVT_MENU, self.OnTextAlceste, id=ID_TEXTALCESTE)
348 self.Bind(wx.EVT_MENU, self.OnPamSimple, id=ID_TEXTPAM)
349 self.Bind(wx.EVT_MENU, self.OnSimiTxt, id=ID_SimiTxt)
350 self.Bind(wx.EVT_MENU, self.OnWordCloud, id=ID_WC)
351 self.Bind(wx.EVT_MENU, self.OnSimi, id=ID_SIMI)
352 self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
353 self.Bind(wx.EVT_MENU, self.OnSaveTabAs, id=ID_SaveTab)
354 self.Bind(wx.EVT_MENU, self.OnAbout, id=wx.ID_ABOUT)
355 self.Bind(wx.EVT_MENU, self.OnHelp, id=wx.ID_HELP)
356 self.Bind(wx.EVT_MENU, self.OnPref, id=wx.ID_PREFERENCES)
357 self.Bind(wx.EVT_CLOSE, self.OnClose)
358 ##################################################################
359 flags = self._mgr.GetAGWFlags()
360 #flags &= ~wx.aui.AUI_MGR_TRANSPARENT_HINT
361 #flags &= ~wx.aui.AUI_MGR_VENETIAN_BLINDS_HINT
362 #flags &= ~wx.aui.AUI_MGR_RECTANGLE_HINT
363 flags &= ~(aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING)
364 self._mgr.SetAGWFlags(self._mgr.GetAGWFlags() ^ (aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING))
365 self._mgr.GetArtProvider().SetMetric(aui.AUI_DOCKART_GRADIENT_TYPE, aui.AUI_GRADIENT_HORIZONTAL)
366 self.GetDockArt().SetColor(aui.AUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR, "#00FFF9")
369 self._icon = wx.Icon(os.path.join(ImagePath, "iraicone.ico"), wx.BITMAP_TYPE_ICO)
370 self.SetIcon(self._icon)
371 ##########################
373 self.input_path = [False]
374 self.TEMPDIR = tempfile.mkdtemp('iramuteq')
375 self.FileTabList = []
381 self.g_header = False
388 self.SysEncoding = sys.getdefaultencoding()
389 self.syscoding = sys.getdefaultencoding()
390 #print 'SysEncoding',self.SysEncoding
391 if self.SysEncoding == 'mac-roman' : self.SysEncoding = 'MacRoman'
395 self.pref.read(self.ConfigPath['preferences'])
404 self.pref.read(self.ConfigPath['preferences'])
406 #configuration des chemins de R
407 self.PathPath = ConfigParser()
408 self.PathPath.read(ConfigPath['path'])
410 if not CheckRPath(self.PathPath) :
411 if sys.platform == 'win32':
412 BestRPath = FindRPAthWin32()
414 BestRPath = FindRPathNix()
416 self.PathPath.set('PATHS', 'rpath', BestRPath)
417 with open(ConfigPath['path'], 'w') as f :
418 self.PathPath.write(f)
422 self.RPath = self.PathPath.get('PATHS', 'rpath')
425 if not RLibsAreInstalled(self) :
429 Le chemin de l'executable de R n'a pas été trouvé.
430 Si R n'est pas installé, vous devez l'installer (http://www.r-project.org/).
431 Si R n'est pas installé dans le répertoire par défaut
432 (souvent C:\Program Files\R\R-2.x.x\R.exe sous windows ou /usr/bin/R sous linux ou Mac Os X)
433 vous devez signaler le chemin de l'éxecutable de R dans les préférences."""
434 dlg = wx.MessageDialog(self, msg, u"Problème de configuration", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
436 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
442 self.sound = self.pref.getboolean('iramuteq', 'sound')
443 self.check_update = self.pref.getboolean('iramuteq', 'checkupdate')
444 self.version = ConfigGlob.get('DEFAULT', 'version')
447 ##############################################################@
448 self.DisEnSaveTabAs(False)
449 self.ShowMenu(_("View"), False)
450 self.ShowMenu(_("Spreadsheet analysis"), False)
451 self.ShowMenu(_("Text analysis"), False)
455 def OnVerif(self, evt) :
456 pack = CheckRPackages(self)
458 dlg = wx.MessageDialog(self, u"Installation OK", u"Installation", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
460 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
463 #FIXME marche pas sous mac ?
464 def DisEnSaveTabAs(self, DISEN):
466 file_menu = self.mb.GetMenu(0)
467 items = file_menu.GetMenuItems()
468 items[4].Enable(DISEN)
470 def ShowMenu(self, menu, Show=True):
471 menu_pos = self.mb.FindMenu(menu)
472 self.mb.EnableTop(menu_pos, Show)
473 self.mb.UpdateMenus()
476 #--------------------------------------------------------------------
477 def OnClose(self, event):
479 with open(self.ConfigPath['path'], 'w') as f :
480 self.PathPath.write(f)
481 if self.DictTab != {} :
482 savestates = [self.DictTab[item][0] for item in self.DictTab]
483 if False in savestates :
484 notsave = [item for item in self.DictTab if self.DictTab[item][0] == False]
486 Certains résultats ne sont pas enregistrés.
487 Voulez-vous fermer quand même ?"""
488 dlg = wx.MessageDialog(self, msg, "Sauvegarde",
489 wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
491 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
496 for item in notsave :
497 for tmpfile in self.DictTab[item][1:] :
499 print 'remove : ' + tmpfile
511 #if sys.platform == 'win32' :
512 # os.system("taskkill /im iramuteq.exe /f")
513 # print 'meurtre de process'
515 def OnOpenData(self, event):
516 inputname, self.input_path = OnOpen(self, "Data")
518 self.filename = self.input_path[0]
519 self.tableau = Tableau(self,os.path.abspath(self.input_path[0]))
520 get_table_param(self, self.input_path[0])
521 self.tableau.make_content()
522 self.tableau.show_tab()
524 def OnOpenAnalyse(self, event):
525 self.AnalysePath = OnOpen(self, "Analyse")
526 OpenAnalyse(self, self.AnalysePath[1][0], True)
527 self.ShowMenu(_("View"))
529 def OnOpenText(self, event):
530 inputname, self.input_path = OnOpen(self, "Texte")
531 self.filename = self.input_path[0]
535 def OnViewData(self, event):
538 if self.type == "Data":
539 if not self.DataPop :
540 self.Sheet.Populate(self.content)
543 self.ShowAPane(u"Data")
544 elif self.type == "Texte" or self.type == 'Analyse' :
545 if not self.DataTxt :
546 self.text_ctrl_txt.Clear()
547 self.text_ctrl_txt.write(self.content)
548 self.text_ctrl_txt.ShowPosition(0)
551 self.ShowAPane(u"Text")
555 #dial = EncodeDialog(self)
556 dlg = wx.ProgressDialog("Ouverture...",
557 "Veuillez patienter...",
560 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
563 builder = Builder(self, dlg)
564 if builder.res == wx.ID_OK :
566 corpus = builder.doanalyse()
567 self.history.add(corpus.parametres)
568 self.tree.OnItemAppend(corpus.parametres)
569 OpenAnalyse(self, corpus.parametres)
572 #self.content = DoConf().totext(corpus.parametres)
573 # parametres = DoConf(os.path.join(UserConfigPath,'corpus.cfg')).getoptions('corpus')
574 # parametres['originalpath'] = self.filename
576 # parametres['pathout'] = PathOut(self.filename, 'corpus').dirout
577 # dial = CorpusPref(self, parametres)
578 # dial.CenterOnParent()
579 # dial.txtpath.SetLabel(self.filename)
580 # res = dial.ShowModal()
581 # parametres = dial.doparametres()
583 # ReadLexique(self, lang = parametres['lang'])
584 # self.expressions = ReadDicoAsDico(self.DictPath.get(parametres['lang'], 'french_exp'))
585 # corpus = BuildFromAlceste(self.filename, parametres, self.lexique, self.expressions).corpus
586 #self.corpus_encodage = dial.encodages[dial.list_encodages.GetSelection()][0]
587 #self.corpus_lang = dial.langues[dial.choice_dict.GetSelection()]
590 keepGoing = dlg.Update(count, u"Lecture du fichier")
591 # msg = u"Ce fichier ne semble pas être encodé en %s" % self.corpus_encodage
592 # dial = wx.MessageDialog(self, msg, u"Problème d'encodage", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
593 # dial.CenterOnParent()
594 # res = dial.ShowModal()
597 self.ShowMenu(_("View"))
598 self.ShowMenu(_("Text analysis"))
599 self.ShowMenu(_(u"Spreadsheet analysis"), False)
604 keepGoing = dlg.Update(count, u"Chargement du dictionnaire")
606 #self.OnViewData(wx.EVT_BUTTON)
608 def OnExit(self, event):
611 def OnAbout(self, event):
612 info = wx.AboutDialogInfo()
613 info.Name = ConfigGlob.get('DEFAULT', 'name')
614 info.Version = ConfigGlob.get('DEFAULT', 'version')
615 info.Copyright = ConfigGlob.get('DEFAULT', 'copyright')
616 info.Description = u"""
617 Interface de R pour les Analyses Multidimensionnelles
618 de Textes et de Questionnaires
621 construit avec des logiciels libres.
627 info.WebSite = ("http://www.iramuteq.org", u"Site web IRaMuTeQ")
628 dev = ConfigGlob.get('DEFAULT', 'dev').split(';')
629 info.Developers = dev
630 info.License = u"""Iramuteq est un logiciel libre ; vous pouvez le diffuser et/ou le modifier
631 suivant les termes de la Licence Publique Générale GNU telle que publiée
632 par la Free Software Foundation ; soit la version 2 de cette licence,
633 soit (à votre convenance) une version ultérieure.
635 Iramuteq est diffusé dans l'espoir qu'il sera utile,
636 mais SANS AUCUNE GARANTIE ; sans même une garantie implicite
637 de COMMERCIALISATION ou d'ADÉQUATION À UN USAGE PARTICULIER.
638 Voyez la Licence Publique Générale GNU pour plus de détails.
640 Vous devriez avoir reçu une copie de la Licence Publique Générale GNU
641 avec Iramuteq ; sinon, veuillez écrire à la Free Software Foundation,
642 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, États-Unis."""
645 def GetDockArt(self):
646 return self._mgr.GetArtProvider()
651 def OnPageChanged(self, event) :
652 new = event.GetSelection()
653 nobject = event.GetEventObject()
654 parent = nobject.GetParent()
655 if isinstance(parent, IraFrame) :
656 npage = self.nb.GetPage(new)
657 self.tree.GiveFocus(uuid=npage.parametres['uuid'])
659 def OnCloseTab(self, evt):
660 #log.info('Closing tab %s' % str(evt.GetEventObject()))
661 ctrl = evt.GetEventObject()
662 if isinstance(ctrl.GetParent(), aui.AuiNotebook) or isinstance(ctrl.GetParent(), wx.Panel):
666 page = self.nb.GetPage(self.nb.GetSelection())
667 if 'parametres' in dir(page) and isinstance(ctrl.GetParent(), IraFrame) :
668 self.history.rmtab(page.parametres)
669 self.tree.CloseItem(uuid = page.parametres['uuid'])
670 TabTitle = self.nb.GetPageText(self.nb.GetSelection())
671 if self.DictTab != {} :
672 if TabTitle in self.DictTab :
673 ListFile=self.DictTab[TabTitle]
674 if False in ListFile:
676 Certains résultats ne sont pas enregistrer.
677 Voulez-vous fermer quand même ?"""
678 dlg = wx.MessageDialog(self, msg, "Sauvegarde",wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
681 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
686 for f in ListFile[1:] :
691 elif True in ListFile :
694 del self.DictTab[TabTitle]
699 if self.nb.GetPageCount() == 1 and remove and not notebook :
702 def LastTabClose(self) :
703 if self.nb.GetPageCount() == 1 :
704 self.DisEnSaveTabAs(False)
706 self.ShowAPane("Text")
708 self.ShowAPane("Data")
710 self.ShowAPane("Intro_Text")
712 def OnSaveTabAs(self, event):
713 SelectTab = self.nb.GetSelection()
714 TabTitle = self.nb.GetPageText(SelectTab)
715 FileToSave = self.DictTab[TabTitle]
718 self, message="Enregistrer sous...", defaultDir=os.getcwd(),
719 defaultFile="resultat.html", wildcard="Tous les fichiers|*", style=wx.SAVE | wx.OVERWRITE_PROMPT
721 dlg.SetFilterIndex(2)
724 if dlg.ShowModal() == wx.ID_OK:
726 Dirname = os.path.dirname(Path)
727 Filename = dlg.GetFilename()
732 shutil.copyfile(FileToSave[-1], Path)
733 os.remove(FileToSave[len(FileToSave) - 1])
734 NewListFile.append(True)
735 NewListFile.append(Path)
736 for f in FileToSave[1:-1] :
737 Fileout = os.path.join(Dirname, os.path.basename(f))
738 shutil.copyfile(f, Fileout)
739 NewListFile.append(Fileout)
742 self.DictTab[TabText] = NewListFile
743 del self.DictTab[TabTitle]
744 self.nb.SetPageText(SelectTab, TabText)
746 def GetStartPosition(self):
750 pt = self.ClientToScreen(wx.Point(0, 0))
752 return wx.Point(pt.x + x, pt.y + x)
754 def ShowAPane(self, panel):
755 for pane in self._mgr.GetAllPanes() :
756 if not pane.IsToolbar() and pane.name != 'lefttree':
758 self._mgr.GetPane(panel).Show()
761 def OnAcceuil(self, event):
762 self.ShowAPane(u"Intro_Text")
765 def CreateHTMLCtrl(self):
766 ctrl = wx.html.HtmlWindow(self, -1, wx.DefaultPosition, wx.Size(400, 300))
767 if "gtk2" in wx.PlatformInfo:
768 ctrl.SetStandardFonts()
769 ctrl.SetPage(u"text")
772 def ShowTab(self, evt):
773 self.ShowAPane("Tab_content")
775 ################################################################
777 ################################################################
779 def OnFreq(self, event):
785 def OnChi2(self, event):
787 # print('PAS DE DEBUG SUR CHI2')
788 chi = ChiSquare(self)
792 def OnStudent(self, event):
798 def OnRCode(self, event):
804 def OnCHDSIM(self, event):
806 # print 'ATTENTION!!!!'
807 chdsim = ChdCluster(self)
808 if chdsim.val == wx.ID_OK:
813 def OnCHDAlceste(self, event):
815 # print('PLUS DE BUG SUR ALCESTE QUESTIONNAIRE')
816 self.quest = AnalyseQuest(self)
817 if self.quest.val == wx.ID_OK:
822 def OnSimiTxt(self, evt, corpus = None) :
823 # print 'PLUS DE BUG SUR SIMITXT'
825 #self.Text = SimiTxt(self)
827 corpus = self.tree.getcorpus()
828 self.Text = SimiTxt(self, corpus, parametres = {'type': 'simitxt'}, dlg = progressbar(self, 3))
829 if self.Text.val == wx.ID_OK :
834 def OnWordCloud(self, evt, corpus = None) :
835 # print 'PLUS DE BUG SUR WORDCLOUD'
838 corpus = self.tree.getcorpus()
839 self.Text = WordCloud(self, corpus, parametres = {'type' : 'wordcloud'}, dlg = progressbar(self, 3))
840 if self.Text.val == wx.ID_OK :
846 def OnAFCM(self, event):
852 def OnCheckcorpus(self, evt):
858 def OnTextStat(self, event, corpus = None):
859 print 'PAS DE BUG SUR TEXT STAT'
862 corpus = self.tree.getcorpus()
863 self.Text = Stat(self, corpus, parametres = {'type': 'stat'}, dlg = progressbar(self, 7))
865 if self.Text.val == wx.ID_OK :
870 def OnTextSpec(self, event, corpus = None):
872 #self.Text = AsLexico(self)
873 print('ATTENTION : PLUS DE BUG SUR LEXICO')
875 corpus = self.tree.getcorpus()
876 self.Text = Lexico(self, corpus, parametres = {'type' : 'spec'}, dlg = progressbar(self, 3))
877 if self.Text.val == wx.ID_OK :
882 def OnTextAfcm(self, event):
889 def import_factiva(self,event):
895 def OnTextAlceste(self, event, corpus = None):
897 #print('ATTENTION : PLUS DE BUG SUR ALCESTE')
898 #RunAnalyse(self, corpus, Alceste, OptAlceste)
900 corpus = self.tree.getcorpus()
901 self.Text = Alceste(self, corpus, parametres = {'type': 'alceste'}, dlg = progressbar(self,6))
902 if self.Text.val == wx.ID_OK:
907 def OnPamSimple(self, event):
909 self.Text = PamTxt(self)
910 if self.Text.val == wx.ID_OK:
915 def OnSimi(self,evt):
917 #print 'ATTENTION !!!! VERGES'
918 self.res = DoSimi(self, param = None)
919 #self.res = Verges(self)
920 if self.res.val == wx.ID_OK :
924 #################################################################
926 def OnHelp(self, event):
927 webbrowser.open('http://www.iramuteq.org/documentation')
929 def OnPref(self, event):
930 dlg = PrefDialog(self)
932 self.val = dlg.ShowModal()
935 if self.check_update:
940 #CheckRPackages(self)
942 def OnOpenFromCmdl(self):
944 if options.filename :
945 if os.path.exists(options.filename):
946 self.filename = os.path.abspath(options.filename)
950 if os.path.exists(os.path.realpath(args[0])):
951 self.filename = os.path.abspath(os.path.realpath(args[0]))
957 if os.path.splitext(self.filename)[1] in ['.csv', '.xls', '.ods']:
958 self.tableau = Tableau(self, self.filename)
959 get_table_param(self, self.filename)
960 self.tableau.make_content()
961 self.tableau.show_tab()
962 #open_data(self, self.filename)
963 elif os.path.splitext(self.filename)[1] == '.txt':
965 elif os.path.splitext(self.filename)[1] == '.ira' :
966 #self.corpus = Corpus(self)
967 #self.Text = OpenAnalyse(self, self.filename)
968 OpenAnalyse(self, self.filename)
970 print 'ce fichier n\'existe pas'
974 class IntroPanel(wx.Panel):
975 def __init__(self, parent):
976 wx.Panel.__init__(self, parent)
977 #col = randint(0, 255)
978 #col1 = randint(0,255)
979 #col2 = randint(0,255)
981 bckgrdcolor = wx.Colour(col, col, col)
982 self.SetBackgroundColour(bckgrdcolor)
983 txtcolour = wx.Colour(250, 250, 250)
984 linkcolor = wx.Colour(255, 0, 0)
985 sizer1 = wx.BoxSizer(wx.VERTICAL)
986 sizer2 = wx.BoxSizer(wx.VERTICAL)
987 sizer3 = wx.BoxSizer(wx.HORIZONTAL)
988 sizer4 = wx.BoxSizer(wx.VERTICAL)
989 sizer5 = wx.BoxSizer(wx.HORIZONTAL)
990 grid_sizer_1 = wx.FlexGridSizer(1, 4, 0, 0)
991 grid_sizer_3 = wx.FlexGridSizer(1, 4, 0, 0)
992 grid_sizer_2 = wx.FlexGridSizer(1, 3, 0, 0)
993 PanelPres = wx.Panel(self)
994 PanelPres.SetBackgroundColour(bckgrdcolor)
995 label_1 = wx.StaticText(self, -1, u"IRaMuTeQ", size=(-1, -1))
996 label_1.SetFont(wx.Font(46, wx.TELETYPE, wx.NORMAL, wx.BOLD, 0, "Purisa"))
997 label_1.SetForegroundColour(wx.RED)
998 label2 = wx.StaticText(PanelPres, -1 , u'\nVersion ' + ConfigGlob.get('DEFAULT', 'version') + '\n')
999 label2.SetForegroundColour(txtcolour)
1000 label2.SetBackgroundColour(bckgrdcolor)
1001 #label3 = wx.StaticText(PanelPres, -1 , u'Equipe ')
1002 #label3.SetForegroundColour(txtcolour)
1003 #label3.SetBackgroundColour(bckgrdcolor)
1004 self.hyper2 = hl.HyperLinkCtrl(PanelPres, wx.ID_ANY, u"REPERE", URL="http://repere.no-ip.org/")
1005 self.hyper2.SetColours(linkcolor, linkcolor, "RED")
1006 self.hyper2.SetBackgroundColour(bckgrdcolor)
1007 self.hyper2.EnableRollover(True)
1008 self.hyper2.SetUnderlines(False, False, True)
1009 self.hyper2.SetBold(True)
1010 self.hyper2.UpdateLink()
1011 label_lerass = wx.StaticText(PanelPres, -1, u'Laboratoire ')
1012 label_lerass.SetForegroundColour(txtcolour)
1013 label_lerass.SetBackgroundColour(bckgrdcolor)
1014 self.hyper_lerass = hl.HyperLinkCtrl(PanelPres, -1, u'LERASS', URL="http://www.lerass.com")
1015 self.hyper_lerass.SetColours(linkcolor, linkcolor, "RED")
1016 self.hyper_lerass.SetBackgroundColour(bckgrdcolor)
1017 self.hyper_lerass.EnableRollover(True)
1018 self.hyper_lerass.SetUnderlines(False, False, True)
1019 self.hyper_lerass.SetBold(True)
1020 self.hyper_lerass.UpdateLink()
1021 blank = wx.StaticText(PanelPres, -1, u'\n')
1022 blank1 = wx.StaticText(PanelPres, -1, u'\n')
1023 labellicence = wx.StaticText(PanelPres, -1, u'Licence GNU GPL')
1024 labellicence.SetForegroundColour(txtcolour)
1025 labellicence.SetBackgroundColour(bckgrdcolor)
1026 labelcopy = wx.StaticText(PanelPres, -1, ConfigGlob.get('DEFAULT', 'copyright'))
1027 labelcopy.SetForegroundColour(txtcolour)
1028 labelcopy.SetBackgroundColour(bckgrdcolor)
1029 python_img = wx.Image(os.path.join(ImagePath,'python-logo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1030 r_img = wx.Image(os.path.join(ImagePath,'Rlogo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1031 lexique_img = wx.Image(os.path.join(ImagePath,'LexTexte4.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1032 but_python = wx.BitmapButton(self, -1, python_img)
1033 but_lexique = wx.BitmapButton(self, -1, lexique_img)
1034 but_r = wx.BitmapButton(self, -1, r_img)
1035 self.Bind(wx.EVT_BUTTON, self.OnPython, but_python)
1036 self.Bind(wx.EVT_BUTTON, self.OnLexique, but_lexique)
1037 self.Bind(wx.EVT_BUTTON, self.OnR, but_r)
1040 #grid_sizer_1.Add(label3, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1041 grid_sizer_1.Add(self.hyper2, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1042 grid_sizer_3.Add(label_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1043 grid_sizer_3.Add(self.hyper_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1044 sizer4.Add(label_1, 0, wx.ALIGN_CENTER, 5)
1045 sizer2.Add(label2, 0, wx.ALIGN_CENTER, 5)
1046 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1047 sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1048 sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1049 sizer2.Add(grid_sizer_3, 0, wx.ALIGN_CENTER, 5)
1050 sizer2.Add(wx.StaticText(PanelPres, -1, u' '), 0, wx.ALIGN_CENTER, 5)
1051 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1052 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1053 sizer2.Add(grid_sizer_1, 0, wx.ALIGN_CENTER, 5)
1054 sizer2.Add(labellicence, 0, wx.ALIGN_CENTER, 5)
1055 sizer2.Add(labelcopy, 0, wx.ALIGN_CENTER, 5)
1056 sizer1.Add(sizer4, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1057 PanelPres.SetSizer(sizer2)
1058 sizer5.Add(blank, 1, wx.EXPAND | wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 2)
1059 sizer5.Add(PanelPres, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1060 sizer5.Add(blank1, 1, wx.ALIGN_CENTER_HORIZONTAL,2)
1061 grid_sizer_2.Add(but_python, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1062 grid_sizer_2.Add(but_lexique, 1,wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1063 grid_sizer_2.Add(but_r, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1065 sizer1.Add(sizer5, 3, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 1)
1066 sizer1.Add(grid_sizer_2, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
1067 self.SetSizer(sizer1)
1070 def OnPython(self,evt):
1071 webbrowser.open('http://www.python.org')
1073 def OnLexique(self,evt):
1074 webbrowser.open('http://www.lexique.org')
1077 webbrowser.open('http://www.r-project.org')
1079 class MySplashScreen(wx.SplashScreen):
1081 bmp = wx.Image(os.path.join(ImagePath, 'splash.png')).ConvertToBitmap()
1082 wx.SplashScreen.__init__(self, bmp,
1083 wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
1085 self.Bind(wx.EVT_CLOSE, self.OnClose)
1086 self.fc = wx.FutureCall(1, self.ShowMain)
1088 def OnClose(self, evt):
1092 if self.fc.IsRunning():
1097 frame = IraFrame(None, -1, "IRaMuTeQ " + ConfigGlob.get('DEFAULT', 'version'), size=(1100, 800))
1100 frame.OnOpenFromCmdl()
1101 # if self.fc.IsRunning():
1103 #wx.CallAfter(frame.ShowTip)
1105 class MyApp(wx.App):
1108 Create and show the splash screen. It will then create and show
1109 the main frame when it is time to do so.
1111 wx.SystemOptions.SetOptionInt("mac.window-plain-transition", 1)
1112 self.SetAppName("Iramuteq")
1113 splash = MySplashScreen()
1121 if __name__ == '__main__':