from Tkinter import * from tkMessageBox import * class N3AppGui: """ This is the gui that permits to manipulate a parameter file. Queries can be executed, modified, added and deleted. """ bwidth = 15 def __init__(self): self.root = Tk() self.frame = Frame(self.root) self.lbox = Listbox(self.frame, width = 100, height = 10) self.lbox.pack_propagate(0) self.scrolly = Scrollbar(self.lbox, command = self.lbox.yview,\ orient = VERTICAL) self.lbox.configure(yscrollcommand = self.scrolly.set) self.scrollx = Scrollbar(self.lbox, command = self.lbox.xview,\ orient = HORIZONTAL) self.lbox.configure(xscrollcommand = self.scrollx.set) self.scrolly.pack(side=RIGHT, fill = Y) self.scrollx.pack(side=BOTTOM, fill=X) self.lbox.pack(fill = BOTH) self.entry = Entry(self.frame, width = 100) self.entry.pack() self.button1 = Button(self.frame,text="Execute", command = self.execute,\ width = self.bwidth) self.button1.pack() self.button2 = Button(self.frame,text="Modify", command = self.modify,\ width = self.bwidth) self.button2.pack() self.button3 = Button(self.frame,text="Add", command = self.add,\ width = self.bwidth) self.button3.pack() self.button4 = Button(self.frame,text="Delete", command = self.delete,\ width = self.bwidth) self.button4.pack() self.button5 = Button(self.frame,text="Save", command = self.save,\ width = self.bwidth) self.button5.pack() self.button6 = Button(self.frame,text="Exit", command = "exit",\ width = self.bwidth) self.button6.pack() self.frame.pack() def modify(self): selected = self.lbox.curselection() nr = selected[0] string = self.lbox.get(nr) self.entry.delete(0,END) self.entry.insert(0,string) def execute(self): s = self.entry.get() if s == "": sel = self.lbox.curselection() if s == (): showinfo(message="There is no query to execute") else: s = self.lbox.get(sel[0]) self.paramObj.executeQ(s) def fillBox(self, list): self.list = list for l in list: self.lbox.insert(END, l) def delete(self): sel = self.lbox.curselection() print "sell ", sel if sel == (): showinfo(message = "There is nothing selected to delete.") else: if askokcancel("RDFEngine","Do you really want to delete?"): self.lbox.delete(sel[0]) def save(self): """ save the content of the listbox """ list = self.lbox.get(0, END) s = self.paramObj.saveQ(list) showinfo(message = "The queries were saved to file " + s) def add(self): """ add the query in the Entry to the query file """ s = self.entry.get() self.lbox.insert(END, s) def setParam(self, paramObj): self.paramObj = paramObj if __name__ == "__main__": list = [] list.append("[RDFE:query {:number :requested ?how}].aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") list.append("[RDFE:query {?who :authenticated ?what}].") list.append("[RDFE:query {:number :requested ?how}].") list.append("[RDFE:query {?who :authenticated ?what}].") list.append("[RDFE:query {:number :requested ?how}].") list.append("[RDFE:query {?who :authenticated ?what}].") list.append("[RDFE:query {:number :requested ?how}].") list.append("[RDFE:query {?who :authenticated ?what}].") list.append("") gui = N3AppGui() gui.fillBox(list)