b48140c0c06408d17dab3c408ca28f773c1a5bcb
[minwii.git] / src / minwii / logapp.py
1 # -*- coding: utf-8 -*-
2 """
3 Interface graphique pour l'analyse des fichiers de log minwii.
4
5 $Id$
6 $URL$
7 """
8
9 from Tkinter import *
10 import tkFileDialog
11 from glob import glob
12 from os.path import join as pjoin
13 from os.path import basename
14
15 class Application(Frame) :
16 def __init__(self, master=None) :
17 Frame.__init__(self, master)
18 self.configureStretching()
19 self.createWidgets()
20 self.logDir = ''
21 self.logFiles = []
22
23 def configureStretching(self) :
24 top=self.winfo_toplevel()
25 top.rowconfigure(0, weight=1)
26 top.columnconfigure(0, weight=1)
27
28 self.grid(sticky=N+S+E+W, padx=10, pady=10)
29 self.rowconfigure(0, weight=1)
30 self.columnconfigure(0, weight=1)
31
32 def createWidgets(self) :
33 # zone d'affichage des données'
34 self.dataFrame = df = Frame(self)
35 #df.grid(sticky=NW)
36
37 self.identFrame = Identification(df)
38 self.identFrame.grid(sticky=NW)
39 self.nav = Navbar(df, incCallback=self.loadLogFile, decCallback=self.loadLogFile)
40 self.nav.grid()
41
42
43 # barre de boutons
44 self.btnFrame = bf = Frame(self)
45 bf.grid(row=1, column=0, sticky=W+S+E)
46 bf.rowconfigure(0, weight=1)
47 bf.columnconfigure(0, weight=1)
48 bf.columnconfigure(1, weight=1)
49
50
51 self.chooseLogDir = Button(bf, text="Parcourir…", command=self.openFileDialog)
52 self.chooseLogDir.grid(row=0, column=0, sticky=W)
53
54 self.quitButton = Button(bf, text='Terminer', command=self.quit)
55 self.quitButton.grid(row=0, column=1, sticky=E)
56
57 def openFileDialog(self) :
58 self.logDir = tkFileDialog.askdirectory()
59 if self.logDir :
60 self.logFiles = glob(pjoin(self.logDir, '*.log'))
61 self.logFiles.sort()
62 self.dataFrame.grid(row=0, column=0, sticky=NW)
63 self.nav.setSize(len(self.logFiles))
64 self.loadLogFile(self.nav)
65
66 def loadLogFile(self, nav) :
67 index = nav.index - 1
68 filepath = self.logFiles[index]
69 filename = basename(filepath)
70 self.identFrame.setFileName(filename)
71
72
73 class Navbar(Frame) :
74 def __init__(self, master=None, size=1, incCallback=None, decCallback=None) :
75 Frame.__init__(self, master)
76 self.caption = StringVar()
77 self.createWidgets()
78 self.setSize(size)
79 self.incCallback = incCallback if incCallback else lambda x : None
80 self.decCallback = decCallback if decCallback else lambda x : None
81 self.grid()
82 self.caption.set('%d / %d' % (self.index, self.to))
83
84 def createWidgets(self) :
85 self.backBtn = Button(self,
86 text='◀',
87 command = self.dec
88 )
89 self.backBtn.grid(row=0, column=0)
90
91 self.lbl = Label(self, textvariable=self.caption)
92 self.lbl.grid(row=0, column=1)
93
94 self.nextBtn = Button(self,
95 text='▶',
96 command = self.inc)
97 self.nextBtn.grid(row=0, column=2)
98
99 def refreshStates(self) :
100 if self.index == self.from_ :
101 self.backBtn.configure(state=DISABLED)
102 else :
103 self.backBtn.configure(state=NORMAL)
104
105 if self.index < self.to :
106 self.nextBtn.configure(state=NORMAL)
107 else :
108 self.nextBtn.configure(state=DISABLED)
109
110 self.caption.set('%d / %d' % (self.index, self.to))
111
112
113 def dec(self) :
114 self.index = self.index - 1
115 self.refreshStates()
116 self.decCallback(self)
117
118 def inc(self) :
119 self.index = self.index + 1
120 self.refreshStates()
121 self.incCallback(self)
122
123 def setSize(self, size) :
124 self.from_ = 1
125 self.to = size
126 self.index = 1
127 self.refreshStates()
128
129
130 class Identification(Frame) :
131 def __init__(self, master=None) :
132 Frame.__init__(self, master)
133 self.fileName = StringVar()
134 self.createWidgets()
135
136 def setFileName(self, name) :
137 self.fileName.set(name)
138
139 def createWidgets(self) :
140 fileLbl = Label(self, text='Fichier :')
141 fileLbl.grid(row=0, column=0, sticky=E)
142
143 fileNameLbl = Label(self, textvariable=self.fileName)
144 fileNameLbl.grid(row=0, column=1, sticky=W)
145
146 nameLbl = Label(self, text='Patient :')
147 nameLbl.grid(row=1, column=0, sticky=E)
148
149 self.nameEntry = Entry(self, width=40)
150 self.nameEntry.grid(row=1, column=1, sticky=W)
151
152 commentsLbl = Label(self, text='Commentaires :')
153 commentsLbl.grid(row=2, column=0, sticky=E)
154
155 self.commentsText = Text(self, width=40, height=4, undo=True, wrap=WORD)
156 self.commentsText.grid(row=2, column=1, sticky=W)
157
158
159 app = Application()
160 app.master.title("Analyseur des sessions MINWii")
161 app.mainloop()