├── config.yml ├── .gitignore ├── README.md ├── main.py ├── Launchpad.py ├── window.py └── EDSM.py /config.yml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | config.yml 3 | __pycache__ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EDLaunchpad 2 | 3 | EDLaunchpad is a simple tool that visualizes the progress of your journey from one star-system to another either with a progress bar or with a launchpad. 4 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from EDSM import * 2 | import window 3 | 4 | if read_yaml("commander_name") == "key not found in config": 5 | settings() 6 | elif read_yaml("start_system") == "key not found in config": 7 | settings() 8 | elif read_yaml("end_system") == "key not found in config": 9 | settings() 10 | 11 | window.window() 12 | 13 | try: 14 | import Launchpad 15 | run() 16 | except: 17 | pass 18 | -------------------------------------------------------------------------------- /Launchpad.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from EDSM import refresh 3 | 4 | try: 5 | import launchpad_py as launchpad 6 | except ImportError: 7 | try: 8 | import launchpad 9 | except ImportError: 10 | sys.exit("error loading launchpad.py") 11 | 12 | try: 13 | lp = launchpad.LaunchpadMk2() 14 | except: 15 | try: 16 | lp = launchpad.Launchpad() 17 | except: 18 | try: 19 | lp = launchpad.LaunchpadPro() 20 | except: 21 | sys.exit("No valid Launchpad detected") 22 | 23 | lp.Open() 24 | lp.ButtonFlush() 25 | lp.LedAllOn(0) 26 | 27 | 28 | def button_press(): 29 | while 1: 30 | press = lp.ButtonStateXY() 31 | if press: 32 | if press[0] == 0 and press[1] == 0: 33 | refresh() 34 | 35 | 36 | def rgb(r, g, b): 37 | r = int(round(r / 255 * 63, 0)) 38 | g = int(round(g / 255 * 63, 0)) 39 | b = int(round(b / 255 * 63, 0)) 40 | return r, g, b 41 | 42 | 43 | def color_gradient(col1, col2, state): 44 | r1, g1, b1 = col1 45 | r2, g2, b2 = col2 46 | 47 | step = round((g2 - g1) / 8) 48 | 49 | red_new = 102 50 | green_new = round(g1 + state * step) 51 | blue_new = 0 52 | 53 | return red_new, green_new, blue_new 54 | 55 | 56 | def display(amount): 57 | lp.LedAllOn(0) 58 | for y in range(8): 59 | r, g, b = color_gradient(rgb(102, 0, 0), rgb(102, 102, 0), y + 1) 60 | r = int(r) 61 | g = int(g) 62 | b = int(b) 63 | for x in range(8): 64 | if 8 * y + x < amount: 65 | lp.LedCtrlXY(x, y + 1, r, g, b) 66 | 67 | 68 | # display(2) 69 | -------------------------------------------------------------------------------- /window.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import ttk 3 | from EDSM import refresh 4 | import threading 5 | import time 6 | 7 | count = 0 8 | 9 | 10 | def show(amount): 11 | bar.config(value=amount) 12 | label.config(text="Progress: " + str(amount) + "%") 13 | 14 | 15 | def window(height=100, width=300): 16 | global bar, label 17 | root = tk.Tk() 18 | root.title("EDLaunchpad") 19 | root.resizable(False, False) 20 | ttk.Style().theme_use('vista') 21 | 22 | def auto_refresh(secs=60): 23 | time.sleep(1) 24 | while count == 1: 25 | refresh() 26 | time.sleep(secs) 27 | 28 | def cb_command(): 29 | global count 30 | if count == 0: 31 | threading.Thread(target=auto_refresh).start() 32 | count = 1 33 | else: 34 | count = 0 35 | 36 | canvas = tk.Canvas(root, height=height, width=width) 37 | canvas.pack() 38 | 39 | frame = tk.Frame(root, bd=10) 40 | frame.place(relheight=1, relwidth=1) 41 | 42 | label = ttk.Label(frame, text="Progress: ") 43 | label.grid(row=0, column=0, padx=5, pady=3, sticky="W") 44 | 45 | refresh_button = ttk.Button(frame, text="Refresh", command=refresh) 46 | refresh_button.grid(row=0, column=1, padx=5, ipadx=20, sticky="E") 47 | 48 | checkbox = ttk.Checkbutton(frame, text="Auto Refresh", command=cb_command) 49 | checkbox.grid(row=2, column=0, padx=5, pady=3, sticky="W") 50 | 51 | bar = ttk.Progressbar(frame, mode="determinate", value=0, length=270) 52 | bar.grid(row=1, column=0, columnspan=2, padx=5, pady=3, sticky="W") 53 | 54 | root.mainloop() 55 | 56 | if __name__ == "__main__": 57 | import main -------------------------------------------------------------------------------- /EDSM.py: -------------------------------------------------------------------------------- 1 | from urllib.request import urlopen 2 | import json 3 | import math 4 | import time 5 | 6 | config_filepath = "config.yml" 7 | 8 | 9 | def get_commander_system(commander_name): 10 | 11 | # Get the dataset 12 | url = 'https://www.edsm.net/api-logs-v1/get-position?commanderName=' + commander_name 13 | response = urlopen(url) 14 | 15 | # Convert bytes to string type and string type to dict 16 | string = response.read().decode('utf-8') 17 | json_obj = json.loads(string) 18 | 19 | try: 20 | final_string = json_obj['system'] 21 | except: 22 | final_string = "Commander was not found in the database" 23 | 24 | return final_string 25 | 26 | 27 | def get_system_coordinates(system_name): 28 | 29 | # Get the dataset 30 | url = 'https://www.edsm.net/api-v1/system?systemName=' + system_name + "&showCoordinates=1" 31 | response = urlopen(url) 32 | 33 | # Convert bytes to string type and string type to dict 34 | string = response.read().decode('utf-8') 35 | json_obj = json.loads(string) 36 | 37 | try: 38 | return json_obj["coords"] 39 | except: 40 | print("System was not found in database or coordinates are not known") 41 | return False 42 | 43 | 44 | def distance(system1_coordinates, system2_coordinates): 45 | 46 | a = system1_coordinates["x"] - system2_coordinates["x"] 47 | b = system1_coordinates["y"] - system2_coordinates["y"] 48 | 49 | c = math.sqrt(a*a + b*b) 50 | 51 | a2 = c 52 | b2 = system1_coordinates["z"] - system2_coordinates["z"] 53 | 54 | c2 = math.sqrt(a2*a2 + b2*b2) 55 | 56 | return round(c2, 2) 57 | 58 | 59 | def is_known(commander_name): 60 | # Get the dataset 61 | url = 'https://www.edsm.net/api-logs-v1/get-position?commanderName=' + commander_name 62 | response = urlopen(url) 63 | 64 | # Convert bytes to string type and string type to dict 65 | string = response.read().decode('utf-8') 66 | json_obj = json.loads(string) 67 | 68 | if json_obj['msg'] == "OK": 69 | return True 70 | else: 71 | return False 72 | 73 | 74 | def write_to_yaml(key, value): 75 | 76 | old_content = {} 77 | new_content = {} 78 | 79 | file = open(config_filepath, "r") 80 | content = file.readlines() 81 | lines = [] 82 | 83 | # remove \n 84 | for i in content: 85 | i = i.replace("\n", "") 86 | lines.append(i) 87 | 88 | # convert content to dictionary 89 | for n in lines: 90 | content_list = n.split(": ") 91 | old_content[content_list[0]] = content_list[1] 92 | 93 | if key in old_content: 94 | new_content[key] = value 95 | del old_content[key] 96 | else: 97 | new_content[key] = value 98 | 99 | for f in old_content: 100 | new_content[f] = old_content[f] 101 | 102 | file.close() 103 | 104 | # actual writing 105 | new_file = open(config_filepath, "w") 106 | 107 | # creating new string 108 | final_string = "" 109 | for element in new_content: 110 | final_string += element 111 | final_string += ": " 112 | final_string += new_content[element] 113 | final_string += "\n" 114 | 115 | new_file.write(final_string) 116 | new_file.close() 117 | 118 | 119 | def read_yaml(key): 120 | 121 | file_content = {} 122 | file = open(config_filepath, "r") 123 | content = file.readlines() 124 | lines = [] 125 | 126 | # remove \n 127 | for i in content: 128 | i = i.replace("\n", "") 129 | lines.append(i) 130 | 131 | # convert content to dictionary 132 | for n in lines: 133 | content_list = n.split(": ") 134 | file_content[content_list[0]] = content_list[1] 135 | 136 | try: 137 | return file_content[key] 138 | except: 139 | return "key not found in config" 140 | 141 | 142 | def settings(): 143 | commander_name = input("Commander Name:\n") 144 | if is_known(commander_name): 145 | write_to_yaml("commander_name", commander_name) 146 | else: 147 | settings() 148 | return 149 | start_system = input("Start System:\n") 150 | write_to_yaml("start_system", start_system) 151 | end_system = input("End System:\n") 152 | write_to_yaml("end_system", end_system) 153 | 154 | 155 | def run(refresh_time=60, pixel_amount=64): 156 | 157 | commander_name = read_yaml("commander_name") 158 | start_system = read_yaml("start_system") 159 | end_system = read_yaml("end_system") 160 | 161 | print("commander_name:", commander_name) 162 | print("start_system:", start_system) 163 | print("end_system:", end_system) 164 | 165 | try: 166 | start_system_coordinates = get_system_coordinates(start_system) 167 | end_system_coordinates = get_system_coordinates(end_system) 168 | except: 169 | time.sleep(refresh_time) 170 | run() 171 | return 172 | 173 | total_distance = distance(start_system_coordinates, end_system_coordinates) 174 | print("total_distance:", total_distance) 175 | 176 | distance_per_pixel = round(total_distance / pixel_amount, 2) 177 | print("distance_per_pixel:", distance_per_pixel) 178 | 179 | while 1: 180 | distance_left = distance(get_system_coordinates(get_commander_system(commander_name)), 181 | end_system_coordinates) 182 | print("distance_left:", distance_left) 183 | 184 | pixels_active = int(round(distance_left / distance_per_pixel, 0)) 185 | print("pixels_active:", pixels_active) 186 | 187 | import Launchpad 188 | Launchpad.display(pixels_active) 189 | 190 | time.sleep(refresh_time) 191 | 192 | 193 | def refresh(pixel_amount=64): 194 | 195 | commander_name = read_yaml("commander_name") 196 | start_system = read_yaml("start_system") 197 | end_system = read_yaml("end_system") 198 | 199 | print("commander_name:", commander_name) 200 | print("start_system:", start_system) 201 | print("end_system:", end_system) 202 | 203 | start_system_coordinates = get_system_coordinates(start_system) 204 | end_system_coordinates = get_system_coordinates(end_system) 205 | 206 | total_distance = distance(start_system_coordinates, end_system_coordinates) 207 | print("total_distance:", total_distance) 208 | 209 | distance_per_pixel = round(total_distance / pixel_amount, 2) 210 | print("distance_per_pixel:", distance_per_pixel) 211 | 212 | distance_left = distance(get_system_coordinates(get_commander_system(commander_name)), 213 | end_system_coordinates) 214 | print("distance_left:", distance_left) 215 | 216 | pixels_active = int(round(distance_left / distance_per_pixel, 0)) 217 | print("pixels_active:", pixels_active) 218 | 219 | progress = 100 - int(round(distance_left / (round(total_distance / 100)), 0)) 220 | print("progress: " + str(progress) + "%") 221 | 222 | import window 223 | window.show(progress) 224 | 225 | try: 226 | import Launchpad 227 | Launchpad.display(pixels_active) 228 | except: 229 | pass 230 | --------------------------------------------------------------------------------