remove agw
[iramuteq] / layout.py
index df30cfd..0e2d5a9 100644 (file)
--- a/layout.py
+++ b/layout.py
@@ -6,12 +6,13 @@
 
 import os
 import wx
 
 import os
 import wx
-#import wx.lib.agw.aui as aui
-import agw.aui as aui
+import wx.lib.hyperlink as hl
+#import agw.aui as aui
+import wx.lib.agw.aui as aui
 from chemins import ConstructPathOut, ChdTxtPathOut, FFF, ffr, PathOut, StatTxtPathOut, simipath
 from ConfigParser import ConfigParser
 from chemins import ConstructPathOut, ChdTxtPathOut, FFF, ffr, PathOut, StatTxtPathOut, simipath
 from ConfigParser import ConfigParser
-from functions import ReadProfileAsDico, GetTxtProfile, read_list_file, ReadList, exec_rcode, print_liste, BugReport, DoConf, indices_simi, check_Rresult
-from ProfList import *
+from functions import ReadProfileAsDico, GetTxtProfile, read_list_file, ReadList, exec_rcode, print_liste, BugReport, DoConf, indices_simi, check_Rresult, progressbar
+from ProfList import ProfListctrlPanel
 from guiparam3d import param3d, simi3d
 from PrintRScript import write_afc_graph, print_simi3d, PrintSimiScript
 from profile_segment import ProfileSegment
 from guiparam3d import param3d, simi3d
 from PrintRScript import write_afc_graph, print_simi3d, PrintSimiScript
 from profile_segment import ProfileSegment
@@ -21,12 +22,11 @@ from Liste import *
 from search_tools import SearchFrame
 from dialog import PrefGraph, PrefExport, PrefSimpleFile, PrefDendro
 from guifunct import SelectColumn, PrepSimi
 from search_tools import SearchFrame
 from dialog import PrefGraph, PrefExport, PrefSimpleFile, PrefDendro
 from guifunct import SelectColumn, PrepSimi
-from corpusNG import Corpus
+from corpus import Corpus
 import datetime
 import sys
 import tempfile
 import shutil
 import datetime
 import sys
 import tempfile
 import shutil
-#import webbrowser
 import codecs
 import logging
 
 import codecs
 import logging
 
@@ -59,7 +59,11 @@ class GraphPanelAfc(wx.Panel):
         todel = []
         for i in range(0,len(list_graph)):
             if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
         todel = []
         for i in range(0,len(list_graph)):
             if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
-                self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY)))
+                filename, ext = os.path.splitext(list_graph[i][0])
+                if ext == '.svg' :
+                    self.listimg.append(hl.HyperLinkCtrl(self.panel_1, -1, os.path.join(self.dirout,list_graph[i][0]), URL=os.path.join(self.dirout,list_graph[i][0])))
+                else :
+                    self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY)))
                 self.labels.append(wx.StaticText(self.panel_1, -1, list_graph[i][1]))
                 self.buts.append(wx.Button(self.panel_1, wx.ID_DELETE, name = `i - b`))
             else :
                 self.labels.append(wx.StaticText(self.panel_1, -1, list_graph[i][1]))
                 self.buts.append(wx.Button(self.panel_1, wx.ID_DELETE, name = `i - b`))
             else :
@@ -89,6 +93,7 @@ class GraphPanelAfc(wx.Panel):
               'facteur' : [1,2,3],
               'alpha' : 10,
               'clnb' : clnb,
               'facteur' : [1,2,3],
               'alpha' : 10,
               'clnb' : clnb,
+              'svg' : 0,
             }
 
         self.__set_properties()
             }
 
         self.__set_properties()
@@ -100,7 +105,6 @@ class GraphPanelAfc(wx.Panel):
         self.panel_1.SetScrollRate(20, 20)
 
     def __do_layout(self):    
         self.panel_1.SetScrollRate(20, 20)
 
     def __do_layout(self):    
-        log.info('do layout')
         self.sizer_1 = wx.BoxSizer(wx.VERTICAL)
         self.sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
         self.sizer_3 = wx.BoxSizer(wx.VERTICAL)
         self.sizer_1 = wx.BoxSizer(wx.VERTICAL)
         self.sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
         self.sizer_3 = wx.BoxSizer(wx.VERTICAL)
@@ -129,17 +133,11 @@ class GraphPanelAfc(wx.Panel):
             oldlab.Destroy()
             oldbut = self.buts.pop(image_id)
             oldbut.Show(False)
             oldlab.Destroy()
             oldbut = self.buts.pop(image_id)
             oldbut.Show(False)
-            #No = [but.Destroy() for but in self.buts]
-            #self.buts = [wx.Button(self.panel_1, wx.ID_DELETE, name = `i`) for i, img in enumerate(self.listimg)]
             for i, but in enumerate(self.buts) :
                 but.SetName(`i`)
             todel = self.list_graph.pop(image_id)
             os.remove(os.path.join(self.dirout, todel[0]))
             print_liste(self.Dict[self.itempath], self.list_graph)
             for i, but in enumerate(self.buts) :
                 but.SetName(`i`)
             todel = self.list_graph.pop(image_id)
             os.remove(os.path.join(self.dirout, todel[0]))
             print_liste(self.Dict[self.itempath], self.list_graph)
-            #self.sizer_1.Destroy()
-            #self.sizer_2.Destroy()
-            #self.sizer_3.Destroy()
-            #self.__do_layout()
             self.sizer_3.Fit(self.panel_1)
             self.Layout()
         else :
             self.sizer_3.Fit(self.panel_1)
             self.Layout()
         else :
