Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 78ffba8

Browse files
move singleton reference to _HelpDialog and implement class method show()
1 parent 8818ee3 commit 78ffba8

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

lib/matplotlib/backends/backend_wx.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,17 +1827,19 @@ def remove_rubberband(self, dc=None):
18271827

18281828

18291829
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",
18321835
style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
18331836

18341837
sizer = wx.BoxSizer(wx.VERTICAL)
18351838
grid_sizer = wx.FlexGridSizer(0, 3, 8, 6)
18361839
# create and add the entries
1837-
widths = [100, 140, 300]
18381840
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):
18411843
label = wx.StaticText(self, label=col)
18421844
if r == 0:
18431845
label.SetFont(bold)
@@ -1854,24 +1856,24 @@ def __init__(self, parent, help_entries, title="Help"):
18541856
OK.Bind(wx.EVT_BUTTON, self.OnClose)
18551857

18561858
def OnClose(self, evt):
1857-
HelpWx.dlg = None # remove global reference
1859+
_HelpDialog.instance = None # remove global reference
18581860
self.DestroyLater()
18591861
evt.Skip()
18601862

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+
18611872

18621873
class HelpWx(backend_tools.ToolHelpBase):
1863-
dlg = None # a reference to the opened dialog, to avoid more than one
18641874
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())
18751877

18761878

18771879
backend_tools.ToolSaveFigure = SaveFigureWx

0 commit comments

Comments
 (0)