Laurent@814: #!/usr/bin/env python Laurent@814: # -*- coding: utf-8 -*- Laurent@814: Laurent@814: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor Laurent@814: #based on the plcopen standard. Laurent@814: # Laurent@814: #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD Laurent@814: # Laurent@814: #See COPYING file for copyrights details. Laurent@814: # Laurent@814: #This library is free software; you can redistribute it and/or Laurent@814: #modify it under the terms of the GNU General Public Laurent@814: #License as published by the Free Software Foundation; either Laurent@814: #version 2.1 of the License, or (at your option) any later version. Laurent@814: # Laurent@814: #This library is distributed in the hope that it will be useful, Laurent@814: #but WITHOUT ANY WARRANTY; without even the implied warranty of Laurent@814: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Laurent@814: #General Public License for more details. Laurent@814: # Laurent@814: #You should have received a copy of the GNU General Public Laurent@814: #License along with this library; if not, write to the Free Software Laurent@814: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Laurent@814: Laurent@814: import wx, os, wx.html, subprocess 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) Laurent@814: 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: Laurent@814: wx.MessageBox('Please point your browser at: %s' % url)