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 tools import Extract
69 from tree import LeftTree
70 ##########################################################
71 ID_OpenData = wx.NewId()
72 ID_Import = wx.NewId()
73 ID_OpenText = wx.NewId()
74 ID_OnOpenAnalyse = wx.NewId()
77 ID_Student = wx.NewId()
78 ID_CHDSIM = wx.NewId()
79 ID_CHDAlceste = wx.NewId()
80 ID_TEXTAFCM = wx.NewId()
81 ID_TEXTSTAT = wx.NewId()
83 ID_TEXTALCESTE = wx.NewId()
84 ID_TEXTPAM = wx.NewId()
85 ID_CHECKCORPUS = wx.NewId()
86 ID_Tabcontent = wx.NewId()
89 ID_CloseTab = wx.NewId()
90 ID_SaveTab = wx.NewId()
91 ID_CreateText = wx.NewId()
92 ID_ACCEUIL = wx.NewId()
93 ID_RESULT = wx.NewId()
94 ID_VIEWDATA = wx.NewId()
95 ID_HTMLcontent = wx.NewId()
96 ID_SimiTxt = wx.NewId()
97 ##########################################################
98 #elements de configuration
99 ##########################################################
101 if sys.platform == 'darwin' :
102 sys.setdefaultencoding('utf-8')
103 wx.SetDefaultPyEncoding('utf-8')
105 sys.setdefaultencoding(locale.getpreferredencoding())
106 #chemin de l'application
107 AppliPath = os.path.abspath(os.path.dirname(os.path.realpath(sys.argv[0])))
109 ImagePath = os.path.join(AppliPath, 'images')
110 #configuration generale
111 DictConfigPath = ConstructGlobalPath(AppliPath)
112 ConfigGlob = ConfigParser()
113 ConfigGlob.read(DictConfigPath['global'])
114 #repertoire de l'utilisateur
115 if os.getenv('HOME') != None:
116 user_home = os.getenv('HOME')
118 user_home = os.getenv('HOMEPATH')
119 UserConfigPath = os.path.abspath(os.path.join(user_home, '.iramuteq'))
120 #Si pas de fichiers de config utilisateur, on cree le repertoire
121 CreateIraDirectory(UserConfigPath, AppliPath)
122 #fichiers log pour windows (py2exe)
123 log = logging.getLogger('iramuteq')
124 fh = logging.FileHandler(os.path.join(UserConfigPath,'stdout.log'))
125 ch = logging.StreamHandler()
126 formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
127 ch.setFormatter(formatter)
128 fh.setFormatter(formatter)
131 log.setLevel(logging.INFO)
134 class writer(object):
135 def write(self, data):
136 if data.strip() != '' :
137 log.info('BUG : %s' % data)
138 sys.stderr = writer()
139 ConfigPath = ConstructConfigPath(UserConfigPath)
140 #####################################################################
142 class IraFrame(wx.Frame):
143 def __init__(self, parent, id= -1, title="", pos=wx.DefaultPosition,
144 size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE |
147 log.info('Starting...')
148 wx.Frame.__init__(self, parent, id, title, pos, size, style)
150 self.AppliPath = AppliPath
151 self.images_path = os.path.join(AppliPath,'images')
152 self.UserConfigPath = UserConfigPath
153 self.RscriptsPath = ConstructRscriptsPath(AppliPath)
154 #self.DictPath = ConstructDicoPath(AppliPath)
155 self.DictPath = ConstructDicoPath(UserConfigPath)
156 self.ConfigGlob = ConfigGlob
157 self.ConfigPath = ConstructConfigPath(UserConfigPath)
158 self.pref = RawConfigParser()
159 #workaround for import problem
160 self.SimiFromCluster = SimiFromCluster
162 mylocale = wx.Locale(wx.LANGUAGE_FRENCH)
163 mylocale.AddCatalogLookupPathPrefix(os.path.join(AppliPath,'locale'))
164 mylocale.AddCatalog('iramuteq')
165 presLan_en = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['en'])
166 presLan_fr = gettext.translation("iramuteq", os.path.join(AppliPath,'locale'), languages=['fr_FR'])
170 # tell FrameManager to manage this frame
171 #self._mgr = wx.aui.AuiManager()
172 self._mgr = aui.AuiManager()
173 self._mgr.SetManagedWindow(self)
176 #--------------------------------------------------------------------------------
177 self.mb = wx.MenuBar()
179 file_menu = wx.Menu()
180 item = wx.MenuItem(file_menu, ID_OpenData, _(u"Open a matrix"), _(u"Open a matrix"))
181 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
182 file_menu.AppendItem(item)
184 item = wx.MenuItem(file_menu, ID_OpenText, _(u"Open a text corpora"), _(u"Open a text corpora"))
185 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
186 file_menu.AppendItem(item)
188 item = wx.MenuItem(file_menu, ID_OnOpenAnalyse, _(u"Open an analysis"), _("Open an analysis"))
189 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
190 file_menu.AppendItem(item)
193 menuFactiva = wx.Menu()
194 fact_from_xml = wx.MenuItem(menuFactiva, wx.ID_ANY, _(u"from xml"))
195 fact_from_mail = wx.MenuItem(menuFactiva, wx.ID_ANY, _(u"from mail"))
196 fact_from_txt = wx.MenuItem(menuFactiva, wx.ID_ANY, _(u"from copy/paste"))
197 menuFactiva.AppendItem(fact_from_xml)
198 menuFactiva.AppendItem(fact_from_mail)
199 menuFactiva.AppendItem(fact_from_txt)
200 file_menu.AppendMenu(-1, _(u"Import from factiva"), menuFactiva)
202 menuTools = wx.Menu()
203 splitvar = wx.MenuItem(menuTools, wx.ID_ANY, _(u"Split from variable"))
204 extractmod = wx.MenuItem(menuTools, wx.ID_ANY, _(u"Extract mods"))
205 menuTools.AppendItem(splitvar)
206 menuTools.AppendItem(extractmod)
207 self.ID_splitvar = splitvar.GetId()
208 self.ID_extractmod = extractmod.GetId()
209 file_menu.AppendMenu(-1, _(u"Tools"), menuTools)
212 item = wx.MenuItem(file_menu, ID_SaveTab, _(u"Save tab as..."), _(u"Save tab as..."))
213 item.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FILE_SAVE_AS))
214 file_menu.AppendItem(item)
216 file_menu.Append(wx.ID_EXIT, _(u"Exit"))
218 edit_menu = wx.Menu()
219 edit_menu.Append(wx.ID_PREFERENCES, '', _(u'Preferences'))
221 view_menu = wx.Menu()
222 view_menu.Append(ID_ACCEUIL, _(u"Home page"))
223 view_menu.Append(ID_VIEWDATA, _(u"Show data"))
224 view_menu.Append(ID_RESULT, _(u'Show results'))
225 #view_menu.AppendSeparator()
227 analyse_menu = wx.Menu()
228 analyse_menu.Append(ID_Freq, u"Fréquences")
229 analyse_menu.Append(ID_Chi2, u"Chi2")
230 #analyse_menu.Append(ID_Student, u"t de Student")
231 menu_classif = wx.Menu()
232 menu_classif.Append(ID_CHDAlceste, u"Méthode Alceste")
233 menu_classif.Append(ID_CHDSIM, u"Par matrice des distances")
234 analyse_menu.AppendMenu(-1, u"Classification", menu_classif)
235 analyse_menu.Append(ID_AFCM, u"AFCM")
236 analyse_menu.Append(ID_SIMI, u"Analyse de similitudes")
237 ID_RCODE = wx.NewId()
238 analyse_menu.Append(ID_RCODE, u"Code R...")
240 text_menu = wx.Menu()
241 text_menu.Append(ID_CHECKCORPUS, u"Vérifier le corpus")
242 text_menu.Append(ID_TEXTSTAT, u"Statistiques textuelles")
243 text_menu.Append(ID_ASLEX, u"Spécificités et AFC")
244 #text_menu.Append(ID_TEXTAFCM, u"AFC sur UCI / Vocabulaire")
245 menu_classiftxt = wx.Menu()
246 menu_classiftxt.Append(ID_TEXTALCESTE, u"Méthode Alceste")
247 menu_classiftxt.Append(ID_TEXTPAM, u"Par matrice des distances")
248 text_menu.AppendMenu(-1, u"Classification", menu_classiftxt)
249 text_menu.Append(ID_SimiTxt, u'Analyse de similitude')
251 text_menu.Append(ID_WC, u'Nuage de mots')
253 help_menu = wx.Menu()
254 help_menu.Append(wx.ID_ABOUT, u'À propos...')
255 help_menu.Append(wx.ID_HELP, u'Aide en ligne')
257 self.mb.Append(file_menu, _(u"File"))
258 self.mb.Append(edit_menu, _(u"Edition"))
259 self.mb.Append(view_menu, _(u"View"))
260 self.mb.Append(analyse_menu, _("Spreadsheet analysis"))
261 self.mb.Append(text_menu, _(u"Text analysis"))
262 self.mb.Append(help_menu, _(u"Help"))
264 self.SetMenuBar(self.mb)
265 #--------------------------------------------------------------------
266 self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
267 self.statusbar.SetStatusWidths([-2, -3])
268 self.statusbar.SetStatusText(u"Prêt", 0)
269 self.statusbar.SetStatusText(u"Bienvenue", 1)
271 # min size for the frame itself isn't completely done.
272 # see the end up FrameManager::Update() for the test
273 # code. For now, just hard code a frame minimum size
274 self.SetMinSize(wx.Size(400, 400))
276 # create some toolbars
277 tb1 = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
278 wx.TB_FLAT | wx.TB_NODIVIDER)
279 tb1.SetToolBitmapSize(wx.Size(16, 16))
280 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")
282 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")
286 #------------------------------------------------------------------------------------------------
288 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)
290 #self._mgr.AddPane(self.text_ctrl_txt, wx.aui.AuiPaneInfo().
291 # Name("Text").CenterPane())
292 self._mgr.AddPane(self.text_ctrl_txt, aui.AuiPaneInfo().
293 Name("Text").CenterPane())
294 #self._mgr.AddPane(IntroPanel(self), wx.aui.AuiPaneInfo().Name("Intro_Text").
296 self._mgr.AddPane(IntroPanel(self), aui.AuiPaneInfo().Name("Intro_Text").
298 #if not os.path.exists(os.path.join(UserConfigPath, 'history.db')) :
299 # with open(os.path.join(UserConfigPath, 'history.db'), 'w') as f :
301 self.history = History(os.path.join(UserConfigPath, 'history.db'))
302 self.tree = LeftTree(self)
303 self._mgr.AddPane(self.tree, aui.AuiPaneInfo().Name("lefttree").Caption("Navigateur").
304 Left().MinSize(wx.Size(200,500)).Layer(1).Position(1).CloseButton(False).MaximizeButton(True).
305 MinimizeButton(True))
307 #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)
308 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)
309 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
310 self.nb.SetAGWWindowStyleFlag(notebook_flags)
311 self.nb.SetArtProvider(aui.ChromeTabArt())
312 #self.nb.SetArtProvider(aui.VC8TabArt())
313 #self.nb.parent = self
314 #self._notebook_style = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.NO_BORDER
315 #self._mgr.AddPane(self.nb, wx.aui.AuiPaneInfo().
316 # Name("Tab_content").
318 self._mgr.AddPane(self.nb, aui.AuiPaneInfo().
321 self.Sheet = MySheet(self)
322 #self._mgr.AddPane(self.Sheet, wx.aui.AuiPaneInfo().Name("Data").CenterPane())
323 self._mgr.AddPane(self.Sheet, aui.AuiPaneInfo().Name("Data").CenterPane())
324 self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnCloseTab)
325 self.nb.Bind(aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
326 # add the toolbars to the manager
328 #self._mgr.AddPane(tb1, wx.aui.AuiPaneInfo().
329 # Name("tb1").Caption("Fichiers").
330 # ToolbarPane().Top().
331 # LeftDockable(False).RightDockable(False))
332 self._mgr.AddPane(tb1, aui.AuiPaneInfo().
333 Name("tb1").Caption("Fichiers").
335 LeftDockable(True).RightDockable(False))
337 self.ShowAPane("Intro_Text")
338 self._mgr.GetPane("lefttree").Show()
339 self._mgr.GetPane("classif_tb").Hide()
340 # "commit" all changes made to FrameManager
343 # Show How To Use The Closing Panes Event
344 ##################################################################
345 self.Bind(wx.EVT_MENU, self.OnAcceuil, id=ID_ACCEUIL)
346 self.Bind(wx.EVT_MENU, self.OnViewData, id=ID_VIEWDATA)
347 self.Bind(wx.EVT_MENU, self.ShowTab, id=ID_RESULT)
348 self.Bind(wx.EVT_MENU, self.OnOpenData, id=ID_OpenData)
349 self.Bind(wx.EVT_MENU, self.OnOpenText, id=ID_OpenText)
350 self.Bind(wx.EVT_MENU, self.OnOpenAnalyse, id=ID_OnOpenAnalyse)
351 self.Bind(wx.EVT_MENU, self.import_factiva_xml, fact_from_xml)
352 self.Bind(wx.EVT_MENU, self.import_factiva_mail, fact_from_mail)
353 self.Bind(wx.EVT_MENU, self.import_factiva_txt, fact_from_txt)
354 self.Bind(wx.EVT_MENU, self.ExtractTools, splitvar)
355 self.Bind(wx.EVT_MENU, self.ExtractTools, extractmod)
356 self.Bind(wx.EVT_MENU, self.OnFreq, id=ID_Freq)
357 self.Bind(wx.EVT_MENU, self.OnChi2, id=ID_Chi2)
358 self.Bind(wx.EVT_MENU, self.OnStudent, id=ID_Student)
359 self.Bind(wx.EVT_MENU, self.OnCHDSIM, id=ID_CHDSIM)
360 self.Bind(wx.EVT_MENU, self.OnCHDAlceste, id=ID_CHDAlceste)
361 self.Bind(wx.EVT_MENU, self.OnAFCM, id=ID_AFCM)
362 self.Bind(wx.EVT_MENU, self.OnRCode, id=ID_RCODE)
363 self.Bind(wx.EVT_MENU, self.OnCheckcorpus, id = ID_CHECKCORPUS)
364 self.Bind(wx.EVT_MENU, self.OnTextStat, id=ID_TEXTSTAT)
365 self.Bind(wx.EVT_MENU, self.OnTextSpec, id=ID_ASLEX)
366 self.Bind(wx.EVT_MENU, self.OnTextAfcm, id=ID_TEXTAFCM)
367 self.Bind(wx.EVT_MENU, self.OnTextAlceste, id=ID_TEXTALCESTE)
368 self.Bind(wx.EVT_MENU, self.OnPamSimple, id=ID_TEXTPAM)
369 self.Bind(wx.EVT_MENU, self.OnSimiTxt, id=ID_SimiTxt)
370 self.Bind(wx.EVT_MENU, self.OnWordCloud, id=ID_WC)
371 self.Bind(wx.EVT_MENU, self.OnSimi, id=ID_SIMI)
372 self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
373 self.Bind(wx.EVT_MENU, self.OnSaveTabAs, id=ID_SaveTab)
374 self.Bind(wx.EVT_MENU, self.OnAbout, id=wx.ID_ABOUT)
375 self.Bind(wx.EVT_MENU, self.OnHelp, id=wx.ID_HELP)
376 self.Bind(wx.EVT_MENU, self.OnPref, id=wx.ID_PREFERENCES)
377 self.Bind(wx.EVT_CLOSE, self.OnClose)
378 ##################################################################
379 flags = self._mgr.GetAGWFlags()
380 #flags &= ~wx.aui.AUI_MGR_TRANSPARENT_HINT
381 #flags &= ~wx.aui.AUI_MGR_VENETIAN_BLINDS_HINT
382 #flags &= ~wx.aui.AUI_MGR_RECTANGLE_HINT
383 flags &= ~(aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING)
384 self._mgr.SetAGWFlags(self._mgr.GetAGWFlags() ^ (aui.AUI_MGR_RECTANGLE_HINT | aui.AUI_MGR_ALLOW_FLOATING))
385 self._mgr.GetArtProvider().SetMetric(aui.AUI_DOCKART_GRADIENT_TYPE, aui.AUI_GRADIENT_HORIZONTAL)
386 self.GetDockArt().SetColor(aui.AUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR, "#00FFF9")
389 self._icon = wx.Icon(os.path.join(ImagePath, "iraicone.ico"), wx.BITMAP_TYPE_ICO)
390 self.SetIcon(self._icon)
391 ##########################
393 self.input_path = [False]
394 self.TEMPDIR = tempfile.mkdtemp('iramuteq')
395 self.FileTabList = []
401 self.g_header = False
408 self.SysEncoding = sys.getdefaultencoding()
409 self.syscoding = sys.getdefaultencoding()
410 #print 'SysEncoding',self.SysEncoding
411 if self.SysEncoding == 'mac-roman' : self.SysEncoding = 'MacRoman'
415 self.pref.read(self.ConfigPath['preferences'])
424 self.pref.read(self.ConfigPath['preferences'])
426 #configuration des chemins de R
427 self.PathPath = ConfigParser()
428 self.PathPath.read(ConfigPath['path'])
430 if not CheckRPath(self.PathPath) :
431 if sys.platform == 'win32':
432 BestRPath = FindRPAthWin32()
434 BestRPath = FindRPathNix()
436 self.PathPath.set('PATHS', 'rpath', BestRPath)
437 with open(ConfigPath['path'], 'w') as f :
438 self.PathPath.write(f)
442 self.RPath = self.PathPath.get('PATHS', 'rpath')
445 if not RLibsAreInstalled(self) :
449 Le chemin de l'executable de R n'a pas été trouvé.
450 Si R n'est pas installé, vous devez l'installer (http://www.r-project.org/).
451 Si R n'est pas installé dans le répertoire par défaut
452 (souvent C:\Program Files\R\R-2.x.x\R.exe sous windows ou /usr/bin/R sous linux ou Mac Os X)
453 vous devez signaler le chemin de l'éxecutable de R dans les préférences."""
454 dlg = wx.MessageDialog(self, msg, u"Problème de configuration", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
456 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
462 self.sound = self.pref.getboolean('iramuteq', 'sound')
463 self.check_update = self.pref.getboolean('iramuteq', 'checkupdate')
464 self.version = ConfigGlob.get('DEFAULT', 'version')
467 ##############################################################@
468 self.DisEnSaveTabAs(False)
469 self.ShowMenu(_("View"), False)
470 self.ShowMenu(_("Spreadsheet analysis"), False)
471 self.ShowMenu(_("Text analysis"), False)
475 def OnVerif(self, evt) :
476 pack = CheckRPackages(self)
478 dlg = wx.MessageDialog(self, u"Installation OK", u"Installation", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
480 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
483 #FIXME marche pas sous mac ?
484 def DisEnSaveTabAs(self, DISEN):
486 file_menu = self.mb.GetMenu(0)
487 items = file_menu.GetMenuItems()
489 if item.GetId() == ID_SaveTab :
492 def ShowMenu(self, menu, Show=True):
493 menu_pos = self.mb.FindMenu(menu)
494 self.mb.EnableTop(menu_pos, Show)
495 self.mb.UpdateMenus()
498 #--------------------------------------------------------------------
499 def OnClose(self, event):
501 with open(self.ConfigPath['path'], 'w') as f :
502 self.PathPath.write(f)
503 if self.DictTab != {} :
504 savestates = [self.DictTab[item][0] for item in self.DictTab]
505 if False in savestates :
506 notsave = [item for item in self.DictTab if self.DictTab[item][0] == False]
508 Certains résultats ne sont pas enregistrés.
509 Voulez-vous fermer quand même ?"""
510 dlg = wx.MessageDialog(self, msg, "Sauvegarde",
511 wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
513 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
518 for item in notsave :
519 for tmpfile in self.DictTab[item][1:] :
521 print 'remove : ' + tmpfile
533 #if sys.platform == 'win32' :
534 # os.system("taskkill /im iramuteq.exe /f")
535 # print 'meurtre de process'
537 def OnOpenData(self, event):
538 inputname, self.input_path = OnOpen(self, "Data")
540 self.filename = self.input_path[0]
541 self.tableau = Tableau(self,os.path.abspath(self.input_path[0]))
542 get_table_param(self, self.input_path[0])
543 self.tableau.make_content()
544 self.tableau.show_tab()
546 def OnOpenAnalyse(self, event):
547 self.AnalysePath = OnOpen(self, "Analyse")
548 OpenAnalyse(self, self.AnalysePath[1][0], True)
549 self.ShowMenu(_("View"))
551 def OnOpenText(self, event):
552 inputname, self.input_path = OnOpen(self, "Texte")
553 self.filename = self.input_path[0]
557 def OnViewData(self, event):
560 if self.type == "Data":
561 if not self.DataPop :
562 self.Sheet.Populate(self.content)
565 self.ShowAPane(u"Data")
566 elif self.type == "Texte" or self.type == 'Analyse' :
567 if not self.DataTxt :
568 self.text_ctrl_txt.Clear()
569 self.text_ctrl_txt.write(self.content)
570 self.text_ctrl_txt.ShowPosition(0)
573 self.ShowAPane(u"Text")
577 #dial = EncodeDialog(self)
578 dlg = wx.ProgressDialog("Ouverture...",
579 "Veuillez patienter...",
582 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
585 builder = Builder(self, dlg)
586 if builder.res == wx.ID_OK :
588 corpus = builder.doanalyse()
589 self.history.add(corpus.parametres)
590 self.tree.OnItemAppend(corpus.parametres)
591 OpenAnalyse(self, corpus.parametres)
594 #self.content = DoConf().totext(corpus.parametres)
595 # parametres = DoConf(os.path.join(UserConfigPath,'corpus.cfg')).getoptions('corpus')
596 # parametres['originalpath'] = self.filename
598 # parametres['pathout'] = PathOut(self.filename, 'corpus').dirout
599 # dial = CorpusPref(self, parametres)
600 # dial.CenterOnParent()
601 # dial.txtpath.SetLabel(self.filename)
602 # res = dial.ShowModal()
603 # parametres = dial.doparametres()
605 # ReadLexique(self, lang = parametres['lang'])
606 # self.expressions = ReadDicoAsDico(self.DictPath.get(parametres['lang'], 'french_exp'))
607 # corpus = BuildFromAlceste(self.filename, parametres, self.lexique, self.expressions).corpus
608 #self.corpus_encodage = dial.encodages[dial.list_encodages.GetSelection()][0]
609 #self.corpus_lang = dial.langues[dial.choice_dict.GetSelection()]
612 keepGoing = dlg.Update(count, u"Lecture du fichier")
613 # msg = u"Ce fichier ne semble pas être encodé en %s" % self.corpus_encodage
614 # dial = wx.MessageDialog(self, msg, u"Problème d'encodage", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING)
615 # dial.CenterOnParent()
616 # res = dial.ShowModal()
619 self.ShowMenu(_("View"))
620 self.ShowMenu(_("Text analysis"))
621 self.ShowMenu(_(u"Spreadsheet analysis"), False)
626 keepGoing = dlg.Update(count, u"Chargement du dictionnaire")
628 #self.OnViewData(wx.EVT_BUTTON)
630 def OnExit(self, event):
633 def OnAbout(self, event):
634 info = wx.AboutDialogInfo()
635 info.Name = ConfigGlob.get('DEFAULT', 'name')
636 info.Version = ConfigGlob.get('DEFAULT', 'version')
637 info.Copyright = ConfigGlob.get('DEFAULT', 'copyright')
638 info.Description = u"""
639 Interface de R pour les Analyses Multidimensionnelles
640 de Textes et de Questionnaires
643 construit avec des logiciels libres.
649 info.WebSite = ("http://www.iramuteq.org", u"Site web IRaMuTeQ")
650 dev = ConfigGlob.get('DEFAULT', 'dev').split(';')
651 info.Developers = dev
652 info.License = u"""Iramuteq est un logiciel libre ; vous pouvez le diffuser et/ou le modifier
653 suivant les termes de la Licence Publique Générale GNU telle que publiée
654 par la Free Software Foundation ; soit la version 2 de cette licence,
655 soit (à votre convenance) une version ultérieure.
657 Iramuteq est diffusé dans l'espoir qu'il sera utile,
658 mais SANS AUCUNE GARANTIE ; sans même une garantie implicite
659 de COMMERCIALISATION ou d'ADÉQUATION À UN USAGE PARTICULIER.
660 Voyez la Licence Publique Générale GNU pour plus de détails.
662 Vous devriez avoir reçu une copie de la Licence Publique Générale GNU
663 avec Iramuteq ; sinon, veuillez écrire à la Free Software Foundation,
664 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, États-Unis."""
667 def GetDockArt(self):
668 return self._mgr.GetArtProvider()
673 def OnPageChanged(self, event) :
674 new = event.GetSelection()
675 nobject = event.GetEventObject()
676 parent = nobject.GetParent()
677 if isinstance(parent, IraFrame) :
678 npage = self.nb.GetPage(new)
679 self.tree.GiveFocus(uuid=npage.parametres['uuid'])
681 def OnCloseTab(self, evt):
682 #log.info('Closing tab %s' % str(evt.GetEventObject()))
683 ctrl = evt.GetEventObject()
684 if isinstance(ctrl.GetParent(), aui.AuiNotebook) or isinstance(ctrl.GetParent(), wx.Panel):
688 page = self.nb.GetPage(self.nb.GetSelection())
689 if 'parametres' in dir(page) and isinstance(ctrl.GetParent(), IraFrame) :
690 self.history.rmtab(page.parametres)
691 self.tree.CloseItem(uuid = page.parametres['uuid'])
692 TabTitle = self.nb.GetPageText(self.nb.GetSelection())
693 if self.DictTab != {} :
694 if TabTitle in self.DictTab :
695 ListFile=self.DictTab[TabTitle]
696 if False in ListFile:
698 Certains résultats ne sont pas enregistrer.
699 Voulez-vous fermer quand même ?"""
700 dlg = wx.MessageDialog(self, msg, "Sauvegarde",wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
703 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
708 for f in ListFile[1:] :
713 elif True in ListFile :
716 del self.DictTab[TabTitle]
721 if self.nb.GetPageCount() == 1 and remove and not notebook :
724 def LastTabClose(self) :
725 if self.nb.GetPageCount() == 1 :
726 self.DisEnSaveTabAs(False)
728 self.ShowAPane("Text")
730 self.ShowAPane("Data")
732 self.ShowAPane("Intro_Text")
734 def OnSaveTabAs(self, event):
735 SelectTab = self.nb.GetSelection()
736 TabTitle = self.nb.GetPageText(SelectTab)
737 FileToSave = self.DictTab[TabTitle]
740 self, message="Enregistrer sous...", defaultDir=os.getcwd(),
741 defaultFile="resultat.html", wildcard="Tous les fichiers|*", style=wx.SAVE | wx.OVERWRITE_PROMPT
743 dlg.SetFilterIndex(2)
746 if dlg.ShowModal() == wx.ID_OK:
748 Dirname = os.path.dirname(Path)
749 Filename = dlg.GetFilename()
754 shutil.copyfile(FileToSave[-1], Path)
755 os.remove(FileToSave[len(FileToSave) - 1])
756 NewListFile.append(True)
757 NewListFile.append(Path)
758 for f in FileToSave[1:-1] :
759 Fileout = os.path.join(Dirname, os.path.basename(f))
760 shutil.copyfile(f, Fileout)
761 NewListFile.append(Fileout)
764 self.DictTab[TabText] = NewListFile
765 del self.DictTab[TabTitle]
766 self.nb.SetPageText(SelectTab, TabText)
768 def GetStartPosition(self):
772 pt = self.ClientToScreen(wx.Point(0, 0))
774 return wx.Point(pt.x + x, pt.y + x)
776 def ShowAPane(self, panel):
777 for pane in self._mgr.GetAllPanes() :
778 if not pane.IsToolbar() and pane.name != 'lefttree':
780 self._mgr.GetPane(panel).Show()
783 def OnAcceuil(self, event):
784 self.ShowAPane(u"Intro_Text")
787 def CreateHTMLCtrl(self):
788 ctrl = wx.html.HtmlWindow(self, -1, wx.DefaultPosition, wx.Size(400, 300))
789 if "gtk2" in wx.PlatformInfo:
790 ctrl.SetStandardFonts()
791 ctrl.SetPage(u"text")
794 def ShowTab(self, evt):
795 self.ShowAPane("Tab_content")
797 ################################################################
799 ################################################################
801 def OnFreq(self, event):
807 def OnChi2(self, event):
809 # print('PAS DE DEBUG SUR CHI2')
810 chi = ChiSquare(self)
814 def OnStudent(self, event):
820 def OnRCode(self, event):
826 def OnCHDSIM(self, event):
828 # print 'ATTENTION!!!!'
829 chdsim = ChdCluster(self)
830 if chdsim.val == wx.ID_OK:
835 def OnCHDAlceste(self, event):
837 # print('PLUS DE BUG SUR ALCESTE QUESTIONNAIRE')
838 self.quest = AnalyseQuest(self)
839 if self.quest.val == wx.ID_OK:
844 def OnSimiTxt(self, evt, corpus = None) :
845 # print 'PLUS DE BUG SUR SIMITXT'
847 #self.Text = SimiTxt(self)
849 corpus = self.tree.getcorpus()
850 self.Text = SimiTxt(self, corpus, parametres = {'type': 'simitxt'}, dlg = progressbar(self, 3))
851 if self.Text.val == wx.ID_OK :
856 def OnWordCloud(self, evt, corpus = None) :
857 # print 'PLUS DE BUG SUR WORDCLOUD'
860 corpus = self.tree.getcorpus()
861 self.Text = WordCloud(self, corpus, parametres = {'type' : 'wordcloud'}, dlg = progressbar(self, 3))
862 if self.Text.val == wx.ID_OK :
868 def OnAFCM(self, event):
874 def OnCheckcorpus(self, evt):
880 def OnTextStat(self, event, corpus = None):
881 print 'PAS DE BUG SUR TEXT STAT'
884 corpus = self.tree.getcorpus()
885 self.Text = Stat(self, corpus, parametres = {'type': 'stat'}, dlg = progressbar(self, 7))
887 if self.Text.val == wx.ID_OK :
892 def OnTextSpec(self, event, corpus = None):
894 #self.Text = AsLexico(self)
895 print('ATTENTION : PLUS DE BUG SUR LEXICO')
897 corpus = self.tree.getcorpus()
898 self.Text = Lexico(self, corpus, parametres = {'type' : 'spec'}, dlg = progressbar(self, 3))
899 if self.Text.val == wx.ID_OK :
904 def OnTextAfcm(self, event):
911 def import_factiva_xml(self,event):
913 ImportFactiva(self, 'xml')
917 def import_factiva_mail(self, evt) :
919 ImportFactiva(self, 'mail')
923 def import_factiva_txt(self, evt) :
925 ImportFactiva(self, 'txt')
929 def ExtractTools(self, evt) :
931 if ID == self.ID_splitvar :
932 Extract(self, 'splitvar')
934 Extract(self, 'mods')
936 def OnTextAlceste(self, event, corpus = None):
938 #print('ATTENTION : PLUS DE BUG SUR ALCESTE')
939 #RunAnalyse(self, corpus, Alceste, OptAlceste)
941 corpus = self.tree.getcorpus()
942 self.Text = Alceste(self, corpus, parametres = {'type': 'alceste'}, dlg = progressbar(self,6))
943 if self.Text.val == wx.ID_OK:
948 def OnPamSimple(self, event):
950 self.Text = PamTxt(self)
951 if self.Text.val == wx.ID_OK:
956 def OnSimi(self,evt):
958 #print 'ATTENTION !!!! VERGES'
959 self.res = DoSimi(self, param = None)
960 #self.res = Verges(self)
961 if self.res.val == wx.ID_OK :
965 #################################################################
967 def OnHelp(self, event):
968 webbrowser.open('http://www.iramuteq.org/documentation')
970 def OnPref(self, event):
971 dlg = PrefDialog(self)
973 self.val = dlg.ShowModal()
976 if self.check_update:
981 #CheckRPackages(self)
983 def OnOpenFromCmdl(self):
985 if options.filename :
986 if os.path.exists(options.filename):
987 self.filename = os.path.abspath(options.filename)
991 if os.path.exists(os.path.realpath(args[0])):
992 self.filename = os.path.abspath(os.path.realpath(args[0]))
998 if os.path.splitext(self.filename)[1] in ['.csv', '.xls', '.ods']:
999 self.tableau = Tableau(self, self.filename)
1000 get_table_param(self, self.filename)
1001 self.tableau.make_content()
1002 self.tableau.show_tab()
1003 #open_data(self, self.filename)
1004 elif os.path.splitext(self.filename)[1] == '.txt':
1006 elif os.path.splitext(self.filename)[1] == '.ira' :
1007 #self.corpus = Corpus(self)
1008 #self.Text = OpenAnalyse(self, self.filename)
1009 OpenAnalyse(self, self.filename)
1011 print 'ce fichier n\'existe pas'
1015 class IntroPanel(wx.Panel):
1016 def __init__(self, parent):
1017 wx.Panel.__init__(self, parent)
1018 #col = randint(0, 255)
1019 #col1 = randint(0,255)
1020 #col2 = randint(0,255)
1022 bckgrdcolor = wx.Colour(col, col, col)
1023 self.SetBackgroundColour(bckgrdcolor)
1024 txtcolour = wx.Colour(250, 250, 250)
1025 linkcolor = wx.Colour(255, 0, 0)
1026 sizer1 = wx.BoxSizer(wx.VERTICAL)
1027 sizer2 = wx.BoxSizer(wx.VERTICAL)
1028 sizer3 = wx.BoxSizer(wx.HORIZONTAL)
1029 sizer4 = wx.BoxSizer(wx.VERTICAL)
1030 sizer5 = wx.BoxSizer(wx.HORIZONTAL)
1031 grid_sizer_1 = wx.FlexGridSizer(1, 4, 0, 0)
1032 grid_sizer_3 = wx.FlexGridSizer(1, 4, 0, 0)
1033 grid_sizer_2 = wx.FlexGridSizer(1, 3, 0, 0)
1034 PanelPres = wx.Panel(self)
1035 PanelPres.SetBackgroundColour(bckgrdcolor)
1036 label_1 = wx.StaticText(self, -1, u"IRaMuTeQ", size=(-1, -1))
1037 label_1.SetFont(wx.Font(46, wx.TELETYPE, wx.NORMAL, wx.BOLD, 0, "Purisa"))
1038 label_1.SetForegroundColour(wx.RED)
1039 label2 = wx.StaticText(PanelPres, -1 , u'\nVersion ' + ConfigGlob.get('DEFAULT', 'version') + '\n')
1040 label2.SetForegroundColour(txtcolour)
1041 label2.SetBackgroundColour(bckgrdcolor)
1042 #label3 = wx.StaticText(PanelPres, -1 , u'Equipe ')
1043 #label3.SetForegroundColour(txtcolour)
1044 #label3.SetBackgroundColour(bckgrdcolor)
1045 self.hyper2 = hl.HyperLinkCtrl(PanelPres, wx.ID_ANY, u"REPERE", URL="http://repere.no-ip.org/")
1046 self.hyper2.SetColours(linkcolor, linkcolor, "RED")
1047 self.hyper2.SetBackgroundColour(bckgrdcolor)
1048 self.hyper2.EnableRollover(True)
1049 self.hyper2.SetUnderlines(False, False, True)
1050 self.hyper2.SetBold(True)
1051 self.hyper2.UpdateLink()
1052 label_lerass = wx.StaticText(PanelPres, -1, u'Laboratoire ')
1053 label_lerass.SetForegroundColour(txtcolour)
1054 label_lerass.SetBackgroundColour(bckgrdcolor)
1055 self.hyper_lerass = hl.HyperLinkCtrl(PanelPres, -1, u'LERASS', URL="http://www.lerass.com")
1056 self.hyper_lerass.SetColours(linkcolor, linkcolor, "RED")
1057 self.hyper_lerass.SetBackgroundColour(bckgrdcolor)
1058 self.hyper_lerass.EnableRollover(True)
1059 self.hyper_lerass.SetUnderlines(False, False, True)
1060 self.hyper_lerass.SetBold(True)
1061 self.hyper_lerass.UpdateLink()
1062 blank = wx.StaticText(PanelPres, -1, u'\n')
1063 blank1 = wx.StaticText(PanelPres, -1, u'\n')
1064 labellicence = wx.StaticText(PanelPres, -1, u'Licence GNU GPL')
1065 labellicence.SetForegroundColour(txtcolour)
1066 labellicence.SetBackgroundColour(bckgrdcolor)
1067 labelcopy = wx.StaticText(PanelPres, -1, ConfigGlob.get('DEFAULT', 'copyright'))
1068 labelcopy.SetForegroundColour(txtcolour)
1069 labelcopy.SetBackgroundColour(bckgrdcolor)
1070 python_img = wx.Image(os.path.join(ImagePath,'python-logo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1071 r_img = wx.Image(os.path.join(ImagePath,'Rlogo.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1072 lexique_img = wx.Image(os.path.join(ImagePath,'LexTexte4.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1073 but_python = wx.BitmapButton(self, -1, python_img)
1074 but_lexique = wx.BitmapButton(self, -1, lexique_img)
1075 but_r = wx.BitmapButton(self, -1, r_img)
1076 self.Bind(wx.EVT_BUTTON, self.OnPython, but_python)
1077 self.Bind(wx.EVT_BUTTON, self.OnLexique, but_lexique)
1078 self.Bind(wx.EVT_BUTTON, self.OnR, but_r)
1081 #grid_sizer_1.Add(label3, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1082 grid_sizer_1.Add(self.hyper2, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1083 grid_sizer_3.Add(label_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1084 grid_sizer_3.Add(self.hyper_lerass, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1085 sizer4.Add(label_1, 0, wx.ALIGN_CENTER, 5)
1086 sizer2.Add(label2, 0, wx.ALIGN_CENTER, 5)
1087 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1088 sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1089 sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1090 sizer2.Add(grid_sizer_3, 0, wx.ALIGN_CENTER, 5)
1091 sizer2.Add(wx.StaticText(PanelPres, -1, u' '), 0, wx.ALIGN_CENTER, 5)
1092 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1093 #sizer2.Add(wx.StaticText(PanelPres, -1, u''), 0, wx.ALIGN_CENTER, 5)
1094 sizer2.Add(grid_sizer_1, 0, wx.ALIGN_CENTER, 5)
1095 sizer2.Add(labellicence, 0, wx.ALIGN_CENTER, 5)
1096 sizer2.Add(labelcopy, 0, wx.ALIGN_CENTER, 5)
1097 sizer1.Add(sizer4, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1098 PanelPres.SetSizer(sizer2)
1099 sizer5.Add(blank, 1, wx.EXPAND | wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 2)
1100 sizer5.Add(PanelPres, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 0)
1101 sizer5.Add(blank1, 1, wx.ALIGN_CENTER_HORIZONTAL,2)
1102 grid_sizer_2.Add(but_python, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1103 grid_sizer_2.Add(but_lexique, 1,wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1104 grid_sizer_2.Add(but_r, 1, wx.ALIGN_CENTER_HORIZONTAL| wx.ALIGN_CENTER_VERTICAL)
1106 sizer1.Add(sizer5, 3, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 1)
1107 sizer1.Add(grid_sizer_2, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
1108 self.SetSizer(sizer1)
1111 def OnPython(self,evt):
1112 webbrowser.open('http://www.python.org')
1114 def OnLexique(self,evt):
1115 webbrowser.open('http://www.lexique.org')
1118 webbrowser.open('http://www.r-project.org')
1120 class MySplashScreen(wx.SplashScreen):
1122 bmp = wx.Image(os.path.join(ImagePath, 'splash.png')).ConvertToBitmap()
1123 wx.SplashScreen.__init__(self, bmp,
1124 wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
1126 self.Bind(wx.EVT_CLOSE, self.OnClose)
1127 self.fc = wx.FutureCall(1, self.ShowMain)
1129 def OnClose(self, evt):
1133 if self.fc.IsRunning():
1138 frame = IraFrame(None, -1, "IRaMuTeQ " + ConfigGlob.get('DEFAULT', 'version'), size=(1100, 800))
1141 frame.OnOpenFromCmdl()
1142 # if self.fc.IsRunning():
1144 #wx.CallAfter(frame.ShowTip)
1146 class MyApp(wx.App):
1149 Create and show the splash screen. It will then create and show
1150 the main frame when it is time to do so.
1152 wx.SystemOptions.SetOptionInt("mac.window-plain-transition", 1)
1153 self.SetAppName("Iramuteq")
1154 splash = MySplashScreen()
1162 if __name__ == '__main__':