Skip to content
This repository was archived by the owner on Dec 8, 2021. It is now read-only.

Commit 23a7e96

Browse files
authored
Added a basic error system.
1 parent 455fc57 commit 23a7e96

1 file changed

Lines changed: 30 additions & 8 deletions

File tree

Rails.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import oead
55
import zlib
66
import os
7-
#from tkinter import *
7+
from tkinter import messagebox
88
#from tkinter import ttk
99

1010
# Set up points
@@ -37,12 +37,16 @@
3737
#Set up window position
3838
WindowX = 587
3939
WindowY = 152
40+
#Define WriteToFile - this writes your data to the static file.
4041
def WriteToFile(InputText):
4142
InputBytes = oead.byml.from_text(InputText)
4243
BYML = oead.byml.to_binary(InputBytes, True, 2)
4344
Yaz0 = oead.yaz0.compress(BYML)
4445
with open(FilePath, "wb") as OutputFile:
4546
WrittenOutputFile = OutputFile.write(Yaz0)
47+
48+
#Define InsertRail - This takes the unedited static file text and injects the rail into it.
49+
#It then calls WriteToFile.
4650
def InsertRail(Input, RailString):
4751
if (Input.find("Rails: []") == -1):
4852
OutputText = Input + "\n" + RailString
@@ -53,6 +57,10 @@ def InsertRail(Input, RailString):
5357
#clipboard.copy(OutputText)
5458
#print(RailString)
5559
WriteToFile(OutputText)
60+
61+
#Define ReadFromFile. This reads all the data in the file and stores it as a string.
62+
#It then calls InsertRail, only if Continue is passed into it as true.
63+
#This functionality is for when you don't want to continue through, and just want to read the file.
5664
def ReadFromFile(RailString, Continue, CurrentPath):
5765
#FilePath = top.PathEntry.get()
5866
with open(CurrentPath, 'rb') as InputFile:
@@ -67,7 +75,7 @@ def ReadFromFile(RailString, Continue, CurrentPath):
6775
elif (Continue == False):
6876
return Output
6977

70-
78+
#This creates the railstring.
7179
def CoreCalculation(Continue):
7280
#Grab all the needed variables
7381
global X
@@ -87,10 +95,15 @@ def CoreCalculation(Continue):
8795

8896

8997
#Read DefaultPath and save it as FilePath
90-
FolderPath = top.PathEntry
91-
if (FolderPath == ""):
92-
with open("DefaultPath.txt", "r") as Path:
93-
FolderPath = Path.read()
98+
try:
99+
FolderPath = top.PathEntry
100+
if (FolderPath == ""):
101+
with open("DefaultPath.txt", "r") as Path:
102+
FolderPath = Path.read()
103+
except AttributeError:
104+
messagebox.showerror("You messed up.", "You need to specify the seciton folder!")
105+
print("You need to specify the seciton folder!")
106+
return
94107
#Find new HashID
95108
HighestHashID = 0
96109
for i in os.listdir(FolderPath):
@@ -142,6 +155,11 @@ def CoreCalculation(Continue):
142155
IsClosed = top.IsClosedDropdown.get()
143156
#Set RailType
144157
RailType = top.RailTypeDropdown.get()
158+
print(RailType)
159+
if (RailType != "Bezier" and RailType != "Linear"):
160+
messagebox.showerror("You messed up.", "Please specify RailType! It can only be Bezier or Linear.")
161+
print("Please specify RailType! It can only be Bezier or Linear.")
162+
return
145163
# Set NextDistanceIndex
146164
while NextDistanceIndexCounter < len(X)-1:
147165
NextDistanceIndex.append(NextDistanceIndexCounter)
@@ -170,7 +188,8 @@ def CoreCalculation(Continue):
170188
elif (IsClosed == "false"):
171189
InitString = ("- HashId: !u " + HashID + "\n" + " IsClosed: " + str(IsClosed) + "\n" + " RailPoints:" + "\n" + " - '!Parameters': {IsAdjustPosAndDirToPoint: false, WaitASKeyName: Search, WaitFrame: 60.0}" + "\n" + " NextDistance: " + str(NextDistanceArray[0]) + "\n" + " PrevDistance: " + str(NextDistanceArray[0]) + "\n" + " Translate: " + "[" + str(X[0]) + ", " + str(Y[0]) + ", " + str(Z[0]) + "]" + "\n" + " UnitConfigName: GuidePoint")
172190
else:
173-
print("Please specify IsClosed!")
191+
messagebox.showerror("You messed up.", "Please specify IsClosed! It can only be true or false.")
192+
print("Please specify IsClosed! It can only be true or false.")
174193
return
175194

176195
# Create repeatable main body string
@@ -192,7 +211,10 @@ def CoreCalculation(Continue):
192211
def ClipboardCopy():
193212
global FinalString
194213
CoreCalculation(False)
195-
clipboard.copy(FinalString)
214+
try:
215+
clipboard.copy(FinalString)
216+
except NameError:
217+
return
196218

197219
import sys
198220

0 commit comments

Comments
 (0)