Skip to content
This repository has been archived by the owner on Nov 15, 2019. It is now read-only.

Commit

Permalink
Fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriei committed Apr 23, 2018
1 parent aea3e1c commit 320c5b0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

*.bat
*.spec
49 changes: 29 additions & 20 deletions EDPlanetBearing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def callback(ClearLock=True):
root.destroy()
exit()

def resource_path(relative):
if hasattr(sys, "_MEIPASS"):
return os.path.join(sys._MEIPASS, relative)
return os.path.join(relative)

def SingleInstance(FirstRun=False):
global EDPBLock
global SessionID
Expand Down Expand Up @@ -84,9 +89,10 @@ def resize(root, InfoHudLevel, StartingUp=False):

try:
if StartingUp:
# calculate x and y coordinates for the Tk root window
# Calculate x and y coordinates for the Tk root window
x = (ws/2) - (w/2)
y = (hs/100)# - (h/2)
root.after(100, JournalUpdate.on_modified, JournalUpdate, "Startup")
else:
x = root.winfo_rootx()
y = root.winfo_rooty()
Expand Down Expand Up @@ -154,7 +160,6 @@ def hidetip(self):

class JournalUpdate(FileSystemEventHandler):
def on_modified(self, event):
print("Detected change in: " + event.src_path)
global Body
global StarSystem
global BodyRadius
Expand Down Expand Up @@ -190,7 +195,7 @@ def on_modified(self, event):
break
except Exception as e:
print("E.Journal read and parse: "+str(e))
calculate()
Calculate()

class WindowMgr:
"""Encapsulates some calls to the winapi for window management"""
Expand Down Expand Up @@ -266,10 +271,12 @@ def PingLoop():
finally:
root.after(PingDelay,AudioFeedBack.PingLoop)

def PingCycleMode():
def PingCycleMode(AudioModeSet = -1):
global AudioMode
try:
if AudioMode == 2:
if AudioModeSet != -1:
AudioMode = AudioModeSet
elif AudioMode == 2:
AudioMode = 0
else:
AudioMode = AudioMode + 1
Expand All @@ -287,19 +294,20 @@ def GetConfigFromFile(): #Gets config from config file if exists and applies it
if os.path.exists(EDPBConfigFile):
try:
with open(EDPBConfigFile) as f:
EDPBConfigContent = f.read()
EDPBConfigContent = f.read().lower()
Configs = json.loads(EDPBConfigContent)

DstLat = float(Configs["Lat"])
DstLong = float(Configs["Long"])
DstLat = float(Configs["lat"])
DstLong = float(Configs["long"])
try:
AudioMode = int(Configs["Audio"])
AudioFeedBack.PingCycleMode(int(Configs["audio"]))
except:
pass
if DstLat == -0:
DstLat = 0.0

DestinationCoords.set(str(DstLat) + ", " + str(DstLong))
root.after(100,FocusElite)

#Disable GUI
if str(coords_entry["state"]) == "normal":
Expand All @@ -318,7 +326,7 @@ def GetConfigFromFile(): #Gets config from config file if exists and applies it
print("GUI Enabled")
root.after(5000, GetConfigFromFile)

def calculate(event="None"):
def Calculate(event="None"):
#
LeftArrow = ""
RightArrow = ""
Expand Down Expand Up @@ -411,7 +419,7 @@ def calculate(event="None"):

if CurrentHead < Bearing:
CurrentHead += 360 # denormalize ...
DirectionRaw = CurrentHead - Bearing # calculate left turn, will allways be 0..359
DirectionRaw = CurrentHead - Bearing # Calculate left turn, will allways be 0..359
Direction = DirectionRaw
print("DirectionRaw: " + str(DirectionRaw) + "°")
# take the smallest turn
Expand Down Expand Up @@ -521,9 +529,10 @@ def calculate(event="None"):
PingPosX = 0
sound_beep = "Beep.wav" #Default sound file
PingDelay = 1500 #Default Ping delay
BMPingAudio0 = PhotoImage(file="BMPingAudio0.png")
BMPingAudio1 = PhotoImage(file="BMPingAudio1.png")
BMPingAudio2 = PhotoImage(file="BMPingAudio2.png")
data_dir = "."
BMPingAudio0 = PhotoImage(file=resource_path(os.path.join(data_dir, "BMPingAudio0.png")))
BMPingAudio1 = PhotoImage(file=resource_path(os.path.join(data_dir, "BMPingAudio1.png")))
BMPingAudio2 = PhotoImage(file=resource_path(os.path.join(data_dir, "BMPingAudio2.png")))
AudioMode = 0

AudioFeedBack.Start()
Expand Down Expand Up @@ -632,7 +641,7 @@ def calculate(event="None"):
coords_entry = ttk.Entry(mainframe, width=18, justify=CENTER, textvariable=DestinationCoords)
coords_entry.grid(column=2, columnspan=8, row=1, sticky=(W, E))
coords_entry.focus()
coords_entry.bind("<Return>", calculate)
coords_entry.bind("<Return>", Calculate)

ttk.Label(mainframe, textvariable=DestHeading, justify=CENTER, font=("Helvetica", 16)).grid(column=5, columnspan=6, row=2, sticky=(W, E))
ttk.Label(mainframe, textvariable=DestHeadingL, justify=CENTER, font=("Helvetica", 14)).grid(column=2, columnspan=3, row=2, sticky=(E))
Expand Down Expand Up @@ -669,10 +678,10 @@ def getopts(argv):
os.remove(EDPBConfigFile)
except Exception as e:
print("E.Deleting config file: " + str(e))
if "-Audio" in argv or "-audio" in argv:
AudioMode = 1
except:
pass
if "+audio" in myargs:
AudioFeedBack.PingCycleMode(int(myargs["+audio"]))
except Exception as e:
print (e)

#Add Tooltips
CloseB_ttp = CreateToolTip(CloseB, "Close")
Expand All @@ -685,7 +694,7 @@ def getopts(argv):

root.after(PingDelay,AudioFeedBack.PingLoop)
root.after(100, GetConfigFromFile)
root.after(0, SingleInstance,True)
root.after(100, SingleInstance,True)

root.protocol("WM_DELETE_WINDOW", callback)
root.attributes("-topmost", True)
Expand Down

0 comments on commit 320c5b0

Please sign in to comment.