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@1732: import os andrej@1732: import subprocess andrej@1732: import wx andrej@1732: import wx.html Laurent@814: Laurent@814: HtmlFrameOpened = [] Laurent@814: Laurent@814: def OpenHtmlFrame(self, title, file, size): Laurent@814: if title not in HtmlFrameOpened: Laurent@814: HtmlFrameOpened.append(title) Laurent@814: window = HtmlFrame(self, HtmlFrameOpened) Laurent@814: window.SetTitle(title) Laurent@814: window.SetHtmlPage(file) Laurent@814: window.SetClientSize(size) Laurent@814: window.Show() Laurent@814: Laurent@814: [ID_HTMLFRAME, ID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)] Laurent@814: EVT_HTML_URL_CLICK = wx.NewId() Laurent@814: 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()) Laurent@814: 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)) Laurent@814: 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: Laurent@814: wx.html.HtmlWindow.Bind(event, handler, source=source, id=id, id2=id2) Laurent@814: Laurent@814: class HtmlFrame(wx.Frame): Laurent@814: def _init_ctrls(self, prnt): Laurent@814: wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame', Laurent@814: parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616), Laurent@814: style=wx.DEFAULT_FRAME_STYLE, title='') andrej@1490: self.SetIcon(prnt.icon) Laurent@814: self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) Laurent@814: Laurent@814: self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT, Laurent@814: name='HtmlContent', parent=self, pos=wx.Point(0, 0), Laurent@814: size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO|wx.html.HW_NO_SELECTION) Laurent@814: self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick) Laurent@814: Laurent@814: def __init__(self, parent, opened): Laurent@814: self._init_ctrls(parent) Laurent@814: self.HtmlFrameOpened = opened Laurent@814: Laurent@814: def SetHtmlCode(self, htmlcode): Laurent@814: self.HtmlContent.SetPage(htmlcode) Laurent@814: Laurent@814: def SetHtmlPage(self, htmlpage): Laurent@814: self.HtmlContent.LoadPage(htmlpage) Laurent@814: Laurent@814: def OnCloseFrame(self, event): Laurent@814: self.HtmlFrameOpened.remove(self.GetTitle()) Laurent@814: event.Skip() Laurent@814: Laurent@814: def OnLinkClick(self, event): Laurent@814: url = event.linkinfo[0] Laurent@814: try: Laurent@814: if wx.Platform == '__WXMSW__': Laurent@814: import webbrowser Laurent@814: webbrowser.open(url) andrej@1734: elif subprocess.call("firefox %s" % url, shell=True) != 0: Laurent@814: wx.MessageBox("""Firefox browser not found.\nPlease point your browser at :\n%s""" % url) Laurent@814: except ImportError: andrej@1571: wx.MessageBox('Please point your browser at: %s' % url)