323e293dde6ddf065a9b78954d8672c5e583af4a
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
29 #self.chooseDirDialog(dir='/Users/pinbe/minwii_logs')
31 def configureStretching(self
) :
32 top
=self
.winfo_toplevel()
33 top
.rowconfigure(0, weight
=1)
34 top
.columnconfigure(0, weight
=1)
36 self
.grid(sticky
=N
+S
+E
+W
, padx
=10, pady
=10)
37 self
.rowconfigure(0, weight
=1)
38 self
.columnconfigure(0, weight
=1)
40 def createWidgets(self
) :
41 # zone d'affichage des données'
42 self
.dataFrame
= df
= Frame(self
)
44 self
.identFrame
= Identification(df
)
45 self
.identFrame
.grid(sticky
=NW
)
48 self
.btnFrame
= bf
= Frame(self
)
49 bf
.grid(row
=1, column
=0, sticky
=W
+S
+E
)
50 bf
.rowconfigure(0, weight
=1)
52 bf
.columnconfigure(i
, weight
=1)
54 self
.chooseLogDir
= Button(bf
, text
="Parcourir…", command
=self
.chooseDirDialog
)
55 self
.chooseLogDir
.grid(row
=0, column
=0, sticky
=W
)
57 self
.nav
= Navbar(bf
, incCallback
=self
.loadLogFile
, decCallback
=self
.loadLogFile
)
59 self
.quitButton
= Button(bf
, text
='Terminer', command
=self
.quit
)
60 self
.quitButton
.grid(row
=0, column
=2, sticky
=E
)
62 def chooseDirDialog(self
, dir=None) :
64 self
.logDir
= tkFileDialog
.askdirectory(title
='Sélectionnez un dossier de fichiers de logs')
68 self
.logFiles
= glob(pjoin(self
.logDir
, '*.log'))
69 self
._cleanupJunkFiles
()
71 self
.logFiles
.reverse()
72 self
.dataFrame
.grid(row
=0, column
=0, sticky
=NW
)
73 self
.nav
.setSize(len(self
.logFiles
))
74 self
.nav
.grid(row
=0, column
=1)
75 self
.loadLogFile(self
.nav
)
77 def _cleanupJunkFiles(self
) :
81 f
= self
.logFiles
.pop()
86 lfa
= LogFileAnalyser(f
)
87 if lfa
.getLastEventTicks() is None :
99 def loadLogFile(self
, nav
) :
100 index
= nav
.index
- 1
101 filepath
= self
.logFiles
[index
]
102 filename
= basename(filepath
)
103 self
.identFrame
.setFileName(filename
)
104 if self
.resultsFrame
:
105 self
.resultsFrame
.destroy()
106 self
.resultsFrame
= ResultsFrame(self
.dataFrame
, filepath
)
107 self
.resultsFrame
.layResults()
108 self
.resultsFrame
.grid()
111 class Navbar(Frame
) :
112 def __init__(self
, master
=None, size
=1, incCallback
=None, decCallback
=None) :
113 Frame
.__init
__(self
, master
)
114 self
.caption
= StringVar()
117 self
.incCallback
= incCallback
if incCallback
else lambda x
: None
118 self
.decCallback
= decCallback
if decCallback
else lambda x
: None
119 self
.caption
.set('%d / %d' % (self
.index
, self
.to
))
121 def createWidgets(self
) :
122 self
.backBtn
= Button(self
,
126 self
.backBtn
.grid(row
=0, column
=0)
128 self
.lbl
= Label(self
, textvariable
=self
.caption
)
129 self
.lbl
.grid(row
=0, column
=1)
131 self
.nextBtn
= Button(self
,
134 self
.nextBtn
.grid(row
=0, column
=2)
136 def refreshStates(self
) :
137 if self
.index
== self
.from_
:
138 self
.backBtn
.configure(state
=DISABLED
)
140 self
.backBtn
.configure(state
=NORMAL
)
142 if self
.index
< self
.to
:
143 self
.nextBtn
.configure(state
=NORMAL
)
145 self
.nextBtn
.configure(state
=DISABLED
)
147 self
.caption
.set('%d / %d' % (self
.index
, self
.to
))
151 self
.index
= self
.index
- 1
153 self
.decCallback(self
)
156 self
.index
= self
.index
+ 1
158 self
.incCallback(self
)
160 def setSize(self
, size
) :
167 class Identification(Frame
) :
168 def __init__(self
, master
=None) :
169 Frame
.__init
__(self
, master
)
170 self
.fileName
= StringVar()
173 def setFileName(self
, name
) :
174 self
.fileName
.set(name
)
176 def createWidgets(self
) :
177 fileLbl
= Label(self
, text
='Fichier :')
178 fileLbl
.grid(row
=0, column
=0, sticky
=E
)
180 fileNameLbl
= Label(self
, textvariable
=self
.fileName
)
181 fileNameLbl
.grid(row
=0, column
=1, sticky
=W
)
183 nameLbl
= Label(self
, text
='Patient :')
184 nameLbl
.grid(row
=1, column
=0, sticky
=E
)
186 self
.nameEntry
= Entry(self
, width
=40)
187 self
.nameEntry
.grid(row
=1, column
=1, sticky
=W
)
189 commentsLbl
= Label(self
, text
='Commentaires :')
190 commentsLbl
.grid(row
=2, column
=0, sticky
=E
)
192 self
.commentsText
= Text(self
, width
=40, height
=4, undo
=True, wrap
=WORD
)
193 self
.commentsText
.grid(row
=2, column
=1, sticky
=W
)
195 class ResultsFrame(Frame
) :
196 def __init__(self
, master
, logFilePath
) :
197 Frame
.__init
__(self
, master
)
198 self
.logFilePath
= logFilePath
200 def layResults(self
) :
201 lfa
= LogFileAnalyser(self
.logFilePath
)
202 results
= lfa
.analyse()
204 for i
, kv
in enumerate(results
) :
206 kl
= Label(self
, text
='%s :' % k
)
207 kl
.grid(row
=i
, column
=0, sticky
=E
)
209 vl
= Label(self
, text
=v
)
210 vl
.grid(row
=i
, column
=1, sticky
=W
)
212 msg
= Label(self
, text
="Pas de données exploitables.")
218 app
.master
.title("Analyseur des sessions MINWii")