Standalone reader for rFactor 1 RCD (talent) files. The following Python script uses the default tkinter human interface shipped with Python. 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 Talent 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()
shortfilename = os.path.basename(filename)
driverfile = os.path.splitext(os.path.basename(filename));
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('{')): #if opening brace
print (line.rstrip("\r\n"))
text.insert(INSERT, line)
elif(line.startswith('}')): #if closing brace
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)
elif(line.startswith(driverfile)):
print(driverfile)
text.insert(INSERT, line)
else: #if useful info
clean_line = line.lstrip()
key, val = clean_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 = ''
temp = [key, value, comment]
print(temp)
rewrite_file = ' '+key+'='+value+' '+comment
# print (rewrite_file)
text.insert(INSERT, rewrite_file+'\n')
else:
tkMessageBox.showwarning("No", "You did it wrong")
###########QUIT APP################
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")
var = DoubleVar()
scale = Scale(
root,
variable = var,
from_=0,
to=100,
resolution=0.01,
orient=HORIZONTAL,
length=260
)
scale.pack(anchor=CENTER)
#######################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()