Skip to content

Commit

Permalink
Restart to fetch dataset name list when connection is lost (#272)
Browse files Browse the repository at this point in the history
This closes #269.

When the connection is lost, the "restart" button is enabled.

<img width="400"
src="https://github.com/snu-quiqcl/iquip/assets/76851886/a8a3a9e4-2c61-426c-874d-0c8451379e68">
  • Loading branch information
BECATRUE authored Apr 3, 2024
2 parents be70741 + f6ab306 commit d75120b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[MASTER]
extension-pkg-whitelist=PyQt5

[SIMILARITIES]
min-similarity-lines=10

[BASIC]
argument-rgx=_?_?(?:(?:[a-z0-9]+(?:_[a-z0-9]+)*_?_?)|(?:[a-z0-9]+(?:[A-Z][a-z0-9]*)*))$
attr-rgx=_?_?(?:(?:[a-z0-9]+(?:_[a-z0-9]+)*_?_?)|(?:[a-z0-9]+(?:[A-Z][a-z0-9]*)*))$
Expand Down
24 changes: 22 additions & 2 deletions iquip/apps/dataviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ class _RealtimePart(QWidget):
it is disabled. It should be manually enabled after doing proper works.
periodSpinBox: Spinbox for period of fetching a dataset.
label: Status label for showing status including errors.
restartButton: Button for restarting to fetch dataset name list. Once the button is clicked,
it is disabled. It will be enabled once the thread fetching dataset name list is finished.
Signals:
syncToggled(checked): Synchronize button is clicked with the current
Expand All @@ -314,16 +316,20 @@ def __init__(self, parent: Optional[QWidget] = None):
self.periodSpinBox.setDecimals(1)
self.periodSpinBox.setValue(1)
self.label = QLabel(self)
self.restartButton = QPushButton("Restart", self)
self.restartButton.setEnabled(False)
layout = QHBoxLayout(self)
layout.addWidget(QLabel("Sync:", self))
layout.addWidget(self.syncButton)
layout.addWidget(self.periodSpinBox)
layout.addWidget(self.label)
layout.addStretch()
layout.addWidget(self.restartButton)
# signal connection
self.syncButton.toggled.connect(self._buttonToggled)
self.syncButton.clicked.connect(functools.partial(self.syncButton.setEnabled, False))
self.syncButton.clicked.connect(self.syncToggled)
self.restartButton.clicked.connect(functools.partial(self.restartButton.setEnabled, False))

def setStatus(
self,
Expand Down Expand Up @@ -891,9 +897,15 @@ def run(self):
"""Overridden."""
try:
self.websocket = connect(self.url)
for response in self.websocket:
while True:
try:
response = self.websocket.recv(5)
except TimeoutError:
if self.websocket.ping().wait(5):
continue
break # connection is lost
self.fetched.emit(filter_dataset_list(json.loads(response)))
except WebSocketException:
except Exception: # pylint: disable=broad-exception-caught
logger.exception("Failed to fetch the dataset name list.")


Expand Down Expand Up @@ -1095,6 +1107,7 @@ def __init__(self, name: str, parent: Optional[QObject] = None):
for buttonId in SourceWidget.ButtonId)
# signal connection
realtimePart.syncToggled.connect(self._toggleSync)
realtimePart.restartButton.clicked.connect(self.startRealtimeDatasetListThread)
remotePart.dateHourChanged.connect(self.startRidListOfDateHourThread)
remotePart.ridClicked.connect(self.startRemoteListThread)
self.frame.sourceWidget.modeClicked.connect(self.switchSourceMode)
Expand Down Expand Up @@ -1123,11 +1136,18 @@ def switchSourceMode(self, buttonId: int):

def startRealtimeDatasetListThread(self):
"""Creates and starts a new _RealtimeListThread instance."""
realtimePart: _RealtimePart = self.frame.sourceWidget.stack.widget(
SourceWidget.ButtonId.REALTIME
)
self.realtimeListThread = _RealtimeListThread(
self.constants.proxy_ip, # pylint: disable=no-member
self.constants.proxy_port, # pylint: disable=no-member
)
self.realtimeListThread.fetched.connect(self._updateDatasetBox, type=Qt.QueuedConnection)
self.realtimeListThread.finished.connect(
functools.partial(realtimePart.restartButton.setEnabled, True),
type=Qt.QueuedConnection
)
self.realtimeListThread.finished.connect(self.realtimeListThread.deleteLater)
self.realtimeListThread.start()

Expand Down

0 comments on commit d75120b

Please sign in to comment.