@@ -1827,17 +1827,19 @@ def remove_rubberband(self, dc=None):
1827
1827
1828
1828
1829
1829
class _HelpDialog (wx .Dialog ):
1830
- def __init__ (self , parent , help_entries , title = "Help" ):
1831
- wx .Dialog .__init__ (self , parent , title = title ,
1830
+ _instance = None # a reference to an open dialog singleton
1831
+ headers = [("Action" , "Shortcuts" , "Description" )]
1832
+ widths = [100 , 140 , 300 ]
1833
+ def __init__ (self , parent , help_entries ):
1834
+ wx .Dialog .__init__ (self , parent , title = "Help" ,
1832
1835
style = wx .DEFAULT_DIALOG_STYLE | wx .RESIZE_BORDER )
1833
1836
1834
1837
sizer = wx .BoxSizer (wx .VERTICAL )
1835
1838
grid_sizer = wx .FlexGridSizer (0 , 3 , 8 , 6 )
1836
1839
# create and add the entries
1837
- widths = [100 , 140 , 300 ]
1838
1840
bold = self .GetFont ().MakeBold ()
1839
- for r , row in enumerate (help_entries ):
1840
- for (col , width ) in zip (row , widths ):
1841
+ for r , row in enumerate (self . headers + help_entries ):
1842
+ for (col , width ) in zip (row , self . widths ):
1841
1843
label = wx .StaticText (self , label = col )
1842
1844
if r == 0 :
1843
1845
label .SetFont (bold )
@@ -1854,24 +1856,24 @@ def __init__(self, parent, help_entries, title="Help"):
1854
1856
OK .Bind (wx .EVT_BUTTON , self .OnClose )
1855
1857
1856
1858
def OnClose (self , evt ):
1857
- HelpWx . dlg = None # remove global reference
1859
+ _HelpDialog . instance = None # remove global reference
1858
1860
self .DestroyLater ()
1859
1861
evt .Skip ()
1860
1862
1863
+ @classmethod
1864
+ def show (cls , parent , help_entries ):
1865
+ # if no dialog is shown, create one; otherwise just re-raise it
1866
+ if cls ._instance :
1867
+ cls ._instance .Raise ()
1868
+ return
1869
+ cls ._instance = cls (parent , help_entries )
1870
+ cls ._instance .Show ()
1871
+
1861
1872
1862
1873
class HelpWx (backend_tools .ToolHelpBase ):
1863
- dlg = None # a reference to the opened dialog, to avoid more than one
1864
1874
def trigger (self , * args ):
1865
- if HelpWx .dlg :
1866
- # previous dialog is still open
1867
- HelpWx .dlg .Raise ()
1868
- return
1869
- # create new dialog and keep a reference
1870
- help_entries = [("Action" , "Shortcuts" , "Description" )]
1871
- help_entries += self ._get_help_entries ()
1872
- HelpWx .dlg = _HelpDialog (self .figure .canvas .GetTopLevelParent (),
1873
- help_entries )
1874
- HelpWx .dlg .Show ()
1875
+ _HelpDialog .show (self .figure .canvas .GetTopLevelParent (),
1876
+ self ._get_help_entries ())
1875
1877
1876
1878
1877
1879
backend_tools .ToolSaveFigure = SaveFigureWx
0 commit comments