@@ -724,6 +724,13 @@ def _init_toolbar(self):
724
724
self ._actions [callback ] = a
725
725
if callback in ['zoom' , 'pan' ]:
726
726
a .setCheckable (True )
727
+ if callback == 'save_figure' :
728
+ btn = self .widgetForAction (a )
729
+ btn .setPopupMode (QtWidgets .QToolButton .MenuButtonPopup )
730
+ menu = a .__menu = QtWidgets .QMenu ()
731
+ a .setMenu (menu )
732
+ menu .addAction (
733
+ 'Options for saving' , self ._ui_get_save_options )
727
734
if tooltip_text is not None :
728
735
a .setToolTip (tooltip_text )
729
736
if text == 'Subplots' :
@@ -854,32 +861,32 @@ def save_figure(self, *args):
854
861
if startpath != "" :
855
862
matplotlib .rcParams ['savefig.directory' ] = (
856
863
os .path .dirname (six .text_type (fname )))
857
- options = _default_savefig_options
858
- try :
859
- options = (options
860
- + [None ]
861
- + _extra_savefig_options [
862
- os .path .splitext (fname )[1 ].lower ()])
863
- except KeyError :
864
- pass
865
- fedit_arg = []
866
- for option in options :
867
- if option is None :
868
- fedit_arg .append ((None , None ))
869
- else :
870
- fedit_arg .append (option .make_fedit_entry ())
871
- fedit_res = formlayout .fedit (fedit_arg , "Options" )
872
- if not fedit_res :
873
- return
874
- for option , res in zip (filter (None , options ), fedit_res ):
875
- option .setter (res )
876
864
try :
877
865
self .canvas .figure .savefig (six .text_type (fname ))
878
866
except Exception as e :
879
867
QtWidgets .QMessageBox .critical (
880
868
self , "Error saving file" , six .text_type (e ),
881
869
QtWidgets .QMessageBox .Ok , QtWidgets .QMessageBox .NoButton )
882
870
871
+ def _ui_get_save_options (self ):
872
+ fedit_arg = []
873
+ for tab_name , options in _savefig_options :
874
+ fedit_arg .append (([], tab_name , "" ))
875
+ for option in options :
876
+ if option is None :
877
+ fedit_arg [- 1 ][0 ].append ((None , None ))
878
+ else :
879
+ fedit_arg [- 1 ][0 ].append (option .make_fedit_entry ())
880
+ fedit_res = formlayout .fedit (fedit_arg , "Options" )
881
+ if not fedit_res :
882
+ return
883
+ for option , res in zip (
884
+ [option
885
+ for tab_name , options in _savefig_options
886
+ for option in options ],
887
+ [res for tab in fedit_res for res in tab ]):
888
+ option .setter (res )
889
+
883
890
884
891
class _Option (object ):
885
892
@@ -903,55 +910,50 @@ def make_fedit_entry():
903
910
self .setter = setter
904
911
905
912
906
- _default_savefig_options = [
907
- _Option ("DPI" , "savefig.dpi" ),
908
- _Option ("Face color" , "savefig.facecolor" ),
909
- _Option ("Edge color" , "savefig.edgecolor" ),
910
- _Option ("Tight bounding box" ,
911
- getter = lambda : matplotlib .rcParams ["savefig.bbox" ] == "tight" ,
912
- setter = lambda val : matplotlib .rcParams .__setitem__ (
913
- "savefig.bbox" , "tight" if val else "standard" )),
914
- _Option ("Tight bounding box padding" , "savefig.pad_inches" ),
915
- _Option ("Transparent background" , "savefig.transparent" )]
916
-
917
-
918
- _extra_savefig_options = {
919
- ".jpg" : [
920
- _Option ("JPEG quality" , "savefig.jpeg_quality" )],
921
- ".jpeg" : [
922
- _Option ("JPEG quality" , "savefig.jpeg_quality" )],
923
- ".pdf" : [
924
- _Option ("PDF compression" , "pdf.compression" ),
925
- _Option ("PDF font type" ,
913
+ _savefig_options = [
914
+ ("Common" , [
915
+ _Option ("DPI" , "savefig.dpi" ),
916
+ _Option ("Face color" , "savefig.facecolor" ),
917
+ _Option ("Edge color" , "savefig.edgecolor" ),
918
+ _Option ("Tight bounding box" ,
919
+ getter = lambda : matplotlib .rcParams ["savefig.bbox" ] == "tight" ,
920
+ setter = lambda val : matplotlib .rcParams .__setitem__ (
921
+ "savefig.bbox" , "tight" if val else "standard" )),
922
+ _Option ("Tight bounding box padding" , "savefig.pad_inches" ),
923
+ _Option ("Transparent background" , "savefig.transparent" )]),
924
+ ("JPEG" , [
925
+ _Option ("Quality" , "savefig.jpeg_quality" )]),
926
+ ("PDF" , [
927
+ _Option ("Compression" , "pdf.compression" ),
928
+ _Option ("Font type" ,
926
929
getter = lambda :
927
930
[str (matplotlib .rcParams ["pdf.fonttype" ]),
928
931
"3" , "42" ],
929
932
setter = lambda val :
930
- matplotlib .rcParams .__setitem__ ("pdf.fonttype" , val ))],
931
- ".ps" : [
932
- _Option ("PS paper size" ,
933
+ matplotlib .rcParams .__setitem__ ("pdf.fonttype" , val ))]) ,
934
+ ( "PS" , [
935
+ _Option ("Paper size" ,
933
936
getter = lambda :
934
937
[matplotlib .rcParams ["ps.papersize" ]]
935
938
+ ["auto" , "letter" , "legal" , "ledger" ]
936
939
+ ["A{}" .format (i ) for i in range (11 )]
937
940
+ ["B{}" .format (i ) for i in range (11 )],
938
941
setter = lambda val :
939
942
matplotlib .rcParams .__setitem__ ("ps.papersize" , val )),
940
- _Option ("PS use AFM font" , "ps.useafm" ),
941
- _Option ("PS distiller " ,
943
+ _Option ("Use AFM font? " , "ps.useafm" ),
944
+ _Option ("Distiller " ,
942
945
getter = lambda :
943
946
[str (matplotlib .rcParams ["ps.usedistiller" ])]
944
947
+ ["None" , "ghostscript" , "xpdf" ],
945
948
setter = lambda val :
946
949
matplotlib .rcParams .__setitem__ ("ps.usedistiller" , val )),
947
- _Option ("PS distiller resolution" , "ps.distiller.res" ),
948
- _Option ("PS font type" ,
950
+ _Option ("Distiller resolution" , "ps.distiller.res" ),
951
+ _Option ("Font type" ,
949
952
getter = lambda :
950
953
[str (matplotlib .rcParams ["ps.fonttype" ]),
951
954
"3" , "42" ],
952
955
setter = lambda val :
953
- matplotlib .rcParams .__setitem__ ("ps.fonttype" , val ))]
954
- }
956
+ matplotlib .rcParams .__setitem__ ("ps.fonttype" , val ))])]
955
957
956
958
957
959
class SubplotToolQt (UiSubplotTool ):
0 commit comments