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
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.ConfigGlob = ConfigGlob
154 self.ConfigPath = ConstructConfigPath(UserConfigPath)
155 self.pref = RawConfigParser()
157 mylocale = wx.Locale(wx.LANGUAGE_FRENCH)
158 mylocale.AddCatalogLookupPathPrefix(os.path.join(AppliPath,'locale'))
159 mylocale.AddCatalog('iramuteq')
160 presLan_en = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['en'])
161 presLan_fr = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['fr_FR'])
165 # tell FrameManager to manage this frame
166 #self._mgr = wx.aui.AuiManager()
167 self._mgr = aui.AuiManager()
168 self._mgr.SetManagedWindow(self)
171 #--------------------------------------------------------------------------------
172 self.mb = wx.MenuBar()
174 file_menu = wx.Menu()
175 item = wx.MenuItem(file_menu, ID_OpenData, _(u"Open a matrix"), _(u"Open a matrix"))
176 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
177 file_menu.AppendItem(item)
179 item = wx.MenuItem(file_menu, ID_OpenText, _(u"Open a text corpora"), _(u"Open a text corpora"))
180 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
181 file_menu.AppendItem(item)
183 item = wx.MenuItem(file_menu, ID_OnOpenAnalyse, _(u"Open an analysis"), _("Open an analysis"))
184 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
185 file_menu.AppendItem(item)
187 item1 = wx.MenuItem(file_menu, ID_Import, _(u"Import a factiva corpora..."), _("Import a factiva corpora..."))
188 item1.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_TIP))
189 file_menu.AppendItem(item1)
192 item = wx.MenuItem(file_menu, ID_SaveTab, _(u"Save tab as..."), _(u"Save tab as..."))
193 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_SAVE_AS))
195 file_menu.AppendItem(item)
197 file_menu.Append(wx.ID_EXIT, _(u"Exit"))
199 edit_menu = wx.Menu()
200 edit_menu.Append(wx.ID_PREFERENCES, '', _(u'Preferences'))
202 view_menu = wx.Menu()
203 view_menu.Append(ID_ACCEUIL, _(u"Home page"))
204 view_menu.Append(ID_VIEWDATA, _(u"Show data"))
205 view_menu.Append(ID_RESULT, _(u'Show results'))
206 #view_menu.AppendSeparator()
208 analyse_menu = wx.Menu()
209 analyse_menu.Append(ID_Freq, u"Fréquences")
210 analyse_menu.Append(ID_Chi2, u"Chi2")
211 #analyse_menu.Append(ID_Student, u"t de Student")
212 menu_classif = wx.Menu()
213 menu_classif.Append(ID_CHDAlceste, u"Méthode Alceste")
214 menu_classif.Append(ID_CHDSIM, u"Par matrice des distances")
215 analyse_menu.AppendMenu(-1, u"Classification", menu_classif)
216 analyse_menu.Append(ID_AFCM, u"AFCM")
217 analyse_menu.Append(ID_SIMI, u"Analyse de similitudes")
218 ID_RCODE = wx.NewId()
219 analyse_menu.Append(ID_RCODE, u"Code R...")
221 text_menu = wx.Menu()
222 text_menu.Append(ID_CHECKCORPUS, u"Vérifier le corpus")
223 text_menu.Append(ID_TEXTSTAT, u"Statistiques textuelles")
224 text_menu.Append(ID_ASLEX, u"Spécificités et AFC")
225 #text_menu.Append(ID_TEXTAFCM, u"AFC sur UCI / Vocabulaire")
226 menu_classiftxt = wx.Menu()
227 menu_classiftxt.Append(ID_TEXTALCESTE, u"Méthode Alceste")
228 menu_classiftxt.Append(ID_TEXTPAM, u"Par matrice des distances")
229 text_menu.AppendMenu(-1, u"Classification", menu_classiftxt)
230 text_menu.Append(ID_SimiTxt, u'Analyse de similitude')
232 text_menu.Append(ID_WC, u'Nuage de mots')
234 help_menu = wx.Menu()
235 help_menu.Append(wx.ID_ABOUT, u'À propos...')
236 help_menu.Append(wx.ID_HELP, u'Aide en ligne')
238 self.mb.Append(file_menu, _(u"File"))
239 self.mb.Append(edit_menu, _(u"Edition"))
240 self.mb.Append(view_menu, _(u"View"))
241 self.mb.Append(analyse_menu, _("Spreadsheet analysis"))
242 self.mb.Append(text_menu, _(u"Text analysis"))
243 self.mb.Append(help_menu, _(u"Help"))
245 self.SetMenuBar(self.mb)
246 #--------------------------------------------------------------------
247 self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
248 self.statusbar.SetStatusWidths([-2, -3])
249 self.statusbar.SetStatusText(u"Prêt", 0)
250 self.statusbar.SetStatusText(u"Bienvenue", 1)
252 # min size for the frame itself isn't completely done.
253 # see the end up FrameManager::Update() for the test
254 # code. For now, just hard code a frame minimum size
255 self.SetMinSize(wx.Size(400, 400))
257 # create some toolbars
258 tb1 = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
259 wx.TB_FLAT | wx.TB_NODIVIDER)
260 tb1.SetToolBitmapSize(wx.Size(16, 16))
261 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")
263 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")
267 #------------------------------------------------------------------------------------------------
269 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)
271 #self._mgr.AddPane(self.text_ctrl_txt, wx.aui.AuiPaneInfo().
272 # Name("Text").CenterPane())
273 self._mgr.AddPane(self.text_ctrl_txt, aui.AuiPaneInfo().
274 Name("Text").CenterPane())
275 #self._mgr.AddPane(IntroPanel(self), wx.aui.AuiPaneInfo().Name("Intro_Text").
277 self._mgr.AddPane(IntroPanel(self), aui.AuiPaneInfo().Name("Intro_Text").
279 #if not os.path.exists(os.path.join(UserConfigPath, 'history.db')) :
280 # with open(os.path.join(UserConfigPath, 'history.db'), 'w') as f :
282 self.history = History(os.path.join(UserConfigPath, 'history.db'))
283 self.tree = LeftTree(self)
284 self._mgr.AddPane(self.tree, aui.AuiPaneInfo().Name("lefttree").Caption("Navigateur").
285 Left().MinSize(wx.Size(200,500)).Layer(1).Position(1).CloseButton(False).MaximizeButton(True).
286 MinimizeButton(True))
288 #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)
289 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)
290 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
291 self.nb.SetAGWWindowStyleFlag(notebook_flags)
292 self.nb.SetArtProvider(aui.ChromeTabArt())
293 #self.nb.SetArtProvider(aui.VC8TabArt())
294 #self.nb.parent = self
295 #self._notebook_style = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.NO_BORDER
296 #self._mgr.AddPane(self.nb, wx.aui.AuiPaneInfo().
297 # Name("Tab_content").
299 self._mgr.AddPane(self.nb, aui.AuiPaneInfo().
302 self.Sheet = MySheet(self)
303 #self._mgr.AddPane(self.Sheet, wx.aui.AuiPaneInfo().Name("Data").CenterPane())
304 self._mgr.AddPane(self.Sheet, aui.AuiPaneInfo().Name("Data").CenterPane())
305 self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnCloseTab)
306 self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
307 # add the toolbars to the manager
309 #self._mgr.AddPane(tb1, wx.aui.AuiPaneInfo().
310 # Name("tb1").Caption("Fichiers").
311 # ToolbarPane().Top().
312 # LeftDockable(False).RightDockable(False))
313 self._mgr.AddPane(tb1, aui.AuiPaneInfo().
314 Name("tb1").Caption("Fichiers").
316 LeftDockable(True).RightDockable(False))
318 self.ShowAPane("Intro_Text")
319 self._mgr.GetPane("lefttree").Show()
320 self._mgr.GetPane("classif_tb").Hide()
321 # "commit" all changes made to FrameManager
324 # Show How To Use The Closing Panes Event
325 ##################################################################
326 self.Bind(wx.EVT_MENU, self.OnAcceuil, id=ID_ACCEUIL)
327 self.Bind(wx.EVT_MENU, self.OnViewData, id=ID_VIEWDATA)
328 self.Bind(wx.EVT_MENU, self.ShowTab, id=ID_RESULT)
329 self.Bind(wx.EVT_MENU, self.OnOpenData, id=ID_OpenData)
330 self.Bind(wx.EVT_MENU, self.OnOpenText, id=ID_OpenText)
331 self.Bind(wx.EVT_MENU, self.OnOpenAnalyse, id=ID_OnOpenAnalyse)
332 self.Bind(wx.EVT_MENU, self.import_factiva, id= ID_Import)
333 self.Bind(wx.EVT_MENU, self.OnFreq, id=ID_Freq)
334 self.Bind(wx.EVT_MENU, self.OnChi2, id=ID_Chi2)
335 self.Bind(wx.EVT_MENU, self.OnStudent, id=ID_Student)
336 self.Bind(wx.EVT_MENU, self.OnCHDSIM, id=ID_CHDSIM)
337 self.Bind(wx.EVT_MENU, self.OnCHDAlceste, id=ID_CHDAlceste)
338 self.Bind(wx.EVT_MENU, self.OnAFCM, id=ID_AFCM)
339 self.Bind(wx.EVT_MENU, self.OnRCode, id=ID_RCODE)
340 self.Bind(wx.EVT_MENU, self.OnCheckcorpus, id = ID_CHECKCORPUS)
341 self.Bind(wx.EVT_MENU, self.OnTextStat, id=ID_TEXTSTAT)
342 self.Bind(wx.EVT_MENU, self.OnTextSpec, id=ID_ASLEX)
343 self.Bind(wx.EVT_MENU, self.OnTextAfcm, id=ID_TEXTAFCM)
344 self.Bind(wx.EVT_MENU, self.OnTextAlceste, id=ID_TEXTALCESTE)
345 self.Bind(wx.EVT_MENU, self.OnPamSimple, id=ID_TEXTPAM)
346 self.Bind(wx.EVT_MENU, self.OnSimiTxt, id=ID_SimiTxt)
347 self.Bind(wx.EVT_MENU, self.OnWordCloud, id=ID_WC)
348 self.Bind(wx.EVT_MENU, self.OnSimi, id=ID_SIMI)
349 self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
350 self.Bind(wx.EVT_MENU, self.OnSaveTabAs, id=ID_SaveTab)
351 self.Bind(wx.EVT_MENU, self.OnAbout, id=wx.ID_ABOUT)
352 self.Bind(wx.EVT_MENU, self.OnHelp, id=wx.ID_HELP)
353 self.Bind(wx.EVT_MENU, self.OnPref, id=wx.ID_PREFERENCES)
354 self.Bind(wx.EVT_CLOSE, self.OnClose)
355 ##################################################################
356 flags = self._mgr.GetAGWFlags()
357 #flags &= ~wx.aui.AUI_MGR_TRANSPARENT_HINT
358 #flags &= ~wx.aui.AUI_MGR_VENETIAN_BLINDS_HINT
359 #flags &= ~wx.aui.AUI_MGR_RECTANGLE_HINT
360 flags &= ~(aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING)
361 self._mgr.SetAGWFlags(self._mgr.GetAGWFlags() ^ (aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING))
362 self._mgr.GetArtProvider().SetMetric(aui.AUI_DOCKART_GRADIENT_TYPE, aui.AUI_GRADIENT_HORIZONTAL)
363 self.GetDockArt().SetColor(aui.AUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR, "#00FFF9")
366 self._icon = wx.Icon(os.path.join(ImagePath, "iraicone.ico"), wx.BITMAP_TYPE_ICO)
367 self.SetIcon(self._icon)
368 ##########################
370 self.input_path = [False]
371 self.TEMPDIR = tempfile.mkdtemp('iramuteq')
372 self.FileTabList = []
378 self.g_header = False
385 self.SysEncoding = sys.getdefaultencoding()
386 self.syscoding = sys.getdefaultencoding()
387 #print 'SysEncoding',self.SysEncoding
388 if self.SysEncoding == 'mac-roman' : self.SysEncoding = 'MacRoman'
392 self.pref.read(self.ConfigPath['preferences'])
401 self.pref.read(self.ConfigPath['preferences'])
403 #configuration des chemins de R
404 self.PathPath = ConfigParser()
405 self.PathPath.read(ConfigPath['path'])
407 if not CheckRPath(self.PathPath) :
408 if sys.platform == 'win32':
409 BestRPath = FindRPAthWin32()
411 BestRPath = FindRPathNix()
413 self.PathPath.set('PATHS', 'rpath', BestRPath)
414 with open(ConfigPath['path'], 'w') as f :
415 self.PathPath.write(f)
419 self.RPath = self.PathPath.get('PATHS', 'rpath')
422 if not RLibsAreInstalled(self) :
426 Le chemin de l'executable de R n'a pas été trouvé.
427 Si R n'est pas installé, vous devez l'installer (http://www.r-project.org/).
428 Si R n'est pas installé dans le répertoire par défaut
429 (souvent C:\Program Files\R\R-2.x.x\R.exe sous windows ou /usr/bin/R sous linux ou Mac Os X)
430 vous devez signaler le chemin de l'éxecutable de R dans les préférences."""
431 dlg = wx.MessageDialog(self, msg, u"Problème de configuration", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
433 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
439 self.sound = self.pref.getboolean('iramuteq', 'sound')
440 self.check_update = self.pref.getboolean('iramuteq', 'checkupdate')
441 self.version = ConfigGlob.get('DEFAULT', 'version')
444 ##############################################################@
445 self.DisEnSaveTabAs(False)
446 self.ShowMenu(_("View"), False)
447 self.ShowMenu(_("Spreadsheet analysis"), False)
448 self.ShowMenu(_("Text analysis"), False)
452 def OnVerif(self, evt) :
453 pack = CheckRPackages(self)
455 dlg = wx.MessageDialog(self, u"Installation OK", u"Installation", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
457 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
460 #FIXME marche pas sous mac ?
461 def DisEnSaveTabAs(self, DISEN):
463 file_menu = self.mb.GetMenu(0)
464 items = file_menu.GetMenuItems()
465 items[4].Enable(DISEN)
467 def ShowMenu(self, menu, Show=True):
468 menu_pos = self.mb.FindMenu(menu)
469 self.mb.EnableTop(menu_pos, Show)
470 self.mb.UpdateMenus()
473 #--------------------------------------------------------------------
474 def OnClose(self, event):
476 with open(self.ConfigPath['path'], 'w') as f :
477 self.PathPath.write(f)
478 if self.DictTab != {} :
479 savestates = [self.DictTab[item][0] for item in self.DictTab]
480 if False in savestates :
481 notsave = [item for item in self.DictTab if self.DictTab[item][0] == False]
483 Certains résultats ne sont pas enregistrés.
484 Voulez-vous fermer quand même ?"""
485 dlg = wx.MessageDialog(self, msg, "Sauvegarde",
486 wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
488 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
493 for item in notsave :
494 for tmpfile in self.DictTab[item][1:] :
496 print 'remove : ' + tmpfile
508 #if sys.platform == 'win32' :
509 # os.system("taskkill /im iramuteq.exe /f")
510 # print 'meurtre de process'
512 def OnOpenData(self, event):
513 inputname, self.input_path = OnOpen(self, "Data")
515 self.filename = self.input_path[0]
516 self.tableau = Tableau(self,os.path.abspath(self.input_path[0]))
517 get_table_param(self, self.input_path[0])
518 self.tableau.make_content()
519 self.tableau.show_tab()
521 def OnOpenAnalyse(self, event):
522 self.AnalysePath = OnOpen(self, "Analyse")
523 OpenAnalyse(self, self.AnalysePath[1][0], True)
524 self.ShowMenu(_("View"))
526 def OnOpenText(self, event):
527 inputname, self.input_path = OnOpen(self, "Texte")
528 self.filename = self.input_path[0]
532 def OnViewData(self, event):
535 if self.type == "Data":
536 if not self.DataPop :
537 self.Sheet.Populate(self.content)
540 self.ShowAPane(u"Data")
541 elif self.type == "Texte" or self.type == 'Analyse' :
542 if not self.DataTxt :
543 self.text_ctrl_txt.Clear()
544 self.text_ctrl_txt.write(self.content)
545 self.text_ctrl_txt.ShowPosition(0)
548 self.ShowAPane(u"Text")
552 #dial = EncodeDialog(self)
553 dlg = wx.ProgressDialog("Ouverture...",
554 "Veuillez patienter...",
557 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
560 builder = Builder(self, dlg)
561 if builder.res == wx.ID_OK :
563 corpus = builder.doanalyse()
564 self.history.add(corpus.parametres)
565 self.tree.OnItemAppend(corpus.parametres)
566 OpenAnalyse(self, corpus.parametres)
569 #self.content = DoConf().totext(corpus.parametres)
570 # parametres = DoConf(os.path.join(UserConfigPath,'corpus.cfg')).getoptions('corpus')
571 # parametres['originalpath'] = self.filename
573 # parametres['pathout'] = PathOut(self.filename, 'corpus').dirout
574 # dial = CorpusPref(self, parametres)
575 # dial.CenterOnParent()
576 # dial.txtpath.SetLabel(self.filename)
577 # res = dial.ShowModal()
578 # parametres = dial.doparametres()
580 # ReadLexique(self, lang = parametres['lang'])
581 # self.expressions = ReadDicoAsDico(self.DictPath.get(parametres['lang'], 'french_exp'))
582 # corpus = BuildFromAlceste(self.filename, parametres, self.lexique, self.expressions).corpus
583 #self.corpus_encodage = dial.encodages[dial.list_encodages.GetSelection()][0]
584 #self.corpus_lang = dial.langues[dial.choice_dict.GetSelection()]
587 keepGoing = dlg.Update(count, u"Lecture du fichier")
588 # msg = u"Ce fichier ne semble pas être encodé en %s" % self.corpus_encodage
589 # dial = wx.MessageDialog(self, msg, u"Problème d'encodage", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
590 # dial.CenterOnParent()
591 # res = dial.ShowModal()
594 self.ShowMenu(_("View"))
595 self.ShowMenu(_("Text analysis"))
596 self.ShowMenu(_(u"Spreadsheet analysis"), False)
601 keepGoing = dlg.Update(count, u"Chargement du dictionnaire")
603 #self.OnViewData(wx.EVT_BUTTON)
605 def OnExit(self, event):
608 def OnAbout(self, event):
609 info = wx.AboutDialogInfo()
610 info.Name = ConfigGlob.get('DEFAULT', 'name')
611 info.Version = ConfigGlob.get('DEFAULT', 'version')
612 info.Copyright = ConfigGlob.get('DEFAULT', 'copyright')
613 info.Description = u"""
614 Interface de R pour les Analyses Multidimensionnelles
615 de Textes et de Questionnaires
618 construit avec des logiciels libres.
624 info.WebSite = ("http://www.iramuteq.org", u"Site web IRaMuTeQ")
625 dev = ConfigGlob.get('DEFAULT', 'dev').split(';')
626 info.Developers = dev
627 info.License = u"""Iramuteq est un logiciel libre ; vous pouvez le diffuser et/ou le modifier
628 suivant les termes de la Licence Publique Générale GNU telle que publiée
629 par la Free Software Foundation ; soit la version 2 de cette licence,
630 soit (à votre convenance) une version ultérieure.
632 Iramuteq est diffusé dans l'espoir qu'il sera utile,
633 mais SANS AUCUNE GARANTIE ; sans même une garantie implicite
634 de COMMERCIALISATION ou d'ADÉQUATION À UN USAGE PARTICULIER.
635 Voyez la Licence Publique Générale GNU pour plus de détails.
637 Vous devriez avoir reçu une copie de la Licence Publique Générale GNU
638 avec Iramuteq ; sinon, veuillez écrire à la Free Software Foundation,
639 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, États-Unis."""
642 def GetDockArt(self):
643 return self._mgr.GetArtProvider()
648 def OnPageChanged(self, event) :
649 new = event.GetSelection()
650 nobject = event.GetEventObject()
651 parent = nobject.GetParent()
652 if isinstance(parent, IraFrame) :
653 npage = self.nb.GetPage(new)
654 self.tree.GiveFocus(uuid=npage.parametres['uuid'])
656 def OnCloseTab(self, evt):
657 #log.info('Closing tab %s' % str(evt.GetEventObject()))
658 ctrl = evt.GetEventObject()
659 if isinstance(ctrl.GetParent(), aui.AuiNotebook) or isinstance(ctrl.GetParent(), wx.Panel):
663 page = self.nb.GetPage(self.nb.GetSelection())
664 if 'parametres' in dir(page) and isinstance(ctrl.GetParent(), IraFrame) :
665 self.history.rmtab(page.parametres)
666 self.tree.CloseItem(uuid = page.parametres['uuid'])
667 TabTitle = self.nb.GetPageText(self.nb.GetSelection())
668 if self.DictTab != {} :
669 if TabTitle in self.DictTab :
670 ListFile=self.DictTab[TabTitle]
671 if False in ListFile:
673 Certains résultats ne sont pas enregistrer.
674 Voulez-vous fermer quand même ?"""
675 dlg = wx.MessageDialog(self, msg, "Sauvegarde",wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
678 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
683 for f in ListFile[1:] :
688 elif True in ListFile :
691 del self.DictTab[TabTitle]
696 if self.nb.GetPageCount() == 1 and remove and not notebook :
699 def LastTabClose(self) :
700 if self.nb.GetPageCount() == 1 :
701 self.DisEnSaveTabAs(False)
703 self.ShowAPane("Text")
705 self.ShowAPane("Data")
707 self.ShowAPane("Intro_Text")
709 def OnSaveTabAs(self, event):
710 SelectTab = self.nb.GetSelection()
711 TabTitle = self.nb.GetPageText(SelectTab)
712 FileToSave = self.DictTab[TabTitle]
715 self, message="Enregistrer sous...", defaultDir=os.getcwd(),
716 defaultFile="resultat.html", wildcard="Tous les fichiers|*", style=wx.SAVE | wx.OVERWRITE_PROMPT
718 dlg.SetFilterIndex(2)
721 if dlg.ShowModal() == wx.ID_OK:
723 Dirname = os.path.dirname(Path)
724 Filename = dlg.GetFilename()
729 shutil.copyfile(FileToSave[-1], Path)
730 os.remove(FileToSave[len(FileToSave) - 1])
731 NewListFile.append(True)
732 NewListFile.append(Path)
733 for f in FileToSave[1:-1] :
734 Fileout = os.path.join(Dirname, os.path.basename(f))
735 shutil.copyfile(f, Fileout)
736 NewListFile.append(Fileout)
739 self.DictTab[TabText] = NewListFile
740 del self.DictTab[TabTitle]
741 self.nb.SetPageText(SelectTab, TabText)
743 def GetStartPosition(self):
747 pt = self.ClientToScreen(wx.Point(0, 0))
749 return wx.Point(pt.x + x, pt.y + x)
751 def ShowAPane(self, panel):
752 for pane in self._mgr.GetAllPanes() :
753 if not pane.IsToolbar() and pane.name != 'lefttree':
755 self._mgr.GetPane(panel).Show()
758 def OnAcceuil(self, event):
759 self.ShowAPane(u"Intro_Text")
762 def CreateHTMLCtrl(self):
763 ctrl = wx.html.HtmlWindow(self, -1, wx.DefaultPosition, wx.Size(400, 300))
764 if "gtk2" in wx.PlatformInfo:
765 ctrl.SetStandardFonts()
766 ctrl.SetPage(u"text")
769 def ShowTab(self, evt):
770 self.ShowAPane("Tab_content")
772 ################################################################
774 ################################################################
776 def OnFreq(self, event):
782 def OnChi2(self, event):
784 # print('PAS DE DEBUG SUR CHI2')
785 chi = ChiSquare(self)
789 def OnStudent(self, event):
795 def OnRCode(self, event):
801 def OnCHDSIM(self, event):
803 # print 'ATTENTION!!!!'
804 chdsim = ChdCluster(self)
805 if chdsim.val == wx.ID_OK:
810 def OnCHDAlceste(self, event):
812 # print('PLUS DE BUG SUR ALCESTE QUESTIONNAIRE')
813 self.quest = AnalyseQuest(self)
814 if self.quest.val == wx.ID_OK:
819 def OnSimiTxt(self, evt, corpus = None) :
820 # print 'PLUS DE BUG SUR SIMITXT'
822 #self.Text = SimiTxt(self)
824 corpus = self.tree.getcorpus()
825 self.Text = SimiTxt(self, corpus, parametres = {'type': 'simitxt'}, dlg = progressbar(self, 3))
826 if self.Text.val == wx.ID_OK :
831 def OnWordCloud(self, evt, corpus = None) :
832 # print 'PLUS DE BUG SUR WORDCLOUD'
835 corpus = self.tree.getcorpus()
836 self.Text = WordCloud(self, corpus, parametres = {'type' : 'wordcloud'}, dlg = progressbar(self, 3))
837 if self.Text.val == wx.ID_OK :
843 def OnAFCM(self, event):
849 def OnCheckcorpus(self, evt):
855 def OnTextStat(self, event, corpus = None):
856 print 'PAS DE BUG SUR TEXT STAT'
859 corpus = self.tree.getcorpus()
860 self.Text = Stat(self, corpus, parametres = {'type': 'stat'}, dlg = progressbar(self, 7))
862 if self.Text.val == wx.ID_OK :
867 def OnTextSpec(self, event, corpus = None):
869 #self.Text = AsLexico(self)
870 print('ATTENTION : PLUS DE BUG SUR LEXICO')
872 corpus = self.tree.getcorpus()
873 self.Text = Lexico(self, corpus, parametres = {'type' : 'spec'}, dlg = progressbar(self, 3))
874 if self.Text.val == wx.ID_OK :
879 def OnTextAfcm(self, event):
886 def import_factiva(self,event):
892 def OnTextAlceste(self, event, corpus = None):
894 #print('ATTENTION : PLUS DE BUG SUR ALCESTE')
895 #RunAnalyse(self, corpus, Alceste, OptAlceste)
897 corpus = self.tree.getcorpus()
898 self.Text = Alceste(self, corpus, parametres = {'type': 'alceste'}, dlg = progressbar(self,6))
899 if self.Text.val == wx.ID_OK:
904 def OnPamSimple(self, event):
906 self.Text = PamTxt(self)
907 if self.Text.val == wx.ID_OK:
912 def OnSimi(self,evt):
914 #print 'ATTENTION !!!! VERGES'
915 self.res = DoSimi(self, param = None)
916 #self.res = Verges(self)
917 if self.res.val == wx.ID_OK :
921 #################################################################
923 def OnHelp(self, event):
924 webbrowser.open('http://www.iramuteq.org/documentation')
926 def OnPref(self, event):
927 dlg = PrefDialog(self)
929 self.val = dlg.ShowModal()
932 if self.check_update:
937 #CheckRPackages(self)
939 def OnOpenFromCmdl(self):
941 if options.filename :
942 if os.path.exists(options.filename):
943 self.filename = os.path.abspath(options.filename)
947 if os.path.exists(os.path.realpath(args[0])):
948 self.filename = os.path.abspath(os.path.realpath(args[0]))
954 if os.path.splitext(self.filename)[1] in ['.csv', '.xls', '.ods']:
955 self.tableau = Tableau(self, self.filename)
956 get_table_param(self, self.filename)
957 self.tableau.make_content()
958 self.tableau.show_tab()
959 #open_data(self, self.filename)
960 elif os.path.splitext(self.filename)[1] == '.txt':
962 elif os.path.splitext(self.filename)[1] == '.ira' :
963 #self.corpus = Corpus(self)
964 #self.Text = OpenAnalyse(self, self.filename)
965 OpenAnalyse(self, self.filename)
967 print 'ce fichier n\'existe pas'
971 class IntroPanel(wx.Panel):
972 def __init__(self, parent):
973 wx.Panel.__init__(self, parent)
974 #col = randint(0, 255)
975 #col1 = randint(0,255)
976 #col2 = randint(0,255)
978 bckgrdcolor = wx.Colour(col, col, col)
979 self.SetBackgroundColour(bckgrdcolor)
980 txtcolour = wx.Colour(250, 250, 250)
981 linkcolor = wx.Colour(255, 0, 0)
982 sizer1 = wx.BoxSizer(wx.VERTICAL)
983 sizer2 = wx.BoxSizer(wx.VERTICAL)
984 sizer3 = wx.BoxSizer(wx.HORIZONTAL)
985 sizer4 = wx.BoxSizer(wx.VERTICAL)
986 sizer5 = wx.BoxSizer(wx.HORIZONTAL)
987 grid_sizer_1 = wx.FlexGridSizer(1, 4, 0, 0)
988 grid_sizer_3 = wx.FlexGridSizer(1, 4, 0, 0)
989 grid_sizer_2 = wx.FlexGridSizer(1, 3, 0, 0)
990 PanelPres = wx.Panel(self)
991 PanelPres.SetBackgroundColour(bckgrdcolor)
992 label_1 = wx.StaticText(self, -1, u"IRaMuTeQ", size=(-1, -1))
993 label_1.SetFont(wx.Font(46, wx.TELETYPE, wx.NORMAL, wx.BOLD, 0, "Purisa"))
994 label_1.SetForegroundColour(wx.RED)
995 label2 = wx.StaticText(PanelPres, -1 , u'\nVersion ' + ConfigGlob.get('DEFAULT', 'version') + '\n')
996 label2.SetForegroundColour(txtcolour)
997 label2.SetBackgroundColour(bckgrdcolor)
998 #label3 = wx.StaticText(PanelPres, -1 , u'Equipe ')
999 #label3.SetForegroundColour(txtcolour)
1000 #label3.SetBackgroundColour(bckgrdcolor)
1001 self.hyper2 = hl.HyperLinkCtrl(PanelPres, wx.ID_ANY, u"REPERE", URL="http://repere.no-ip.org/")
1002 self.hyper2.SetColours(linkcolor, linkcolor, "RED")
1003 self.hyper2.SetBackgroundColour(bckgrdcolor)
1004 self.hyper2.EnableRollover(True)
1005 self.hyper2.SetUnderlines(False, False, True)
1006 self.hyper2.SetBold(True)
1007 self.hyper2.UpdateLink()
1008 label_lerass = wx.StaticText(PanelPres, -1, u'Laboratoire ')
1009 label_lerass.SetForegroundColour(txtcolour)
1010 label_lerass.SetBackgroundColour(bckgrdcolor)
1011 self.hyper_lerass = hl.HyperLinkCtrl(PanelPres, -1, u'LERASS', URL="http://www.lerass.com")
1012 self.hyper_lerass.SetColours(linkcolor, linkcolor, "RED")
1013 self.hyper_lerass.SetBackgroundColour(bckgrdcolor)
1014 self.hyper_lerass.EnableRollover(True)
1015 self.hyper_lerass.SetUnderlines(False, False, True)
1016 self.hyper_lerass.SetBold(True)
1017 self.hyper_lerass.UpdateLink()
1018 blank = wx.StaticText(PanelPres, -1, u'\n')
1019 blank1 = wx.StaticText(PanelPres, -1, u'\n')
1020 labellicence = wx.StaticText(PanelPres, -1, u'Licence GNU GPL')
1021 labellicence.SetForegroundColour(txtcolour)
1022 labellicence.SetBackgroundColour(bckgrdcolor)
1023 labelcopy = wx.StaticText(PanelPres, -1, ConfigGlob.get('DEFAULT', 'copyright'))
1024 labelcopy.SetForegroundColour(txtcolour)
1025 labelcopy.SetBackgroundColour(bckgrdcolor)
1026 python_img = wx.Image(os.path.join(ImagePath,'python-logo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1027 r_img = wx.Image(os.path.join(ImagePath,'Rlogo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1028 lexique_img = wx.Image(os.path.join(ImagePath,'LexTexte4.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1029 but_python = wx.BitmapButton(self, -1, python_img)
1030 but_lexique = wx.BitmapButton(self, -1, lexique_img)
1031 but_r = wx.BitmapButton(self, -1, r_img)
1032 self.Bind(wx.EVT_BUTTON, self.OnPython, but_python)
1033 self.Bind(wx.EVT_BUTTON, self.OnLexique, but_lexique)
1034 self.Bind(wx.EVT_BUTTON, self.OnR, but_r)
1037 #grid_sizer_1.Add(label3, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1038 grid_sizer_1.Add(self.hyper2, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1039 grid_sizer_3.Add(label_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1040 grid_sizer_3.Add(self.hyper_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1041 sizer4.Add(label_1, 0, wx.ALIGN_CENTER, 5)
1042 sizer2.Add(label2, 0, wx.ALIGN_CENTER, 5)
1043 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1044 sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1045 sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1046 sizer2.Add(grid_sizer_3, 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(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1050 sizer2.Add(grid_sizer_1, 0, wx.ALIGN_CENTER, 5)
1051 sizer2.Add(labellicence, 0, wx.ALIGN_CENTER, 5)
1052 sizer2.Add(labelcopy, 0, wx.ALIGN_CENTER, 5)
1053 sizer1.Add(sizer4, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1054 PanelPres.SetSizer(sizer2)
1055 sizer5.Add(blank, 1, wx.EXPAND | wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 2)
1056 sizer5.Add(PanelPres, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1057 sizer5.Add(blank1, 1, wx.ALIGN_CENTER_HORIZONTAL,2)
1058 grid_sizer_2.Add(but_python, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1059 grid_sizer_2.Add(but_lexique, 1,wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1060 grid_sizer_2.Add(but_r, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1062 sizer1.Add(sizer5, 3, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 1)
1063 sizer1.Add(grid_sizer_2, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
1064 self.SetSizer(sizer1)
1067 def OnPython(self,evt):
1068 webbrowser.open('http://www.python.org')
1070 def OnLexique(self,evt):
1071 webbrowser.open('http://www.lexique.org')
1074 webbrowser.open('http://www.r-project.org')
1076 class MySplashScreen(wx.SplashScreen):
1078 bmp = wx.Image(os.path.join(ImagePath, 'splash.png')).ConvertToBitmap()
1079 wx.SplashScreen.__init__(self, bmp,
1080 wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
1082 self.Bind(wx.EVT_CLOSE, self.OnClose)
1083 self.fc = wx.FutureCall(1, self.ShowMain)
1085 def OnClose(self, evt):
1089 if self.fc.IsRunning():
1094 frame = IraFrame(None, -1, "IRaMuTeQ " + ConfigGlob.get('DEFAULT', 'version'), size=(1100, 800))
1097 frame.OnOpenFromCmdl()
1098 # if self.fc.IsRunning():
1100 #wx.CallAfter(frame.ShowTip)
1102 class MyApp(wx.App):
1105 Create and show the splash screen. It will then create and show
1106 the main frame when it is time to do so.
1108 wx.SystemOptions.SetOptionInt("mac.window-plain-transition", 1)
1109 self.SetAppName("Iramuteq")
1110 splash = MySplashScreen()
1118 if __name__ == '__main__':