update Rust code, update Python code - Add Download functionality to GUI - Update rust code for use with GUI - Add callbacks to rust code - Add python modules for routing and download
52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
from multiprocessing import Process, Queue, freeze_support
|
|
import queue
|
|
from datetime import datetime, timedelta
|
|
import _ed_lrr
|
|
from collections import namedtuple
|
|
|
|
|
|
class Router(Process):
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__()
|
|
self.state = {}
|
|
self.queue = Queue()
|
|
self.daemon = True
|
|
self.args = args
|
|
self.kwargs = kwargs
|
|
self.kwargs["callback"] = self.callback
|
|
self.start()
|
|
|
|
def __iter__(self):
|
|
while self.is_alive():
|
|
try:
|
|
self.state.update(self.queue.get(True, 0.5))
|
|
yield self.state
|
|
except queue.Empty:
|
|
pass
|
|
while not self.queue.empty():
|
|
self.state.update(self.queue.get(True, 0.5))
|
|
yield self.state
|
|
|
|
def callback(self, state):
|
|
self.queue.put({"status": state})
|
|
|
|
def run(self):
|
|
route = _ed_lrr.route(*self.args, **self.kwargs)
|
|
self.queue.put({"return": route})
|
|
|
|
|
|
if __name__ == "__main__":
|
|
freeze_support()
|
|
r = Router(
|
|
["Ix", "Beagle Point"],
|
|
48,
|
|
"BFS",
|
|
False,
|
|
False,
|
|
None,
|
|
None,
|
|
r"D:\devel\rust\ED_LRR\stars.csv",
|
|
)
|
|
for e in r:
|
|
print(e)
|