@@ -155,6 +153,10 @@ class GraphPanelAfc(wx.Panel):
         dial.CenterOnParent()
         val = dial.ShowModal()
         if val == wx.ID_OK :
         dial.CenterOnParent()
         val = dial.ShowModal()
         if val == wx.ID_OK :
+            if dial.choix_format.GetSelection() == 0 :
+                svg = 0
+            else :
+                svg = 1
             self.param = {'typegraph' : dial.choicetype.GetSelection(),
                           'width' : dial.spin1.GetValue(),
                           'height' : dial.spin2.GetValue(),
             self.param = {'typegraph' : dial.choicetype.GetSelection(),
                           'width' : dial.spin1.GetValue(),
                           'height' : dial.spin2.GetValue(),
@@ -177,7 +179,8 @@ class GraphPanelAfc(wx.Panel):
                           'facteur' : [dial.spin_f1.GetValue(),dial.spin_f2.GetValue(), dial.spin_f3.GetValue()],
                           'clnb' : self.clnb,
                           'film' : str(dial.film.GetValue()).upper(),
                           'facteur' : [dial.spin_f1.GetValue(),dial.spin_f2.GetValue(), dial.spin_f3.GetValue()],
                           'clnb' : self.clnb,
                           'film' : str(dial.film.GetValue()).upper(),
-                          'alpha' : dial.slider_sphere.GetValue()
+                          'alpha' : dial.slider_sphere.GetValue(),
+                          'svg' : svg
                         }
             self.nb.parent = self.ira
             self.DictPathOut = self.Dict
                         }
             self.nb.parent = self.ira
             self.DictPathOut = self.Dict
@@ -190,12 +193,6 @@ class GraphPanelAfc(wx.Panel):
                 afc <- afcf
                 afc_table <- afcf_table
                 chistabletot <- specfp
                 afc <- afcf
                 afc_table <- afcf_table
                 chistabletot <- specfp
-                infp <- which(is.infinite(chistabletot) & chistabletot > 0)
-                infm <- which(is.infinite(chistabletot) & chistabletot < 0)
-                chistabletot[infp] <- 0
-                chistabletot[infm] <- 0
-                chistabletot[infp] <- max(chistabletot) + 1
-                chistabletot[infm] <- min(chistabletot) - 1
                 """ 
             elif self.itempath == 'liste_graph_afct' :
                 txt +="""
                 """ 
             elif self.itempath == 'liste_graph_afct' :
                 txt +="""
@@ -205,9 +202,8 @@ class GraphPanelAfc(wx.Panel):
                 """
             txt += write_afc_graph(self)
             filetmp = tempfile.mktemp()
                 """
             txt += write_afc_graph(self)
             filetmp = tempfile.mktemp()
-            file = open(filetmp,'w')
-            file.write(txt)
-            file.close()
+            with open(filetmp, 'w') as f :
+                f.write(txt)
             pid = exec_rcode(self.ira.RPath, filetmp)
             check_Rresult(self.ira, pid)
             if self.param['typegraph'] == 0 :
             pid = exec_rcode(self.ira.RPath, filetmp)
             check_Rresult(self.ira, pid)
             if self.param['typegraph'] == 0 :
@@ -226,9 +222,15 @@ class GraphPanelAfc(wx.Panel):
                 if self.param['cex_txt'] : txt += u' - taille du texte proportionnel à la masse'
                 if self.param['tchi'] : txt += u' - taille du texte proportionnel au chi2 d\'association'
                 #list_graph = read_list_file(self.DictPathOut[self.itempath], self.coding)
                 if self.param['cex_txt'] : txt += u' - taille du texte proportionnel à la masse'
                 if self.param['tchi'] : txt += u' - taille du texte proportionnel au chi2 d\'association'
                 #list_graph = read_list_file(self.DictPathOut[self.itempath], self.coding)
-                self.list_graph.append([self.fileout, txt])
+                if self.param['svg'] :
+                    filename, ext = os.path.splitext(self.fileout)
+                    self.fileout = filename + '.svg'
+                self.list_graph.append([os.path.basename(self.fileout), txt])
                 print_liste(self.DictPathOut[self.itempath], self.list_graph)
                 print_liste(self.DictPathOut[self.itempath], self.list_graph)
-                self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(self.fileout, wx.BITMAP_TYPE_ANY)))
+                if not self.param['svg'] :
+                    self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(self.fileout, wx.BITMAP_TYPE_ANY)))
+                else :
+                    self.listimg.append(hl.HyperLinkCtrl(self.panel_1, -1, self.fileout, URL=self.fileout))
                 self.sizer_3.Add( self.listimg[-1], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
                 self.labels.append(wx.StaticText(self.panel_1,-1, txt))
                 self.sizer_3.Add(self.labels[-1], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
                 self.sizer_3.Add( self.listimg[-1], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
                 self.labels.append(wx.StaticText(self.panel_1,-1, txt))
                 self.sizer_3.Add(self.labels[-1], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
@@ -587,9 +589,8 @@ def PrintRapport(self, corpus, parametres, txt = True):
 temps d'analyse : %s
 ###########################
 """ % parametres['time']
 temps d'analyse : %s
 ###########################
 """ % parametres['time']
-    file = open(self.pathout['pre_rapport'], 'w')
-    file.write(txt)
-    file.close()
+    with open(self.pathout['pre_rapport'], 'w') as f :
+        f.write(txt)
 
 class dolexlayout :
     def __init__(self, ira, corpus, parametres):
 
 class dolexlayout :
     def __init__(self, ira, corpus, parametres):