44 class HtmlWindowUrlClick(wx.PyEvent): |
44 class HtmlWindowUrlClick(wx.PyEvent): |
45 def __init__(self, linkinfo): |
45 def __init__(self, linkinfo): |
46 wx.PyEvent.__init__(self) |
46 wx.PyEvent.__init__(self) |
47 self.SetEventType(EVT_HTML_URL_CLICK) |
47 self.SetEventType(EVT_HTML_URL_CLICK) |
48 self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) |
48 self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) |
49 |
49 |
50 class UrlClickHtmlWindow(wx.html.HtmlWindow): |
50 class UrlClickHtmlWindow(wx.html.HtmlWindow): |
51 """ HTML window that generates and OnLinkClicked event. |
51 """ HTML window that generates and OnLinkClicked event. |
52 |
52 |
53 Use this to avoid having to override HTMLWindow |
53 Use this to avoid having to override HTMLWindow |
54 """ |
54 """ |
55 def OnLinkClicked(self, linkinfo): |
55 def OnLinkClicked(self, linkinfo): |
56 wx.PostEvent(self, HtmlWindowUrlClick(linkinfo)) |
56 wx.PostEvent(self, HtmlWindowUrlClick(linkinfo)) |
57 |
57 |
58 def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY): |
58 def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY): |
59 if event == HtmlWindowUrlClick: |
59 if event == HtmlWindowUrlClick: |
60 self.Connect(-1, -1, EVT_HTML_URL_CLICK, handler) |
60 self.Connect(-1, -1, EVT_HTML_URL_CLICK, handler) |
61 else: |
61 else: |
62 wx.html.HtmlWindow.Bind(event, handler, source=source, id=id, id2=id2) |
62 wx.html.HtmlWindow.Bind(event, handler, source=source, id=id, id2=id2) |
66 wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame', |
66 wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame', |
67 parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616), |
67 parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616), |
68 style=wx.DEFAULT_FRAME_STYLE, title='') |
68 style=wx.DEFAULT_FRAME_STYLE, title='') |
69 self.SetIcon(prnt.icon) |
69 self.SetIcon(prnt.icon) |
70 self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
70 self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
71 |
71 |
72 self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT, |
72 self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT, |
73 name='HtmlContent', parent=self, pos=wx.Point(0, 0), |
73 name='HtmlContent', parent=self, pos=wx.Point(0, 0), |
74 size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO|wx.html.HW_NO_SELECTION) |
74 size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO|wx.html.HW_NO_SELECTION) |
75 self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick) |
75 self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick) |
76 |
76 |
77 def __init__(self, parent, opened): |
77 def __init__(self, parent, opened): |
78 self._init_ctrls(parent) |
78 self._init_ctrls(parent) |
79 self.HtmlFrameOpened = opened |
79 self.HtmlFrameOpened = opened |
80 |
80 |
81 def SetHtmlCode(self, htmlcode): |
81 def SetHtmlCode(self, htmlcode): |
82 self.HtmlContent.SetPage(htmlcode) |
82 self.HtmlContent.SetPage(htmlcode) |
83 |
83 |
84 def SetHtmlPage(self, htmlpage): |
84 def SetHtmlPage(self, htmlpage): |
85 self.HtmlContent.LoadPage(htmlpage) |
85 self.HtmlContent.LoadPage(htmlpage) |
86 |
86 |
87 def OnCloseFrame(self, event): |
87 def OnCloseFrame(self, event): |
88 self.HtmlFrameOpened.remove(self.GetTitle()) |
88 self.HtmlFrameOpened.remove(self.GetTitle()) |
89 event.Skip() |
89 event.Skip() |
90 |
90 |
91 def OnLinkClick(self, event): |
91 def OnLinkClick(self, event): |
92 url = event.linkinfo[0] |
92 url = event.linkinfo[0] |
93 try: |
93 try: |
94 if wx.Platform == '__WXMSW__': |
94 if wx.Platform == '__WXMSW__': |
95 import webbrowser |
95 import webbrowser |