...
[iramuteq] / guifunct.py
1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2011 Pierre Ratinaud
4 #Lisense: GNU/GPL
5
6 import wx
7 import os
8 import sys
9 from copy import copy
10 import dialog
11
12 def OnOpen(self, type):
13         if type == "Data":
14              wildcard = u"Fichiers supportés|*.ods;*.xls;*.csv;*.txt|Openoffice Clac|*.ods|Fichier excel|*.xls|Fichier csv|*.csv|Fichier texte|*.txt|Tous les fichiers|*"
15         elif type == "Texte":
16             wildcard = "Fichier texte|*.txt|Tous les fichiers|*"
17         elif type == "Analyse":
18             wildcard = "Fichier analyse|*.ira"
19         defaultDir = self.PathPath.get('PATHS', 'lastpath')
20         if defaultDir.strip() == '':
21             defaultDir = self.UserConfigPath.replace('.iramuteq','')
22         dlg = wx.FileDialog(
23         self, message="Choisissez un fichier", defaultDir=defaultDir,
24         defaultFile="", wildcard=wildcard, style=wx.OPEN | wx.CHANGE_DIR)
25         dlg.CenterOnParent()
26         if dlg.ShowModal() == wx.ID_OK :
27             fileName = dlg.GetFilename()
28             path = dlg.GetPaths()
29             dlg.Destroy()
30             self.PathPath.set('PATHS', 'lastpath', os.path.dirname(path[0]))
31             self.type = type
32             return fileName, path
33         else:
34             dlg.Destroy()
35             if type == "Data":
36                 return False, [False]
37             elif type == "Texte":
38                 return False, [False]
39             elif type == "Analyse":
40                 return [False]
41
42 def getfileextension(file) :
43     return os.path.splitext(file)[1]
44
45 def get_table_param(self, filename) :
46     if getfileextension(filename) == '.csv':
47         dlg = dialog.FileOptionDialog(self, -1, u"Format du fichier", sep=True, size=(350, 200),
48                      style=wx.DEFAULT_DIALOG_STYLE)
49         dlg.CenterOnParent()
50         val = dlg.ShowModal()
51         if val == wx.ID_OK:
52             self.tableau.parametre['colsep'] = dlg.colsep[dlg.choice3.GetSelection()]
53             self.tableau.parametre['txtsep'] = dlg.txtsep[dlg.choice4.GetSelection()]
54             if self.tableau.parametre['colsep'] == 'tabulation' :
55                 self.tableau.parametre['colsep'] = '\t'
56             self.tableau.parametre['filetype'] = 'csv'
57         else :
58             dlg.Destroy()
59     elif  getfileextension(filename) == '.xls' :
60         dlg = dialog.FileOptionDialog(self, -1, u"Format du fichier", sep=False, sheet = True, size=(350, 200),
61                      style=wx.DEFAULT_DIALOG_STYLE)
62         dlg.CenterOnParent()
63         val = dlg.ShowModal()
64         if val == wx.ID_OK:    
65             self.tableau.parametre['colsep'] = ';'
66             self.tableau.parametre['txtsep'] = '\"'
67             self.tableau.parametre['encodage'] = sys.getdefaultencoding()
68             self.tableau.parametre['sheetnb'] = dlg.spin1.GetValue()
69             self.tableau.parametre['filetype'] = 'xls'
70         else :
71             dlg.Destroy()
72     elif getfileextension(filename) == '.ods':
73         dlg = dialog.FileOptionDialog(self, -1, u"Format du fichier", sep=False, size=(350, 200),
74                      style=wx.DEFAULT_DIALOG_STYLE)
75         dlg.CenterOnParent()
76         val = dlg.ShowModal()
77         if val == wx.ID_OK:          
78             self.tableau.parametre['colsep'] = ';'
79             self.tableau.parametre['txtsep'] = '\"'
80             self.tableau.parametre['filetype'] = 'ods'
81         else :
82             dlg.Destroy()
83     else :
84         val = False
85     if val == wx.ID_OK:       
86         if dlg.radio_box_1.GetSelection() == 0:
87             self.tableau.firstrowiscolnames = True
88         else:
89             self.tableau.firstrowiscolnames = False
90         if dlg.radio_box_2.GetSelection() == 0:
91             self.tableau.firstcolisrownames = True
92         else:
93             self.tableau.firstcolisrownames = False
94         dlg.Destroy()
95
96 def getPage(ira) :
97     if '_mgr' in dir(ira) :
98         if not ira._mgr.GetPane('Text').IsShown() :
99             if ira.nb.GetPageCount() >= 1:
100                 return ira.nb.GetPage(ira.nb.GetSelection())
101             else :
102                 return None
103         else :
104             return None
105     else :
106         return None
107
108 def getCorpus(page) :
109     if 'corpus' in page.__dict__:
110         return copy(page.corpus)
111     else :
112         return None
113