I am close to finishing a program for my A - Level Computing Project. The last problem that need solving is the appending of Entry Field values into a KML code I have also written. Would anyone know how this is done.
This is the source code for the program.
from Tkinter import *
from tkMessageBox import askokcancel
class Quitter(Frame):
def __init__(self, parent=None):
Frame.__init__(self, parent)
self.pack()
widget = Button(self, text='Quit', command=self.quit)
widget.pack(expand=YES, fill=BOTH, side=LEFT)
def quit(self):
ans = askokcancel('Verify exit', "Really quit?")
if ans: Frame.quit(self)
fields = 'Name','SAR Reprot No.', 'Rotor Start', 'Rotor Stop', 'Nature', 'Alerted By', 'Captian', 'Co Pilot', 'Helicopter','Latitude','Longitude'
def makeform(root, fields):
entries = []
for field in fields:
row = Frame(root)
lab = Label(row, width=15, text=field)
ent = Entry(row)
row.pack(side=TOP, fill=X)
lab.pack(side=LEFT)
ent.pack(side=RIGHT, expand=YES, fill=X)
entries.append(ent)
return entries
def callback(e):
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append('<?xml version="1.0" encoding="UTF-8"?><kml xmlns=" xmlns:gx=" xmlns:kml=" xmlns:atom=" name="MissionDetails" id="MissionDetailsId"><SimpleField type="string" name="ReportNumberValue"><displayName><b>ReportNumber</b></displayName></SimpleField><SimpleField type="int" name="Date"><displayName><b>Date</b></displayName></SimpleField><SimpleField type="double" name="RotorStart"><displayName><b>RotorStart</b></displayName></SimpleField><SimpleField type="double" name="RotorStop"><displayName><b>RotorStop</b></displayName></SimpleField><SimpleField type="string" name="Nature"><displayName><b>Nature</b></displayName></SimpleField><SimpleField type="string" name="AlertedBy"><displayName><b>AlertedBy</b></displayName></SimpleField><SimpleField type="string" name="Captain"><displayName><b>Captain</b></displayName></SimpleField><SimpleField type="string" name="CoPilot"><displayName><b>CoPilot</b></displayName></SimpleField><SimpleField type="string" name="Helicopter"><displayName><b>Helicopter</b></displayName></SimpleField></Schema><Placemark><name>{makeform(root, fields):entries = [Name].clipboard_append}</name><ExtendedData><SchemaData schemaUrl="#MissionDetailsId"><SimpleData name="Nature">Diver overdue or missing</SimpleData><SimpleData name="AlertedBy">Portland CG</SimpleData><SimpleData name="Captain">Balls K.</SimpleData><SimpleData name="CoPilot">Stracey G.</SimpleData><SimpleData name="Helicopter">G-CGWB</SimpleData></SchemaData><Data name="sarReportNumber"><value>9210</value></Data><Data name="date"><value>26062010</value></Data><Data name="rotorStart"><value>13.19</value></Data><Data name="rotorStop"><value>13.50</value></Data></ExtendedData><gx:balloonVisibility>1</gx:balloonVisibility><Point><coordinates>-1.957759,50.60696,0</coordinates></Point></Placemark></Document></kml>')
r.destroy()
if __name__ == '__main__':
root = Tk()
ents = makeform(root, fields)
root.bind('<Return>', (lambda event, e=ents: callback(e)))
Button(root, text='Print KML',
command=(lambda e=ents: callback(e))).pack(side=LEFT)
Quitter(root).pack(side=RIGHT)
root.mainloop()
Any help would be appriciated.
This is the source code for the program.
from Tkinter import *
from tkMessageBox import askokcancel
class Quitter(Frame):
def __init__(self, parent=None):
Frame.__init__(self, parent)
self.pack()
widget = Button(self, text='Quit', command=self.quit)
widget.pack(expand=YES, fill=BOTH, side=LEFT)
def quit(self):
ans = askokcancel('Verify exit', "Really quit?")
if ans: Frame.quit(self)
fields = 'Name','SAR Reprot No.', 'Rotor Start', 'Rotor Stop', 'Nature', 'Alerted By', 'Captian', 'Co Pilot', 'Helicopter','Latitude','Longitude'
def makeform(root, fields):
entries = []
for field in fields:
row = Frame(root)
lab = Label(row, width=15, text=field)
ent = Entry(row)
row.pack(side=TOP, fill=X)
lab.pack(side=LEFT)
ent.pack(side=RIGHT, expand=YES, fill=X)
entries.append(ent)
return entries
def callback(e):
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append('<?xml version="1.0" encoding="UTF-8"?><kml xmlns=" xmlns:gx=" xmlns:kml=" xmlns:atom=" name="MissionDetails" id="MissionDetailsId"><SimpleField type="string" name="ReportNumberValue"><displayName><b>ReportNumber</b></displayName></SimpleField><SimpleField type="int" name="Date"><displayName><b>Date</b></displayName></SimpleField><SimpleField type="double" name="RotorStart"><displayName><b>RotorStart</b></displayName></SimpleField><SimpleField type="double" name="RotorStop"><displayName><b>RotorStop</b></displayName></SimpleField><SimpleField type="string" name="Nature"><displayName><b>Nature</b></displayName></SimpleField><SimpleField type="string" name="AlertedBy"><displayName><b>AlertedBy</b></displayName></SimpleField><SimpleField type="string" name="Captain"><displayName><b>Captain</b></displayName></SimpleField><SimpleField type="string" name="CoPilot"><displayName><b>CoPilot</b></displayName></SimpleField><SimpleField type="string" name="Helicopter"><displayName><b>Helicopter</b></displayName></SimpleField></Schema><Placemark><name>{makeform(root, fields):entries = [Name].clipboard_append}</name><ExtendedData><SchemaData schemaUrl="#MissionDetailsId"><SimpleData name="Nature">Diver overdue or missing</SimpleData><SimpleData name="AlertedBy">Portland CG</SimpleData><SimpleData name="Captain">Balls K.</SimpleData><SimpleData name="CoPilot">Stracey G.</SimpleData><SimpleData name="Helicopter">G-CGWB</SimpleData></SchemaData><Data name="sarReportNumber"><value>9210</value></Data><Data name="date"><value>26062010</value></Data><Data name="rotorStart"><value>13.19</value></Data><Data name="rotorStop"><value>13.50</value></Data></ExtendedData><gx:balloonVisibility>1</gx:balloonVisibility><Point><coordinates>-1.957759,50.60696,0</coordinates></Point></Placemark></Document></kml>')
r.destroy()
if __name__ == '__main__':
root = Tk()
ents = makeform(root, fields)
root.bind('<Return>', (lambda event, e=ents: callback(e)))
Button(root, text='Print KML',
command=(lambda e=ents: callback(e))).pack(side=LEFT)
Quitter(root).pack(side=RIGHT)
root.mainloop()
Any help would be appriciated.