~ubuntu-branches/ubuntu/trusty/drpython/trusty

« back to all changes in this revision

Viewing changes to drHtmlBrowser.py

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-07-03 22:11:49 UTC
  • mfrom: (0.1.3 upstream) (8 intrepid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20080703221149-puu681p4w33g3s3m
* New upstream release.
* Bump epoch due to new version numbering system.
* debian/control:
  - Adjust dependencies for wxwidgets2.8.
* debian/patches/15_output_redirection.dpatch:
  - Set standard output and error to valid UNIX locations.
* Adjust patches for new upstream release:
  - debian/patches/03_pythonfix.dpatch
* Drop patches, implemented upstream:
  - debian/patches/10_ctrl_q_to_exit_as_default_shortcut.dpatch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# drHtmlBrowser.py
 
2
# Programmer: Eur Ing Christopher Thoday.
 
3
# Copyright: assigned to the DrPython project
 
4
 
 
5
import wx, os
 
6
import wx.html
 
7
"""This module provides a browser for displaying HTML files composed in
 
8
   the DrPython text editor.  Links are displayed within separate pages
 
9
   within the browser. The tab name for the page is the HTML title if given,
 
10
   else it is the file name."""
 
11
 
 
12
note = None
 
13
history = {}
 
14
 
 
15
def _AddPage(href):
 
16
    if href[0:5] != "http:":
 
17
        if not os.path.exists(href):
 
18
            href = os.path.normpath(os.path.join(dir, href))
 
19
            if not os.path.exists(href):
 
20
                wx.MessageBox("File does not exist: " + href, "DrPython HTML Browser")
 
21
                return
 
22
    if href in history:
 
23
        note.SetSelection(history[href])
 
24
        return
 
25
    np = note.GetPageCount()
 
26
    history[href] = np
 
27
    page = HtmlPage(note, -1)
 
28
    note.AddPage(page, "", True)
 
29
    page.LoadPage(href)
 
30
    title = page.GetOpenedPageTitle()
 
31
    (fname, ext) = os.path.splitext(title)
 
32
    if ext[0:4] == ".htm" or ext[0:5] == ".html":
 
33
        title = fname.title()
 
34
    note.SetPageText(np, title)
 
35
    
 
36
class HtmlPage(wx.html.HtmlWindow):
 
37
    def __init__(self, parent, id):
 
38
        wx.html.HtmlWindow.__init__(self, parent, id,
 
39
            style=wx.NO_FULL_REPAINT_ON_RESIZE)
 
40
        if "gtk2" in wx.PlatformInfo: self.SetStandardFonts()
 
41
            
 
42
    def OnLinkClicked(self, link):
 
43
        href = link.GetHref()
 
44
        #print href
 
45
        _AddPage(href)
 
46
    
 
47
class HtmlBrowser(wx.Dialog):
 
48
    def __init__(self,  parent, file, title):
 
49
        global note, dir
 
50
        dir = os.path.dirname(file)
 
51
        wx.Dialog.__init__(self, parent, -1, title, size=(500, 600), style=wx.DEFAULT_DIALOG_STYLE | wx.THICK_FRAME)
 
52
        note = wx.Notebook(self, -1)
 
53
        history.clear()
 
54
        _AddPage(file)
 
55
        note.SetSelection(0)
 
56
        #else nothing is displayed
 
57
        event = wx.SizeEvent()
 
58
        self.GetEventHandler().ProcessEvent(event)
 
59
 
 
60
 
 
61
def ShowHtmlFile(parent, file, title=""):
 
62
    if title == "":
 
63
        title = file
 
64
    d = HtmlBrowser(parent, file, title)
 
65
    d.ShowModal()
 
66
    d.Destroy()
 
67
    
 
68
 
 
69
 
 
70
                        
 
 
b'\\ No newline at end of file'