0981be2df3a6510149623194680dddccc8fb8d3f
[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
63
64 class Navbar(Frame) :
65 def __init__(self, master=None, from_=1, to=10, start=1, step=1) :
66 Frame.__init__(self, master)
67 self.from_ = from_
68 self.to = to
69 self.index = start
70 self.step = step
71 self.grid()
72 self.caption = StringVar()
73 self.caption.set('%d / %d' % (self.index, self.to))
74 self.createWidgets()
75
76 def createWidgets(self) :
77 self.backBtn = Button(self,
78 text='◀',
79 state = DISABLED if self.index==self.from_ else NORMAL,
80 command = self.dec
81 )
82 self.backBtn.grid(row=0, column=0)
83
84 self.lbl = Label(self, textvariable=self.caption)
85 self.lbl.grid(row=0, column=1)
86
87 self.nextBtn = Button(self,
88 text='▶',
89 state = DISABLED if self.index==self.to else NORMAL,
90 command = self.inc)
91 self.nextBtn.grid(row=0, column=2)
92
93 def dec(self) :
94 self.index = self.index - self.step
95 self.caption.set('%d / %d' % (self.index, self.to))
96 if self.index == self.from_ :
97 self.backBtn.configure(state=DISABLED)
98 if self.index < self.to :
99 self.nextBtn.configure(state=NORMAL)
100
101 def inc(self) :
102 self.index = self.index + self.step
103 self.caption.set('%d / %d' % (self.index, self.to))
104 if self.index == self.to :
105 self.nextBtn.configure(state=DISABLED)
106 if self.index > self.from_ :
107 self.backBtn.configure(state=NORMAL)
108
109
110 class Identification(Frame) :
111 def __init__(self, master=None) :
112 Frame.__init__(self, master)
113 self.createWidgets()
114
115 def createWidgets(self) :
116 nameLbl = Label(self, text='Patient :')
117 nameLbl.grid(row=0, column=0)
118
119 self.nameEntry = Entry(self, width=40)
120 self.nameEntry.grid(row=0, column=1)
121
122 commentsLbl = Label(self, text='Commentaires :')
123 commentsLbl.grid(row=1, column=0)
124
125 self.commentsText = Text(self, width=40, height=4, undo=True, wrap=WORD)
126 self.commentsText.grid(row=1, column=1)
127
128
129 app = Application()
130 app.master.title("Analyseur des sessions MINWii")
131 app.mainloop()