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
) :
80 f
= self
.logFiles
.pop()
85 lfa
= LogFileAnalyser(f
)
86 if lfa
.getLastEventTicks() is None :
95 def loadLogFile(self
, nav
) :
97 filepath
= self
.logFiles
[index
]
98 filename
= basename(filepath
)
99 self
.identFrame
.setFileName(filename
)
100 if self
.resultsFrame
:
101 self
.resultsFrame
.destroy()
102 self
.resultsFrame
= ResultsFrame(self
.dataFrame
, filepath
)
103 self
.resultsFrame
.layResults()
104 self
.resultsFrame
.grid()
107 class Navbar(Frame
) :
108 def __init__(self
, master
=None, size
=1, incCallback
=None, decCallback
=None) :
109 Frame
.__init
__(self
, master
)
110 self
.caption
= StringVar()
113 self
.incCallback
= incCallback
if incCallback
else lambda x
: None
114 self
.decCallback
= decCallback
if decCallback
else lambda x
: None
115 self
.caption
.set('%d / %d' % (self
.index
, self
.to
))
117 def createWidgets(self
) :
118 self
.backBtn
= Button(self
,
122 self
.backBtn
.grid(row
=0, column
=0)
124 self
.lbl
= Label(self
, textvariable
=self
.caption
)
125 self
.lbl
.grid(row
=0, column
=1)
127 self
.nextBtn
= Button(self
,
130 self
.nextBtn
.grid(row
=0, column
=2)
132 def refreshStates(self
) :
133 if self
.index
== self
.from_
:
134 self
.backBtn
.configure(state
=DISABLED
)
136 self
.backBtn
.configure(state
=NORMAL
)
138 if self
.index
< self
.to
:
139 self
.nextBtn
.configure(state
=NORMAL
)
141 self
.nextBtn
.configure(state
=DISABLED
)
143 self
.caption
.set('%d / %d' % (self
.index
, self
.to
))
147 self
.index
= self
.index
- 1
149 self
.decCallback(self
)
152 self
.index
= self
.index
+ 1
154 self
.incCallback(self
)
156 def setSize(self
, size
) :
163 class Identification(Frame
) :
164 def __init__(self
, master
=None) :
165 Frame
.__init
__(self
, master
)
166 self
.fileName
= StringVar()
169 def setFileName(self
, name
) :
170 self
.fileName
.set(name
)
172 def createWidgets(self
) :
173 fileLbl
= Label(self
, text
='Fichier :')
174 fileLbl
.grid(row
=0, column
=0, sticky
=E
)
176 fileNameLbl
= Label(self
, textvariable
=self
.fileName
)
177 fileNameLbl
.grid(row
=0, column
=1, sticky
=W
)
179 nameLbl
= Label(self
, text
='Patient :')
180 nameLbl
.grid(row
=1, column
=0, sticky
=E
)
182 self
.nameEntry
= Entry(self
, width
=40)
183 self
.nameEntry
.grid(row
=1, column
=1, sticky
=W
)
185 commentsLbl
= Label(self
, text
='Commentaires :')
186 commentsLbl
.grid(row
=2, column
=0, sticky
=E
)
188 self
.commentsText
= Text(self
, width
=40, height
=4, undo
=True, wrap
=WORD
)
189 self
.commentsText
.grid(row
=2, column
=1, sticky
=W
)
191 class ResultsFrame(Frame
) :
192 def __init__(self
, master
, logFilePath
) :
193 Frame
.__init
__(self
, master
)
194 self
.logFilePath
= logFilePath
196 def layResults(self
) :
197 lfa
= LogFileAnalyser(self
.logFilePath
)
198 results
= lfa
.analyse()
200 for i
, kv
in enumerate(results
) :
202 kl
= Label(self
, text
='%s :' % k
)
203 kl
.grid(row
=i
, column
=0, sticky
=E
)
205 vl
= Label(self
, text
=v
)
206 vl
.grid(row
=i
, column
=1, sticky
=W
)
208 msg
= Label(self
, text
="Pas de données exploitables.")
214 app
.master
.title("Analyseur des sessions MINWii")