@@ -627,6 +627,13 @@ def _init_toolbar(self):
627
627
self ._actions [callback ] = a
628
628
if callback in ['zoom' , 'pan' ]:
629
629
a .setCheckable (True )
630
+ if callback == 'save_figure' :
631
+ btn = self .widgetForAction (a )
632
+ btn .setPopupMode (QtWidgets .QToolButton .MenuButtonPopup )
633
+ menu = a .__menu = QtWidgets .QMenu ()
634
+ a .setMenu (menu )
635
+ menu .addAction (
636
+ 'Options for saving' , self ._ui_get_save_options )
630
637
if tooltip_text is not None :
631
638
a .setToolTip (tooltip_text )
632
639
if text == 'Subplots' :
@@ -767,32 +774,28 @@ def save_figure(self, *args):
767
774
# save dir for next time
768
775
savefig_dir = os .path .dirname (six .text_type (fname ))
769
776
matplotlib .rcParams ['savefig.directory' ] = savefig_dir
770
- options = _default_savefig_options
771
- try :
772
- options = (options
773
- + [None ]
774
- + _extra_savefig_options [
775
- os .path .splitext (fname )[1 ].lower ()])
776
- except KeyError :
777
- pass
778
- fedit_arg = []
779
- for option in options :
780
- if option is None :
781
- fedit_arg .append ((None , None ))
782
- else :
783
- fedit_arg .append (option .make_fedit_entry ())
784
- fedit_res = formlayout .fedit (fedit_arg , "Options" )
785
- if not fedit_res :
786
- return
787
- for option , res in zip (filter (None , options ), fedit_res ):
788
- option .setter (res )
789
777
try :
790
778
self .canvas .print_figure (six .text_type (fname ))
791
779
except Exception as e :
792
780
QtWidgets .QMessageBox .critical (
793
781
self , "Error saving file" , six .text_type (e ),
794
782
QtWidgets .QMessageBox .Ok , QtWidgets .QMessageBox .NoButton )
795
783
784
+ def _ui_get_save_options (self ):
785
+ fedit_arg = []
786
+ for tab_name , options in _savefig_options :
787
+ fedit_arg .append (([], tab_name , "" ))
788
+ for option in options :
789
+ if option is None :
790
+ fedit_arg [- 1 ][0 ].append ((None , None ))
791
+ else :
792
+ fedit_arg [- 1 ][0 ].append (option .make_fedit_entry ())
793
+ fedit_res = formlayout .fedit (fedit_arg , "Options" )
794
+ if not fedit_res :
795
+ return
796
+ for option , res in zip (filter (None , options ), fedit_res ):
797
+ option .setter (res )
798
+
796
799
797
800
class _Option (object ):
798
801
@@ -816,55 +819,50 @@ def make_fedit_entry():
816
819
self .setter = setter
817
820
818
821
819
- _default_savefig_options = [
820
- _Option ("DPI" , "savefig.dpi" ),
821
- _Option ("Face color" , "savefig.facecolor" ),
822
- _Option ("Edge color" , "savefig.edgecolor" ),
823
- _Option ("Tight bounding box" ,
824
- getter = lambda : matplotlib .rcParams ["savefig.bbox" ] == "tight" ,
825
- setter = lambda val : matplotlib .rcParams .__setitem__ (
826
- "savefig.bbox" , "tight" if val else "standard" )),
827
- _Option ("Tight bounding box padding" , "savefig.pad_inches" ),
828
- _Option ("Transparent background" , "savefig.transparent" )]
829
-
830
-
831
- _extra_savefig_options = {
832
- ".jpg" : [
833
- _Option ("JPEG quality" , "savefig.jpeg_quality" )],
834
- ".jpeg" : [
835
- _Option ("JPEG quality" , "savefig.jpeg_quality" )],
836
- ".pdf" : [
837
- _Option ("PDF compression" , "pdf.compression" ),
838
- _Option ("PDF font type" ,
822
+ _savefig_options = [
823
+ ("Common" , [
824
+ _Option ("DPI" , "savefig.dpi" ),
825
+ _Option ("Face color" , "savefig.facecolor" ),
826
+ _Option ("Edge color" , "savefig.edgecolor" ),
827
+ _Option ("Tight bounding box" ,
828
+ getter = lambda : matplotlib .rcParams ["savefig.bbox" ] == "tight" ,
829
+ setter = lambda val : matplotlib .rcParams .__setitem__ (
830
+ "savefig.bbox" , "tight" if val else "standard" )),
831
+ _Option ("Tight bounding box padding" , "savefig.pad_inches" ),
832
+ _Option ("Transparent background" , "savefig.transparent" )]),
833
+ ("JPEG" , [
834
+ _Option ("Quality" , "savefig.jpeg_quality" )]),
835
+ ("PDF" , [
836
+ _Option ("Compression" , "pdf.compression" ),
837
+ _Option ("Font type" ,
839
838
getter = lambda :
840
839
[str (matplotlib .rcParams ["pdf.fonttype" ]),
841
840
"3" , "42" ],
842
841
setter = lambda val :
843
- matplotlib .rcParams .__setitem__ ("pdf.fonttype" , val ))],
844
- ".ps" : [
845
- _Option ("PS paper size" ,
842
+ matplotlib .rcParams .__setitem__ ("pdf.fonttype" , val ))]) ,
843
+ ( "PS" , [
844
+ _Option ("Paper size" ,
846
845
getter = lambda :
847
846
[matplotlib .rcParams ["ps.papersize" ]]
848
847
+ ["auto" , "letter" , "legal" , "ledger" ]
849
848
+ ["A{}" .format (i ) for i in range (11 )]
850
849
+ ["B{}" .format (i ) for i in range (11 )],
851
850
setter = lambda val :
852
851
matplotlib .rcParams .__setitem__ ("ps.papersize" , val )),
853
- _Option ("PS use AFM font" , "ps.useafm" ),
854
- _Option ("PS distiller " ,
852
+ _Option ("Use AFM font? " , "ps.useafm" ),
853
+ _Option ("Distiller " ,
855
854
getter = lambda :
856
855
[str (matplotlib .rcParams ["ps.usedistiller" ])]
857
856
+ ["None" , "ghostscript" , "xpdf" ],
858
857
setter = lambda val :
859
858
matplotlib .rcParams .__setitem__ ("ps.usedistiller" , val )),
860
- _Option ("PS distiller resolution" , "ps.distiller.res" ),
861
- _Option ("PS font type" ,
859
+ _Option ("Distiller resolution" , "ps.distiller.res" ),
860
+ _Option ("Font type" ,
862
861
getter = lambda :
863
862
[str (matplotlib .rcParams ["ps.fonttype" ]),
864
863
"3" , "42" ],
865
864
setter = lambda val :
866
- matplotlib .rcParams .__setitem__ ("ps.fonttype" , val ))]
867
- }
865
+ matplotlib .rcParams .__setitem__ ("ps.fonttype" , val ))])]
868
866
869
867
870
868
class SubplotToolQt (UiSubplotTool ):
0 commit comments