@@ -750,11 +750,14 @@ def remove_rubberband(self):
750750 self .canvas .drawRectangle (None )
751751
752752 def configure_subplots (self ):
753- image = str (cbook ._get_data_path ('images/matplotlib.png' ))
754- self ._subplot_dialog = SubplotToolQt (
755- self .canvas .figure , self .canvas .parent ())
756- self ._subplot_dialog .setWindowIcon (QtGui .QIcon (image ))
753+ if self ._subplot_dialog is None :
754+ self ._subplot_dialog = SubplotToolQt (
755+ self .canvas .figure , self .canvas .parent ())
756+ self .canvas .mpl_connect (
757+ "close_event" , lambda e : self ._subplot_dialog .reject ())
758+ self ._subplot_dialog .update_from_current_subplotpars ()
757759 self ._subplot_dialog .show ()
760+ return self ._subplot_dialog
758761
759762 def save_figure (self , * args ):
760763 filetypes = self .canvas .get_supported_filetypes_grouped ()
@@ -799,6 +802,8 @@ def set_history_buttons(self):
799802class SubplotToolQt (QtWidgets .QDialog ):
800803 def __init__ (self , targetfig , parent ):
801804 super ().__init__ ()
805+ self .setWindowIcon (QtGui .QIcon (
806+ str (cbook ._get_data_path ("images/matplotlib.png" ))))
802807 self .setObjectName ("SubplotTool" )
803808 self ._spinboxes = {}
804809 main_layout = QtWidgets .QHBoxLayout ()
@@ -819,7 +824,6 @@ def __init__(self, targetfig, parent):
819824 inner = QtWidgets .QFormLayout (box )
820825 for name in spinboxes :
821826 self ._spinboxes [name ] = spinbox = QtWidgets .QDoubleSpinBox ()
822- spinbox .setValue (getattr (targetfig .subplotpars , name ))
823827 spinbox .setRange (0 , 1 )
824828 spinbox .setDecimals (3 )
825829 spinbox .setSingleStep (0.005 )
@@ -836,9 +840,14 @@ def __init__(self, targetfig, parent):
836840 if name == "Close" :
837841 button .setFocus ()
838842 self ._figure = targetfig
839- self ._defaults = {spinbox : vars (self ._figure .subplotpars )[attr ]
840- for attr , spinbox in self ._spinboxes .items ()}
843+ self ._defaults = {}
841844 self ._export_values_dialog = None
845+ self .update_from_current_subplotpars ()
846+
847+ def update_from_current_subplotpars (self ):
848+ self ._defaults = {spinbox : getattr (self ._figure .subplotpars , name )
849+ for name , spinbox in self ._spinboxes .items ()}
850+ self ._reset () # Set spinbox current values without triggering signals.
842851
843852 def _export_values (self ):
844853 # Explicitly round to 3 decimals (which is also the spinbox precision)
0 commit comments