Merge branch 'HEAD' into other_formats2

This commit is contained in:
Kiel42 2019-10-28 19:33:44 +01:00
commit 26efd0b680
5 changed files with 71 additions and 29 deletions

View File

@ -2,6 +2,13 @@
All notable changes to this project will be documented in this file.
## 2.2.0
- Now supports any CSV having columns named "System Name" and "Jumps". The "Jumps" column is optional
- Supports text files given by EDTS (it is the only .txt file supported for now)
- The "Start System" in the potter is now automatically set to the one you are currently in
- Fixed a bug where the plugin could make EDMC crash by accessing TkInter state in a thread
## 2.1.4
- Autosaves your progress more often in case EDMC crashes

View File

@ -13,7 +13,17 @@ This plugin's purpose is to automatically copy to your clipboard the next waypoi
## How to use
You can either plot your route directly from EDMC, or you can import a CSV file from [Spansh](https://www.spansh.co.uk/plotter)
You can either plot your route directly from EDMC by clicking the "Plot Route" button, or you can import a CSV file from [Spansh](https://www.spansh.co.uk/plotter)
You can also create your own CSV file, as long as it contains the columns "System Name" and "Jumps" (that last one is optional).
A valid CSV file could look like:
```csv
System Name,Jumps
Saggitarius A*,5
Beagle Point,324
```
You can also use a .txt file created with [EDTS](https://bitbucket.org/Esvandiary/edts/wiki/edts)
Once your route is plotted, and every time you reach a waypoint, the next one is automatically copied to your clipboard.

View File

@ -76,11 +76,12 @@ class AutoCompleter(Entry, PlaceHolder):
def changed(self, name, index, mode):
self.set_default_style()
if self.var.get().__len__() < 3 and self.lb_up or self.has_selected:
value = self.var.get()
if value.__len__() < 3 and self.lb_up or self.has_selected:
self.hide_list()
self.has_selected = False
else:
t = threading.Thread(target=self.query_systems)
t = threading.Thread(target=self.query_systems, args=[value])
t.start()
def selection(self, event=None):
@ -143,8 +144,8 @@ class AutoCompleter(Entry, PlaceHolder):
self.lb.grid_remove()
self.lb_up = False
def query_systems(self):
inp = self.var.get().strip()
def query_systems(self, inp):
inp = inp.strip()
if inp != self.placeholder and inp.__len__() >= 3:
url = "https://spansh.co.uk/api/systems?"
try:

View File

@ -37,6 +37,8 @@ class SpanshRouter():
self.jumps_left = 0
self.error_txt = tk.StringVar()
self.plot_error = "Error while trying to plot a route, please try again."
self.system_header = "System Name"
self.jumps_header = "Jumps"
# -- GUI part --
def init_gui(self, parent):
@ -241,22 +243,34 @@ class SpanshRouter():
def open_last_route(self):
try:
has_headers = False
with open(self.save_route_path, 'r') as csvfile:
route_reader = csv.reader(csvfile)
# Check if the file has a header for compatibility with previous versions
dict_route_reader = csv.DictReader(csvfile)
if dict_route_reader.fieldnames[0] == self.system_header:
has_headers = True
for row in route_reader:
if row not in (None, "", []):
self.route.append(row)
if has_headers:
self.plot_csv(self.save_route_path, clear_previous_route=False)
else:
with open(self.save_route_path, 'r') as csvfile:
route_reader = csv.reader(csvfile)
try:
with open(self.offset_file_path, 'r') as offset_fh:
self.offset = int(offset_fh.readline())
for row in route_reader:
if row not in (None, "", []):
self.route.append(row)
except:
self.offset = 0
try:
with open(self.offset_file_path, 'r') as offset_fh:
self.offset = int(offset_fh.readline())
except:
self.offset = 0
self.jumps_left = 0
for row in self.route[self.offset:]:
self.jumps_left += int(row[1])
if row[1] not in [None, "", []]:
self.jumps_left += int(row[1])
self.next_stop = self.route[self.offset][0]
self.copy_waypoint()
@ -282,11 +296,13 @@ class SpanshRouter():
def update_route(self, direction=1):
if direction > 0:
self.jumps_left -= int(self.route[self.offset][1])
if self.route[self.offset][1] not in [None, "", []]:
self.jumps_left -= int(self.route[self.offset][1])
self.offset += 1
else:
self.offset -= 1
self.jumps_left += int(self.route[self.offset][1])
if self.route[self.offset][1] not in [None, "", []]:
self.jumps_left += int(self.route[self.offset][1])
if self.offset >= self.route.__len__():
self.next_stop = "End of the road!"
@ -315,17 +331,8 @@ class SpanshRouter():
ftype_supported = False
if filename.endswith(".csv"):
ftype_supported = True
with open(filename, 'r') as csvfile:
route_reader = csv.reader(csvfile)
# Skip the header
route_reader.next()
self.clear_route(False)
for row in route_reader:
if row not in (None, "", []):
self.route.append([row[0], row[4]])
self.jumps_left += int(row[4])
self.plot_csv(filename)
elif filename.endswith(".txt"):
ftype_supported = True
self.plot_edts(filename)
@ -345,6 +352,21 @@ class SpanshRouter():
self.enable_plot_gui(True)
self.show_error("An error occured while reading the file.")
def plot_csv(self, filename, clear_previous_route=True):
with open(filename, 'r') as csvfile:
route_reader = csv.DictReader(csvfile)
if clear_previous_route:
self.clear_route(False)
for row in route_reader:
if row not in (None, "", []):
self.route.append([
row[self.system_header],
row.get(self.jumps_header, "") # Jumps column is optional
])
if row.get(self.jumps_header) != None:
self.jumps_left += int(row[self.jumps_header])
def plot_route(self):
self.hide_error()
try:
@ -490,7 +512,9 @@ class SpanshRouter():
def save_route(self):
if self.route.__len__() != 0:
with open(self.save_route_path, 'w') as csvfile:
fieldnames = [self.system_header, self.jumps_header]
writer = csv.writer(csvfile)
writer.writerow(fieldnames)
writer.writerows(self.route)
else:
try:

View File

@ -1 +1 @@
2.1.4
2.2.0