docutil/dochtml.py
changeset 1838 646245c1c0d9
parent 1836 d42b6cf00fa6
child 1850 614396cbffbf
equal deleted inserted replaced
1837:c507c363625e 1838:646245c1c0d9
    29 
    29 
    30 HtmlFrameOpened = []
    30 HtmlFrameOpened = []
    31 
    31 
    32 
    32 
    33 def OpenHtmlFrame(self, title, file, size):
    33 def OpenHtmlFrame(self, title, file, size):
    34         if title not in HtmlFrameOpened:
    34     if title not in HtmlFrameOpened:
    35             HtmlFrameOpened.append(title)
    35         HtmlFrameOpened.append(title)
    36             window = HtmlFrame(self, HtmlFrameOpened)
    36         window = HtmlFrame(self, HtmlFrameOpened)
    37             window.SetTitle(title)
    37         window.SetTitle(title)
    38             window.SetHtmlPage(file)
    38         window.SetHtmlPage(file)
    39             window.SetClientSize(size)
    39         window.SetClientSize(size)
    40             window.Show()
    40         window.Show()
    41 
    41 
    42 
    42 
    43 [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)]
    44 EVT_HTML_URL_CLICK = wx.NewId()
    44 EVT_HTML_URL_CLICK = wx.NewId()
    45 
    45 
    65         else:
    65         else:
    66             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)
    67 
    67 
    68 
    68 
    69 class HtmlFrame(wx.Frame):
    69 class HtmlFrame(wx.Frame):
    70         def _init_ctrls(self, prnt):
    70     def _init_ctrls(self, prnt):
    71             self.SetIcon(prnt.icon)
    71         self.SetIcon(prnt.icon)
    72             self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
    72         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
    73 
    73 
    74             self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT,
    74         self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT,
    75                                                   name='HtmlContent', parent=self, pos=wx.Point(0, 0),
    75                                               name='HtmlContent', parent=self, pos=wx.Point(0, 0),
    76                                                   size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO | wx.html.HW_NO_SELECTION)
    76                                               size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO | wx.html.HW_NO_SELECTION)
    77             self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick)
    77         self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick)
    78 
    78 
    79         def __init__(self, parent, opened):
    79     def __init__(self, parent, opened):
    80             wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame',
    80         wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame',
    81                               parent=parent, pos=wx.Point(320, 231),
    81                           parent=parent, pos=wx.Point(320, 231),
    82                               size=wx.Size(853, 616),
    82                           size=wx.Size(853, 616),
    83                               style=wx.DEFAULT_FRAME_STYLE, title='')
    83                           style=wx.DEFAULT_FRAME_STYLE, title='')
    84             self._init_ctrls(parent)
    84         self._init_ctrls(parent)
    85             self.HtmlFrameOpened = opened
    85         self.HtmlFrameOpened = opened
    86 
    86 
    87         def SetHtmlCode(self, htmlcode):
    87     def SetHtmlCode(self, htmlcode):
    88             self.HtmlContent.SetPage(htmlcode)
    88         self.HtmlContent.SetPage(htmlcode)
    89 
    89 
    90         def SetHtmlPage(self, htmlpage):
    90     def SetHtmlPage(self, htmlpage):
    91             self.HtmlContent.LoadPage(htmlpage)
    91         self.HtmlContent.LoadPage(htmlpage)
    92 
    92 
    93         def OnCloseFrame(self, event):
    93     def OnCloseFrame(self, event):
    94             self.HtmlFrameOpened.remove(self.GetTitle())
    94         self.HtmlFrameOpened.remove(self.GetTitle())
    95             event.Skip()
    95         event.Skip()
    96 
    96 
    97         def OnLinkClick(self, event):
    97     def OnLinkClick(self, event):
    98             url = event.linkinfo[0]
    98         url = event.linkinfo[0]
    99             try:
    99         try:
   100                 if wx.Platform == '__WXMSW__':
   100             if wx.Platform == '__WXMSW__':
   101                     import webbrowser
   101                 import webbrowser
   102                     webbrowser.open(url)
   102                 webbrowser.open(url)
   103                 elif subprocess.call("firefox %s" % url, shell=True) != 0:
   103             elif subprocess.call("firefox %s" % url, shell=True) != 0:
   104                     wx.MessageBox("""Firefox browser not found.\nPlease point your browser at :\n%s""" % url)
   104                 wx.MessageBox("""Firefox browser not found.\nPlease point your browser at :\n%s""" % url)
   105             except ImportError:
   105         except ImportError:
   106                 wx.MessageBox('Please point your browser at: %s' % url)
   106             wx.MessageBox('Please point your browser at: %s' % url)