16 July 2020
Obtaining list of aircraft from fgfs --show aircraft and displaying in list box. Select is next:
from tkinter import *import osos.nice(5)# June 15, 2020 restarted development : need a complete working software with exe#this program runs in Python 3 Note for Python 3 in Linux change build environment commands to # *** python3 -m py_compile "%f" *** and execute command to *** python3 "%f" ***# From Sept 18, 2011 Version fgwalk25M# Main windowwin = Tk()win.title("fgw2020_1")win.geometry("640x480+100+100")# # ***** NEED TO CHANGE***** First thing this aircraft list should be obtained from system fgfs --show-aircraft#aircraftlist=["c172p", "dhc2W","j3cub", "Dragonfly", "b1900d", "777-200ER" "SenecaII"]#print(aircraftlist)airportlist=["KHAF","KOAK", "KSFO","KHRV"]#Variablesautocoordvar=IntVar()a=IntVar()CheckVar1=StringVar()cloudvar=StringVar()turbvar=StringVar()texturevar=StringVar()shadingvar=StringVar()autocoordvar=StringVar()daytimevar=StringVar()seasonvar=StringVar()fogvar=StringVar()v = StringVar()fgcommand = StringVar()aircraftvariable = StringVar()# Run the fgfs command and get the aircraft info data#os.system("fgfs --show-aircraft >> fgfsshowaircraft.txt")AircraftList = open('fgfsshowaircraft.txt', 'r') aircraftline = AircraftList.readlines() # # ***** NEED TO CHANGE***** First thing this aircraft list should be obtained from system fgfs --show-aircraftaircraftcode = aircraftline[3:15]#print(aircraftline[1])# Base frame or top frametop_frame1 = Frame(win)#Put top frame in grid of win, that is, the parent frame, in row1 col1 (not 0 0)top_frame1.grid(row=1, column=1)#Image of One Aircraft only - logoimgpath1 = "c172p.gif/"photo1 = PhotoImage(file=imgpath1)#Create a lableFrame inside the top frame 1 for aircraftlabelframe1 = LabelFrame(top_frame1, text="Choose Aircraft")#put this lable frame in the grid of top framelabelframe1.grid(row=1, column=0, padx=16, pady=5)#Create a lableFrame inside the top frame 1 for airportlabelframe2 = LabelFrame(top_frame1, text="Choose Airport")#put this lable frame in the grid of top framelabelframe2.grid(row=1, column=1, padx=16, pady=5)#Create a lableFrame inside the top frame 1 for airportlabelframe3 = LabelFrame(top_frame1, text="Weather")#put this lable frame in the grid of top framelabelframe3.grid(row=2, column=0, padx=16, pady=5, columnspan = 2)#Create a lableFrame inside the top frame 1 labelframe4 = LabelFrame(top_frame1, text="Graphic Settings")#put this lable frame in the grid of top framelabelframe4.grid(row=3, column=0, padx=16, pady=5, columnspan = 4)#Create a lableFrame inside the top frame 1 labelframe5 = LabelFrame(top_frame1, text="Autocoordination")#put this lable frame in the grid of top framelabelframe5.grid(row=4, column=0, padx=16, pady=5)#Create a lableFrame inside the top frame 1 labelframe6 = LabelFrame(top_frame1, text="Command line:")#put this lable frame in the grid of top framelabelframe6.grid(row=5, column=0, padx=16, pady=5, columnspan = 6)# Aircraft Images labelImageL1 = Label(labelframe1, image=photo1)ImageL1.photo = photo1# Add image to grid. Only one image is needed, it changes according to selected itemImageL1.grid(row=0, column=0, padx=16, pady=5)# Define Listbox for aircraftlb = Listbox(labelframe1, height=7, exportselection=0)lb.insert(END, )for item in aircraftline: #print(item) lb.insert('end', item)lb.selection_set(first=0)#For default scenery so set airport to default airports# Define Listbox for AirportAirportList = Listbox(labelframe2, height=8, exportselection=0)AirportList.insert(END,"PHTO")AirportList.insert(END,"PHNL")AirportList.insert(END,"PHMK")AirportList.insert(END,"PHLI")AirportList.insert(END,"KHAF")AirportList.insert(END,"KSFO")AirportList.insert(END,"KOAK")AirportList.insert(END,"KHRV")AirportList.selection_set(first=0)#Check boxes for selecting season, turbulence, clouds... CHK_season = Checkbutton(labelframe3, text = "Winter Season", variable =CheckVar1, onvalue = " --season=winter ", offvalue = " ", font=("Helvetica", 11))CHK_season.deselect()CHK_turbulence = Checkbutton(labelframe3, text = "Turbulence", variable =turbvar, onvalue = "--turbulence=0.4", offvalue = " ", font=("Helvetica", 11))CHK_turbulence.select()CHK_clouds = Checkbutton(labelframe4, text = "Clouds On", variable =cloudvar, onvalue = "", offvalue = " --disable-clouds ", font=("Helvetica", 11))CHK_clouds.select()CHK_textures = Checkbutton(labelframe4, text = "Textures on", variable =texturevar, onvalue = "", offvalue = " --disable-textures ", font=("Helvetica", 11))CHK_textures.select()CHK_noontime = Checkbutton(labelframe4, text = "Noon Time", variable =daytimevar, onvalue = " --timeofday=noon ", offvalue = " ", font=("Helvetica", 11))CHK_noontime.select()CHK_autocoord = Checkbutton(labelframe5, text = "Auto coordination", variable =autocoordvar, onvalue = " --enable-auto-coordination", offvalue = " ", font=("Helvetica", 11))CHK_autocoord.select()CHK_fog = Checkbutton(labelframe4, text = "Fog (fastest)", variable =fogvar, onvalue = " --fog-fastest ", offvalue = " --fog-disable ", font=("Helvetica", 11))CHK_fog .select()#Define OK Button b1 = Button(labelframe6 , text="OK")text = Text(labelframe6, height =4, width =54)text.grid(row=0, column=0, padx=16, pady=5)b1.grid(row=0, column=3, padx=16, pady=5)lb.grid(row=0, column=1, padx=16, pady=5)AirportList.grid(row=1, column=2, padx=16, pady=5)# Add check boxesCHK_season.grid(row=1, column=0, padx=16, pady=5)CHK_turbulence.grid(row=1, column=1, padx=16, pady=5)CHK_clouds.grid(row=1, column=1, padx=16, pady=5)CHK_textures.grid(row=1, column=2, padx=16, pady=5)CHK_noontime.grid(row=1, column=3, padx=16, pady=5)CHK_clouds.grid(row=1, column=4, padx=16, pady=5)CHK_autocoord.grid(row=1, column=5, padx=16, pady=5)CHK_fog.grid(row=1, column=2, padx=16, pady=5)# Event for changing image when a item when list box is selected# To DO automatically obtain gif file# List box lb is being bound to an event get_list#Main button and actions that are triggereddef but1() : print("button 1 pressed") print(lb.curselection()) print(AirportList.curselection()) # Check variable access print(CheckVar1.get()) seltext1 = lb.curselection() a =int(seltext1[0]) seltext2 = AirportList.curselection() b =int(seltext2[0]) # put this into press button event #span = "--timeofday=value --season=winter --fog-disable --disable-clouds --disable-textures --shading-flat " fgcommand="fgfs --aircraft=" fgcommand = fgcommand + aircraftcode[a] fgcommand = fgcommand +" --airport=" fgcommand = fgcommand + airportlist[b] fgcommand = fgcommand + CheckVar1.get() fgcommand = fgcommand + daytimevar.get() fgcommand = fgcommand + turbvar.get() fgcommand = fgcommand + cloudvar.get() fgcommand = fgcommand + seasonvar.get() fgcommand = fgcommand + texturevar.get() fgcommand = fgcommand + fogvar.get() fgcommand = fgcommand + autocoordvar.get() text.insert(INSERT, fgcommand) print(fgcommand) #os.system(fgcommand) #Configure GUI button to code that runs as but1()b1.configure(command=but1)win.mainloop()Implementing auto reading of aircraft list and populating select boxes with the data. 11 July 2019
11 July 2019
Obtain list of aircraft in text format. It follows the following format:
777-200 Boeing 777-200
777-200ER Boeing 777-200ER
777-200LR Boeing 777-200LR
777-300 Boeing 777-300
777-300ER Boeing 777-300ER
a24 Aeroprakt A 24 Viking
The following code extracts the aircraft name and decription:
aircraftstring= (" 777-200 Boeing 777-200 ")
print(aircraftstring)
x = aircraftstring.split(" ")
print(x)
print(x[1])
print(x[8])
Output:
777-200 Boeing 777-200
['', '777-200', '', '', '', '', '', '', ' Boeing 777-200', '', '']
777-200
Boeing 777-200
#open file for reading
f = open('aircraftlist.txt', 'r')
#Print contents to screen
print f.read()
#Wait for enter key to be pressed
raw_input()
Simulated Output : (File previously generated by copying and pasting output from fgfs --show-aircraft
pt22 Ryan PT 22 (YASim)
pushback Pushback
rallye-MS893 Socata Rallye MS893E
RV-6A RV-6A (YASim)
s11 Fokker S 11
santa Santa Claus (3d cockpit)
SenecaII PA34-200T Seneca II
SenecaII-panelonly PA34-200T Seneca II (no 3d model, 2d panel only)
sopwithCamel Sopwith Camel 1F.1 (uiuc)
sopwithCamel-v1-nl-uiuc Sopwith Camel (larcsim)
sopwithCamel-YASim Sopwith Camel 1F.1 (YASim)
st10 Socata ST10 Diplomate (YASim)
stampe Stampe SV 4 Br
ufo UFO from the 'White Project' of the UNESCO
yak18t Yak 18 T (YASim)
ZF_Navy_free_balloon US Navy ZF free gas balloon
Adding to the code:
#
#open file for reading
f = open('aircraftlist.txt', 'r')
linearray = f.readlines()
x = linearray[1]
print(x)
plane=x.split(' ', 1)
print(plane)
raw_input()
Output
777-200ER Boeing 777 200 ER