Laurent@814: #!/usr/bin/env python Laurent@814: # -*- coding: utf-8 -*- Laurent@814: andrej@1571: # This file is part of Beremiz, a Integrated Development Environment for andrej@1571: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. Laurent@814: # andrej@1571: # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD Laurent@814: # andrej@1571: # See COPYING file for copyrights details. Laurent@814: # andrej@1571: # This program is free software; you can redistribute it and/or andrej@1571: # modify it under the terms of the GNU General Public License andrej@1571: # as published by the Free Software Foundation; either version 2 andrej@1571: # of the License, or (at your option) any later version. Laurent@814: # andrej@1571: # This program is distributed in the hope that it will be useful, andrej@1571: # but WITHOUT ANY WARRANTY; without even the implied warranty of andrej@1571: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrej@1571: # GNU General Public License for more details. Laurent@814: # andrej@1571: # You should have received a copy of the GNU General Public License andrej@1571: # along with this program; if not, write to the Free Software andrej@1571: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Laurent@814: andrej@1881: andrej@1881: from __future__ import absolute_import andrej@1732: import subprocess andrej@1732: import wx andrej@1732: import wx.html Laurent@814: Laurent@814: HtmlFrameOpened = [] Laurent@814: andrej@1736: Laurent@814: def OpenHtmlFrame(self, title, file, size): andrej@1838: if title not in HtmlFrameOpened: andrej@1838: HtmlFrameOpened.append(title) andrej@1838: window = HtmlFrame(self, HtmlFrameOpened) andrej@1838: window.SetTitle(title) andrej@1838: window.SetHtmlPage(file) andrej@1838: window.SetClientSize(size) andrej@1838: window.Show() Laurent@814: andrej@1749: Laurent@814: [ID_HTMLFRAME, ID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)] Laurent@814: EVT_HTML_URL_CLICK = wx.NewId() Laurent@814: andrej@1736: Laurent@814: class HtmlWindowUrlClick(wx.PyEvent): Laurent@814: def __init__(self, linkinfo): Laurent@814: wx.PyEvent.__init__(self) Laurent@814: self.SetEventType(EVT_HTML_URL_CLICK) Laurent@814: self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) andrej@1735: andrej@1736: Laurent@814: class UrlClickHtmlWindow(wx.html.HtmlWindow): Laurent@814: """ HTML window that generates and OnLinkClicked event. Laurent@814: Laurent@814: Use this to avoid having to override HTMLWindow Laurent@814: """ Laurent@814: def OnLinkClicked(self, linkinfo): Laurent@814: wx.PostEvent(self, HtmlWindowUrlClick(linkinfo)) andrej@1735: Laurent@814: def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY): Laurent@814: if event == HtmlWindowUrlClick: Laurent@814: self.Connect(-1, -1, EVT_HTML_URL_CLICK, handler) Laurent@814: else: andrej@1865: wx.html.HtmlWindow.Bind(self, event, handler, source=source, id=id, id2=id2) Laurent@814: andrej@1736: Laurent@814: class HtmlFrame(wx.Frame): andrej@1838: def _init_ctrls(self, prnt): andrej@1838: self.SetIcon(prnt.icon) andrej@1838: self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) andrej@1735: andrej@1838: self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT, andrej@1838: name='HtmlContent', parent=self, pos=wx.Point(0, 0), andrej@1838: size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO | wx.html.HW_NO_SELECTION) andrej@1838: self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick) Laurent@814: andrej@1838: def __init__(self, parent, opened): andrej@1838: wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame', andrej@1838: parent=parent, pos=wx.Point(320, 231), andrej@1838: size=wx.Size(853, 616), andrej@1838: style=wx.DEFAULT_FRAME_STYLE, title='') andrej@1838: self._init_ctrls(parent) andrej@1838: self.HtmlFrameOpened = opened andrej@1735: andrej@1838: def SetHtmlCode(self, htmlcode): andrej@1838: self.HtmlContent.SetPage(htmlcode) andrej@1735: andrej@1838: def SetHtmlPage(self, htmlpage): andrej@1838: self.HtmlContent.LoadPage(htmlpage) andrej@1735: andrej@1838: def OnCloseFrame(self, event): andrej@1838: self.HtmlFrameOpened.remove(self.GetTitle()) andrej@1838: event.Skip() andrej@1735: andrej@1838: def OnLinkClick(self, event): andrej@1838: url = event.linkinfo[0] andrej@1838: try: andrej@1838: if wx.Platform == '__WXMSW__': andrej@1838: import webbrowser andrej@1838: webbrowser.open(url) andrej@1838: elif subprocess.call("firefox %s" % url, shell=True) != 0: andrej@1838: wx.MessageBox("""Firefox browser not found.\nPlease point your browser at :\n%s""" % url) andrej@1838: except ImportError: andrej@1838: wx.MessageBox('Please point your browser at: %s' % url)