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, CheckRapp, 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)
130 ConfigPath = ConstructConfigPath(UserConfigPath)
131 #####################################################################
133 class IraFrame(wx.Frame):
134 def __init__(self, parent, id= -1, title="", pos=wx.DefaultPosition,
135 size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE |
138 log.info('Starting...')
139 wx.Frame.__init__(self, parent, id, title, pos, size, style)
141 self.AppliPath = AppliPath
142 self.images_path = os.path.join(AppliPath,'images')
143 self.UserConfigPath = UserConfigPath
144 self.RscriptsPath = ConstructRscriptsPath(AppliPath)
145 self.DictPath = ConstructDicoPath(AppliPath)
146 self.ConfigGlob = ConfigGlob
147 self.ConfigPath = ConstructConfigPath(UserConfigPath)
148 self.pref = RawConfigParser()
150 mylocale = wx.Locale(wx.LANGUAGE_FRENCH)
151 mylocale.AddCatalogLookupPathPrefix(os.path.join(AppliPath,'locale'))
152 mylocale.AddCatalog('iramuteq')
153 presLan_en = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['en'])
154 presLan_fr = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['fr_FR'])
158 # tell FrameManager to manage this frame
159 #self._mgr = wx.aui.AuiManager()
160 self._mgr = aui.AuiManager()
161 self._mgr.SetManagedWindow(self)
164 #--------------------------------------------------------------------------------
165 self.mb = wx.MenuBar()
167 file_menu = wx.Menu()
168 item = wx.MenuItem(file_menu, ID_OpenData, _(u"Open a matrix"), _(u"Open a matrix"))
169 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
170 file_menu.AppendItem(item)
172 item = wx.MenuItem(file_menu, ID_OpenText, _(u"Open a text corpora"), _(u"Open a text corpora"))
173 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
174 file_menu.AppendItem(item)
176 item = wx.MenuItem(file_menu, ID_OnOpenAnalyse, _(u"Open an analysis"), _("Open an analysis"))
177 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
178 file_menu.AppendItem(item)
180 item1 = wx.MenuItem(file_menu, ID_Import, _(u"Import a factiva corpora..."), _("Import a factiva corpora..."))
181 item1.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_TIP))
182 file_menu.AppendItem(item1)
185 item = wx.MenuItem(file_menu, ID_SaveTab, _(u"Save tab as..."), _(u"Save tab as..."))
186 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_SAVE_AS))
188 file_menu.AppendItem(item)
190 file_menu.Append(wx.ID_EXIT, _(u"Exit"))
192 edit_menu = wx.Menu()
193 edit_menu.Append(wx.ID_PREFERENCES, '', _(u'Preferences'))
195 view_menu = wx.Menu()
196 view_menu.Append(ID_ACCEUIL, _(u"Home page"))
197 view_menu.Append(ID_VIEWDATA, _(u"Show data"))
198 view_menu.Append(ID_RESULT, _(u'Show results'))
199 #view_menu.AppendSeparator()
201 analyse_menu = wx.Menu()
202 analyse_menu.Append(ID_Freq, u"Fréquences")
203 analyse_menu.Append(ID_Chi2, u"Chi2")
204 #analyse_menu.Append(ID_Student, u"t de Student")
205 menu_classif = wx.Menu()
206 menu_classif.Append(ID_CHDAlceste, u"Méthode Alceste")
207 menu_classif.Append(ID_CHDSIM, u"Par matrice des distances")
208 analyse_menu.AppendMenu(-1, u"Classification", menu_classif)
209 analyse_menu.Append(ID_AFCM, u"AFCM")
210 analyse_menu.Append(ID_SIMI, u"Analyse de similitudes")
211 ID_RCODE = wx.NewId()
212 analyse_menu.Append(ID_RCODE, u"Code R...")
214 text_menu = wx.Menu()
215 text_menu.Append(ID_CHECKCORPUS, u"Vérifier le corpus")
216 text_menu.Append(ID_TEXTSTAT, u"Statistiques textuelles")
217 text_menu.Append(ID_ASLEX, u"Spécificités et AFC")
218 #text_menu.Append(ID_TEXTAFCM, u"AFC sur UCI / Vocabulaire")
219 menu_classiftxt = wx.Menu()
220 menu_classiftxt.Append(ID_TEXTALCESTE, u"Méthode Alceste")
221 menu_classiftxt.Append(ID_TEXTPAM, u"Par matrice des distances")
222 text_menu.AppendMenu(-1, u"Classification", menu_classiftxt)
223 text_menu.Append(ID_SimiTxt, u'Analyse de similitude')
225 text_menu.Append(ID_WC, u'Nuage de mots')
227 help_menu = wx.Menu()
228 help_menu.Append(wx.ID_ABOUT, u'À propos...')
229 help_menu.Append(wx.ID_HELP, u'Aide en ligne')
231 self.mb.Append(file_menu, _(u"File"))
232 self.mb.Append(edit_menu, _(u"Edition"))
233 self.mb.Append(view_menu, _(u"View"))
234 self.mb.Append(analyse_menu, _("Spreadsheet analysis"))
235 self.mb.Append(text_menu, _(u"Text analysis"))
236 self.mb.Append(help_menu, _(u"Help"))
238 self.SetMenuBar(self.mb)
239 #--------------------------------------------------------------------
240 self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
241 self.statusbar.SetStatusWidths([-2, -3])
242 self.statusbar.SetStatusText(u"Prêt", 0)
243 self.statusbar.SetStatusText(u"Bienvenue", 1)
245 # min size for the frame itself isn't completely done.
246 # see the end up FrameManager::Update() for the test
247 # code. For now, just hard code a frame minimum size
248 self.SetMinSize(wx.Size(400, 400))
250 # create some toolbars
251 tb1 = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
252 wx.TB_FLAT | wx.TB_NODIVIDER)
253 tb1.SetToolBitmapSize(wx.Size(16, 16))
254 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")
256 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")
260 #------------------------------------------------------------------------------------------------
262 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)
264 #self._mgr.AddPane(self.text_ctrl_txt, wx.aui.AuiPaneInfo().
265 # Name("Text").CenterPane())
266 self._mgr.AddPane(self.text_ctrl_txt, aui.AuiPaneInfo().
267 Name("Text").CenterPane())
268 #self._mgr.AddPane(IntroPanel(self), wx.aui.AuiPaneInfo().Name("Intro_Text").
270 self._mgr.AddPane(IntroPanel(self), aui.AuiPaneInfo().Name("Intro_Text").
272 #if not os.path.exists(os.path.join(UserConfigPath, 'history.db')) :
273 # with open(os.path.join(UserConfigPath, 'history.db'), 'w') as f :
275 self.history = History(os.path.join(UserConfigPath, 'history.db'))
276 self.tree = LeftTree(self)
277 self._mgr.AddPane(self.tree, aui.AuiPaneInfo().Name("lefttree").Caption("Navigateur").
278 Left().MinSize(wx.Size(200,500)).Layer(1).Position(1).CloseButton(False).MaximizeButton(True).
279 MinimizeButton(True))
281 #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)
282 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)
283 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
284 self.nb.SetAGWWindowStyleFlag(notebook_flags)
285 self.nb.SetArtProvider(aui.ChromeTabArt())
286 #self.nb.SetArtProvider(aui.VC8TabArt())
287 #self.nb.parent = self
288 #self._notebook_style = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.NO_BORDER
289 #self._mgr.AddPane(self.nb, wx.aui.AuiPaneInfo().
290 # Name("Tab_content").
292 self._mgr.AddPane(self.nb, aui.AuiPaneInfo().
295 self.Sheet = MySheet(self)
296 #self._mgr.AddPane(self.Sheet, wx.aui.AuiPaneInfo().Name("Data").CenterPane())
297 self._mgr.AddPane(self.Sheet, aui.AuiPaneInfo().Name("Data").CenterPane())
298 #self.nb.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnCloseTab)
299 self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnCloseTab)
300 self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
301 # add the toolbars to the manager
303 #self._mgr.AddPane(tb1, wx.aui.AuiPaneInfo().
304 # Name("tb1").Caption("Fichiers").
305 # ToolbarPane().Top().
306 # LeftDockable(False).RightDockable(False))
307 self._mgr.AddPane(tb1, aui.AuiPaneInfo().
308 Name("tb1").Caption("Fichiers").
310 LeftDockable(True).RightDockable(False))
312 self.ShowAPane("Intro_Text")
313 self._mgr.GetPane("lefttree").Show()
314 self._mgr.GetPane("classif_tb").Hide()
315 # "commit" all changes made to FrameManager
318 # Show How To Use The Closing Panes Event
319 ##################################################################
320 self.Bind(wx.EVT_MENU, self.OnAcceuil, id=ID_ACCEUIL)
321 self.Bind(wx.EVT_MENU, self.OnViewData, id=ID_VIEWDATA)
322 self.Bind(wx.EVT_MENU, self.ShowTab, id=ID_RESULT)
323 self.Bind(wx.EVT_MENU, self.OnOpenData, id=ID_OpenData)
324 self.Bind(wx.EVT_MENU, self.OnOpenText, id=ID_OpenText)
325 self.Bind(wx.EVT_MENU, self.OnOpenAnalyse, id=ID_OnOpenAnalyse)
326 self.Bind(wx.EVT_MENU, self.import_factiva, id= ID_Import)
327 self.Bind(wx.EVT_MENU, self.OnFreq, id=ID_Freq)
328 self.Bind(wx.EVT_MENU, self.OnChi2, id=ID_Chi2)
329 self.Bind(wx.EVT_MENU, self.OnStudent, id=ID_Student)
330 self.Bind(wx.EVT_MENU, self.OnCHDSIM, id=ID_CHDSIM)
331 self.Bind(wx.EVT_MENU, self.OnCHDAlceste, id=ID_CHDAlceste)
332 self.Bind(wx.EVT_MENU, self.OnAFCM, id=ID_AFCM)
333 self.Bind(wx.EVT_MENU, self.OnRCode, id=ID_RCODE)
334 self.Bind(wx.EVT_MENU, self.OnCheckcorpus, id = ID_CHECKCORPUS)
335 self.Bind(wx.EVT_MENU, self.OnTextStat, id=ID_TEXTSTAT)
336 self.Bind(wx.EVT_MENU, self.OnTextSpec, id=ID_ASLEX)
337 self.Bind(wx.EVT_MENU, self.OnTextAfcm, id=ID_TEXTAFCM)
338 self.Bind(wx.EVT_MENU, self.OnTextAlceste, id=ID_TEXTALCESTE)
339 self.Bind(wx.EVT_MENU, self.OnPamSimple, id=ID_TEXTPAM)
340 self.Bind(wx.EVT_MENU, self.OnSimiTxt, id=ID_SimiTxt)
341 self.Bind(wx.EVT_MENU, self.OnWordCloud, id=ID_WC)
342 self.Bind(wx.EVT_MENU, self.OnSimi, id=ID_SIMI)
343 self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
344 self.Bind(wx.EVT_MENU, self.OnSaveTabAs, id=ID_SaveTab)
345 self.Bind(wx.EVT_MENU, self.OnAbout, id=wx.ID_ABOUT)
346 self.Bind(wx.EVT_MENU, self.OnHelp, id=wx.ID_HELP)
347 self.Bind(wx.EVT_MENU, self.OnPref, id=wx.ID_PREFERENCES)
348 self.Bind(wx.EVT_CLOSE, self.OnClose)
349 ##################################################################
350 flags = self._mgr.GetAGWFlags()
351 #flags &= ~wx.aui.AUI_MGR_TRANSPARENT_HINT
352 #flags &= ~wx.aui.AUI_MGR_VENETIAN_BLINDS_HINT
353 #flags &= ~wx.aui.AUI_MGR_RECTANGLE_HINT
354 flags &= ~(aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING)
355 self._mgr.SetAGWFlags(self._mgr.GetAGWFlags() ^ (aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING))
356 self._mgr.GetArtProvider().SetMetric(aui.AUI_DOCKART_GRADIENT_TYPE, aui.AUI_GRADIENT_HORIZONTAL)
357 self.GetDockArt().SetColor(aui.AUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR, "#00FFF9")
360 self._icon = wx.Icon(os.path.join(ImagePath, "iraicone.ico"), wx.BITMAP_TYPE_ICO)
361 self.SetIcon(self._icon)
362 ##########################
364 self.input_path = [False]
365 self.TEMPDIR = tempfile.mkdtemp('iramuteq')
366 self.FileTabList = []
372 self.g_header = False
379 self.SysEncoding = sys.getdefaultencoding()
380 self.syscoding = sys.getdefaultencoding()
381 #print 'SysEncoding',self.SysEncoding
382 if self.SysEncoding == 'mac-roman' : self.SysEncoding = 'MacRoman'
386 self.pref.read(self.ConfigPath['preferences'])
395 self.pref.read(self.ConfigPath['preferences'])
397 #configuration des chemins de R
398 self.PathPath = ConfigParser()
399 self.PathPath.read(ConfigPath['path'])
401 if not CheckRPath(self.PathPath) :
402 if sys.platform == 'win32':
403 BestRPath = FindRPAthWin32()
405 BestRPath = FindRPathNix()
407 self.PathPath.set('PATHS', 'rpath', BestRPath)
408 with open(ConfigPath['path'], 'w') as f :
409 self.PathPath.write(f)
413 self.RPath = self.PathPath.get('PATHS', 'rpath')
416 if not RLibsAreInstalled(self) :
420 Le chemin de l'executable de R n'a pas été trouvé.
421 Si R n'est pas installé, vous devez l'installer (http://www.r-project.org/).
422 Si R n'est pas installé dans le répertoire par défaut
423 (C:\Program Files\R\R-2.x.x\R.exe sous windows ou /usr/bin/R sous linux ou Mac Os X)
424 vous devez signaler le chemin de l'éxecutable de R dans les préférences."""
425 dlg = wx.MessageDialog(self, msg, u"Problème de configuration", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
427 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
431 if sys.platform == 'darwin':
432 self.Rapp = self.PathPath.get('PATHS', 'rapp')
433 RappOk = CheckRapp(self.Rapp)
437 self.sound = self.pref.getboolean('iramuteq', 'sound')
438 self.check_update = self.pref.getboolean('iramuteq', 'checkupdate')
439 self.version = ConfigGlob.get('DEFAULT', 'version')
442 ##############################################################@
443 self.DisEnSaveTabAs(False)
444 self.ShowMenu(_("View"), False)
445 self.ShowMenu(_("Spreadsheet analysis"), False)
446 self.ShowMenu(_("Text analysis"), False)
450 def OnVerif(self, evt) :
451 pack = CheckRPackages(self)
453 dlg = wx.MessageDialog(self, u"Installation OK", u"Installation", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
455 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
458 #FIXME marche pas sous mac ?
459 def DisEnSaveTabAs(self, DISEN):
461 file_menu = self.mb.GetMenu(0)
462 items = file_menu.GetMenuItems()
463 items[4].Enable(DISEN)
465 def ShowMenu(self, menu, Show=True):
466 menu_pos = self.mb.FindMenu(menu)
467 self.mb.EnableTop(menu_pos, Show)
468 self.mb.UpdateMenus()
471 #--------------------------------------------------------------------
472 def OnClose(self, event):
474 with open(self.ConfigPath['path'], 'w') as f :
475 self.PathPath.write(f)
476 if self.DictTab != {} :
477 savestates = [self.DictTab[item][0] for item in self.DictTab]
478 if False in savestates :
479 notsave = [item for item in self.DictTab if self.DictTab[item][0] == False]
481 Certains résultats ne sont pas enregistrés.
482 Voulez-vous fermer quand même ?"""
483 dlg = wx.MessageDialog(self, msg, "Sauvegarde",
484 wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
486 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
491 for item in notsave :
492 for tmpfile in self.DictTab[item][1:] :
494 print 'remove : ' + tmpfile
506 #if sys.platform == 'win32' :
507 # os.system("taskkill /im iramuteq.exe /f")
508 # print 'meurtre de process'
510 def OnOpenData(self, event):
511 inputname, self.input_path = OnOpen(self, "Data")
513 self.filename = self.input_path[0]
514 self.tableau = Tableau(self,os.path.abspath(self.input_path[0]))
515 get_table_param(self, self.input_path[0])
516 self.tableau.make_content()
517 self.tableau.show_tab()
519 def OnOpenAnalyse(self, event):
520 self.AnalysePath = OnOpen(self, "Analyse")
521 OpenAnalyse(self, self.AnalysePath[1][0], True)
522 self.ShowMenu(_("View"))
524 def OnOpenText(self, event):
525 inputname, self.input_path = OnOpen(self, "Texte")
526 self.filename = self.input_path[0]
530 def OnViewData(self, event):
533 if self.type == "Data":
534 if not self.DataPop :
535 self.Sheet.Populate(self.content)
538 self.ShowAPane(u"Data")
539 elif self.type == "Texte" or self.type == 'Analyse' :
540 if not self.DataTxt :
541 self.text_ctrl_txt.Clear()
542 self.text_ctrl_txt.write(self.content)
543 self.text_ctrl_txt.ShowPosition(0)
546 self.ShowAPane(u"Text")
550 #dial = EncodeDialog(self)
551 dlg = wx.ProgressDialog("Ouverture...",
552 "Veuillez patienter...",
555 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
558 builder = Builder(self, dlg)
559 if builder.res == wx.ID_OK :
561 corpus = builder.doanalyse()
562 self.history.add(corpus.parametres)
563 self.tree.OnItemAppend(corpus.parametres)
564 OpenAnalyse(self, corpus.parametres)
567 #self.content = DoConf().totext(corpus.parametres)
568 # parametres = DoConf(os.path.join(UserConfigPath,'corpus.cfg')).getoptions('corpus')
569 # parametres['originalpath'] = self.filename
571 # parametres['pathout'] = PathOut(self.filename, 'corpus').dirout
572 # dial = CorpusPref(self, parametres)
573 # dial.CenterOnParent()
574 # dial.txtpath.SetLabel(self.filename)
575 # res = dial.ShowModal()
576 # parametres = dial.doparametres()
578 # ReadLexique(self, lang = parametres['lang'])
579 # self.expressions = ReadDicoAsDico(self.DictPath.get(parametres['lang'], 'french_exp'))
580 # corpus = BuildFromAlceste(self.filename, parametres, self.lexique, self.expressions).corpus
581 #self.corpus_encodage = dial.encodages[dial.list_encodages.GetSelection()][0]
582 #self.corpus_lang = dial.langues[dial.choice_dict.GetSelection()]
585 keepGoing = dlg.Update(count, u"Lecture du fichier")
586 # msg = u"Ce fichier ne semble pas être encodé en %s" % self.corpus_encodage
587 # dial = wx.MessageDialog(self, msg, u"Problème d'encodage", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
588 # dial.CenterOnParent()
589 # res = dial.ShowModal()
592 self.ShowMenu(_("View"))
593 self.ShowMenu(_("Text analysis"))
594 self.ShowMenu(_(u"Spreadsheet analysis"), False)
599 keepGoing = dlg.Update(count, u"Chargement du dictionnaire")
601 #self.OnViewData(wx.EVT_BUTTON)
603 def OnExit(self, event):
606 def OnAbout(self, event):
607 info = wx.AboutDialogInfo()
608 info.Name = ConfigGlob.get('DEFAULT', 'name')
609 info.Version = ConfigGlob.get('DEFAULT', 'version')
610 info.Copyright = ConfigGlob.get('DEFAULT', 'copyright')
611 info.Description = u"""
612 Interface de R pour les Analyses Multidimensionnelles
613 de Textes et de Questionnaires
616 construit avec des logiciels libres.
622 info.WebSite = ("http://www.iramuteq.org", u"Site web IRaMuTeQ")
623 dev = ConfigGlob.get('DEFAULT', 'dev').split(';')
624 info.Developers = dev
625 info.License = u"""Iramuteq est un logiciel libre ; vous pouvez le diffuser et/ou le modifier
626 suivant les termes de la Licence Publique Générale GNU telle que publiée
627 par la Free Software Foundation ; soit la version 2 de cette licence,
628 soit (à votre convenance) une version ultérieure.
630 Iramuteq est diffusé dans l'espoir qu'il sera utile,
631 mais SANS AUCUNE GARANTIE ; sans même une garantie implicite
632 de COMMERCIALISATION ou d'ADÉQUATION À UN USAGE PARTICULIER.
633 Voyez la Licence Publique Générale GNU pour plus de détails.
635 Vous devriez avoir reçu une copie de la Licence Publique Générale GNU
636 avec Iramuteq ; sinon, veuillez écrire à la Free Software Foundation,
637 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, États-Unis."""
640 def GetDockArt(self):
641 return self._mgr.GetArtProvider()
646 def OnPageChanged(self, event) :
647 new = event.GetSelection()
648 nobject = event.GetEventObject()
649 parent = nobject.GetParent()
650 if isinstance(parent, IraFrame) :
651 npage = self.nb.GetPage(new)
652 self.tree.GiveFocus(uuid=npage.parametres['uuid'])
654 def OnCloseTab(self, evt):
655 log.info('Closing tab %s' % str(evt.GetEventObject()))
656 ctrl = evt.GetEventObject()
657 if isinstance(ctrl.GetParent(), aui.AuiNotebook) or isinstance(ctrl.GetParent(), wx.Panel):
661 page = self.nb.GetPage(self.nb.GetSelection())
662 if 'parametres' in dir(page) :
663 self.history.rmtab(page.parametres)
664 self.tree.CloseItem(uuid = page.parametres['uuid'])
665 TabTitle = self.nb.GetPageText(self.nb.GetSelection())
666 if self.DictTab != {} :
667 if TabTitle in self.DictTab :
668 ListFile=self.DictTab[TabTitle]
669 if False in ListFile:
671 Certains résultats ne sont pas enregistrer.
672 Voulez-vous fermer quand même ?"""
673 dlg = wx.MessageDialog(self, msg, "Sauvegarde",wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
676 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
681 for f in ListFile[1:] :
686 elif True in ListFile :
689 del self.DictTab[TabTitle]
694 if self.nb.GetPageCount() == 1 and remove and not notebook :
697 def LastTabClose(self) :
698 if self.nb.GetPageCount() == 1 :
699 self.DisEnSaveTabAs(False)
701 self.ShowAPane("Text")
703 self.ShowAPane("Data")
705 self.ShowAPane("Intro_Text")
707 def OnSaveTabAs(self, event):
708 SelectTab = self.nb.GetSelection()
709 TabTitle = self.nb.GetPageText(SelectTab)
710 FileToSave = self.DictTab[TabTitle]
713 self, message="Enregistrer sous...", defaultDir=os.getcwd(),
714 defaultFile="resultat.html", wildcard="Tous les fichiers|*", style=wx.SAVE | wx.OVERWRITE_PROMPT
716 dlg.SetFilterIndex(2)
719 if dlg.ShowModal() == wx.ID_OK:
721 Dirname = os.path.dirname(Path)
722 Filename = dlg.GetFilename()
727 shutil.copyfile(FileToSave[-1], Path)
728 os.remove(FileToSave[len(FileToSave) - 1])
729 NewListFile.append(True)
730 NewListFile.append(Path)
731 for f in FileToSave[1:-1] :
732 Fileout = os.path.join(Dirname, os.path.basename(f))
733 shutil.copyfile(f, Fileout)
734 NewListFile.append(Fileout)
737 self.DictTab[TabText] = NewListFile
738 del self.DictTab[TabTitle]
739 self.nb.SetPageText(SelectTab, TabText)
741 def GetStartPosition(self):
745 pt = self.ClientToScreen(wx.Point(0, 0))
747 return wx.Point(pt.x + x, pt.y + x)
749 def ShowAPane(self, panel):
750 for pane in self._mgr.GetAllPanes() :
751 if not pane.IsToolbar() and pane.name != 'lefttree':
753 self._mgr.GetPane(panel).Show()
756 def OnAcceuil(self, event):
757 self.ShowAPane(u"Intro_Text")
760 def CreateHTMLCtrl(self):
761 ctrl = wx.html.HtmlWindow(self, -1, wx.DefaultPosition, wx.Size(400, 300))
762 if "gtk2" in wx.PlatformInfo:
763 ctrl.SetStandardFonts()
764 ctrl.SetPage(u"text")
767 def ShowTab(self, evt):
768 self.ShowAPane("Tab_content")
770 ################################################################
772 ################################################################
774 def OnFreq(self, event):
780 def OnChi2(self, event):
782 # print('PAS DE DEBUG SUR CHI2')
783 chi = ChiSquare(self)
787 def OnStudent(self, event):
793 def OnRCode(self, event):
799 def OnCHDSIM(self, event):
801 # print 'ATTENTION!!!!'
802 chdsim = ChdCluster(self)
803 if chdsim.val == wx.ID_OK:
808 def OnCHDAlceste(self, event):
810 # print('PLUS DE BUG SUR ALCESTE QUESTIONNAIRE')
811 self.quest = AnalyseQuest(self)
812 if self.quest.val == wx.ID_OK:
817 def OnSimiTxt(self, evt, corpus = None) :
818 print 'PLUS DE BUG SUR SIMITXT'
820 #self.Text = SimiTxt(self)
821 self.Text = SimiTxt(self, corpus, parametres = {'type': 'simitxt'}, dlg = progressbar(self, 3))
822 if self.Text.val == wx.ID_OK :
827 def OnWordCloud(self, evt, corpus = None) :
828 # print 'PLUS DE BUG SUR WORDCLOUD'
830 self.Text = WordCloud(self, corpus, parametres = {'type' : 'wordcloud'}, dlg = progressbar(self, 3))
831 if self.Text.val == wx.ID_OK :
837 def OnAFCM(self, event):
843 def OnCheckcorpus(self, evt):
849 def OnTextStat(self, event, corpus = None):
850 print 'PAS DE BUG SUR TEXT STAT'
852 self.Text = Stat(self, corpus, parametres = {'type': 'stat'}, dlg = progressbar(self, 7))
854 if self.Text.val == wx.ID_OK :
859 def OnTextSpec(self, event, corpus = None):
861 #self.Text = AsLexico(self)
862 print('ATTENTION : PLUS DE BUG SUR LEXICO')
863 self.Text = Lexico(self, corpus, parametres = {'type' : 'spec'}, dlg = progressbar(self, 3))
864 if self.Text.val == wx.ID_OK :
869 def OnTextAfcm(self, event):
876 def import_factiva(self,event):
882 def OnTextAlceste(self, event, corpus = None):
884 print('ATTENTION : PLUS DE BUG SUR ALCESTE')
885 #RunAnalyse(self, corpus, Alceste, OptAlceste)
886 self.Text = Alceste(self, corpus, parametres = {'type': 'alceste'}, dlg = progressbar(self,6))
887 #self.history.addtab(self.Text.parametres)
888 #OpenAnalyse(self, self.Text.parametres['ira'])
889 if self.Text.val == wx.ID_OK:
894 def OnPamSimple(self, event):
896 self.Text = PamTxt(self)
897 if self.Text.val == wx.ID_OK:
902 def OnSimi(self,evt):
904 #print 'ATTENTION !!!! VERGES'
905 self.res = DoSimi(self, param = None)
906 #self.res = Verges(self)
907 if self.res.val == wx.ID_OK :
911 #################################################################
913 def OnHelp(self, event):
914 webbrowser.open('http://www.iramuteq.org/documentation')
916 def OnPref(self, event):
917 dlg = PrefDialog(self)
919 self.val = dlg.ShowModal()
922 if self.check_update:
927 #CheckRPackages(self)
929 def OnOpenFromCmdl(self):
931 if options.filename :
932 if os.path.exists(options.filename):
933 self.filename = os.path.abspath(options.filename)
937 if os.path.exists(os.path.realpath(args[0])):
938 self.filename = os.path.abspath(os.path.realpath(args[0]))
944 if os.path.splitext(self.filename)[1] in ['.csv', '.xls', '.ods']:
945 self.tableau = Tableau(self, self.filename)
946 get_table_param(self, self.filename)
947 self.tableau.make_content()
948 self.tableau.show_tab()
949 #open_data(self, self.filename)
950 elif os.path.splitext(self.filename)[1] == '.txt':
952 elif os.path.splitext(self.filename)[1] == '.ira' :
953 #self.corpus = Corpus(self)
954 #self.Text = OpenAnalyse(self, self.filename)
955 OpenAnalyse(self, self.filename)
957 print 'ce fichier n\'existe pas'
961 class IntroPanel(wx.Panel):
962 def __init__(self, parent):
963 wx.Panel.__init__(self, parent)
964 #col = randint(0, 255)
965 #col1 = randint(0,255)
966 #col2 = randint(0,255)
968 bckgrdcolor = wx.Colour(col, col, col)
969 self.SetBackgroundColour(bckgrdcolor)
970 txtcolour = wx.Colour(250, 250, 250)
971 linkcolor = wx.Colour(255, 0, 0)
972 sizer1 = wx.BoxSizer(wx.VERTICAL)
973 sizer2 = wx.BoxSizer(wx.VERTICAL)
974 sizer3 = wx.BoxSizer(wx.HORIZONTAL)
975 sizer4 = wx.BoxSizer(wx.VERTICAL)
976 sizer5 = wx.BoxSizer(wx.HORIZONTAL)
977 grid_sizer_1 = wx.FlexGridSizer(1, 4, 0, 0)
978 grid_sizer_3 = wx.FlexGridSizer(1, 4, 0, 0)
979 grid_sizer_2 = wx.FlexGridSizer(1, 3, 0, 0)
980 PanelPres = wx.Panel(self)
981 PanelPres.SetBackgroundColour(bckgrdcolor)
982 label_1 = wx.StaticText(self, -1, u"IRaMuTeQ", size=(-1, -1))
983 label_1.SetFont(wx.Font(46, wx.TELETYPE, wx.NORMAL, wx.BOLD, 0, "Purisa"))
984 label_1.SetForegroundColour(wx.RED)
985 label2 = wx.StaticText(PanelPres, -1 , u'\nVersion ' + ConfigGlob.get('DEFAULT', 'version') + '\n')
986 label2.SetForegroundColour(txtcolour)
987 label2.SetBackgroundColour(bckgrdcolor)
988 #label3 = wx.StaticText(PanelPres, -1 , u'Equipe ')
989 #label3.SetForegroundColour(txtcolour)
990 #label3.SetBackgroundColour(bckgrdcolor)
991 self.hyper2 = hl.HyperLinkCtrl(PanelPres, wx.ID_ANY, u"REPERE", URL="http://repere.no-ip.org/")
992 self.hyper2.SetColours(linkcolor, linkcolor, "RED")
993 self.hyper2.SetBackgroundColour(bckgrdcolor)
994 self.hyper2.EnableRollover(True)
995 self.hyper2.SetUnderlines(False, False, True)
996 self.hyper2.SetBold(True)
997 self.hyper2.UpdateLink()
998 label_lerass = wx.StaticText(PanelPres, -1, u'Laboratoire ')
999 label_lerass.SetForegroundColour(txtcolour)
1000 label_lerass.SetBackgroundColour(bckgrdcolor)
1001 self.hyper_lerass = hl.HyperLinkCtrl(PanelPres, -1, u'LERASS', URL="http://www.lerass.com")
1002 self.hyper_lerass.SetColours(linkcolor, linkcolor, "RED")
1003 self.hyper_lerass.SetBackgroundColour(bckgrdcolor)
1004 self.hyper_lerass.EnableRollover(True)
1005 self.hyper_lerass.SetUnderlines(False, False, True)
1006 self.hyper_lerass.SetBold(True)
1007 self.hyper_lerass.UpdateLink()
1008 blank = wx.StaticText(PanelPres, -1, u'\n')
1009 blank1 = wx.StaticText(PanelPres, -1, u'\n')
1010 labellicence = wx.StaticText(PanelPres, -1, u'Licence GNU GPL')
1011 labellicence.SetForegroundColour(txtcolour)
1012 labellicence.SetBackgroundColour(bckgrdcolor)
1013 labelcopy = wx.StaticText(PanelPres, -1, ConfigGlob.get('DEFAULT', 'copyright'))
1014 labelcopy.SetForegroundColour(txtcolour)
1015 labelcopy.SetBackgroundColour(bckgrdcolor)
1016 python_img = wx.Image(os.path.join(ImagePath,'python-logo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1017 r_img = wx.Image(os.path.join(ImagePath,'Rlogo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1018 lexique_img = wx.Image(os.path.join(ImagePath,'LexTexte4.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1019 but_python = wx.BitmapButton(self, -1, python_img)
1020 but_lexique = wx.BitmapButton(self, -1, lexique_img)
1021 but_r = wx.BitmapButton(self, -1, r_img)
1022 self.Bind(wx.EVT_BUTTON, self.OnPython, but_python)
1023 self.Bind(wx.EVT_BUTTON, self.OnLexique, but_lexique)
1024 self.Bind(wx.EVT_BUTTON, self.OnR, but_r)
1027 #grid_sizer_1.Add(label3, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1028 grid_sizer_1.Add(self.hyper2, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1029 grid_sizer_3.Add(label_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1030 grid_sizer_3.Add(self.hyper_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1031 sizer4.Add(label_1, 0, wx.ALIGN_CENTER, 5)
1032 sizer2.Add(label2, 0, wx.ALIGN_CENTER, 5)
1033 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1034 sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1035 sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1036 sizer2.Add(grid_sizer_3, 0, wx.ALIGN_CENTER, 5)
1037 sizer2.Add(wx.StaticText(PanelPres, -1, u' '), 0, wx.ALIGN_CENTER, 5)
1038 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1039 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1040 sizer2.Add(grid_sizer_1, 0, wx.ALIGN_CENTER, 5)
1041 sizer2.Add(labellicence, 0, wx.ALIGN_CENTER, 5)
1042 sizer2.Add(labelcopy, 0, wx.ALIGN_CENTER, 5)
1043 sizer1.Add(sizer4, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1044 PanelPres.SetSizer(sizer2)
1045 sizer5.Add(blank, 1, wx.EXPAND | wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 2)
1046 sizer5.Add(PanelPres, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1047 sizer5.Add(blank1, 1, wx.ALIGN_CENTER_HORIZONTAL,2)
1048 grid_sizer_2.Add(but_python, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1049 grid_sizer_2.Add(but_lexique, 1,wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1050 grid_sizer_2.Add(but_r, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1052 sizer1.Add(sizer5, 3, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 1)
1053 sizer1.Add(grid_sizer_2, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
1054 self.SetSizer(sizer1)
1057 def OnPython(self,evt):
1058 webbrowser.open('http://www.python.org')
1060 def OnLexique(self,evt):
1061 webbrowser.open('http://www.lexique.org')
1064 webbrowser.open('http://www.r-project.org')
1066 class MySplashScreen(wx.SplashScreen):
1068 bmp = wx.Image(os.path.join(ImagePath, 'splash.png')).ConvertToBitmap()
1069 wx.SplashScreen.__init__(self, bmp,
1070 wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
1072 self.Bind(wx.EVT_CLOSE, self.OnClose)
1073 self.fc = wx.FutureCall(1, self.ShowMain)
1075 def OnClose(self, evt):
1079 if self.fc.IsRunning():
1084 frame = IraFrame(None, -1, "IRaMuTeQ " + ConfigGlob.get('DEFAULT', 'version'), size=(1100, 800))
1087 frame.OnOpenFromCmdl()
1088 # if self.fc.IsRunning():
1090 #wx.CallAfter(frame.ShowTip)
1092 class MyApp(wx.App):
1095 Create and show the splash screen. It will then create and show
1096 the main frame when it is time to do so.
1098 wx.SystemOptions.SetOptionInt("mac.window-plain-transition", 1)
1099 self.SetAppName("Iramuteq")
1100 splash = MySplashScreen()
1108 if __name__ == '__main__':