From a0eda846821b650d82e47c926b855f771f3c22e1 Mon Sep 17 00:00:00 2001 From: Doyle Rowland Date: Sat, 5 Mar 2022 11:23:38 -0500 Subject: [PATCH 1/6] refactor: update do_log_debug to do_log_debug_msg in calls --- .../programdb_design_electric_record.py | 6 ++--- src/ramstk/models/dbtables/basetable.py | 18 +++++++------- .../dbtables/programdb_similar_item_table.py | 2 +- src/ramstk/views/gtk3/widgets/panel.py | 24 +++++++++---------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/ramstk/models/dbrecords/programdb_design_electric_record.py b/src/ramstk/models/dbrecords/programdb_design_electric_record.py index 3f2eeae65..924b72043 100644 --- a/src/ramstk/models/dbrecords/programdb_design_electric_record.py +++ b/src/ramstk/models/dbrecords/programdb_design_electric_record.py @@ -408,7 +408,7 @@ def do_calculate_current_ratio(self) -> None: ) except ZeroDivisionError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"Failed to calculate current ratio for hardware ID " @@ -430,7 +430,7 @@ def do_calculate_power_ratio(self) -> None: ) except ZeroDivisionError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"Failed to calculate power ratio for hardware ID " @@ -453,7 +453,7 @@ def do_calculate_voltage_ratio(self) -> None: ) except ZeroDivisionError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"Failed to calculate voltage ratio for hardware ID " diff --git a/src/ramstk/models/dbtables/basetable.py b/src/ramstk/models/dbtables/basetable.py index 8b07a7b63..59cb07e76 100644 --- a/src/ramstk/models/dbtables/basetable.py +++ b/src/ramstk/models/dbtables/basetable.py @@ -172,7 +172,7 @@ def do_delete(self, node_id: int) -> None: # sourcery skip: extract-method ) except (AttributeError, DataAccessError, NodeIDAbsentError): pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"Attempted to delete non-existent " @@ -194,7 +194,7 @@ def do_get_attributes(self, node_id: int) -> None: ) except AttributeError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"No attributes found for record ID {node_id} in {self._tag} table." @@ -245,13 +245,13 @@ def do_insert( ) except DataAccessError as _error: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=str(_error.msg), ) except NodeIDAbsentError as _error: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=str(_error), ) @@ -274,7 +274,7 @@ def do_select(self, node_id: Any) -> Any: TypeError, ): pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"No data package for node ID {node_id} in module {self._tag}." @@ -341,7 +341,7 @@ def do_set_attributes( _attributes = self.do_select(node_id).get_attributes() except (AttributeError, KeyError): pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"No data package for node ID {node_id} in module {self._tag}." @@ -405,7 +405,7 @@ def do_update(self, node_id: int) -> None: ) except AttributeError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"Attempted to save non-existent {self._tag.replace('_', ' ')} " @@ -414,7 +414,7 @@ def do_update(self, node_id: int) -> None: ) except KeyError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"No data package found for {self._tag.replace('_', ' ')} ID " @@ -430,7 +430,7 @@ def do_update(self, node_id: int) -> None: else: _error_msg = _(f"Attempting to update the root node {node_id}.") pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_error_msg, ) diff --git a/src/ramstk/models/dbtables/programdb_similar_item_table.py b/src/ramstk/models/dbtables/programdb_similar_item_table.py index 6bcdf514c..e4bec9aa2 100644 --- a/src/ramstk/models/dbtables/programdb_similar_item_table.py +++ b/src/ramstk/models/dbtables/programdb_similar_item_table.py @@ -116,7 +116,7 @@ def do_calculate_similar_item(self, node_id: int) -> None: ) except KeyError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"Failed to calculate similar item reliability for hardware ID " diff --git a/src/ramstk/views/gtk3/widgets/panel.py b/src/ramstk/views/gtk3/widgets/panel.py index fb3127946..c1cd9b3d8 100644 --- a/src/ramstk/views/gtk3/widgets/panel.py +++ b/src/ramstk/views/gtk3/widgets/panel.py @@ -353,7 +353,7 @@ def on_changed_combo( ) except (KeyError, ValueError): pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"An error occurred while editing {self._tag} data for record ID " @@ -485,7 +485,7 @@ def on_edit(self, node_id: List[int], package: Dict[str, Any]) -> None: _widget.do_update(_value, _signal) # type: ignore except KeyError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"An error occurred while updating {self._tag} data for record ID " @@ -495,7 +495,7 @@ def on_edit(self, node_id: List[int], package: Dict[str, Any]) -> None: ) except TypeError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"An error occurred while updating {self._tag} data for record ID " @@ -530,7 +530,7 @@ def on_toggled( ) except KeyError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"An error occurred while updating {self._tag} data for record ID " @@ -562,7 +562,7 @@ def __do_read_text( _new_text = str(entry.do_get_text()) except (KeyError, ValueError): pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"An error occurred while reading {self._tag} data for record ID " @@ -766,7 +766,7 @@ def do_load_panel(self, tree: treelib.Tree) -> None: self.show_all() except TypeError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"An error occurred while loading {self._tag} data for Record ID " @@ -776,7 +776,7 @@ def do_load_panel(self, tree: treelib.Tree) -> None: ) except ValueError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"An error occurred while loading {self._tag} data for Record ID " @@ -916,7 +916,7 @@ def do_refresh_tree(self, node_id: int, package: Dict[str, Any]) -> None: _model.set_value(_row, _position, _value) except KeyError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"An error occurred while refreshing {self._tag} data for Record " @@ -926,7 +926,7 @@ def do_refresh_tree(self, node_id: int, package: Dict[str, Any]) -> None: ) except TypeError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"An error occurred while refreshing {self._tag} data " @@ -1068,7 +1068,7 @@ def on_cell_change( ) except KeyError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"An error occurred while editing {self._tag} data for record ID " @@ -1110,7 +1110,7 @@ def on_cell_edit( ) except KeyError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"An error occurred while editing {self._tag} data for record ID " @@ -1144,7 +1144,7 @@ def on_cell_toggled( ) except KeyError: pub.sendMessage( - "do_log_debug", + "do_log_debug_msg", logger_name="DEBUG", message=_( f"An error occurred while editing {self._tag} data for record ID " From 81dd9bb5f53d485b7c2e9406f08a61c054481e05 Mon Sep 17 00:00:00 2001 From: Doyle Rowland Date: Sat, 5 Mar 2022 11:25:20 -0500 Subject: [PATCH 2/6] refactor: update information to info in logger calls --- src/ramstk/views/gtk3/assistants/project.py | 2 +- src/ramstk/views/gtk3/hardware/view.py | 6 +++--- tests/views/gtk3/widgets/test_dialog.py | 9 +++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ramstk/views/gtk3/assistants/project.py b/src/ramstk/views/gtk3/assistants/project.py index 5f183034b..03ddd6cca 100644 --- a/src/ramstk/views/gtk3/assistants/project.py +++ b/src/ramstk/views/gtk3/assistants/project.py @@ -222,7 +222,7 @@ def __project_is_open(self) -> None: ) _dialog = RAMSTKMessageDialog(parent=self._parent) _dialog.do_set_message(_prompt) - _dialog.do_set_message_type("information") + _dialog.do_set_message_type("info") if _dialog.run() == Gtk.ResponseType.OK: _dialog.destroy() diff --git a/src/ramstk/views/gtk3/hardware/view.py b/src/ramstk/views/gtk3/hardware/view.py index b2e730fe9..919e841f3 100644 --- a/src/ramstk/views/gtk3/hardware/view.py +++ b/src/ramstk/views/gtk3/hardware/view.py @@ -223,7 +223,7 @@ def _do_request_insert_child(self, __button: Gtk.ToolButton) -> Any: ) _dialog = super().do_raise_dialog(parent=_parent) _dialog.do_set_message(message=_message) - _dialog.do_set_message_type(message_type="information") + _dialog.do_set_message_type(message_type="info") _dialog.do_run() _dialog.do_destroy() return @@ -273,7 +273,7 @@ def _do_request_insert_part(self, __button: Gtk.ToolButton) -> None: ) _dialog = super().do_raise_dialog(parent=_parent) _dialog.do_set_message(message=_message) - _dialog.do_set_message_type(message_type="information") + _dialog.do_set_message_type(message_type="info") _dialog.do_run() _dialog.do_destroy() return @@ -325,7 +325,7 @@ def _do_request_insert_sibling(self, __button: Gtk.ToolButton) -> Any: ) _dialog = super().do_raise_dialog(parent=_parent) _dialog.do_set_message(message=_message) - _dialog.do_set_message_type(message_type="information") + _dialog.do_set_message_type(message_type="info") _dialog.do_run() _dialog.do_destroy() return diff --git a/tests/views/gtk3/widgets/test_dialog.py b/tests/views/gtk3/widgets/test_dialog.py index 6b8182b0d..d2f31f359 100644 --- a/tests/views/gtk3/widgets/test_dialog.py +++ b/tests/views/gtk3/widgets/test_dialog.py @@ -89,10 +89,11 @@ def test_create_error_message_dialog(self): assert DUT.get_property("text") == ( "Test Prompt Check the error log for additional information " "(if any). Please e-mail bugs@reliaqual.com " + "HARDWARE:%20%0d%0a%0d%0aYOUR OS:%20%0d%0a%0d%0aDETAILED PROBLEM " + "DESCRIPTION:%20%0d%0a'>bugs@reliaqual.com " "with a detailed description of the problem, the workflow you are " "using and the error log attached if the problem persists." ) @@ -116,7 +117,7 @@ def test_create_info_message_dialog(self): """__init__() should create an info type RAMSTKMessageDialog.""" DUT = RAMSTKMessageDialog() DUT.do_set_message("Test Info Prompt") - DUT.do_set_message_type("information") + DUT.do_set_message_type("info") assert isinstance(DUT, RAMSTKMessageDialog) assert DUT.get_destroy_with_parent() From b4eda2f8595eaa52cccec6f51bd58ffedb2f10c9 Mon Sep 17 00:00:00 2001 From: Doyle Rowland Date: Sat, 5 Mar 2022 11:28:04 -0500 Subject: [PATCH 3/6] refactor: add DEBUG as message dialog type with MessageType as OTHER --- src/ramstk/views/gtk3/widgets/dialog.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ramstk/views/gtk3/widgets/dialog.py b/src/ramstk/views/gtk3/widgets/dialog.py index ffebef407..1208aec51 100644 --- a/src/ramstk/views/gtk3/widgets/dialog.py +++ b/src/ramstk/views/gtk3/widgets/dialog.py @@ -469,8 +469,9 @@ def do_set_message_type(self, message_type: str = "error") -> None: _dic_message_type = { "error": Gtk.MessageType.ERROR, "warning": Gtk.MessageType.WARNING, - "information": Gtk.MessageType.INFO, + "info": Gtk.MessageType.INFO, "question": Gtk.MessageType.QUESTION, + "debug": Gtk.MessageType.OTHER, } _prompt = self.get_property("text") @@ -489,7 +490,7 @@ def do_set_message_type(self, message_type: str = "error") -> None: self.set_markup(_prompt) self.set_property("message-type", _dic_message_type[message_type]) - if message_type in {"error", "warning", "information"}: + if message_type in {"error", "warning", "info", "debug"}: self.add_buttons("_OK", Gtk.ResponseType.OK) elif message_type == "question": self.add_buttons( From a606a0bc42d4b6b900fb87dc40cabe79240170e0 Mon Sep 17 00:00:00 2001 From: Doyle Rowland Date: Sat, 5 Mar 2022 11:28:50 -0500 Subject: [PATCH 4/6] refactor: add method to raise a message dialog in response to logger messages --- src/ramstk/views/gtk3/desktop.py | 311 ++++++++++++++++++------------- 1 file changed, 179 insertions(+), 132 deletions(-) diff --git a/src/ramstk/views/gtk3/desktop.py b/src/ramstk/views/gtk3/desktop.py index ed39d262a..67c9d13f6 100644 --- a/src/ramstk/views/gtk3/desktop.py +++ b/src/ramstk/views/gtk3/desktop.py @@ -3,12 +3,12 @@ # ramstk.views.gtk3.desktop.py is part of The RAMSTK Project # # All rights reserved. -# Copyright 2007 - 2020 Doyle Rowland doyle.rowland reliaqual com -"""The RAMSTK GTK3 basebook.""" +# Copyright since 2007 Doyle "weibulguy" Rowland doyle.rowland reliaqual com +"""The RAMSTK GTK3 desktop.""" # Standard Library Imports import locale -from typing import List, TypeVar +from typing import Dict, List, TypeVar # Third Party Imports # noinspection PyPackageRequirements @@ -27,6 +27,7 @@ from ramstk.views.gtk3.books import RAMSTKModuleBook, RAMSTKWorkBook from ramstk.views.gtk3.options import OptionsDialog from ramstk.views.gtk3.preferences import PreferencesDialog +from ramstk.views.gtk3.widgets import RAMSTKMessageDialog Tconfiguration = TypeVar( "Tconfiguration", RAMSTKUserConfiguration, RAMSTKSiteConfiguration @@ -143,9 +144,62 @@ def __init__(self, configuration: Tconfiguration, logger: RAMSTKLogManager) -> N self.__set_callbacks() # Subscribe to PyPubSub messages. - pub.subscribe(self._on_request_open, "request_open_program ") - pub.subscribe(self._on_select, "request_set_title") - pub.subscribe(self._do_set_status, "request_set_status") + pub.subscribe( + self._on_request_open, + "request_open_program", + ) + pub.subscribe( + self._on_select, + "request_set_title", + ) + pub.subscribe( + self._do_set_status, + "request_set_status", + ) + pub.subscribe( + self._do_raise_message_dialog, + "do_log_critical_msg", + ) + pub.subscribe( + self._do_raise_message_dialog, + "do_log_debug_msg", + ) + pub.subscribe( + self._do_raise_message_dialog, + "do_log_error_msg", + ) + pub.subscribe( + self._do_raise_message_dialog, + "do_log_warning_msg", + ) + + def _do_raise_message_dialog(self, logger_name: str, message: str) -> None: + """Raise a message dialog to alert the user to an issue. + + :param logger_name: the name of the logger the message is indtended for. + The message will only be presented to the user if it's the same or higher + than the user selected log level. + :param message: the info, debug, error, etc. message. + :return: None + :rtype: None + """ + self.statusbar.push(2, message) + if logger_name == self.RAMSTK_USER_CONFIGURATION.RAMSTK_LOGLEVEL: + _dialog = RAMSTKMessageDialog(parent=self) + _dialog.do_set_message(message) + _dialog.do_set_message_type(logger_name.lower()) + if _dialog.do_run() == Gtk.ResponseType.OK: + _dialog.do_destroy() + + @staticmethod + def _do_request_close_project(__widget: Gtk.Widget) -> None: + """Request to close the open RAMSTK Program. + + :param Gtk.Widget __widget: the Gtk.Widget() that called this method. + :return: None + :rtype: None + """ + pub.sendMessage("request_close_project") def _do_request_options_assistant(self, __widget: Gtk.ImageMenuItem) -> None: """Request the EditOptions assistant be launched. @@ -188,6 +242,125 @@ def _do_request_preferences_assistant(self, __widget: Gtk.ImageMenuItem) -> None _assistant.show_all() + # noinspection PyDeepBugsSwappedArgs + def _do_request_save_project(self, widget: Gtk.Widget, end: bool = False) -> None: + """Request to save the open RAMSTK Program. + + :param Gtk.Widget widget: the Gtk.Widget() that called this method. + :keyword bool end: indicates whether or not to quit RAMSTK after saving + the project. + :return: None + :rtype: None + """ + _message = _("Saving Program Database {0:s}").format( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_PROG_INFO["database"] + ) + self.statusbar.push(2, _message) + + pub.sendMessage("request_save_project") + + if end: + destroy(widget) + + def _do_set_status(self, status: str) -> None: + """Set the status message. + + :param status: the status message to display. + :return: None + :rtype: None + """ + self.statusbar.push(1, status) + + def _do_set_status_icon(self, connected: bool = False) -> None: + """Set the status icon in the system tay to indicate connection status. + + :param bool connected: whether or not RAMSTK is connected to a program + database. + :return: None + :rtype: None + """ + _pixbuf: GdkPixbuf.Pixbuf = GdkPixbuf.Pixbuf() + + if connected: + _icon: str = ( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_ICON_DIR + + "/32x32/db-connected.png" + ) + _tooltip: str = _( + f"RAMSTK is connected to program database " + f"{self.RAMSTK_USER_CONFIGURATION.RAMSTK_PROG_INFO['database']}." + ) + else: + _icon = ( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_ICON_DIR + + "/32x32/db-disconnected.png" + ) + _tooltip = _("RAMSTK is not currently connected to a project database.") + + self.icoStatus.set_from_pixbuf(_pixbuf.new_from_file_at_size(_icon, 22, 22)) + self.icoStatus.set_tooltip_markup(_tooltip) + + def _on_button_press(self, __book: object, event: Gdk.EventButton) -> None: + """Handle mouse clicks on the RAMSTKBook. + + :param __book: the RAMSTKBook that was 'clicked'. + :param event: the Gdk.Event() that called this method (the + important attribute is which mouse button was clicked). + + * 1 = left + * 2 = scrollwheel + * 3 = right + * 4 = forward + * 5 = backward + * 8 = + * 9 = + + :type event: :class:`Gdk.Event` + :return: None + :rtype: None + """ + if event.button == 1: + self.present() + + # pylint: disable=unused-argument + # noinspection PyUnusedLocal + def _on_request_open(self, program_db: object, database: Dict[str, str]) -> None: + """Set the status bar and update the progress bar. + + :param program_db: the BaseDatabase used for the ProgramDB. Unused in this + method, but required as it is part of the message payload. + :param database: the dict containing the database connection information. + :return: None + :rtype: None + """ + _message = _( + f"Opening Program Database {database['database']} on server " + f"{database['host']}" + ) + # noinspection PyDeepBugsSwappedArgs + self.statusbar.push(1, _message) + + _message = _(f"Analyzing {database['database']} on server {database['host']}") + # noinspection PyDeepBugsSwappedArgs + self.statusbar.push(1, _message) + self.set_title(_message) + + def _on_select(self, title: str) -> None: + """Respond to load the Work View Gtk.Notebook() widgets. + + This method handles the results of the an individual module's + _on_select() method. It sets the title of the RAMSTK Work Book and + raises an error dialog if needed. + + :return: None + :rtype: None + """ + try: + self.set_title(title) + except AttributeError as _error: + self.RAMSTK_LOGGER.do_log_exception(__name__, _error) + self.do_raise_dialog(severity="warning", user_msg=_error) + def __make_menu(self) -> None: """Make the menu for the Module Book. @@ -447,129 +620,3 @@ def __set_properties(self) -> None: _height = 15 * self._height / 16 self.resize(_width, _height) self.move(50, 5) - - @staticmethod - def _do_request_close_project(__widget: Gtk.Widget) -> None: - """Request to close the open RAMSTK Program. - - :param Gtk.Widget __widget: the Gtk.Widget() that called this method. - :return: None - :rtype: None - """ - pub.sendMessage("request_close_project") - - # noinspection PyDeepBugsSwappedArgs - def _do_request_save_project(self, widget: Gtk.Widget, end: bool = False) -> None: - """Request to save the open RAMSTK Program. - - :param Gtk.Widget widget: the Gtk.Widget() that called this method. - :keyword bool end: indicates whether or not to quit RAMSTK after saving - the project. - :return: None - :rtype: None - """ - _message = _("Saving Program Database {0:s}").format( - self.RAMSTK_USER_CONFIGURATION.RAMSTK_PROG_INFO["database"] - ) - self.statusbar.push(2, _message) - - pub.sendMessage("request_save_project") - - if end: - destroy(widget) - - def _do_set_status(self, status: str) -> None: - """Set the status message. - - :param status: the status message to display. - :return: None - :rtype: None - """ - self.statusbar.push(1, status) - - def _do_set_status_icon(self, connected: bool = False) -> None: - """Set the status icon in the system tay to indicate connection status. - - :param bool connected: whether or not RAMSTK is connected to a program - database. - :return: None - :rtype: None - """ - _pixbuf: GdkPixbuf.Pixbuf = GdkPixbuf.Pixbuf() - - if connected: - _icon: str = ( - self.RAMSTK_USER_CONFIGURATION.RAMSTK_ICON_DIR - + "/32x32/db-connected.png" - ) - _tooltip: str = _( - f"RAMSTK is connected to program database " - f"{self.RAMSTK_USER_CONFIGURATION.RAMSTK_PROG_INFO['database']}." - ) - else: - _icon = ( - self.RAMSTK_USER_CONFIGURATION.RAMSTK_ICON_DIR - + "/32x32/db-disconnected.png" - ) - _tooltip = _("RAMSTK is not currently connected to a project database.") - - self.icoStatus.set_from_pixbuf(_pixbuf.new_from_file_at_size(_icon, 22, 22)) - self.icoStatus.set_tooltip_markup(_tooltip) - - def _on_button_press(self, __book: object, event: Gdk.EventButton) -> None: - """Handle mouse clicks on the RAMSTKBook. - - :param __book: the RAMSTKBook that was 'clicked'. - :param event: the Gdk.Event() that called this method (the - important attribute is which mouse button was clicked). - - * 1 = left - * 2 = scrollwheel - * 3 = right - * 4 = forward - * 5 = backward - * 8 = - * 9 = - - :type event: :class:`Gdk.Event` - :return: None - :rtype: None - """ - if event.button == 1: - self.present() - - def _on_request_open(self) -> None: - """Set the status bar and update the progress bar. - - :return: None - :rtype: None - """ - _message = _( - f"Opening Program Database " - f"{self.RAMSTK_USER_CONFIGURATION.RAMSTK_PROG_INFO['database']}" - ) - - # noinspection PyDeepBugsSwappedArgs - self.statusbar.push(1, _message) - self.set_title( - _( - f"RAMSTK - Analyzing " - f"{self.RAMSTK_USER_CONFIGURATION.RAMSTK_PROG_INFO['database']}" - ) - ) - - def _on_select(self, title: str) -> None: - """Respond to load the Work View Gtk.Notebook() widgets. - - This method handles the results of the an individual module's - _on_select() method. It sets the title of the RAMSTK Work Book and - raises an error dialog if needed. - - :return: None - :rtype: None - """ - try: - self.set_title(title) - except AttributeError as _error: - self.RAMSTK_LOGGER.do_log_exception(__name__, _error) - self.do_raise_dialog(severity="warning", user_msg=_error) From a4d26699bbf32671d72efc74dbfa9570b13e10aa Mon Sep 17 00:00:00 2001 From: Doyle Rowland Date: Sat, 5 Mar 2022 11:48:10 -0500 Subject: [PATCH 5/6] fix: add message dialog notifying user why the Revision module was default selected --- src/ramstk/views/gtk3/books/modulebook.py | 88 ++++++++++++++--------- 1 file changed, 54 insertions(+), 34 deletions(-) diff --git a/src/ramstk/views/gtk3/books/modulebook.py b/src/ramstk/views/gtk3/books/modulebook.py index 8ff9dc785..ac23fb889 100644 --- a/src/ramstk/views/gtk3/books/modulebook.py +++ b/src/ramstk/views/gtk3/books/modulebook.py @@ -6,6 +6,9 @@ # Copyright since 2007 Doyle "weibullguy" Rowland doyle.rowland reliaqual com """RAMSTK Module Book Module.""" +# Standard Library Imports +from typing import Dict + # Third Party Imports from pubsub import pub from treelib import Tree @@ -13,7 +16,7 @@ # RAMSTK Package Imports from ramstk.configuration import RAMSTKUserConfiguration from ramstk.logger import RAMSTKLogManager -from ramstk.views.gtk3 import Gtk +from ramstk.views.gtk3 import Gtk, _ from ramstk.views.gtk3.function import FunctionModuleView from ramstk.views.gtk3.hardware import HardwareModuleView from ramstk.views.gtk3.requirement import RequirementModuleView @@ -44,7 +47,7 @@ def __init__( RAMSTKBaseBook.__init__(self, configuration) # Initialize private dictionary attributes. - self._dic_module_views = { + self._dic_module_views: Dict[str, object] = { "revision": RevisionModuleView(configuration, logger), "function": FunctionModuleView(configuration, logger), "requirement": RequirementModuleView(configuration, logger), @@ -68,35 +71,13 @@ def __init__( self.__set_callbacks() # Subscribe to PyPubSub messages. - pub.subscribe(self._on_open, "succeed_retrieve_all_revision") - pub.subscribe(self._on_close, "succeed_closed_program") - - def __make_ui(self) -> None: - """Build the user interface. - - :return: None - :rtype: None - """ - self.insert_page( - self._dic_module_views["revision"], - tab_label=self._dic_module_views["revision"].hbx_tab_label, - position=0, + pub.subscribe( + self._on_open, + "succeed_retrieve_all_revision", ) - - self.show_all() - self.set_current_page(0) - - def __set_callbacks(self) -> None: - """Set callback methods for the RAMSTKModuleBook and widgets. - - :return: None - :rtype: None - """ - self.dic_handler_id["select-page"] = self.connect( - "select-page", self._on_switch_page - ) - self.dic_handler_id["switch-page"] = self.connect( - "switch-page", self._on_switch_page + pub.subscribe( + self._on_close, + "succeed_closed_program", ) def _on_close(self) -> None: @@ -108,11 +89,11 @@ def _on_close(self) -> None: # Remove all the non-Revision pages. _n_pages = self.get_n_pages() # pylint: disable=unused-variable - for _page in range(_n_pages - 1): + for __ in range(_n_pages - 1): self.remove_page(-1) # Clear the Revision page treeview. - _model = self._dic_module_views["revision"].treeview.get_model() + _model = self._dic_module_views["revision"].treeview.get_model() # type: ignore _model.clear() # pylint: disable=unused-argument @@ -133,7 +114,9 @@ def _on_open(self, tree: Tree) -> None: try: _module = self._dic_module_views[_mkey] self.insert_page( - _module, tab_label=_module.hbx_tab_label, position=_key + _module, + tab_label=_module.hbx_tab_label, # type: ignore + position=_key, ) except KeyError: pass @@ -163,10 +146,47 @@ def _on_switch_page( :return: None :rtype: None """ - # See ISSUE #1005 try: _module = self.RAMSTK_USER_CONFIGURATION.RAMSTK_PAGE_NUMBER[page_num] except KeyError: _module = "revision" + pub.sendMessage( + "do_log_debug_msg", + logger_name="DEBUG", + message=_( + f"Page number {page_num} is not active in this Program. " + f"Active page numbers and their associated work flow " + f"module are {self.RAMSTK_USER_CONFIGURATION.RAMSTK_PAGE_NUMBER}. " + f"Selecting the Revision work flow module by default." + ), + ) pub.sendMessage("mvwSwitchedPage", module=_module) + + def __make_ui(self) -> None: + """Build the user interface. + + :return: None + :rtype: None + """ + self.insert_page( + self._dic_module_views["revision"], + tab_label=self._dic_module_views["revision"].hbx_tab_label, # type: ignore + position=0, + ) + + self.show_all() + self.set_current_page(0) + + def __set_callbacks(self) -> None: + """Set callback methods for the RAMSTKModuleBook and widgets. + + :return: None + :rtype: None + """ + self.dic_handler_id["select-page"] = self.connect( + "select-page", self._on_switch_page + ) + self.dic_handler_id["switch-page"] = self.connect( + "switch-page", self._on_switch_page + ) From e09d652d1838b7eb94da3221975cda48ef64a9f7 Mon Sep 17 00:00:00 2001 From: Doyle Rowland Date: Sat, 5 Mar 2022 11:48:39 -0500 Subject: [PATCH 6/6] style: update stub file --- src/ramstk/views/gtk3/books/modulebook.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ramstk/views/gtk3/books/modulebook.pyi b/src/ramstk/views/gtk3/books/modulebook.pyi index c8da0fa57..7ffa46ba5 100644 --- a/src/ramstk/views/gtk3/books/modulebook.pyi +++ b/src/ramstk/views/gtk3/books/modulebook.pyi @@ -1,5 +1,5 @@ # Standard Library Imports -from typing import Any +from typing import Dict # Third Party Imports from treelib import Tree as Tree @@ -13,8 +13,8 @@ from ramstk.views.gtk3.revision import RevisionModuleView as RevisionModuleView from ramstk.views.gtk3.widgets import RAMSTKBaseBook as RAMSTKBaseBook class RAMSTKModuleBook(RAMSTKBaseBook): - _dic_module_views: Any - icoStatus: Any + _dic_module_views: Dict[str, object] + icoStatus: Gtk.StatusIcon def __init__( self, configuration: RAMSTKUserConfiguration, logger: RAMSTKLogManager ) -> None: ...