This reads a rFactor 1 VEH file using Python's built-in human interface library, tkinter. See the above article Standalone Python for more info.
from tkinter import *
from tkinter import ttk
import tkinter.messagebox as tkMessageBox
import tkinter.simpledialog as tkSimpleDialog
import tkinter.filedialog as tkFileDialog
import os
root = Tk()
root.title("Read VEH File")
# create a textarea
text = Text(root, width=1, height=1)
text.pack(fill=BOTH, expand=1)
root.geometry('500x400')
############SELECT FILE#################
def fileselect():
filename = tkFileDialog.askopenfilename()
if filename:
data_file = open(filename, 'r')
text.delete(1.0,END)
for line in data_file:
if (line.startswith('//')): #if single line comment
print (line.rstrip("\r\n"))
text.insert(INSERT, line)
elif(line.startswith('\n')): #if blank line
print (line.rstrip("\r\n"))
text.insert(INSERT, line)
else: #if useful info
key, val = line.split('=',1)
if (val.find('//') >= 0):
cleanValue, comment = val.rsplit('//')
value = cleanValue.strip()
comment = '\t\t//'+comment.rstrip('\r\n')
else:
value = val.strip()
comment = ''
rewrite_file = key+'='+value+' '+comment
print (rewrite_file)
text.insert(INSERT, rewrite_file+'\n')
else:
tkMessageBox.showwarning("No", "You did it wrong")
def windowclose():
# if tkMessageBox.askokcancel("Quit", "Do you really wish to quit?"):
root.destroy()
###########INPUT DATA################
def inputdata():
x = tkSimpleDialog.askinteger("Input","Multiplier")
if x:
tkMessageBox.showwarning("Yes",x)
listbox.insert(END, x)
else:
tkMessageBox.showwarning("No","You did it wrong")
def tempwindow2():
tkMessageBox.showwarning("Hi","close me")
def myAboutCmd():
tkMessageBox.showwarning("About Me","close me")
#######################MENU#################
menu = Menu(root)
root.config(menu=menu)
filemenu = Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="Open", command=fileselect)
filemenu.add_command(label="Quit", command=windowclose)
editmenu = Menu(menu)
menu.add_cascade(label="Edit", menu=editmenu)
editmenu.add_command(label="Input", command=inputdata)
helpmenu = Menu(menu)
menu.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label = "About", command=tempwindow2)
root.mainloop()