20 # |
20 # |
21 # You should have received a copy of the GNU General Public License |
21 # You should have received a copy of the GNU General Public License |
22 # along with this program; if not, write to the Free Software |
22 # along with this program; if not, write to the Free Software |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
24 |
25 import wx, os, wx.html, subprocess |
25 import os |
|
26 import subprocess |
|
27 import wx |
|
28 import wx.html |
26 |
29 |
27 HtmlFrameOpened = [] |
30 HtmlFrameOpened = [] |
|
31 |
28 |
32 |
29 def OpenHtmlFrame(self, title, file, size): |
33 def OpenHtmlFrame(self, title, file, size): |
30 if title not in HtmlFrameOpened: |
34 if title not in HtmlFrameOpened: |
31 HtmlFrameOpened.append(title) |
35 HtmlFrameOpened.append(title) |
32 window = HtmlFrame(self, HtmlFrameOpened) |
36 window = HtmlFrame(self, HtmlFrameOpened) |
33 window.SetTitle(title) |
37 window.SetTitle(title) |
34 window.SetHtmlPage(file) |
38 window.SetHtmlPage(file) |
35 window.SetClientSize(size) |
39 window.SetClientSize(size) |
36 window.Show() |
40 window.Show() |
37 |
41 |
|
42 |
38 [ID_HTMLFRAME, ID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)] |
43 [ID_HTMLFRAME, ID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)] |
39 EVT_HTML_URL_CLICK = wx.NewId() |
44 EVT_HTML_URL_CLICK = wx.NewId() |
|
45 |
40 |
46 |
41 class HtmlWindowUrlClick(wx.PyEvent): |
47 class HtmlWindowUrlClick(wx.PyEvent): |
42 def __init__(self, linkinfo): |
48 def __init__(self, linkinfo): |
43 wx.PyEvent.__init__(self) |
49 wx.PyEvent.__init__(self) |
44 self.SetEventType(EVT_HTML_URL_CLICK) |
50 self.SetEventType(EVT_HTML_URL_CLICK) |
45 self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) |
51 self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) |
46 |
52 |
|
53 |
47 class UrlClickHtmlWindow(wx.html.HtmlWindow): |
54 class UrlClickHtmlWindow(wx.html.HtmlWindow): |
48 """ HTML window that generates and OnLinkClicked event. |
55 """ HTML window that generates and OnLinkClicked event. |
49 |
56 |
50 Use this to avoid having to override HTMLWindow |
57 Use this to avoid having to override HTMLWindow |
51 """ |
58 """ |
52 def OnLinkClicked(self, linkinfo): |
59 def OnLinkClicked(self, linkinfo): |
53 wx.PostEvent(self, HtmlWindowUrlClick(linkinfo)) |
60 wx.PostEvent(self, HtmlWindowUrlClick(linkinfo)) |
54 |
61 |
55 def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY): |
62 def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY): |
56 if event == HtmlWindowUrlClick: |
63 if event == HtmlWindowUrlClick: |
57 self.Connect(-1, -1, EVT_HTML_URL_CLICK, handler) |
64 self.Connect(-1, -1, EVT_HTML_URL_CLICK, handler) |
58 else: |
65 else: |
59 wx.html.HtmlWindow.Bind(event, handler, source=source, id=id, id2=id2) |
66 wx.html.HtmlWindow.Bind(event, handler, source=source, id=id, id2=id2) |
60 |
67 |
|
68 |
61 class HtmlFrame(wx.Frame): |
69 class HtmlFrame(wx.Frame): |
62 def _init_ctrls(self, prnt): |
70 def _init_ctrls(self, prnt): |
63 wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame', |
71 wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame', |
64 parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616), |
72 parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616), |
65 style=wx.DEFAULT_FRAME_STYLE, title='') |
73 style=wx.DEFAULT_FRAME_STYLE, title='') |
66 self.SetIcon(prnt.icon) |
74 self.SetIcon(prnt.icon) |
67 self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
75 self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
68 |
76 |
69 self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT, |
77 self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT, |
70 name='HtmlContent', parent=self, pos=wx.Point(0, 0), |
78 name='HtmlContent', parent=self, pos=wx.Point(0, 0), |
71 size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO|wx.html.HW_NO_SELECTION) |
79 size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO | wx.html.HW_NO_SELECTION) |
72 self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick) |
80 self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick) |
73 |
81 |
74 def __init__(self, parent, opened): |
82 def __init__(self, parent, opened): |
75 self._init_ctrls(parent) |
83 self._init_ctrls(parent) |
76 self.HtmlFrameOpened = opened |
84 self.HtmlFrameOpened = opened |
77 |
85 |
78 def SetHtmlCode(self, htmlcode): |
86 def SetHtmlCode(self, htmlcode): |
79 self.HtmlContent.SetPage(htmlcode) |
87 self.HtmlContent.SetPage(htmlcode) |
80 |
88 |
81 def SetHtmlPage(self, htmlpage): |
89 def SetHtmlPage(self, htmlpage): |
82 self.HtmlContent.LoadPage(htmlpage) |
90 self.HtmlContent.LoadPage(htmlpage) |
83 |
91 |
84 def OnCloseFrame(self, event): |
92 def OnCloseFrame(self, event): |
85 self.HtmlFrameOpened.remove(self.GetTitle()) |
93 self.HtmlFrameOpened.remove(self.GetTitle()) |
86 event.Skip() |
94 event.Skip() |
87 |
95 |
88 def OnLinkClick(self, event): |
96 def OnLinkClick(self, event): |
89 url = event.linkinfo[0] |
97 url = event.linkinfo[0] |
90 try: |
98 try: |
91 if wx.Platform == '__WXMSW__': |
99 if wx.Platform == '__WXMSW__': |
92 import webbrowser |
100 import webbrowser |
93 webbrowser.open(url) |
101 webbrowser.open(url) |
94 elif subprocess.call("firefox %s"%url, shell=True) != 0: |
102 elif subprocess.call("firefox %s" % url, shell=True) != 0: |
95 wx.MessageBox("""Firefox browser not found.\nPlease point your browser at :\n%s""" % url) |
103 wx.MessageBox("""Firefox browser not found.\nPlease point your browser at :\n%s""" % url) |
96 except ImportError: |
104 except ImportError: |
97 wx.MessageBox('Please point your browser at: %s' % url) |
105 wx.MessageBox('Please point your browser at: %s' % url) |