@@ -1958,6 +1958,57 @@ def remove_rubberband(self, dc=None):
1958
1958
self ._rect = None
1959
1959
1960
1960
1961
+ class _HelpDialog (wx .Dialog ):
1962
+ _instance = None # a reference to an open dialog singleton
1963
+ headers = [("Action" , "Shortcuts" , "Description" )]
1964
+ widths = [100 , 140 , 300 ]
1965
+
1966
+ def __init__ (self , parent , help_entries ):
1967
+ wx .Dialog .__init__ (self , parent , title = "Help" ,
1968
+ style = wx .DEFAULT_DIALOG_STYLE | wx .RESIZE_BORDER )
1969
+
1970
+ sizer = wx .BoxSizer (wx .VERTICAL )
1971
+ grid_sizer = wx .FlexGridSizer (0 , 3 , 8 , 6 )
1972
+ # create and add the entries
1973
+ bold = self .GetFont ().MakeBold ()
1974
+ for r , row in enumerate (self .headers + help_entries ):
1975
+ for (col , width ) in zip (row , self .widths ):
1976
+ label = wx .StaticText (self , label = col )
1977
+ if r == 0 :
1978
+ label .SetFont (bold )
1979
+ label .Wrap (width )
1980
+ grid_sizer .Add (label , 0 , 0 , 0 )
1981
+ # finalize layout, create button
1982
+ sizer .Add (grid_sizer , 0 , wx .ALL , 6 )
1983
+ OK = wx .Button (self , wx .ID_OK )
1984
+ sizer .Add (OK , 0 , wx .ALIGN_CENTER_HORIZONTAL | wx .ALL , 8 )
1985
+ self .SetSizer (sizer )
1986
+ sizer .Fit (self )
1987
+ self .Layout ()
1988
+ self .Bind (wx .EVT_CLOSE , self .OnClose )
1989
+ OK .Bind (wx .EVT_BUTTON , self .OnClose )
1990
+
1991
+ def OnClose (self , evt ):
1992
+ _HelpDialog ._instance = None # remove global reference
1993
+ self .DestroyLater ()
1994
+ evt .Skip ()
1995
+
1996
+ @classmethod
1997
+ def show (cls , parent , help_entries ):
1998
+ # if no dialog is shown, create one; otherwise just re-raise it
1999
+ if cls ._instance :
2000
+ cls ._instance .Raise ()
2001
+ return
2002
+ cls ._instance = cls (parent , help_entries )
2003
+ cls ._instance .Show ()
2004
+
2005
+
2006
+ class HelpWx (backend_tools .ToolHelpBase ):
2007
+ def trigger (self , * args ):
2008
+ _HelpDialog .show (self .figure .canvas .GetTopLevelParent (),
2009
+ self ._get_help_entries ())
2010
+
2011
+
1961
2012
class ToolCopyToClipboardWx (backend_tools .ToolCopyToClipboardBase ):
1962
2013
def trigger (self , * args , ** kwargs ):
1963
2014
if not self .canvas ._isDrawn :
@@ -1974,6 +2025,7 @@ def trigger(self, *args, **kwargs):
1974
2025
backend_tools .ToolConfigureSubplots = ConfigureSubplotsWx
1975
2026
backend_tools .ToolSetCursor = SetCursorWx
1976
2027
backend_tools .ToolRubberband = RubberbandWx
2028
+ backend_tools .ToolHelp = HelpWx
1977
2029
backend_tools .ToolCopyToClipboard = ToolCopyToClipboardWx
1978
2030
1979
2031
0 commit comments