1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
| # -*- coding: ISO-8859-1 -*-
import Tkinter
from Action import Action
from Section import Section
from Process import Process
from xml.dom.minidom import Document,parse
from os.path import isfile
class SapristiGUI:
def __init__(self,process):
self.etat = 0
self.root = Tkinter.Tk()
self.root.rowconfigure(1, weight=1)
self.root.columnconfigure(0, weight=1)
# Set process
self.process = process
# Set title of main window
self.root.title(self.process.name)
# MILIEU --------------------------------
self.center()
# BAS -----------------------------------
self.bottom()
# MENU ----------------------------------
self.menu()
# Launch GUI
self.root.protocol("WM_DELETE_WINDOW", self.catchClose)
self.root.mainloop()
def menu(self):
# Place Frame for menu at North
self.f_top = Tkinter.Frame(self.root,width=200,height=500)
# Frame f_top at first line, first column and sticks to West side
self.f_top.grid(row=0, column=0, sticky=Tkinter.W)
# Add menu File
self.menuFile = Tkinter.Menubutton(self.f_top, text="File")
# Add commands in File
m_file = Tkinter.Menu(self.menuFile)
self.menuFile.configure(menu=m_file)
m_file.add_command(label='Open',command=self.catchOpen)
m_file.add_command(label='Quit',command=self.catchClose)
# Place menu File as first element in frame f_top
self.menuFile.grid(row=0, column=0, sticky=Tkinter.W)
# Add menu Edit
self.menuEdit = Tkinter.Menubutton(self.f_top, text="Edit")
# Place menu Edit as second element in frame f_top
self.menuEdit.grid(row=0, column=1, sticky=Tkinter.W)
# Add menu About
self.menuAbout = Tkinter.Menubutton(self.f_top, text="About")
# Place menu About as third element in frame f_top
self.menuAbout.grid(row=0, column=2, sticky=Tkinter.W)
def center(self):
self.f_middle = Tkinter.Frame(self.root)
self.f_middle.grid(row=1, column=0)
#------------------
# Middle West
#------------------
self.f_left = Tkinter.Frame(self.f_middle)
self.f_left.grid(row=0, column=0)
self.checkb = []
self.b_sect = []
for sect in self.process.sections:
self.b_sect.append(Tkinter.Button(self.f_left, text=sect.name, command=self.select_section,width=15).pack())
for act in sect.actions:
c_act = Tkinter.Checkbutton(self.f_left, text=act.name)
c_act.var = Tkinter.IntVar()
c_act.configure(variable=c_act.var)
c_act.pack(side=Tkinter.TOP, anchor='nw')
self.checkb.append(c_act)
#------------------
# Middle
#-------------------
# Current action thread frame
self.f_running = Tkinter.LabelFrame(self.f_middle,text="Running",width=100,height=100)
self.f_running.grid(row=0,column=1,sticky=Tkinter.W)
# Name of the current action thread
self.runningLab = Tkinter.StringVar()
Tkinter.Label(self.f_running, textvariable=self.runningLab).pack()
self.setRunningLab("<action name>")
# List of arguments of the current action thread
self.argList = Tkinter.Text(self.f_running,width=50,height=15)
self.argList.insert(Tkinter.END, 'None\n')
self.argList.pack()
# Log frame
self.f_log = Tkinter.LabelFrame(self.f_middle,text="Log",width=100,height=100)
self.f_log.grid(row=1,column=1,sticky=Tkinter.W)
# Log text box
self.logText = Tkinter.Text(self.f_log,width=50,height=15)
self.logText.pack()
#------------------
# Middle East
#------------------
self.f_right = Tkinter.Frame(self.f_middle)
self.f_right.grid(row=0, column=2,sticky=Tkinter.E)
def bottom(self):
self.f_bottom = Tkinter.Frame(self.root)
self.f_bottom.grid(row=2, column=0)
lbuttons = [("Run",self.run),\
("Select all",self.select_all),\
("Disable all",self.disable_all),\
("Clear log",self.clearLog)]
for b in lbuttons:
Tkinter.Button(self.f_bottom, text=b[0], command=b[1],width=10).pack(side=Tkinter.LEFT)
b = ("Panic!",self.panic)
bpanic = Tkinter.Button(self.f_bottom, text=b[0], command=b[1],width=10,bg="red",border=6)
bpanic.pack(side=Tkinter.RIGHT)
bpanic.configure()
def select_all(self):
#[_.select() for _ in self.checkb]
map(lambda w: w.select(), self.checkb)
self.setRunningLab("Select all!")
return
def select_section(self):
# map(lambda w: w.select(), self.checksect[sectName])
if self.etat == 0:
self.etat = 1
print 'section sélectionnée'
else:
self.etat = 0
print 'section désélectionnée'
def disable_all(self):
#[_.deselect() for _ in self.checkb]
self.setRunningLab("Disable all!")
map(lambda w: w.deselect(), self.checkb)
return
def run(self):
# @TODO: branch to action path creating a thread for each action
# @TODO: Update labels while running
# @TODO: Update log while running
# @TODO: Update log file with success and fails and warn user
self.logText.insert(Tkinter.END,self.process.name+'\n')
for c in self.checkb:
if (c.var.get() == 1):
self.setRunningLab(c.cget('text'))
i=0
while(i<1e+6):
i = i + 1
self.setRunningLab('-')
pid = 0
return pid
def setRunningLab(self,text):
self.runningLab.set(str(text))
def clearLog(self):
self.logText.delete(1.0, Tkinter.END)
def panic(self):
pass
def catchOpen(self):
from tkFileDialog import askopenfilename
from ProcessParser import ProcessParser
processFile = askopenfilename()
# @TODO: Validate XML process file
dom = parse(processFile)
self.process = ProcessParser().extractProcess(dom)
# @TODO: Update display
self.refresh()
def catchClose(self):
self.root.destroy()
def refresh(self):
# Set title of main window
self.root.title(self.process.name)
if __name__ == '__main__':
# Construction à la main du processus
args = ['SRC','1','mika']
act = Action('test',0,'test.ksh',args)
act.setHelp('This action allows to test new Action func')
args = ['0']
act2 = Action('act',1,'act.ksh',args)
act2.setHelp('toto')
act3 = Action('test',1,'test.py',args)
sect = Section('Export Source', 1)
sect.actions.append(act)
sect.actions.append(act2)
sect.actions.append(act3)
sect.setHelp('section test')
sect2 = Section('Validate',0)
sect2.actions.append(act2)
proc = Process('ProcessTest',0)
proc.sections.append(sect)
proc.sections.append(sect2)
proc.setHelp('process test')
sap = SapristiGUI(proc) |