950a4780357672763a6bfd5da81b5f5f783c103a
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 pprint
import pprint
20 class Application(Frame
) :
21 def __init__(self
, master
=None) :
22 Frame
.__init
__(self
, master
)
23 self
.configureStretching()
27 self
.resultsFrame
= None
30 #self.chooseDirDialog(dir='/Users/pinbe/minwii_logs')
32 def configureStretching(self
) :
33 top
=self
.winfo_toplevel()
34 top
.rowconfigure(0, weight
=1)
35 top
.columnconfigure(0, weight
=1)
37 self
.grid(sticky
=N
+S
+E
+W
, padx
=10, pady
=10)
38 self
.rowconfigure(0, weight
=1)
39 self
.columnconfigure(0, weight
=1)
41 def createWidgets(self
) :
42 # zone d'affichage des données'
43 self
.dataFrame
= df
= Frame(self
)
45 self
.identFrame
= Identification(df
)
46 self
.identFrame
.grid(sticky
=NW
)
49 self
.btnFrame
= bf
= Frame(self
)
50 bf
.grid(row
=1, column
=0, sticky
=W
+S
+E
)
51 bf
.rowconfigure(0, weight
=1)
53 bf
.columnconfigure(i
, weight
=1)
55 self
.chooseLogDir
= Button(bf
, text
="Parcourir…", command
=self
.chooseDirDialog
)
56 self
.chooseLogDir
.grid(row
=0, column
=0, sticky
=W
)
58 self
.nav
= Navbar(bf
, incCallback
=self
.loadLogFile
, decCallback
=self
.loadLogFile
)
60 self
.quitButton
= Button(bf
, text
='Terminer', command
=self
.quit
)
61 self
.quitButton
.grid(row
=0, column
=2, sticky
=E
)
63 def chooseDirDialog(self
, dir=None) :
65 self
.logDir
= tkFileDialog
.askdirectory(title
='Sélectionnez un dossier de fichiers de logs')
69 self
.logFiles
= glob(pjoin(self
.logDir
, '*.log'))
70 self
._cleanupJunkFiles
()
72 self
.logFiles
.reverse()
73 self
.dataFrame
.grid(row
=0, column
=0, sticky
=NW
)
74 self
.nav
.setSize(len(self
.logFiles
))
75 self
.nav
.grid(row
=0, column
=1)
76 self
.loadLogFile(self
.nav
)
78 def _cleanupJunkFiles(self
) :
81 f
= self
.logFiles
.pop()
87 lfa
= LogFileAnalyser(of
)
88 if lfa
.getLastEventTicks() is None :
100 def loadLogFile(self
, nav
) :
101 index
= nav
.index
- 1
102 filepath
= self
.logFiles
[index
]
103 filename
= basename(filepath
)
104 self
.identFrame
.setFileName(filename
)
105 if self
.resultsFrame
:
106 self
.resultsFrame
.destroy()
107 self
.resultsFrame
= ResultsFrame(self
.dataFrame
, filepath
)
108 self
.resultsFrame
.layResults()
109 self
.resultsFrame
.grid()
112 class Navbar(Frame
) :
113 def __init__(self
, master
=None, size
=1, incCallback
=None, decCallback
=None) :
114 Frame
.__init
__(self
, master
)
115 self
.caption
= StringVar()
118 self
.incCallback
= incCallback
if incCallback
else lambda x
: None
119 self
.decCallback
= decCallback
if decCallback
else lambda x
: None
120 self
.caption
.set('%d / %d' % (self
.index
, self
.to
))
122 def createWidgets(self
) :
123 self
.backBtn
= Button(self
,
127 self
.backBtn
.grid(row
=0, column
=0)
129 self
.lbl
= Label(self
, textvariable
=self
.caption
)
130 self
.lbl
.grid(row
=0, column
=1)
132 self
.nextBtn
= Button(self
,
135 self
.nextBtn
.grid(row
=0, column
=2)
137 def refreshStates(self
) :
138 if self
.index
== self
.from_
:
139 self
.backBtn
.configure(state
=DISABLED
)
141 self
.backBtn
.configure(state
=NORMAL
)
143 if self
.index
< self
.to
:
144 self
.nextBtn
.configure(state
=NORMAL
)
146 self
.nextBtn
.configure(state
=DISABLED
)
148 self
.caption
.set('%d / %d' % (self
.index
, self
.to
))
152 self
.index
= self
.index
- 1
154 self
.decCallback(self
)
157 self
.index
= self
.index
+ 1
159 self
.incCallback(self
)
161 def setSize(self
, size
) :
168 class Identification(Frame
) :
169 def __init__(self
, master
=None) :
170 Frame
.__init
__(self
, master
)
171 self
.fileName
= StringVar()
174 def setFileName(self
, name
) :
175 self
.fileName
.set(name
)
177 def createWidgets(self
) :
178 fileLbl
= Label(self
, text
='Fichier :')
179 fileLbl
.grid(row
=0, column
=0, sticky
=E
)
181 fileNameLbl
= Label(self
, textvariable
=self
.fileName
)
182 fileNameLbl
.grid(row
=0, column
=1, sticky
=W
)
184 nameLbl
= Label(self
, text
='Patient :')
185 nameLbl
.grid(row
=1, column
=0, sticky
=E
)
187 self
.nameEntry
= Entry(self
, width
=40)
188 self
.nameEntry
.grid(row
=1, column
=1, sticky
=W
)
190 commentsLbl
= Label(self
, text
='Commentaires :')
191 commentsLbl
.grid(row
=2, column
=0, sticky
=E
)
193 self
.commentsText
= Text(self
, width
=40, height
=4, undo
=True, wrap
=WORD
)
194 self
.commentsText
.grid(row
=2, column
=1, sticky
=W
)
196 class ResultsFrame(Frame
) :
197 def __init__(self
, master
, logFilePath
) :
198 Frame
.__init
__(self
, master
)
199 self
.logFilePath
= logFilePath
201 def layResults(self
) :
202 lfa
= LogFileAnalyser(self
.logFilePath
)
203 results
= lfa
.analyse()
205 for i
, kv
in enumerate(results
) :
207 kl
= Label(self
, text
='%s :' % k
)
208 kl
.grid(row
=i
, column
=0, sticky
=E
)
210 vl
= Label(self
, text
=v
)
211 vl
.grid(row
=i
, column
=1, sticky
=W
)
213 msg
= Label(self
, text
="Pas de données exploitables.")
219 app
.master
.title("Analyseur des sessions MINWii")