55
66
77class WizardMethodController (WizardPageSimple ):
8- def __init__ (self , parent , series_service ):
8+ def __init__ (self , parent , series_service , current_method = None ):
99 WizardPageSimple .__init__ (self , parent )
1010
1111 main_sizer = wx .BoxSizer (wx .VERTICAL )
12+
1213 self .method_view = WizardMethodView (self )
1314 main_sizer .Add (self .method_view , 1 , wx .EXPAND | wx .RIGHT , - 16 ) # Sufficient to hide the scroll bar
1415 self .SetSizer (main_sizer )
@@ -17,24 +18,40 @@ def __init__(self, parent, series_service):
1718 table_columns = ["ID" , "Descriptions" , "Link" , "Code" , "Type" ]
1819 self .cv_types = []
1920 self .method_view .existing_method_table .set_columns (table_columns )
21+
2022 self .on_auto_radio (None )
2123
24+ self .all_methods = []
25+ self .current_method_in_series = current_method # Not the same as the selected method in the table
26+ self .__populate_table ()
27+ self .select_current_method ()
28+ self .method_view .method_type_combo .AppendItems (self .cv_types )
29+ self .on_existing_method_radio (None )
30+
2231 self .method_view .auto_method_radio .Bind (wx .EVT_RADIOBUTTON , self .on_auto_radio )
2332 self .method_view .existing_method_radio .Bind (wx .EVT_RADIOBUTTON , self .on_existing_method_radio )
2433 self .method_view .create_method_radio .Bind (wx .EVT_RADIOBUTTON , self .on_create_method_radio )
2534
26- self .__fetch_data ()
27- self .method_view .method_type_combo .AppendItems (self .cv_types )
35+ def select_current_method (self ):
36+ if self .current_method_in_series is None :
37+ return
38+
39+ if self .current_method_in_series not in self .all_methods :
40+ return # the current method is not in the table
41+
42+ index = self .all_methods .index (self .current_method_in_series )
43+ self .method_view .existing_method_table .Select (index )
2844
2945 def on_auto_radio (self , event ):
30- self .method_view .existing_method_table .Enable ( False )
31- self .__set_create_method_section_ (False )
46+ self .method_view .existing_method_table .Disable ( )
47+ self .enable_create_method_section (False )
3248
3349 def on_existing_method_radio (self , event ):
3450 self .method_view .existing_method_table .Enable ()
35- self .__set_create_method_section_ (False )
51+ self .enable_create_method_section (False )
52+ self .method_view .existing_method_table .SetFocus ()
3653
37- def __set_create_method_section_ (self , active ):
54+ def enable_create_method_section (self , active ):
3855 if not isinstance (active , bool ):
3956 raise Exception ("active must be type bool" )
4057
@@ -47,12 +64,12 @@ def __set_create_method_section_(self, active):
4764
4865 def on_create_method_radio (self , event ):
4966 self .method_view .existing_method_table .Disable ()
50- self .__set_create_method_section_ (True )
67+ self .enable_create_method_section (True )
5168
52- def __fetch_data (self ):
53- methods = self .series_service .get_all_methods ()
69+ def __populate_table (self ):
70+ self . all_methods = self .series_service .get_all_methods ()
5471 data = []
55- for meth in methods :
72+ for meth in self . all_methods :
5673 data .append ([
5774 meth .MethodID , meth .MethodDescription ,
5875 meth .MethodLink , meth .MethodCode ,
@@ -64,7 +81,7 @@ def __fetch_data(self):
6481
6582 self .method_view .existing_method_table .set_table_content (data = data )
6683
67- def getMethod (self ):
84+ def get_method (self ):
6885 if self .method_view .auto_method_radio .GetValue ():
6986 return self .__auto_generate_a_method ()
7087
@@ -87,14 +104,7 @@ def __auto_generate_a_method(self):
87104
88105 def __select_existing_method (self ):
89106 index = self .method_view .existing_method_table .GetFirstSelected ()
90- desc = self .method_view .existing_method_table .GetItem (index , 1 ).GetText ()
91- link = self .method_view .existing_method_table .GetItem (index , 2 ).GetText ()
92- code = self .method_view .existing_method_table .GetItem (index , 3 ).GetText ()
93-
94- method = self .series_service .get_method_by_code (method_code = code )
95- method .MethodLink = link
96- method .MethodDescription = desc
97- return method
107+ return self .all_methods [index ]
98108
99109 def __create_new_method (self ):
100110 code = self .method_view .method_code_text_ctrl .GetValue ()
0 commit comments