feat(Router): finish implementing route computation progress display
This commit is contained in:
parent
935891c852
commit
93f655c7ce
3 changed files with 60 additions and 42 deletions
|
@ -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,
|
||||
|
|
|
@ -10,16 +10,16 @@
|
|||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
|
||||
|
||||
class Ui_Dialog(object):
|
||||
def setupUi(self, Dialog):
|
||||
Dialog.setObjectName("Dialog")
|
||||
Dialog.setWindowModality(QtCore.Qt.WindowModal)
|
||||
Dialog.resize(430, 300)
|
||||
self.layout_main = QtWidgets.QGridLayout(Dialog)
|
||||
class Ui_diag_route(object):
|
||||
def setupUi(self, diag_route):
|
||||
diag_route.setObjectName("diag_route")
|
||||
diag_route.setWindowModality(QtCore.Qt.WindowModal)
|
||||
diag_route.resize(430, 300)
|
||||
self.layout_main = QtWidgets.QGridLayout(diag_route)
|
||||
self.layout_main.setObjectName("layout_main")
|
||||
self.layout_top = QtWidgets.QGridLayout()
|
||||
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.setDefaultDropAction(QtCore.Qt.IgnoreAction)
|
||||
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_bottom = QtWidgets.QGridLayout()
|
||||
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.layout_bottom.addWidget(self.chk_copy, 1, 0, 1, 1)
|
||||
self.pushButton = QtWidgets.QPushButton(Dialog)
|
||||
self.pushButton.setObjectName("pushButton")
|
||||
self.layout_bottom.addWidget(self.pushButton, 1, 1, 1, 1)
|
||||
self.btn_close = QtWidgets.QPushButton(diag_route)
|
||||
self.btn_close.setObjectName("btn_close")
|
||||
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.retranslateUi(Dialog)
|
||||
QtCore.QMetaObject.connectSlotsByName(Dialog)
|
||||
self.retranslateUi(diag_route)
|
||||
QtCore.QMetaObject.connectSlotsByName(diag_route)
|
||||
|
||||
def retranslateUi(self, Dialog):
|
||||
def retranslateUi(self, diag_route):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
Dialog.setWindowTitle(_translate("Dialog", "Route"))
|
||||
self.lst_route.headerItem().setText(0, _translate("Dialog", "Num"))
|
||||
self.lst_route.headerItem().setText(1, _translate("Dialog", "System"))
|
||||
self.lst_route.headerItem().setText(2, _translate("Dialog", "Body"))
|
||||
self.lst_route.headerItem().setText(3, _translate("Dialog", "Distance (Ls)"))
|
||||
self.chk_copy.setText(_translate("Dialog", "Auto-copy next hop to clipboard"))
|
||||
self.pushButton.setText(_translate("Dialog", "Close"))
|
||||
diag_route.setWindowTitle(_translate("diag_route", "Route"))
|
||||
self.lst_route.headerItem().setText(0, _translate("diag_route", "Num"))
|
||||
self.lst_route.headerItem().setText(1, _translate("diag_route", "System"))
|
||||
self.lst_route.headerItem().setText(2, _translate("diag_route", "Body"))
|
||||
self.lst_route.headerItem().setText(3, _translate("diag_route", "Distance (Ls)"))
|
||||
self.chk_copy.setText(_translate("diag_route", "Auto-copy next hop to clipboard"))
|
||||
self.btn_close.setText(_translate("diag_route", "Close"))
|
||||
self.btn_export.setText(_translate("diag_route", "Export"))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<class>diag_route</class>
|
||||
<widget class="QDialog" name="diag_route">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::WindowModal</enum>
|
||||
</property>
|
||||
|
@ -78,13 +78,20 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="btn_close">
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="btn_export">
|
||||
<property name="text">
|
||||
<string>Export</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
Loading…
Reference in a new issue