Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: raise dialog to inform user of issues encountered while running application #1023

Merged
merged 6 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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 "
Expand All @@ -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 "
Expand Down
18 changes: 9 additions & 9 deletions src/ramstk/models/dbtables/basetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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."
Expand Down Expand Up @@ -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),
)
Expand All @@ -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}."
Expand Down Expand Up @@ -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}."
Expand Down Expand Up @@ -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('_', ' ')} "
Expand All @@ -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 "
Expand All @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion src/ramstk/models/dbtables/programdb_similar_item_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
2 changes: 1 addition & 1 deletion src/ramstk/views/gtk3/assistants/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
88 changes: 54 additions & 34 deletions src/ramstk/views/gtk3/books/modulebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
# Copyright since 2007 Doyle "weibullguy" Rowland doyle.rowland <AT> reliaqual <DOT> com
"""RAMSTK Module Book Module."""

# Standard Library Imports
from typing import Dict

# Third Party Imports
from pubsub import pub
from treelib import Tree

# 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
Expand Down Expand Up @@ -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),
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
)
6 changes: 3 additions & 3 deletions src/ramstk/views/gtk3/books/modulebook.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Standard Library Imports
from typing import Any
from typing import Dict

# Third Party Imports
from treelib import Tree as Tree
Expand All @@ -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: ...
Expand Down
Loading