1 # -*- coding: utf-8 -*-
3 Interface graphique pour l'analyse des fichiers de log minwii.
13 from os
.path
import join
as pjoin
14 from os
.path
import basename
15 from os
.path
import getsize
16 from minwii
.loganalyse
import LogFileAnalyser
17 from pprint
import pprint
19 class Application(Frame
) :
20 def __init__(self
, master
=None) :
21 Frame
.__init
__(self
, master
)
22 self
.configureStretching()
26 self
.resultsFrame
= None
28 def configureStretching(self
) :
29 top
=self
.winfo_toplevel()
30 top
.rowconfigure(0, weight
=1)
31 top
.columnconfigure(0, weight
=1)
33 self
.grid(sticky
=N
+S
+E
+W
, padx
=10, pady
=10)
34 self
.rowconfigure(0, weight
=1)
35 self
.columnconfigure(0, weight
=1)
37 def createWidgets(self
) :
38 # zone d'affichage des données'
39 self
.dataFrame
= df
= Frame(self
)
42 self
.identFrame
= Identification(df
)
43 self
.identFrame
.grid(sticky
=NW
)
44 self
.nav
= Navbar(df
, incCallback
=self
.loadLogFile
, decCallback
=self
.loadLogFile
)
49 self
.btnFrame
= bf
= Frame(self
)
50 bf
.grid(row
=1, column
=0, sticky
=W
+S
+E
)
51 bf
.rowconfigure(0, weight
=1)
52 bf
.columnconfigure(0, weight
=1)
53 bf
.columnconfigure(1, weight
=1)
56 self
.chooseLogDir
= Button(bf
, text
="Parcourir…", command
=self
.openFileDialog
)
57 self
.chooseLogDir
.grid(row
=0, column
=0, sticky
=W
)
59 self
.nav
= Navbar(bf
, incCallback
=self
.loadLogFile
, decCallback
=self
.loadLogFile
)
60 #self.nav.grid(row=0, column=1)
62 self
.quitButton
= Button(bf
, text
='Terminer', command
=self
.quit
)
63 self
.quitButton
.grid(row
=0, column
=2, sticky
=E
)
65 def openFileDialog(self
) :
66 self
.logDir
= tkFileDialog
.askdirectory()
68 self
.logFiles
= glob(pjoin(self
.logDir
, '*.log'))
69 self
._cleanupJunkFiles
()
71 self
.dataFrame
.grid(row
=0, column
=0, sticky
=NW
)
72 self
.nav
.setSize(len(self
.logFiles
))
73 self
.nav
.grid(row
=0, column
=1)
74 self
.loadLogFile(self
.nav
)
76 def _cleanupJunkFiles(self
) :
79 f
= self
.logFiles
.pop()
83 # TODO : vérifier qu'il existe des événements
90 def loadLogFile(self
, nav
) :
92 filepath
= self
.logFiles
[index
]
93 filename
= basename(filepath
)
94 self
.identFrame
.setFileName(filename
)
95 if self
.resultsFrame
:
96 self
.resultsFrame
.destroy()
97 self
.resultsFrame
= ResultsFrame(self
.dataFrame
, filepath
)
98 self
.resultsFrame
.layResults()
99 self
.resultsFrame
.grid()
102 class Navbar(Frame
) :
103 def __init__(self
, master
=None, size
=1, incCallback
=None, decCallback
=None) :
104 Frame
.__init
__(self
, master
)
105 self
.caption
= StringVar()
108 self
.incCallback
= incCallback
if incCallback
else lambda x
: None
109 self
.decCallback
= decCallback
if decCallback
else lambda x
: None
110 self
.caption
.set('%d / %d' % (self
.index
, self
.to
))
112 def createWidgets(self
) :
113 self
.backBtn
= Button(self
,
117 self
.backBtn
.grid(row
=0, column
=0)
119 self
.lbl
= Label(self
, textvariable
=self
.caption
)
120 self
.lbl
.grid(row
=0, column
=1)
122 self
.nextBtn
= Button(self
,
125 self
.nextBtn
.grid(row
=0, column
=2)
127 def refreshStates(self
) :
128 if self
.index
== self
.from_
:
129 self
.backBtn
.configure(state
=DISABLED
)
131 self
.backBtn
.configure(state
=NORMAL
)
133 if self
.index
< self
.to
:
134 self
.nextBtn
.configure(state
=NORMAL
)
136 self
.nextBtn
.configure(state
=DISABLED
)
138 self
.caption
.set('%d / %d' % (self
.index
, self
.to
))
142 self
.index
= self
.index
- 1
144 self
.decCallback(self
)
147 self
.index
= self
.index
+ 1
149 self
.incCallback(self
)
151 def setSize(self
, size
) :
158 class Identification(Frame
) :
159 def __init__(self
, master
=None) :
160 Frame
.__init
__(self
, master
)
161 self
.fileName
= StringVar()
164 def setFileName(self
, name
) :
165 self
.fileName
.set(name
)
167 def createWidgets(self
) :
168 fileLbl
= Label(self
, text
='Fichier :')
169 fileLbl
.grid(row
=0, column
=0, sticky
=E
)
171 fileNameLbl
= Label(self
, textvariable
=self
.fileName
)
172 fileNameLbl
.grid(row
=0, column
=1, sticky
=W
)
174 nameLbl
= Label(self
, text
='Patient :')
175 nameLbl
.grid(row
=1, column
=0, sticky
=E
)
177 self
.nameEntry
= Entry(self
, width
=40)
178 self
.nameEntry
.grid(row
=1, column
=1, sticky
=W
)
180 commentsLbl
= Label(self
, text
='Commentaires :')
181 commentsLbl
.grid(row
=2, column
=0, sticky
=E
)
183 self
.commentsText
= Text(self
, width
=40, height
=4, undo
=True, wrap
=WORD
)
184 self
.commentsText
.grid(row
=2, column
=1, sticky
=W
)
186 class ResultsFrame(Frame
) :
187 def __init__(self
, master
, logFilePath
) :
188 Frame
.__init
__(self
, master
)
189 self
.logFilePath
= logFilePath
191 def layResults(self
) :
192 lfa
= LogFileAnalyser(self
.logFilePath
)
193 results
= lfa
.analyse()
195 for i
, kv
in enumerate(results
.items()) :
197 kl
= Label(self
, text
='%s :' % k
)
198 kl
.grid(row
=i
, column
=0, sticky
=E
)
200 vl
= Label(self
, text
=v
)
201 vl
.grid(row
=i
, column
=1, sticky
=W
)
203 msg
= Label(self
, text
="Pas de données exploitables.")
209 app
.master
.title("Analyseur des sessions MINWii")