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