如何解决将TNoodle放入python rubicks立方体争夺生成器
我正在用 Python 开发一个 Tkinter 应用程序,该应用程序将自动生成 任何 WCA 谜题并记录您的解决时间。
到目前为止,我已经实现了除扰码器部分之外的所有内容。我做了一些研究,发现您应该为此使用 TNoodle。我查看了 TNoodle wiki,发现这些内容是用 Java 编写的。 Here 它描述了如何使用 PuzzleRegistry 枚举生成打乱(使用 TNoodle-Lib。IDK 差异)。
我不知道如何在python中调用这些函数或如何处理将返回的数据。这是我当前的代码,供任何想要查看的人使用。我也想用绘制打乱的SVG。
import tkinter as tk
from tkinter import ttk
import tkinter.font as font
from tkinter.constants import FLAT
from tkinter import *
import os
root = tk.Tk()
root.title('samsTimer')
myFont = font.Font(family='Courier',size=8,weight='bold')
root.minsize(width=1599,height=708)
mainBg = "black"
buttonBg = "#000000"
buttonFg = "#ffffff"
buttonHoverBg = "#adadad"
buttonHoverFg = "#000000"
timesInSession = []
# Mathmatics Stuff
def Average(lst):
return sum(lst) / len(lst)
def truncate(f,n):
'''Truncates/pads a float f to n decimal places without rounding'''
s = '{}'.format(f)
if 'e' in s or 'E' in s:
return '{0:.{1}f}'.format(f,n)
i,p,d = s.partition('.')
return '.'.join([i,(d+'0'*n)[:n]])
# Reading and Writing times
def getSession():
session = "3x3"
return session
def saveTime():
session = "3x3"
time = "3.47"
sessionFile = session + ".txt"
if os.path.exists(sessionFile):
append_write = 'a' # append if already exists
else:
append_write = 'w' # make a new file if not
file = open(sessionFile,append_write)
file.write(f"{time}\n")
file.close()
def readTimes():
timesInSession.clear()
for widget in timesPanel.winfo_children():
widget.destroy()
session = "3x3"
sessionFile = session + ".txt"
with open(sessionFile,'r') as f:
file = f.read()
times = file.split("\n")
i = 1
for time in times:
if time == "":
continue
else:
timeFloat = float(time)
timesInSession.append(timeFloat)
if (len(timesInSession) >= 5):
last5times = timesInSession[-5:]
currentLast5times = last5times
currentLast5times.remove(max(currentLast5times))
currentLast5times.remove(min(currentLast5times))
averageOf5 = Average(currentLast5times)
smallAO5 = truncate(averageOf5,3)
ao5Label = tk.Label(timesPanel,text=smallAO5,bg=mainBg,fg="White")
ao5Label.grid(row=i,column=3)
if (len(timesInSession) >= 12):
last12times = timesInSession[-12:]
currentLast12times = last12times
currentLast12times.remove(max(currentLast12times))
currentLast12times.remove(min(currentLast12times))
averageOf12 = Average(currentLast12times)
smallAO12 = truncate(averageOf12,3)
ao12Label = tk.Label(timesPanel,text=smallAO12,fg="White")
ao12Label.grid(row=i,column=4)
i += 1
i = 1
for t in timesInSession:
idLabel = tk.Label(timesPanel,text=i,fg="White")
idLabel.grid(row=i,column=1)
timeLabel = tk.Label(timesPanel,text=t,fg="White")
timeLabel.grid(row=i,column=2)
i += 1
print(f"Times recorded for the current session: {timesInSession}")
class Timer(Frame):
def __init__(self,master=None):
Frame.__init__(self,master)
self.place(relwidth=0.5,relheight=0.3,relx=0.25)
self.widgets()
self.running = False
self.timer = [0,0] # [minutes,seconds,centiseconds]
self.timeString = str(self.timer[0]) + ':' + str(self.timer[1]) + ':' + str(self.timer[2])
self.update_time()
def widgets(self):
self.show = Label(root,text='00:00:00',font=('Helvetica',50))
self.show.pack()
def update_time(self):
if (self.running == True): # Clock is running
self.timer[2] += 1 # Count Down
if (self.timer[2] >= 100): # 100 centiseconds --> 1 second
self.timer[2] = 0 # reset to zero centiseconds
self.timer[1] += 1 # add 1 second
if (self.timer[1] >= 60): # 60 seconds --> 1 minute
self.timer[0] += 1 # add 1 minute
self.timer[1] = 0 # reset to 0 seconds
self.timeString = str(self.timer[0]) + ':' + str(self.timer[1]) + ':' + str(self.timer[2])
self.show.config(text=self.timeString)
root.after(10,self.update_time)
def start(self): # Start the clock
self.running = True
print('Clock Running...')
def pause(self): # Pause the clock
self.running = False
print('Clock Paused')
def resetTime(self): # Reset the clock
self.running = False
self.timer = [0,0]
print('Clock is Reset')
self.show.config(text='00:00:00')
# The side panel bit
sidePanel = tk.Frame(root,bg="white")
sidePanel.place(relwidth=0.15,relheight=1)
optionsSection = tk.Frame(sidePanel,bg=mainBg)
optionsSection.place(relwidth=1,relheight=0.333)
settingButton = tk.Button(optionsSection,text="Settings",bg=buttonBg,fg=buttonFg,relief=FLAT,font=myFont)
settingButton.place(relwidth=0.333,relheight=0.333)
exportButton = tk.Button(optionsSection,text="Export",font=myFont)
exportButton.place(relwidth=0.333,relheight=0.333,relx=0.33)
scrambletoggle = tk.Button(optionsSection,text="Scramble",font=myFont)
scrambletoggle.place(relwidth=0.333,relx=0.66)
brandIcon = tk.Button(optionsSection,text="SamsTimer.tech",font=myFont)
brandIcon.place(relwidth=1,rely=0.333)
listTimesToggle= tk.Button(optionsSection,text="List\nTimes",font=myFont)
listTimesToggle.place(relwidth=0.333,rely=0.666)
aboutButton= tk.Button(optionsSection,text="About",font=myFont)
aboutButton.place(relwidth=0.333,rely=0.666,relx=0.33)
toolsToggle= tk.Button(optionsSection,text="Tools",font=myFont)
toolsToggle.place(relwidth=0.333,relx=0.66)
saveTimes= tk.Button(sidePanel,text="Save\nTime",font=myFont,command=saveTime)
saveTimes.place(relwidth=0.333,relheight=0.15,rely=0.5)
readTime = tk.Button(sidePanel,text="Read\nTimes",command=readTimes)
readTime.place(relwidth=0.333,relx=0.333,rely=0.5)
# The actual timer!!!
timerPanel = tk.Frame(root,bg="white")
timerPanel.place(relwidth=0.7,relheight=1,relx=0.15)
timer = Timer(timerPanel)
startTimer = tk.Button(sidePanel,text="Start\nTimer",command=timer.start)
startTimer.place(relwidth=0.333,rely=0.65)
stopTimer = tk.Button(sidePanel,text="Stop\nTimer",command=timer.resetTime)
stopTimer.place(relwidth=0.333,rely=0.65)
# Stuff for displaying the times
outerTimesFrame = Frame(root)
outerTimesFrame.place(relwidth=0.15,relx=0.85)
timesCanvas = Canvas(outerTimesFrame)
timesCanvas.pack(side=LEFT,fill=BOTH,expand=1)
timesScrollbar = ttk.Scrollbar(outerTimesFrame,orient=VERTICAL,command=timesCanvas.yview)
timesScrollbar.pack(side=RIGHT,fill=Y)
timesCanvas.configure(yscrollcommand=timesScrollbar.set)
timesCanvas.bind('<Configure>',lambda e: timesCanvas.configure(scrollregion = timesCanvas.bBox("all")))
timesPanel = tk.Frame(timesCanvas)
timesCanvas.create_window((0,0),window=timesPanel,anchor="nw")
readTimes()
root.mainloop()
我在 Java 方面经验不足,任何建议将不胜感激。 (我已经研究过 Jpype,但文档没有说明如何访问 Java 文件和内容)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。