555c9fd2ad674b7193b3f51bfa79323308f6a524
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
17 from minwii
.loganalyse
import LogFileAnalyser
18 from minwii
.config
import LOGS_DIR
19 from pprint
import pprint
21 class Application(Frame
) :
22 def __init__(self
, master
=None) :
23 Frame
.__init
__(self
, master
)
24 self
.configureStretching()
28 self
.resultsFrame
= None
30 if os
.path
.exists(LOGS_DIR
) :
31 self
.chooseDirDialog(dir=LOGS_DIR
)
33 def configureStretching(self
) :
34 top
=self
.winfo_toplevel()
35 top
.rowconfigure(0, weight
=1)
36 top
.columnconfigure(0, weight
=1)
38 self
.grid(sticky
=N
+S
+E
+W
, padx
=10, pady
=10)
39 self
.rowconfigure(0, weight
=1)
40 self
.columnconfigure(0, weight
=1)
42 def createWidgets(self
) :
43 # zone d'affichage des données'
44 self
.dataFrame
= df
= Frame(self
)
46 self
.identFrame
= Identification(df
)
47 self
.identFrame
.grid(sticky
=NW
)
50 self
.btnFrame
= bf
= Frame(self
)
51 bf
.grid(row
=1, column
=0, sticky
=W
+S
+E
)
52 bf
.rowconfigure(0, weight
=1)
54 bf
.columnconfigure(i
, weight
=1)
56 self
.chooseLogDir
= Button(bf
, text
="Parcourir…", command
=self
.chooseDirDialog
)
57 self
.chooseLogDir
.grid(row
=0, column
=0, sticky
=W
)
59 self
.nav
= Navbar(bf
, incCallback
=self
.loadLogFile
, decCallback
=self
.loadLogFile
)
61 self
.quitButton
= Button(bf
, text
='Terminer', command
=self
.quit
)
62 self
.quitButton
.grid(row
=0, column
=2, sticky
=E
)
64 def chooseDirDialog(self
, dir=None) :
66 self
.logDir
= tkFileDialog
.askdirectory(title
='Sélectionnez un dossier de fichiers de logs')
70 self
.logFiles
= glob(pjoin(self
.logDir
, '*.log'))
71 self
._cleanupJunkFiles
()
73 self
.logFiles
.reverse()
74 self
.dataFrame
.grid(row
=0, column
=0, sticky
=NW
)
75 self
.nav
.setSize(len(self
.logFiles
))
76 self
.nav
.grid(row
=0, column
=1)
77 self
.loadLogFile(self
.nav
)
79 def _cleanupJunkFiles(self
) :
82 f
= self
.logFiles
.pop()
88 lfa
= LogFileAnalyser(of
)
89 if lfa
.getLastEventTicks() is None :
101 def loadLogFile(self
, nav
) :
102 index
= nav
.index
- 1
103 filepath
= self
.logFiles
[index
]
104 filename
= basename(filepath
)
105 self
.identFrame
.setFileName(filename
)
106 if self
.resultsFrame
:
107 self
.resultsFrame
.destroy()
108 self
.resultsFrame
= ResultsFrame(self
.dataFrame
, filepath
)
109 self
.resultsFrame
.layResults()
110 self
.resultsFrame
.grid()
113 class Navbar(Frame
) :
114 def __init__(self
, master
=None, size
=1, incCallback
=None, decCallback
=None) :
115 Frame
.__init
__(self
, master
)
116 self
.caption
= StringVar()
119 self
.incCallback
= incCallback
if incCallback
else lambda x
: None
120 self
.decCallback
= decCallback
if decCallback
else lambda x
: None
121 self
.caption
.set('%d / %d' % (self
.index
, self
.to
))
123 def createWidgets(self
) :
124 self
.backBtn
= Button(self
,
128 self
.backBtn
.grid(row
=0, column
=0)
130 self
.lbl
= Label(self
, textvariable
=self
.caption
)
131 self
.lbl
.grid(row
=0, column
=1)
133 self
.nextBtn
= Button(self
,
136 self
.nextBtn
.grid(row
=0, column
=2)
138 def refreshStates(self
) :
139 if self
.index
== self
.from_
:
140 self
.backBtn
.configure(state
=DISABLED
)
142 self
.backBtn
.configure(state
=NORMAL
)
144 if self
.index
< self
.to
:
145 self
.nextBtn
.configure(state
=NORMAL
)
147 self
.nextBtn
.configure(state
=DISABLED
)
149 self
.caption
.set('%d / %d' % (self
.index
, self
.to
))
153 self
.index
= self
.index
- 1
155 self
.decCallback(self
)
158 self
.index
= self
.index
+ 1
160 self
.incCallback(self
)
162 def setSize(self
, size
) :
169 class Identification(Frame
) :
170 def __init__(self
, master
=None) :
171 Frame
.__init
__(self
, master
)
172 self
.fileName
= StringVar()
175 def setFileName(self
, name
) :
176 self
.fileName
.set(name
)
178 def createWidgets(self
) :
179 fileLbl
= Label(self
, text
='Fichier :')
180 fileLbl
.grid(row
=0, column
=0, sticky
=E
)
182 fileNameLbl
= Label(self
, textvariable
=self
.fileName
)
183 fileNameLbl
.grid(row
=0, column
=1, sticky
=W
)
185 nameLbl
= Label(self
, text
='Patient :')
186 nameLbl
.grid(row
=1, column
=0, sticky
=E
)
188 self
.nameEntry
= Entry(self
, width
=40)
189 self
.nameEntry
.grid(row
=1, column
=1, sticky
=W
)
191 commentsLbl
= Label(self
, text
='Commentaires :')
192 commentsLbl
.grid(row
=2, column
=0, sticky
=E
)
194 self
.commentsText
= Text(self
, width
=40, height
=4, undo
=True, wrap
=WORD
)
195 self
.commentsText
.grid(row
=2, column
=1, sticky
=W
)
197 class ResultsFrame(Frame
) :
198 def __init__(self
, master
, logFilePath
) :
199 Frame
.__init
__(self
, master
)
200 self
.logFilePath
= logFilePath
202 def layResults(self
) :
203 lfa
= LogFileAnalyser(self
.logFilePath
)
204 results
= lfa
.analyse()
206 for i
, kv
in enumerate(results
) :
208 kl
= Label(self
, text
='%s :' % k
)
209 kl
.grid(row
=i
, column
=0, sticky
=E
)
211 vl
= Label(self
, text
=v
)
212 vl
.grid(row
=i
, column
=1, sticky
=W
)
214 msg
= Label(self
, text
="Pas de données exploitables.")
220 app
.master
.title("Analyseur des sessions MINWii")