@@ -558,13 +558,27 @@ def set_central_widget(self, name):
558
558
----------
559
559
name: str or QWidget
560
560
The key or the plugin widget in the :attr:`plugins` dictionary"""
561
+ from PyQt5 .QtCore import QTimer
562
+ self .setUpdatesEnabled (False )
561
563
current = self .centralWidget ()
562
564
if isinstance (name , six .string_types ):
563
565
new = self .plugins [name ]
564
566
else :
565
567
new = name
566
568
name = next (key for key , val in self .plugins .items () if val is new )
567
569
if new is not current :
570
+
571
+ self ._dock_widths = dock_widths = OrderedDict ()
572
+ self ._dock_heights = dock_heights = OrderedDict ()
573
+ for key , w in self .plugins .items ():
574
+ if w .dock is not None and w .is_shown :
575
+ s = w .dock .size ()
576
+ dock_widths [w ] = s .width ()
577
+ if w is not new :
578
+ dock_heights [w ] = s .height ()
579
+
580
+ new_pos = self .dockWidgetArea (new .dock )
581
+
568
582
self .removeDockWidget (new .dock )
569
583
new .dock .close ()
570
584
self .panes_menu .removeAction (new ._view_action )
@@ -576,8 +590,28 @@ def set_central_widget(self, name):
576
590
new ._set_central_action .setChecked (True )
577
591
current .show_plugin ()
578
592
current .to_dock (self )
593
+ new_width = dock_widths .pop (new )
579
594
if current .hidden :
580
595
current .hide_plugin ()
596
+ else :
597
+ current_pos = self .dockWidgetArea (current .dock )
598
+ if current_pos == new_pos :
599
+ dock_widths [current ] = new_width
600
+
601
+ self ._custom_layout_timer = QTimer (self )
602
+ self ._custom_layout_timer .timeout .connect (self ._reset_dock_widths )
603
+ self ._custom_layout_timer .setSingleShot (True )
604
+ self ._custom_layout_timer .start (5000 )
605
+
606
+ def _reset_dock_widths (self ):
607
+ # resize the plugins
608
+ if with_qt5 :
609
+ for w , width in self ._dock_widths .items ():
610
+ self .resizeDocks ([w .dock ], [width ], Qt .Horizontal )
611
+ for w , height in self ._dock_heights .items ():
612
+ self .resizeDocks ([w .dock ], [height ], Qt .Vertical )
613
+
614
+ self .setUpdatesEnabled (True )
581
615
582
616
def _save_project (self , p , new_fname = False , * args , ** kwargs ):
583
617
if new_fname or 'project_file' not in p .attrs :
0 commit comments