@@ -251,40 +251,33 @@ def create_main_layout(self):
251251 all_zones_array = np .transpose (np .reshape (all_zones , (2 ,4 )))
252252 is_zone = np .array ([(widgets_zone .get (zone ) is not None ) and (len (widgets_zone .get (zone )) > 0 ) for zone in all_zones ])
253253 is_zone_array = np .reshape (is_zone , (2 ,4 ))
254- original_zone_array = copy (is_zone_array )
255-
256- first_nonzero_column = np .arange (4 )[np .any (original_zone_array , axis = 0 )][0 ]
257- first_is_top = original_zone_array [:,first_nonzero_column ][0 ]
258- if not first_is_top :
259- top_zone = f"zone{ first_nonzero_column + 1 } "
260- bottom_zone = f"zone{ first_nonzero_column + 5 } "
261- widgets_zone [top_zone ] = widgets_zone [bottom_zone ]
262- widgets_zone [bottom_zone ] = []
254+
255+ # If the first non-zero zero (from left to right) is on the bottom, move it up
256+ for column_index , zones_in_columns in enumerate (is_zone_array ):
257+ if np .any (zones_in_columns ):
258+ first_is_top = zones_in_columns [0 ]
259+ if not first_is_top :
260+ top_zone = f"zone{ column_index + 1 } "
261+ bottom_zone = f"zone{ column_index + 5 } "
262+ widgets_zone [top_zone ] = widgets_zone [bottom_zone ]
263+ widgets_zone [bottom_zone ] = []
263264
264265 is_zone = np .array ([(widgets_zone .get (zone ) is not None ) and (len (widgets_zone .get (zone )) > 0 ) for zone in all_zones ])
265266 is_zone_array = np .reshape (is_zone , (2 ,4 ))
266267 original_zone_array = copy (is_zone_array )
267268
268- num_rows_1 , num_cols_1 = get_size_top_row (0 ,0 , is_zone_array , original_zone_array )
269- num_rows_2 , num_cols_2 = get_size_top_row (0 ,1 , is_zone_array , original_zone_array )
270- num_rows_3 , num_cols_3 = get_size_top_row (0 ,2 , is_zone_array , original_zone_array )
271- num_rows_4 , num_cols_4 = get_size_top_row (0 ,3 , is_zone_array , original_zone_array )
272-
273- num_rows_5 , num_cols_5 = get_size_bottom_row (1 ,0 , is_zone_array , original_zone_array )
274- num_rows_6 , num_cols_6 = get_size_bottom_row (1 ,1 , is_zone_array , original_zone_array )
275- num_rows_7 , num_cols_7 = get_size_bottom_row (1 ,2 , is_zone_array , original_zone_array )
276- num_rows_8 , num_cols_8 = get_size_bottom_row (1 ,3 , is_zone_array , original_zone_array )
277-
278- num_rows = np .array ([num_rows_1 , num_rows_2 , num_rows_3 , num_rows_4 , num_rows_5 , num_rows_6 , num_rows_7 , num_rows_8 ])
279- num_cols = np .array ([num_cols_1 , num_cols_2 , num_cols_3 , num_cols_4 , num_cols_5 , num_cols_6 , num_cols_7 , num_cols_8 ])
280-
281- num_rows_array = np .reshape (num_rows , (2 ,4 ))
282- num_cols_array = np .reshape (num_cols , (2 ,4 ))
283-
284- group = []
269+ # First we split horizontally any columns which are two rows long.
270+ # For later, group the zones between these splits
285271 all_groups = []
286- for num_row , num_col , is_a_zone , zones in zip (np .transpose (num_rows_array ), np .transpose (num_cols_array ), np .transpose (original_zone_array ), all_zones_array ):
287- if num_row [0 ] == 2 :
272+ group = []
273+ for col_index , zones in enumerate (all_zones_array ):
274+ col = col_index % 4
275+ is_a_zone = original_zone_array [:,col ]
276+ num_row_0 , _ = get_size_top_row (0 , col , is_zone_array , original_zone_array )
277+ # this function affects is_zone_array so must be run
278+ _ , _ = get_size_bottom_row (0 , col , is_zone_array , original_zone_array )
279+
280+ if num_row_0 == 2 :
288281 if len (group ) > 0 :
289282 all_groups .append (group )
290283 group = []
@@ -297,14 +290,7 @@ def create_main_layout(self):
297290 if len (group ) > 0 :
298291 all_groups .append (group )
299292
300- first_dock = None
301- print (f"{ all_groups } " )
302293 first_zone = all_groups [0 ][0 ]
303- print (f"{ first_zone = } " )
304- if first_zone in ['zone5' , 'zone6' , 'zone7' , 'zone8' ]:
305- above_zone = f'zone{ int (first_zone [- 1 ])- 4 } '
306- widgets_zone [above_zone ] = widgets_zone [first_zone ]
307- first_zone = above_zone
308294 first_dock = widgets_zone [first_zone ][0 ]
309295 dock = self .docks [first_dock ]
310296 self .addDockWidget (areas ['left' ], dock )
@@ -315,87 +301,43 @@ def create_main_layout(self):
315301 sorted_arr = np .array (group )[sorted_indices ]
316302 view_name = widgets_zone [sorted_arr [0 ]][0 ]
317303 dock = self .docks [view_name ]
318- print (f"Splitting { first_dock } , { view_name } " )
319304 self .splitDockWidget (self .docks [first_dock ], dock , orientations ['horizontal' ])
320305
306+ # Now take each sub-group, and split vertically if appropriate
321307 new_all_groups = []
322308 for group in all_groups :
309+
323310 if len (group ) == 1 :
311+ # if only one in group, not need to split
324312 continue
325- else :
326- top_zones = [zone for zone in group if zone in ['zone1' , 'zone2' , 'zone3' , 'zone4' ]]
327- bottom_zones = [zone for zone in group if zone in ['zone5' , 'zone6' , 'zone7' , 'zone8' ]]
328- new_all_groups .append ([top_zones , bottom_zones ])
329-
330- for top_and_bottom_groups in new_all_groups :
331313
332- top_groups , bottom_groups = top_and_bottom_groups
314+ top_zones = [zone for zone in group if zone in ['zone1' , 'zone2' , 'zone3' , 'zone4' ]]
315+ bottom_zones = [zone for zone in group if zone in ['zone5' , 'zone6' , 'zone7' , 'zone8' ]]
316+ new_all_groups .append ([top_zones , bottom_zones ])
333317
334- if len (top_groups ) > 0 and len (bottom_groups ) > 0 :
318+ if len (top_zones ) > 0 and len (bottom_zones ) > 0 :
335319
336- top_view_name = widgets_zone [top_groups [0 ]][0 ]
320+ top_view_name = widgets_zone [top_zones [0 ]][0 ]
337321 top_dock = self .docks [top_view_name ]
338322
339- bottom_view_name = widgets_zone [bottom_groups [0 ]][0 ]
323+ bottom_view_name = widgets_zone [bottom_zones [0 ]][0 ]
340324 bottom_dock = self .docks [bottom_view_name ]
341325
342- print (f"Splitting { top_view_name } , { bottom_view_name } " )
343326 self .splitDockWidget (top_dock , bottom_dock , orientations ['vertical' ])
344327
328+ # Finally, split all the sub-sub-groups horizontally
345329 for top_bottom_groups in new_all_groups :
346330 for group in top_bottom_groups :
331+
347332 if len (group ) <= 1 :
333+ # if only one in group, no need to split
348334 continue
349- else :
350- first_zone_name = widgets_zone [group [0 ]][0 ]
351-
352- for zone in reversed (group [1 :]):
353- zone_name = widgets_zone [zone ][0 ]
354- print (f"Splitting { first_zone_name } , { zone_name } " )
355- self .splitDockWidget (self .docks [first_zone_name ], self .docks [zone_name ], orientations ['horizontal' ])
356-
357- # ## Handle left
358- # first_left = None
359- # for zone in ['zone1', 'zone5', 'zone2', 'zone6']:
360- # if len(widgets_zone[zone]) == 0:
361- # continue
362- # view_name = widgets_zone[zone][0]
363- # dock = self.docks[view_name]
364- # if len(widgets_zone[zone]) > 0 and first_left is None:
365- # self.addDockWidget(areas['left'], dock)
366- # first_left = view_name
367- # elif zone == 'zone5':
368- # self.splitDockWidget(self.docks[first_left], dock, orientations['vertical'])
369- # elif zone == 'zone2':
370- # self.splitDockWidget(self.docks[first_left], dock, orientations['horizontal'])
371- # elif zone == 'zone6':
372- # if len(widgets_zone['zone5']) > 0:
373- # z = widgets_zone['zone5'][0]
374- # self.splitDockWidget(self.docks[z], dock, orientations['horizontal'])
375- # else:
376- # self.splitDockWidget(self.docks[first_left], dock, orientations['vertical'])
377-
378- # ## Handle right
379- # first_top = None
380- # for zone in ['zone3', 'zone4', 'zone7', 'zone8']:
381- # if len(widgets_zone[zone]) == 0:
382- # continue
383- # view_name = widgets_zone[zone][0]
384- # dock = self.docks[view_name]
385- # if len(widgets_zone[zone]) > 0 and first_top is None:
386- # self.addDockWidget(areas['right'], dock)
387- # first_top = view_name
388- # elif zone == 'zone4':
389- # self.splitDockWidget(self.docks[first_top], dock, orientations['horizontal'])
390- # elif zone == 'zone7':
391- # self.splitDockWidget(self.docks[first_top], dock, orientations['vertical'])
392- # elif zone == 'zone8':
393- # if len(widgets_zone['zone4']) > 0:
394- # z = widgets_zone['zone4'][0]
395- # self.splitDockWidget(self.docks[z], dock, orientations['vertical'])
396- # else:
397- # self.splitDockWidget(self.docks[first_top], dock, orientations['horizontal'])
398-
335+
336+ first_zone_name = widgets_zone [group [0 ]][0 ]
337+ for zone in reversed (group [1 :]):
338+ zone_name = widgets_zone [zone ][0 ]
339+ self .splitDockWidget (self .docks [first_zone_name ], self .docks [zone_name ], orientations ['horizontal' ])
340+
399341 # make tabs
400342 for zone , view_names in widgets_zone .items ():
401343 n = len (widgets_zone [zone ])
0 commit comments