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

View file

@ -10,16 +10,16 @@
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object): class Ui_diag_route(object):
def setupUi(self, Dialog): def setupUi(self, diag_route):
Dialog.setObjectName("Dialog") diag_route.setObjectName("diag_route")
Dialog.setWindowModality(QtCore.Qt.WindowModal) diag_route.setWindowModality(QtCore.Qt.WindowModal)
Dialog.resize(430, 300) diag_route.resize(430, 300)
self.layout_main = QtWidgets.QGridLayout(Dialog) self.layout_main = QtWidgets.QGridLayout(diag_route)
self.layout_main.setObjectName("layout_main") self.layout_main.setObjectName("layout_main")
self.layout_top = QtWidgets.QGridLayout() self.layout_top = QtWidgets.QGridLayout()
self.layout_top.setObjectName("layout_top") self.layout_top.setObjectName("layout_top")
self.lst_route = QtWidgets.QTreeWidget(Dialog) self.lst_route = QtWidgets.QTreeWidget(diag_route)
self.lst_route.setProperty("showDropIndicator", False) self.lst_route.setProperty("showDropIndicator", False)
self.lst_route.setDefaultDropAction(QtCore.Qt.IgnoreAction) self.lst_route.setDefaultDropAction(QtCore.Qt.IgnoreAction)
self.lst_route.setAlternatingRowColors(True) self.lst_route.setAlternatingRowColors(True)
@ -33,23 +33,27 @@ class Ui_Dialog(object):
self.layout_main.addLayout(self.layout_top, 0, 0, 1, 1) self.layout_main.addLayout(self.layout_top, 0, 0, 1, 1)
self.layout_bottom = QtWidgets.QGridLayout() self.layout_bottom = QtWidgets.QGridLayout()
self.layout_bottom.setObjectName("layout_bottom") self.layout_bottom.setObjectName("layout_bottom")
self.chk_copy = QtWidgets.QCheckBox(Dialog) self.chk_copy = QtWidgets.QCheckBox(diag_route)
self.chk_copy.setObjectName("chk_copy") self.chk_copy.setObjectName("chk_copy")
self.layout_bottom.addWidget(self.chk_copy, 1, 0, 1, 1) self.layout_bottom.addWidget(self.chk_copy, 1, 0, 1, 1)
self.pushButton = QtWidgets.QPushButton(Dialog) self.btn_close = QtWidgets.QPushButton(diag_route)
self.pushButton.setObjectName("pushButton") self.btn_close.setObjectName("btn_close")
self.layout_bottom.addWidget(self.pushButton, 1, 1, 1, 1) self.layout_bottom.addWidget(self.btn_close, 1, 2, 1, 1)
self.btn_export = QtWidgets.QPushButton(diag_route)
self.btn_export.setObjectName("btn_export")
self.layout_bottom.addWidget(self.btn_export, 1, 1, 1, 1)
self.layout_main.addLayout(self.layout_bottom, 1, 0, 1, 1) self.layout_main.addLayout(self.layout_bottom, 1, 0, 1, 1)
self.retranslateUi(Dialog) self.retranslateUi(diag_route)
QtCore.QMetaObject.connectSlotsByName(Dialog) QtCore.QMetaObject.connectSlotsByName(diag_route)
def retranslateUi(self, Dialog): def retranslateUi(self, diag_route):
_translate = QtCore.QCoreApplication.translate _translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Route")) diag_route.setWindowTitle(_translate("diag_route", "Route"))
self.lst_route.headerItem().setText(0, _translate("Dialog", "Num")) self.lst_route.headerItem().setText(0, _translate("diag_route", "Num"))
self.lst_route.headerItem().setText(1, _translate("Dialog", "System")) self.lst_route.headerItem().setText(1, _translate("diag_route", "System"))
self.lst_route.headerItem().setText(2, _translate("Dialog", "Body")) self.lst_route.headerItem().setText(2, _translate("diag_route", "Body"))
self.lst_route.headerItem().setText(3, _translate("Dialog", "Distance (Ls)")) self.lst_route.headerItem().setText(3, _translate("diag_route", "Distance (Ls)"))
self.chk_copy.setText(_translate("Dialog", "Auto-copy next hop to clipboard")) self.chk_copy.setText(_translate("diag_route", "Auto-copy next hop to clipboard"))
self.pushButton.setText(_translate("Dialog", "Close")) self.btn_close.setText(_translate("diag_route", "Close"))
self.btn_export.setText(_translate("diag_route", "Export"))

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>Dialog</class> <class>diag_route</class>
<widget class="QDialog" name="Dialog"> <widget class="QDialog" name="diag_route">
<property name="windowModality"> <property name="windowModality">
<enum>Qt::WindowModal</enum> <enum>Qt::WindowModal</enum>
</property> </property>
@ -78,13 +78,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="2">
<widget class="QPushButton" name="pushButton"> <widget class="QPushButton" name="btn_close">
<property name="text"> <property name="text">
<string>Close</string> <string>Close</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1">
<widget class="QPushButton" name="btn_export">
<property name="text">
<string>Export</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>