4c680ba3a23a902f82c932eb476e181613505f5c
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()
25 def configureStretching(self
) :
26 top
=self
.winfo_toplevel()
27 top
.rowconfigure(0, weight
=1)
28 top
.columnconfigure(0, weight
=1)
30 self
.grid(sticky
=N
+S
+E
+W
, padx
=10, pady
=10)
31 self
.rowconfigure(0, weight
=1)
32 self
.columnconfigure(0, weight
=1)
34 def createWidgets(self
) :
35 # zone d'affichage des données'
36 self
.dataFrame
= df
= Frame(self
)
39 self
.identFrame
= Identification(df
)
40 self
.identFrame
.grid(sticky
=NW
)
41 self
.nav
= Navbar(df
, incCallback
=self
.loadLogFile
, decCallback
=self
.loadLogFile
)
46 self
.btnFrame
= bf
= Frame(self
)
47 bf
.grid(row
=1, column
=0, sticky
=W
+S
+E
)
48 bf
.rowconfigure(0, weight
=1)
49 bf
.columnconfigure(0, weight
=1)
50 bf
.columnconfigure(1, weight
=1)
53 self
.chooseLogDir
= Button(bf
, text
="Parcourir…", command
=self
.openFileDialog
)
54 self
.chooseLogDir
.grid(row
=0, column
=0, sticky
=W
)
56 self
.quitButton
= Button(bf
, text
='Terminer', command
=self
.quit
)
57 self
.quitButton
.grid(row
=0, column
=1, sticky
=E
)
59 def openFileDialog(self
) :
60 self
.logDir
= tkFileDialog
.askdirectory()
62 self
.logFiles
= glob(pjoin(self
.logDir
, '*.log'))
64 self
.dataFrame
.grid(row
=0, column
=0, sticky
=NW
)
65 self
.nav
.setSize(len(self
.logFiles
))
66 self
.loadLogFile(self
.nav
)
68 def loadLogFile(self
, nav
) :
70 filepath
= self
.logFiles
[index
]
71 filename
= basename(filepath
)
72 self
.identFrame
.setFileName(filename
)
73 rf
= ResultsFrame(self
.dataFrame
, filepath
)
79 def __init__(self
, master
=None, size
=1, incCallback
=None, decCallback
=None) :
80 Frame
.__init
__(self
, master
)
81 self
.caption
= StringVar()
84 self
.incCallback
= incCallback
if incCallback
else lambda x
: None
85 self
.decCallback
= decCallback
if decCallback
else lambda x
: None
87 self
.caption
.set('%d / %d' % (self
.index
, self
.to
))
89 def createWidgets(self
) :
90 self
.backBtn
= Button(self
,
94 self
.backBtn
.grid(row
=0, column
=0)
96 self
.lbl
= Label(self
, textvariable
=self
.caption
)
97 self
.lbl
.grid(row
=0, column
=1)
99 self
.nextBtn
= Button(self
,
102 self
.nextBtn
.grid(row
=0, column
=2)
104 def refreshStates(self
) :
105 if self
.index
== self
.from_
:
106 self
.backBtn
.configure(state
=DISABLED
)
108 self
.backBtn
.configure(state
=NORMAL
)
110 if self
.index
< self
.to
:
111 self
.nextBtn
.configure(state
=NORMAL
)
113 self
.nextBtn
.configure(state
=DISABLED
)
115 self
.caption
.set('%d / %d' % (self
.index
, self
.to
))
119 self
.index
= self
.index
- 1
121 self
.decCallback(self
)
124 self
.index
= self
.index
+ 1
126 self
.incCallback(self
)
128 def setSize(self
, size
) :
135 class Identification(Frame
) :
136 def __init__(self
, master
=None) :
137 Frame
.__init
__(self
, master
)
138 self
.fileName
= StringVar()
141 def setFileName(self
, name
) :
142 self
.fileName
.set(name
)
144 def createWidgets(self
) :
145 fileLbl
= Label(self
, text
='Fichier :')
146 fileLbl
.grid(row
=0, column
=0, sticky
=E
)
148 fileNameLbl
= Label(self
, textvariable
=self
.fileName
)
149 fileNameLbl
.grid(row
=0, column
=1, sticky
=W
)
151 nameLbl
= Label(self
, text
='Patient :')
152 nameLbl
.grid(row
=1, column
=0, sticky
=E
)
154 self
.nameEntry
= Entry(self
, width
=40)
155 self
.nameEntry
.grid(row
=1, column
=1, sticky
=W
)
157 commentsLbl
= Label(self
, text
='Commentaires :')
158 commentsLbl
.grid(row
=2, column
=0, sticky
=E
)
160 self
.commentsText
= Text(self
, width
=40, height
=4, undo
=True, wrap
=WORD
)
161 self
.commentsText
.grid(row
=2, column
=1, sticky
=W
)
163 class ResultsFrame(Frame
) :
164 def __init__(self
, master
, logFilePath
) :
165 Frame
.__init
__(self
, master
)
166 self
.logFilePath
= logFilePath
168 def layResults(self
) :
169 lfa
= LogFileAnalyser(self
.logFilePath
)
170 results
= lfa
.analyse()
172 rawPrint
= Label(self
, text
=str(results
))
177 app
.master
.title("Analyseur des sessions MINWii")