diff --git a/CHANGELOG.md b/CHANGELOG.md index 9258caa..b3c63ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/pyleco_extras/gui/data_logger/data_logger.py b/pyleco_extras/gui/data_logger/data_logger.py index 4e35caa..2bf7790 100644 --- a/pyleco_extras/gui/data_logger/data_logger.py +++ b/pyleco_extras/gui/data_logger/data_logger.py @@ -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 @@ -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() @@ -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) diff --git a/pyleco_extras/gui/data_logger/data_logger_remote.py b/pyleco_extras/gui/data_logger/data_logger_remote.py index 886c092..18deb07 100644 --- a/pyleco_extras/gui/data_logger/data_logger_remote.py +++ b/pyleco_extras/gui/data_logger/data_logger_remote.py @@ -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) @@ -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) @@ -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: diff --git a/pyleco_extras/gui_utils/base_main_window.py b/pyleco_extras/gui_utils/base_main_window.py index 7e8753d..5a98b22 100644 --- a/pyleco_extras/gui_utils/base_main_window.py +++ b/pyleco_extras/gui_utils/base_main_window.py @@ -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):