a632d601209b57e0b1d7262239543615ffc44187
1 # -*- coding: utf-8 -*-
3 Interface graphique pour l'analyse des fichiers de log minwii.
12 from os
.path
import join
as pjoin
13 from os
.path
import basename
14 from loganalyse
import LogFileAnalyser
15 from pprint
import pprint
17 class Application(Frame
) :
18 def __init__(self
, master
=None) :
19 Frame
.__init
__(self
, master
)
20 self
.configureStretching()
24 self
.resultsFrame
= None
26 def configureStretching(self
) :
27 top
=self
.winfo_toplevel()
28 top
.rowconfigure(0, weight
=1)
29 top
.columnconfigure(0, weight
=1)
31 self
.grid(sticky
=N
+S
+E
+W
, padx
=10, pady
=10)
32 self
.rowconfigure(0, weight
=1)
33 self
.columnconfigure(0, weight
=1)
35 def createWidgets(self
) :
36 # zone d'affichage des données'
37 self
.dataFrame
= df
= Frame(self
)
40 self
.identFrame
= Identification(df
)
41 self
.identFrame
.grid(sticky
=NW
)
42 self
.nav
= Navbar(df
, incCallback
=self
.loadLogFile
, decCallback
=self
.loadLogFile
)
47 self
.btnFrame
= bf
= Frame(self
)
48 bf
.grid(row
=1, column
=0, sticky
=W
+S
+E
)
49 bf
.rowconfigure(0, weight
=1)
50 bf
.columnconfigure(0, weight
=1)
51 bf
.columnconfigure(1, weight
=1)
54 self
.chooseLogDir
= Button(bf
, text
="Parcourir…", command
=self
.openFileDialog
)
55 self
.chooseLogDir
.grid(row
=0, column
=0, sticky
=W
)
57 self
.nav
= Navbar(bf
, incCallback
=self
.loadLogFile
, decCallback
=self
.loadLogFile
)
58 #self.nav.grid(row=0, column=1)
60 self
.quitButton
= Button(bf
, text
='Terminer', command
=self
.quit
)
61 self
.quitButton
.grid(row
=0, column
=2, sticky
=E
)
63 def openFileDialog(self
) :
64 self
.logDir
= tkFileDialog
.askdirectory()
66 self
.logFiles
= glob(pjoin(self
.logDir
, '*.log'))
68 self
.dataFrame
.grid(row
=0, column
=0, sticky
=NW
)
69 self
.nav
.setSize(len(self
.logFiles
))
70 self
.nav
.grid(row
=0, column
=1)
71 self
.loadLogFile(self
.nav
)
73 def loadLogFile(self
, nav
) :
75 filepath
= self
.logFiles
[index
]
76 filename
= basename(filepath
)
77 self
.identFrame
.setFileName(filename
)
78 if self
.resultsFrame
:
79 self
.resultsFrame
.destroy()
80 self
.resultsFrame
= ResultsFrame(self
.dataFrame
, filepath
)
81 self
.resultsFrame
.layResults()
82 self
.resultsFrame
.grid()
86 def __init__(self
, master
=None, size
=1, incCallback
=None, decCallback
=None) :
87 Frame
.__init
__(self
, master
)
88 self
.caption
= StringVar()
91 self
.incCallback
= incCallback
if incCallback
else lambda x
: None
92 self
.decCallback
= decCallback
if decCallback
else lambda x
: None
93 self
.caption
.set('%d / %d' % (self
.index
, self
.to
))
95 def createWidgets(self
) :
96 self
.backBtn
= Button(self
,
100 self
.backBtn
.grid(row
=0, column
=0)
102 self
.lbl
= Label(self
, textvariable
=self
.caption
)
103 self
.lbl
.grid(row
=0, column
=1)
105 self
.nextBtn
= Button(self
,
108 self
.nextBtn
.grid(row
=0, column
=2)
110 def refreshStates(self
) :
111 if self
.index
== self
.from_
:
112 self
.backBtn
.configure(state
=DISABLED
)
114 self
.backBtn
.configure(state
=NORMAL
)
116 if self
.index
< self
.to
:
117 self
.nextBtn
.configure(state
=NORMAL
)
119 self
.nextBtn
.configure(state
=DISABLED
)
121 self
.caption
.set('%d / %d' % (self
.index
, self
.to
))
125 self
.index
= self
.index
- 1
127 self
.decCallback(self
)
130 self
.index
= self
.index
+ 1
132 self
.incCallback(self
)
134 def setSize(self
, size
) :
141 class Identification(Frame
) :
142 def __init__(self
, master
=None) :
143 Frame
.__init
__(self
, master
)
144 self
.fileName
= StringVar()
147 def setFileName(self
, name
) :
148 self
.fileName
.set(name
)
150 def createWidgets(self
) :
151 fileLbl
= Label(self
, text
='Fichier :')
152 fileLbl
.grid(row
=0, column
=0, sticky
=E
)
154 fileNameLbl
= Label(self
, textvariable
=self
.fileName
)
155 fileNameLbl
.grid(row
=0, column
=1, sticky
=W
)
157 nameLbl
= Label(self
, text
='Patient :')
158 nameLbl
.grid(row
=1, column
=0, sticky
=E
)
160 self
.nameEntry
= Entry(self
, width
=40)
161 self
.nameEntry
.grid(row
=1, column
=1, sticky
=W
)
163 commentsLbl
= Label(self
, text
='Commentaires :')
164 commentsLbl
.grid(row
=2, column
=0, sticky
=E
)
166 self
.commentsText
= Text(self
, width
=40, height
=4, undo
=True, wrap
=WORD
)
167 self
.commentsText
.grid(row
=2, column
=1, sticky
=W
)
169 class ResultsFrame(Frame
) :
170 def __init__(self
, master
, logFilePath
) :
171 Frame
.__init
__(self
, master
)
172 self
.logFilePath
= logFilePath
174 def layResults(self
) :
175 lfa
= LogFileAnalyser(self
.logFilePath
)
176 results
= lfa
.analyse()
178 for i
, kv
in enumerate(results
.items()) :
180 kl
= Label(self
, text
='%s :' % k
)
181 kl
.grid(row
=i
, column
=0, sticky
=E
)
183 vl
= Label(self
, text
=v
)
184 vl
.grid(row
=i
, column
=1, sticky
=W
)
186 msg
= Label(self
, text
="Pas de données exploitables.")
192 app
.master
.title("Analyseur des sessions MINWii")