I am currently nearing the end of the final unit in my A - Level computing course in which we are developing a system for a company. My choice of system is a KML generator which creates placemarks with details on rescues. I have developed a working KML and GUI but don't have the knowledge on how to implement the KML into Tkinter. The result should be a system where the user inputs the details into the KML code via the GUI, which on clicking the "Print KML" button should copy the code to the clipboard to be pasted into Google Earth. I am using Python 2.6.2 as it's the version which is compatible with KML. If anyone has knowledge on how this can be done help would be appreciated.
KML Code:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<name>KmlFile</name>
<Schema name="MissionDetails" id="MissionDetailsId0">
<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>Test Marker</name>
<ExtendedData>
<SchemaData schemaUrl="#MissionDetailsId0">
<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="Sar Report Number">
<value>9210</value>
</Data>
<Data name="Date">
<value>26/06/2010</value </Data>
<Data name="Rotor Start">
<value>13.19</value>
</Data>
<Data name="Rotor Stop">
<value>13.50</value>
</Data>
</ExtendedData>
<Point>
<coordinates>-1.957759,50.60696,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
Tkinter Code:
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 = 'SAR Reprot No.', 'Rotor Start', 'Rotor Stop', 'Nature', 'Alerted By', 'Captian', 'Co Pilot', 'Helicopter','Latitude','Longitude'
def fetch(entries):
for entry in entries:
print 'Input => "%s"' % entry.get()
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
if __name__ == '__main__':
root = Tk()
ents = makeform(root, fields)
root.bind('<Return>', (lambda event, e=ents: fetch(e)))
Button(root, text='Print KML',
command=(lambda e=ents: fetch(e))).pack(side=LEFT)
Quitter(root).pack(side=RIGHT)
root.mainloop()