feat(Router): finish implementing route computation progress display

This commit is contained in:
Daniel S. 2019-09-28 19:28:39 +02:00
parent 935891c852
commit 93f655c7ce
3 changed files with 60 additions and 42 deletions

View file

@ -14,7 +14,7 @@ import ed_lrr_gui
import requests as RQ
from ed_lrr_gui import Preprocessor, Router, cfg
from ed_lrr_gui.gui.ed_lrr import Ui_ED_LRR
from ed_lrr_gui.gui.widget_route import Ui_Route
from ed_lrr_gui.gui.widget_route import Ui_diag_route
from PyQt5.QtCore import QObject, Qt, QThread, QTimer, pyqtSignal
from PyQt5.QtGui import QColor, QPalette, QIcon
from PyQt5.QtWidgets import (
@ -82,11 +82,17 @@ class Job(QObject):
self.job.terminate()
self.job = None
def __bool__(self):
return not self.done
@property
def done(self):
if self.job:
return (self.job.is_alive() == False) and (self.job.queue.empty())
return True
def interval(self):
while self.job:
while self:
try:
res = self.job.queue.get(True, 0.1)
except queue.Empty:
@ -103,20 +109,16 @@ class RouterJob(Job):
super().__init__(app, main_window, Router, *args, **kwargs)
self.progress_dialog = ProgressDialog("", "Cancel", 0, 0, self.main_window)
self.progress_dialog.setAutoClose(False)
self.progress_dialog.setLabelText("Loading...")
self.progress_dialog.setLabelText("Loading (this will take a bit) ...")
self.progress_dialog.setWindowTitle("Loading...")
self.progress_dialog.canceled.connect(self.cancel)
self.progress_dialog.show()
self.start()
def done(self,result):
return
def handle_progess(self, state):
if state.get('return') is not None:
self.done(state['return'])
self.progress_dialog.close()
WRoute(state['return'])
route_win=WRoute(self.main_window,state['return'])
return
msg = "Depth: {depth}\nBody: {body}\nQueued: {queue_size}\nDistance remaining: {d_rem:.2f} Ly".format(
**state["status"]
@ -212,15 +214,17 @@ class App(QApplication):
self.styles[style] = palette
self.styles["Light"] = self.style().standardPalette()
class WRoute(Ui_Route):
def __init__(self,hops):
class WRoute(Ui_diag_route):
def __init__(self,main_window,hops):
super().__init__()
dialog=QDialog()
dialog=QDialog(main_window)
self.setupUi(dialog)
for n,item in enumerate(hops):
if item['body'].startswith(item['system']):
item['body']=item['body'].replace(item['system'],"").strip()
item = QTreeWidgetItem(self.lst_route, [str(n+1),item['system'],"{body} ({star_type})".format(**item),str(item['distance']), None])
item.setFlags(item.flags() & ~Qt.ItemIsDropEnabled)
dialog.show()
dialog.exec_()
class ED_LRR(Ui_ED_LRR):
dl_thread = None
@ -343,17 +347,19 @@ class ED_LRR(Ui_ED_LRR):
return
return path
def route_progress(self, job, state):
print("RP:", job, state)
def compute_route(self):
self.bar_status.showMessage("Resolving systems...")
num_resolved=self.resolve_systems()
if num_resolved:
if QMessageBox.question(self.main_window,"ED_LRR","Resolved {} systems, are the names correct?".format(num_resolved))==QMessageBox.No:
if QMessageBox.question(self.main_window,"ED_LRR","Resolved {} system(s), are the names correct?".format(num_resolved))==QMessageBox.No:
return
self.bar_status.clearMessage()
print(self.systems)
systems = [str(s["id"]) for s in self.systems]
jump_range = self.sb_range.value()
if jump_range==0:
self.error("Your jump range is set to zero, you're not going to get anywhere that way")
return
mode = self.cmb_mode.currentText()
primary = self.chk_primary.isChecked()
keep_first = self.chk_permute_keep_first.isChecked()
@ -385,7 +391,8 @@ class ED_LRR(Ui_ED_LRR):
path,
precomp,
)
if (self.current_job is None) or self.current_job.done():
if not self.current_job:
self.bar_status.showMessage("Computing Route...")
self.current_job = RouterJob(
self.app,
self.main_window,