/mothership/tools/textdialog.py

https://github.com/excid3/chromium · Python · 113 lines · 60 code · 29 blank · 24 comment · 1 complexity · dfbf1ce0403c73d92fc0dae045f6f8e0 MD5 · raw file

  1. # Copyright (c) 2001, Stanford University
  2. # All rights reserved.
  3. #
  4. # See the file LICENSE.txt for information on redistributing this software.
  5. #
  6. # Authors:
  7. # Brian Paul
  8. """The TextDialog class defines a dialog window for displaying bulk text."""
  9. from wxPython.wx import *
  10. from wxPython.html import *
  11. class TextDialog(wxDialog):
  12. """Dialog window for showing html text"""
  13. def __init__(self, parent, id, title="Help"):
  14. id_BACK = 17000
  15. id_CLOSE = 17001
  16. wxDialog.__init__(self, parent, id, title, pos=wxPoint(-1,-1),
  17. style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
  18. outerSizer = wxBoxSizer(wxVERTICAL)
  19. p = parent
  20. self.html = wxHtmlWindow(parent=self, id=-1)
  21. outerSizer.Add(self.html, 1, wxGROW)
  22. rowSizer = wxGridSizer(rows=1, cols=2, vgap=4)
  23. self.BackButton = wxButton(parent=self, id=id_BACK, label="Back")
  24. self.CloseButton = wxButton(parent=self, id=id_CLOSE, label="Close")
  25. EVT_BUTTON(self.BackButton, id_BACK, self.__onBack)
  26. EVT_BUTTON(self.CloseButton, id_CLOSE, self.__onClose)
  27. rowSizer.Add(self.BackButton, 0, wxALIGN_CENTER, 8)
  28. rowSizer.Add(self.CloseButton, 0, wxALIGN_CENTER, 8)
  29. outerSizer.Add(rowSizer, 0, wxGROW|wxALL, 8)
  30. self.SetSizer(outerSizer)
  31. self.SetAutoLayout(true)
  32. self.SetSizeHints(minW=720, minH=500)
  33. self.Centre()
  34. def LoadPage(self, url):
  35. """Load the html window with a document from the given URL"""
  36. # XXX this isn't a real URL, it can only be a filename
  37. self.html.LoadPage(url)
  38. def SetPage(self, html):
  39. """Load html into the window"""
  40. self.html.SetPage(html)
  41. def __onBack(self, event):
  42. """Called by Back button"""
  43. self.html.HistoryBack()
  44. # XXX disable back button when we can't go back
  45. # if self.html.HistoryCanBack():
  46. # self.BackButton.Enable(TRUE)
  47. # else:
  48. # self.BackButton.Enable(FALSE)
  49. def __onClose(self, event):
  50. """Called by Close button"""
  51. self.Show(FALSE)
  52. self.EndModal(wxID_OK)
  53. # ======================================================================
  54. # Test routines
  55. class __TestApp(wxApp):
  56. """ Test harness wxApp class."""
  57. class __TestFrame(wxFrame):
  58. def __init__(self, parent, id, title):
  59. wxFrame.__init__(self, parent, id, title,
  60. style = wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS |
  61. wxNO_FULL_REPAINT_ON_RESIZE)
  62. EVT_CLOSE(self, self.doClose)
  63. def doClose(self, event):
  64. global app
  65. self.Destroy()
  66. app.ExitMainLoop()
  67. def OnInit(self):
  68. wxInitAllImageHandlers()
  69. frame = self.__TestFrame(parent=None, id=-1, title="Test App")
  70. frame.Show(TRUE)
  71. dialog = TextDialog(parent=frame, id=-1, title="Help!")
  72. #dialog.LoadPage("reassembly.html")
  73. dialog.LoadPage("../../doc/configtool.html")
  74. dialog.Centre()
  75. #dialog.ShowModal()
  76. dialog.Show()
  77. return TRUE
  78. def _test():
  79. global app
  80. app = __TestApp()
  81. app.MainLoop()
  82. return
  83. if __name__ == "__main__":
  84. _test()