53
53
class StageProgressBar (ttk .LabelFrame ): # pylint: disable=too-many-ancestors
54
54
"""Stage-segmented Configuration sequence progress UI."""
55
55
56
- def __init__ (self , master : Union [tk .Widget , tk .Tk ], phases : dict [str , dict ], total_steps : int , ** kwargs ) -> None :
56
+ def __init__ (
57
+ self , master : Union [tk .Widget , tk .Tk ], phases : dict [str , dict ], total_steps : int , gui_complexity : str , ** kwargs
58
+ ) -> None :
57
59
super ().__init__ (master , text = _ ("Configuration sequence progress" ), ** kwargs )
58
60
self .phases = phases
59
61
self .total_files = total_steps
@@ -63,7 +65,7 @@ def __init__(self, master: Union[tk.Widget, tk.Tk], phases: dict[str, dict], tot
63
65
self .grid_columnconfigure (0 , weight = 1 )
64
66
self .grid_rowconfigure (0 , weight = 1 )
65
67
66
- self .create_phase_frames ()
68
+ self .create_phase_frames (gui_complexity )
67
69
self .bind ("<Configure>" , self ._on_resize )
68
70
show_tooltip (
69
71
self ,
@@ -74,27 +76,40 @@ def __init__(self, master: Union[tk.Widget, tk.Tk], phases: dict[str, dict], tot
74
76
position_below = False ,
75
77
)
76
78
77
- def create_phase_frames (self ) -> None :
79
+ def create_phase_frames (self , gui_complexity : str ) -> None :
78
80
"""Create frames for each phase with progress bars and labels."""
79
81
# Get phases with start positions
80
82
active_phases = {k : v for k , v in self .phases .items () if "start" in v }
81
83
82
84
# Sort phases by start position
83
85
sorted_phases = dict (sorted (active_phases .items (), key = lambda x : x [1 ]["start" ]))
84
86
85
- num_phases = len (sorted_phases )
87
+ # Add the end information to each phase using the start of the next phase
88
+ phase_names = list (sorted_phases .keys ())
89
+ for i , phase_name in enumerate (phase_names ):
90
+ if i < len (phase_names ) - 1 :
91
+ next_phase_name = phase_names [i + 1 ]
92
+ sorted_phases [phase_name ]["end" ] = sorted_phases [next_phase_name ]["start" ]
93
+ else :
94
+ sorted_phases [phase_name ]["end" ] = self .total_files
95
+ sorted_phases [phase_name ]["weight" ] = max (2 , sorted_phases [phase_name ]["end" ] - sorted_phases [phase_name ]["start" ])
96
+
97
+ # Calculate non-optional phases
98
+ non_optional_sorted_phases = {name : data for name , data in sorted_phases .items () if not data .get ("optional" , False )}
99
+
100
+ phases_to_display = non_optional_sorted_phases if gui_complexity == "simple" else sorted_phases
86
101
87
102
# Create container frame that will expand
88
103
container = ttk .Frame (self )
89
104
container .grid (row = 0 , column = 0 , sticky = "nsew" , padx = 5 , pady = 5 )
90
105
91
106
# Configure container columns to expand equally
92
- for i in range ( num_phases ):
93
- container .grid_columnconfigure (i , weight = 1 , uniform = "phase" )
94
-
95
- for i , ( phase_name , phase_data ) in enumerate ( sorted_phases . items ()):
107
+ for i , ( phase_name , phase_data ) in enumerate ( phases_to_display . items () ):
108
+ container .grid_columnconfigure (
109
+ i , weight = phase_data [ "weight" ] if gui_complexity == "simple" else 1 , uniform = "phase"
110
+ )
96
111
start = phase_data ["start" ]
97
- end = list ( sorted_phases . values ())[ i + 1 ][ "start" ] if i < num_phases - 1 else self . total_files
112
+ end = phase_data [ "end" ]
98
113
self .phase_frames [phase_name ] = self ._create_phase_frame (container , i , phase_name , phase_data , (start , end ))
99
114
100
115
def _create_phase_frame ( # pylint: disable=too-many-arguments, too-many-positional-arguments
@@ -229,7 +244,7 @@ def main() -> None:
229
244
config_steps = ConfigurationSteps ("" , "ArduCopter" )
230
245
config_steps .re_init ("" , "ArduCopter" )
231
246
232
- progress = StageProgressBar (root , config_steps .configuration_phases , 54 )
247
+ progress = StageProgressBar (root , config_steps .configuration_phases , 54 , "normal" )
233
248
progress .pack (padx = 10 , pady = 10 , fill = "both" , expand = True )
234
249
235
250
# Demo update function
0 commit comments