svg for wordcloud
[iramuteq] / textwordcloud.py
index b220d9e..ed4c1cf 100644 (file)
@@ -25,26 +25,33 @@ class WordCloud(AnalyseText):
         self.parametres['type'] = 'wordcloud'
         #FIXME
         limit = 3
-        self.make_option()
-        if self.parametres['mode'] == 2 :
-            self.actives = self.corpus.make_actives_limit(limit, 1)
-            self.actives += self.corpus.make_actives_limit(limit, 2)
-        elif self.parametres['mode'] == 0 :
-            self.actives = self.corpus.make_actives_limit(limit, 1)
-        elif self.parametres['mode'] == 1 :
-            self.actives = self.corpus.make_actives_limit(limit, 2)
-        dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)]) 
-        SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], dlg = True)
-        self.make_wordcloud()
-        script = WordCloudRScript(self)
-        script.make_script()
-        self.doR(script.scriptout, dlg = self.dlg, message = 'R...')
+        res = self.make_option()
+        if res == wx.ID_OK :
+            if self.parametres['mode'] == 2 :
+                self.actives = self.corpus.make_actives_limit(limit, 1)
+                self.actives += self.corpus.make_actives_limit(limit, 2)
+            elif self.parametres['mode'] == 0 :
+                self.actives = self.corpus.make_actives_limit(limit, 1)
+            elif self.parametres['mode'] == 1 :
+                self.actives = self.corpus.make_actives_limit(limit, 2)
+            dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)]) 
+            SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], dlg = True)
+            self.make_wordcloud()
+            script = WordCloudRScript(self)
+            script.make_script()
+            self.doR(script.scriptout, dlg = self.dlg, message = 'R...')
+        else :
+            return 'NOK'
     
     def make_option(self) :
         dial = PrefWordCloud(self.ira)
         dial.CenterOnParent()
         res = dial.ShowModal()
         if res == wx.ID_OK :
+            if dial.format.GetSelection() == 0 :
+                svg = 0
+            else :
+                svg = 1
             self.parametres['width'] = dial.spin_L.GetValue()
             self.parametres['height'] = dial.spin_H.GetValue()
             self.parametres['maxword'] = dial.spin_maxword.GetValue()
@@ -53,13 +60,18 @@ class WordCloud(AnalyseText):
             self.parametres['col_text'] = dial.color_text.GetColour()
             self.parametres['col_bg'] = dial.color_bg.GetColour()
             self.parametres['mode'] = dial.typeformeschoice.GetSelection()
+            self.parametres['svg'] = svg
             outgraph = os.path.join(os.path.dirname(self.pathout['zipf.png']), 'nuage_')
             nb = 1
-            while os.path.exists(outgraph + str(nb) + '.png') :
+            if svg :
+                end = '.svg'
+            else :
+                end = '.png'
+            while os.path.exists(outgraph + str(nb) + end) :
                 nb += 1
-            self.parametres['graphout'] = outgraph + str(nb) + '.png'
+            self.parametres['graphout'] = outgraph + str(nb) + end
         dial.Destroy()
-
+        return res
 
     def make_wordcloud(self) :
         act = ['\t'.join([act, `self.corpus.getlemeff(act)`]) for act in self.actives]