You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

2 years ago
  1. import rewx.components as c # type: ignore
  2. import wx # type: ignore
  3. import wx.html2 # type: ignore
  4. from rewx import wsx, render # type: ignore
  5. def _html_window(html):
  6. return wsx(
  7. [c.Block, {'orient': wx.VERTICAL, 'flag': wx.EXPAND},
  8. [c.HtmlWindow, {'style': wx.TE_READONLY, 'flag': wx.EXPAND | wx.ALL,
  9. 'proportion': 1, 'value': html}]]
  10. )
  11. class HtmlDialog(wx.Dialog):
  12. """
  13. A MessageDialog where the central contents are an HTML window
  14. customizable by the user.
  15. """
  16. def __init__(self, *args, **kwargs):
  17. caption = kwargs.pop('caption', '')
  18. html = kwargs.pop('html', '')
  19. super(HtmlDialog, self).__init__(None, *args, **kwargs)
  20. wx.InitAllImageHandlers()
  21. self.SetTitle(caption)
  22. sizer = wx.BoxSizer(wx.VERTICAL)
  23. sizer.Add(render(_html_window(html), self), 1, wx.EXPAND)
  24. # in addition to creating the sizer, this actually attached
  25. # a few common handlers which makes it feel more dialog-y. Thus
  26. # it being done here rather than in rewx
  27. btnSizer = self.CreateStdDialogButtonSizer(wx.OK)
  28. sizer.Add(btnSizer, 0, wx.ALL | wx.EXPAND, 9)
  29. self.SetSizer(sizer)
  30. self.Layout()