Skip to content

Commit

Permalink
fix: properly handle CellRenderCombo returning integers (#940)
Browse files Browse the repository at this point in the history
* fix: CellRendererCombo returning integer not string

* style: update stub files

* docs: update CHANGELOG.md
  • Loading branch information
weibullguy committed Feb 3, 2022
1 parent f5e3a88 commit c05ff87
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 106 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

**Merged pull requests:**

- refactor: move RAMSTKFailureMode to its own package [\#939](https://github.com/ReliaQualAssociates/ramstk/pull/939) ([weibullguy](https://github.com/weibullguy))
- refactor: move RAMSTKSubCategory to its own package [\#937](https://github.com/ReliaQualAssociates/ramstk/pull/937) ([weibullguy](https://github.com/weibullguy))
- refactor: move RAMSTKCategory to its own package [\#933](https://github.com/ReliaQualAssociates/ramstk/pull/933) ([weibullguy](https://github.com/weibullguy))
- refactor: retire listviews and listbook [\#932](https://github.com/ReliaQualAssociates/ramstk/pull/932) ([weibullguy](https://github.com/weibullguy))
Expand Down
143 changes: 107 additions & 36 deletions src/ramstk/views/gtk3/hardware/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class HardwareTreePanel(RAMSTKTreePanel):
# Define private dictionary class attributes.

# Define private list class attributes.
_lst_cost_types: List[str] = ["", "Assessed", "Specified"]

# Define private scalar class attributes.
_record_field = "hardware_id"
Expand Down Expand Up @@ -273,19 +274,19 @@ def __init__(self) -> None:
],
"manufacturer_id": [
13,
Gtk.CellRendererText(),
"edited",
None,
Gtk.CellRendererCombo(),
"changed",
super().on_cell_change,
f"mvw_editing_{self._tag}",
0,
{
"bg_color": "#FFFFFF",
"editable": True,
"fg_color": "#000000",
"visible": False,
"visible": True,
},
_("Manufacturer"),
"gint",
"gchararray",
],
"mission_time": [
14,
Expand Down Expand Up @@ -545,19 +546,19 @@ def __init__(self) -> None:
],
"cost_type_id": [
30,
Gtk.CellRendererText(),
"edited",
None,
Gtk.CellRendererCombo(),
"changed",
super().on_cell_change,
f"mvw_editing_{self._tag}",
0,
{
"bg_color": "#FFFFFF",
"editable": True,
"fg_color": "#000000",
"visible": False,
"visible": True,
},
_("Cost Type"),
"gint",
"gchararray",
],
"attachments": [
31,
Expand All @@ -577,40 +578,43 @@ def __init__(self) -> None:
],
"category_id": [
32,
Gtk.CellRendererText(),
"edited",
None,
Gtk.CellRendererCombo(),
"changed",
super().on_cell_change,
f"mvw_editing_{self._tag}",
0,
{
"bg_color": "#FFFFFF",
"editable": True,
"fg_color": "#000000",
"visible": False,
"visible": True,
},
_("Category"),
"gint",
"gchararray",
],
"subcategory_id": [
33,
Gtk.CellRendererText(),
"edited",
None,
Gtk.CellRendererCombo(),
"changed",
super().on_cell_change,
f"mvw_editing_{self._tag}",
0,
{
"bg_color": "#FFFFFF",
"editable": True,
"fg_color": "#000000",
"visible": False,
"visible": True,
},
_("Subcategory"),
"gint",
"gchararray",
],
}
self.dic_icons = {"assembly": None, "part": None}
self.dic_subcategories: Dict[int, List[str]] = {0: [""]}

# Initialize public list class attributes.
self.lst_categories: List[str] = [""]
self.lst_manufacturers: List[str] = [""]

# Initialize public scalar class attributes.

Expand All @@ -628,8 +632,51 @@ def __init__(self) -> None:
"mvwSwitchedPage",
)

def do_load_comboboxes(self) -> None:
"""Load the Gtk.CellRendererCombo()s.
:return: None
:rtype: None
"""
self.tvwTreeView.do_load_combo_cell(
self.tvwTreeView.position["category_id"],
self.lst_categories,
)

self.tvwTreeView.do_load_combo_cell(
self.tvwTreeView.position["manufacturer_id"],
self.lst_manufacturers,
)

self.tvwTreeView.do_load_combo_cell(
self.tvwTreeView.position["cost_type_id"],
self._lst_cost_types,
)

_cell = self.tvwTreeView.get_column(
self.tvwTreeView.position["category_id"]
).get_cells()
_cell[0].connect("edited", self._on_category_change)

def _on_category_change(
self, __combo: Gtk.CellRendererCombo, path: str, new_text: str
) -> None:
"""Load the subcategories whenever the category combo is changed.
:param __combo: the category list Gtk.CellRendererCombo(). Unused in
this method.
:param path: the path identifying the edited cell.
:param new_text: the new text (category description).
:return: None
:rtype: None
"""
self.__do_load_subcategories(new_text)

_model = self.tvwTreeView.get_model()
_model[path][self.tvwTreeView.position["subcategory_id"]] = ""

def _on_module_switch(self, module: str = "") -> None:
"""Respond to changes in selected Module View module (tab).
"""Respond to change in selected Module View module (tab).
:param module: the name of the module that was just selected.
:return: None
Expand Down Expand Up @@ -660,6 +707,19 @@ def _on_row_change(self, selection: Gtk.TreeSelection) -> None:
self._record_id = _attributes["hardware_id"]
self._parent_id = _attributes["parent_id"]

_attributes["category_id"] = self.lst_categories.index(
_attributes["category_id"]
)
_attributes["cost_type_id"] = ["", "Assessed", "Specified"].index(
_attributes["cost_type_id"]
)
_attributes["manufacturer_id"] = self.lst_manufacturers.index(
_attributes["manufacturer_id"]
)
_attributes["subcategory_id"] = self.dic_subcategories[
_attributes["category_id"]
].index(_attributes["subcategory_id"])

_title = _("Analyzing hardware item {0}: {1}").format(
str(_attributes["comp_ref_des"]), str(_attributes["name"])
)
Expand Down Expand Up @@ -687,7 +747,7 @@ def __do_load_hardware(self, node: treelib.Node, row: Gtk.TreeIter) -> Gtk.TreeI
"""Load a hardware item into the RAMSTKTreeView().
:param node: the treelib Node() with the mode data to load.
:param row: the parent row of the mode to load into the hardware tree.
:param row: the parent row of the item to load into the hardware tree.
:return: _new_row; the row that was just populated with hardware data.
:rtype: :class:`Gtk.TreeIter`
"""
Expand All @@ -696,8 +756,6 @@ def __do_load_hardware(self, node: treelib.Node, row: Gtk.TreeIter) -> Gtk.TreeI
# pylint: disable=unused-variable
_entity = node.data["hardware"]

_model = self.tvwTreeView.get_model()

# noinspection PyArgumentList
_icon = GdkPixbuf.Pixbuf.new_from_file_at_size(
self.dic_icons["assembly"], 22, 22
Expand All @@ -723,7 +781,7 @@ def __do_load_hardware(self, node: treelib.Node, row: Gtk.TreeIter) -> Gtk.TreeI
_entity.figure_number,
_entity.lcn,
_entity.level,
_entity.manufacturer_id,
self.lst_manufacturers[_entity.manufacturer_id],
_entity.mission_time,
_entity.name,
_entity.nsn,
Expand All @@ -740,24 +798,23 @@ def __do_load_hardware(self, node: treelib.Node, row: Gtk.TreeIter) -> Gtk.TreeI
_entity.total_part_count,
_entity.total_power_dissipation,
_entity.year_of_manufacture,
_entity.cost_type_id,
self._lst_cost_types[_entity.cost_type_id],
_entity.attachments,
_entity.category_id,
_entity.subcategory_id,
self.lst_categories[_entity.category_id],
self.dic_subcategories[_entity.category_id][_entity.subcategory_id],
_icon,
]

try:
_new_row = _model.append(row, _attributes)
_new_row = self.tvwTreeView.unfilt_model.append(row, _attributes)
except (AttributeError, TypeError, ValueError):
_new_row = None
_message = _(
"An error occurred when loading hardware item {0} into the "
"hardware tree. This might indicate it was missing it's data "
"package, some of the data in the package was missing, or "
"some of the data was the wrong type. Row data was: "
"{1}"
).format(str(node.identifier), _attributes)
f"An error occurred when loading hardware item {node.identifier} into "
f"the hardware tree. This might indicate it was missing it's data "
f"package, some of the data in the package was missing, or "
f"some of the data was the wrong type. Row data was: "
f"{_attributes}"
)
pub.sendMessage(
"do_log_warning_msg",
logger_name="WARNING",
Expand All @@ -766,6 +823,20 @@ def __do_load_hardware(self, node: treelib.Node, row: Gtk.TreeIter) -> Gtk.TreeI

return _new_row

def __do_load_subcategories(self, category: str) -> None:
"""Load subcategory Gtk.CellRendererCombo() when a new category is selected.
:param category: the ID of the newly selected category.
:return: None
:rtype: None
"""
_category_id = self.lst_categories.index(category)

self.tvwTreeView.do_load_combo_cell(
self.tvwTreeView.position["subcategory_id"],
self.dic_subcategories[_category_id],
)


class HardwareGeneralDataPanel(RAMSTKFixedPanel):
"""Panel to display general data about the selected Hardware item."""
Expand Down
29 changes: 27 additions & 2 deletions src/ramstk/views/gtk3/hardware/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,40 @@ def _do_set_record_id(self, attributes: Dict[str, Any]) -> None:
self.dic_pkeys["parent_id"] = attributes["parent_id"]
self.dic_pkeys["record_id"] = attributes["hardware_id"]

def __do_load_lists(self) -> None:
"""Load the pick lists associated with Hardware.
:return: None
:rtype: None
"""
for _key in self.RAMSTK_USER_CONFIGURATION.RAMSTK_CATEGORIES:
self._pnlPanel.lst_categories.append(
self.RAMSTK_USER_CONFIGURATION.RAMSTK_CATEGORIES[_key]
)
self._pnlPanel.dic_subcategories[_key] = [""]

for _subkey in self.RAMSTK_USER_CONFIGURATION.RAMSTK_SUBCATEGORIES[_key]:
self._pnlPanel.dic_subcategories[_key].append(
self.RAMSTK_USER_CONFIGURATION.RAMSTK_SUBCATEGORIES[_key][_subkey]
)

for _key in self.RAMSTK_USER_CONFIGURATION.RAMSTK_MANUFACTURERS:
self._pnlPanel.lst_manufacturers.append(
self.RAMSTK_USER_CONFIGURATION.RAMSTK_MANUFACTURERS[_key][0]
)

def __make_ui(self) -> None:
"""Build the user interface for the function module view.
:return: None
"""
super().make_ui()

self._pnlPanel.dic_icons = self._dic_icons

self.__do_load_lists()
self._pnlPanel.do_load_comboboxes()

self._pnlPanel.do_set_cell_callbacks(
"mvw_editing_hardware",
[
Expand Down Expand Up @@ -344,8 +371,6 @@ def __make_ui(self) -> None:
] = self._pnlPanel.tvwTreeView.connect(
"button_press_event", super().on_button_press
)
for _element in ["assembly", "part"]:
self._pnlPanel.dic_icons[_element] = self._dic_icons[_element]


class HardwareGeneralDataView(RAMSTKWorkView):
Expand Down
12 changes: 3 additions & 9 deletions src/ramstk/views/gtk3/requirement/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ def __init__(self) -> None:
pub.subscribe(self._on_module_switch, "mvwSwitchedPage")

def _on_module_switch(self, module: str = "") -> None:
"""Respond to changes in selected Module View module (tab).
"""Respond to change in selected Module View module (tab).
:param module: the name of the module that was just selected.
:return: None
Expand Down Expand Up @@ -1230,11 +1230,8 @@ def do_load_requirement_types(
:return: None
:rtype: None
"""
_requirement_types: List[Tuple[str]] = []
_requirement_types: List[Tuple[str]] = list(requirement_types.values())

# pylint: disable=unused-variable
for __, _key in enumerate(requirement_types):
_requirement_types.append(requirement_types[_key])
self.cmbRequirementType.do_load_combo(entries=_requirement_types, simple=False)

def do_load_workgroups(self, workgroups: Dict[int, Tuple[str]]) -> None:
Expand All @@ -1244,11 +1241,8 @@ def do_load_workgroups(self, workgroups: Dict[int, Tuple[str]]) -> None:
:return: None
:rtype: None
"""
_owners = []
_owners = list(workgroups.values())

# pylint: disable=unused-variable
for __, _key in enumerate(workgroups):
_owners.append(workgroups[_key])
self.cmbOwner.do_load_combo(_owners)

def _do_load_code(self, requirement_code: int) -> None:
Expand Down
8 changes: 2 additions & 6 deletions src/ramstk/views/gtk3/requirement/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,12 @@ def __make_ui(self) -> None:
"""
super().make_ui()

for (__, _key) in enumerate( # pylint: disable=unused-variable
self.RAMSTK_USER_CONFIGURATION.RAMSTK_WORKGROUPS
):
for _key in self.RAMSTK_USER_CONFIGURATION.RAMSTK_WORKGROUPS:
self._pnlPanel.lst_owner.append(
self.RAMSTK_USER_CONFIGURATION.RAMSTK_WORKGROUPS[_key][0]
)

for (__, _key) in enumerate( # pylint: disable=unused-variable
self.RAMSTK_USER_CONFIGURATION.RAMSTK_REQUIREMENT_TYPE
):
for _key in self.RAMSTK_USER_CONFIGURATION.RAMSTK_REQUIREMENT_TYPE:
self._pnlPanel.lst_type.append(
self.RAMSTK_USER_CONFIGURATION.RAMSTK_REQUIREMENT_TYPE[_key][1]
)
Expand Down
Loading

0 comments on commit c05ff87

Please sign in to comment.