Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Add show_status_bar_message method.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktBurger committed Apr 9, 2024
1 parent 8aa7cd3 commit 5ab58be
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

- **Breaking:** rename `MotorController` to `TMCMotorActor` and `MotorDirector` to `TMCMotorDirector`

### Added

- `BaseMainWindow` has `show_status_bar_message` method.
- DataLoggerGUI and its variants have now methods to access the data, which allows adding extra data.

### Fixed

- Fix DataLogger multiplot window to show value.
Expand Down
8 changes: 4 additions & 4 deletions pyleco_extras/gui/data_logger/data_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def save_data(self, meta: Optional[dict] = None, suffix: str = "") -> str:
"""
# Preparation.
self.leSavedName.setText("Saving...")
self.statusBar().showMessage("Saving...") # type: ignore
self.show_status_bar_message("Saving...")
settings = QtCore.QSettings()
folder = settings.value("savePath", type=str)
self.listener.message_handler.directory = folder
Expand All @@ -144,13 +144,13 @@ def save_data(self, meta: Optional[dict] = None, suffix: str = "") -> str:
except Exception as exc:
log.exception("Some type error during saving occurred.", exc_info=exc)
self.leSavedName.setText("Error")
self.statusBar().showMessage(f"Writing failed due to Error. {exc}", 5000) # type: ignore
self.show_status_bar_message(f"Writing failed due to Error. {exc}", 5000)
raise
else:
# Indicate the name.
log.info(f"Saved data to '{folder}/{file_name}'.")
self.leSavedName.setText(file_name)
self.statusBar().showMessage(f"Saved data to '{folder}/{file_name}'.", 5000) # type: ignore
self.show_status_bar_message(f"Saved data to '{folder}/{file_name}'.", 5000)
return file_name

@pyqtSlot()
Expand All @@ -175,7 +175,7 @@ def start(self) -> None:
value_repeating=self.value_repeating,
)
except ServerError as exc:
self.statusBar().showMessage(f"Communication error: {exc.rpc_error.message}", 3000) # type: ignore
self.show_status_bar_message(f"Communication error: {exc.rpc_error.message}", 3000)
except (ConnectionError, TimeoutError) as exc:
log.exception("set property communication error", exc_info=exc)

Expand Down
12 changes: 3 additions & 9 deletions pyleco_extras/gui/data_logger/data_logger_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ def read_configuration(self) -> dict[str, Any]:
config = self.communicator.ask_rpc(receiver=self.remote, method="get_configuration")
length = self.communicator.ask_rpc(receiver=self.remote, method="get_list_length")
except ServerError as exc:
self.statusBar().showMessage( # type: ignore
f"Communication error: {exc.rpc_error.message}", 10000
)
self.show_status_bar_message(f"Communication error: {exc.rpc_error.message}", 10000)
return {}
except Exception as exc:
log.exception("Getting configuration failed.", exc_info=exc)
Expand All @@ -124,9 +122,7 @@ def set_properties(self, properties: dict[str, Any]) -> None:
receiver=self.remote, method="set_configuration", configuration=properties
)
except ServerError as exc:
self.statusBar().showMessage( # type: ignore
f"Communication error: {exc.rpc_error.message}", 3000
)
self.show_status_bar_message(f"Communication error: {exc.rpc_error.message}", 3000)
except (ConnectionError, TimeoutError) as exc:
log.exception("set property communication error", exc_info=exc)

Expand Down Expand Up @@ -211,9 +207,7 @@ def saveDataClicked(self) -> None:
try:
value = self.director.save_data()
except ServerError as exc:
self.statusBar().showMessage( # type: ignore
f"Communication error: {exc.rpc_error.message}", 3000
)
self.show_status_bar_message(f"Communication error: {exc.rpc_error.message}", 3000)
except Exception as exc:
log.exception("saveDataClicked", exc_info=exc)
else:
Expand Down
16 changes: 11 additions & 5 deletions pyleco_extras/gui_utils/base_main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,25 @@ def stop_listen(self) -> None:
"""Stop to listen for incoming messages."""
self.listener.stop_listen()

# LECO slots
@Slot(Message)
def message_received(self, message: Message):
def message_received(self, message: Message) -> None:
"""Handle a message received (either a response or unsolicited)."""
log.warning(f"Received an unhandled message: {message}")

# @Slot(str)
def show_namespace_information(self, full_name: str):
@Slot(str)
def show_namespace_information(self, full_name: str) -> None:
"""Show information regarding the namespace."""
if "." in full_name:
namespace = full_name.split(".")[0]
self.statusBar().showMessage(f"Signed in to namespace '{namespace}'.", 5000) # type: ignore # noqa
self.show_status_bar_message(f"Signed in to namespace '{namespace}'.", 5000)
else:
self.statusBar().showMessage("Not signed in.", 5000) # type: ignore
self.show_status_bar_message("Not signed in.", 5000)

# Generic methods
def show_status_bar_message(self, message: str, msecs: int = 0) -> None:
"""Show `message` in the statusbar for `timeout` ms (0 means until next message)."""
self.statusBar().showMessage(message=message, msecs=msecs)


class LECOBaseMainWindowDesigner(_LECOBaseMainWindow):
Expand Down

0 comments on commit 5ab58be

Please sign in to comment.