66# Copyright since 2007 Doyle "weibullguy" Rowland doyle.rowland <AT> reliaqual <DOT> com
77"""RAMSTK Module Book Module."""
88
9+ # Standard Library Imports
10+ from typing import Dict
11+
912# Third Party Imports
1013from pubsub import pub
1114from treelib import Tree
1215
1316# RAMSTK Package Imports
1417from ramstk .configuration import RAMSTKUserConfiguration
1518from ramstk .logger import RAMSTKLogManager
16- from ramstk .views .gtk3 import Gtk
19+ from ramstk .views .gtk3 import Gtk , _
1720from ramstk .views .gtk3 .function import FunctionModuleView
1821from ramstk .views .gtk3 .hardware import HardwareModuleView
1922from ramstk .views .gtk3 .requirement import RequirementModuleView
@@ -44,7 +47,7 @@ def __init__(
4447 RAMSTKBaseBook .__init__ (self , configuration )
4548
4649 # Initialize private dictionary attributes.
47- self ._dic_module_views = {
50+ self ._dic_module_views : Dict [ str , object ] = {
4851 "revision" : RevisionModuleView (configuration , logger ),
4952 "function" : FunctionModuleView (configuration , logger ),
5053 "requirement" : RequirementModuleView (configuration , logger ),
@@ -68,35 +71,13 @@ def __init__(
6871 self .__set_callbacks ()
6972
7073 # Subscribe to PyPubSub messages.
71- pub .subscribe (self ._on_open , "succeed_retrieve_all_revision" )
72- pub .subscribe (self ._on_close , "succeed_closed_program" )
73-
74- def __make_ui (self ) -> None :
75- """Build the user interface.
76-
77- :return: None
78- :rtype: None
79- """
80- self .insert_page (
81- self ._dic_module_views ["revision" ],
82- tab_label = self ._dic_module_views ["revision" ].hbx_tab_label ,
83- position = 0 ,
74+ pub .subscribe (
75+ self ._on_open ,
76+ "succeed_retrieve_all_revision" ,
8477 )
85-
86- self .show_all ()
87- self .set_current_page (0 )
88-
89- def __set_callbacks (self ) -> None :
90- """Set callback methods for the RAMSTKModuleBook and widgets.
91-
92- :return: None
93- :rtype: None
94- """
95- self .dic_handler_id ["select-page" ] = self .connect (
96- "select-page" , self ._on_switch_page
97- )
98- self .dic_handler_id ["switch-page" ] = self .connect (
99- "switch-page" , self ._on_switch_page
78+ pub .subscribe (
79+ self ._on_close ,
80+ "succeed_closed_program" ,
10081 )
10182
10283 def _on_close (self ) -> None :
@@ -108,11 +89,11 @@ def _on_close(self) -> None:
10889 # Remove all the non-Revision pages.
10990 _n_pages = self .get_n_pages ()
11091 # pylint: disable=unused-variable
111- for _page in range (_n_pages - 1 ):
92+ for __ in range (_n_pages - 1 ):
11293 self .remove_page (- 1 )
11394
11495 # Clear the Revision page treeview.
115- _model = self ._dic_module_views ["revision" ].treeview .get_model ()
96+ _model = self ._dic_module_views ["revision" ].treeview .get_model () # type: ignore
11697 _model .clear ()
11798
11899 # pylint: disable=unused-argument
@@ -133,7 +114,9 @@ def _on_open(self, tree: Tree) -> None:
133114 try :
134115 _module = self ._dic_module_views [_mkey ]
135116 self .insert_page (
136- _module , tab_label = _module .hbx_tab_label , position = _key
117+ _module ,
118+ tab_label = _module .hbx_tab_label , # type: ignore
119+ position = _key ,
137120 )
138121 except KeyError :
139122 pass
@@ -163,10 +146,47 @@ def _on_switch_page(
163146 :return: None
164147 :rtype: None
165148 """
166- # See ISSUE #1005
167149 try :
168150 _module = self .RAMSTK_USER_CONFIGURATION .RAMSTK_PAGE_NUMBER [page_num ]
169151 except KeyError :
170152 _module = "revision"
153+ pub .sendMessage (
154+ "do_log_debug_msg" ,
155+ logger_name = "DEBUG" ,
156+ message = _ (
157+ f"Page number { page_num } is not active in this Program. "
158+ f"Active page numbers and their associated work flow "
159+ f"module are { self .RAMSTK_USER_CONFIGURATION .RAMSTK_PAGE_NUMBER } . "
160+ f"Selecting the Revision work flow module by default."
161+ ),
162+ )
171163
172164 pub .sendMessage ("mvwSwitchedPage" , module = _module )
165+
166+ def __make_ui (self ) -> None :
167+ """Build the user interface.
168+
169+ :return: None
170+ :rtype: None
171+ """
172+ self .insert_page (
173+ self ._dic_module_views ["revision" ],
174+ tab_label = self ._dic_module_views ["revision" ].hbx_tab_label , # type: ignore
175+ position = 0 ,
176+ )
177+
178+ self .show_all ()
179+ self .set_current_page (0 )
180+
181+ def __set_callbacks (self ) -> None :
182+ """Set callback methods for the RAMSTKModuleBook and widgets.
183+
184+ :return: None
185+ :rtype: None
186+ """
187+ self .dic_handler_id ["select-page" ] = self .connect (
188+ "select-page" , self ._on_switch_page
189+ )
190+ self .dic_handler_id ["switch-page" ] = self .connect (
191+ "switch-page" , self ._on_switch_page
192+ )
0 commit comments