/usr/lib/python2.7/dist-packages/traitsui/wx/extra/windows/ie_html_editor.py is in python-traitsui 4.4.0-1.3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | #-------------------------------------------------------------------------------
#
# Copyright (c) 2007, Enthought, Inc.
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in enthought/LICENSE.txt and may be redistributed only
# under the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
#
# Author: David C. Morrill
# Date: 03/11/2007
#
#-------------------------------------------------------------------------------
""" Traits UI MS Internet Explorer editor.
"""
#-------------------------------------------------------------------------------
# Imports:
#-------------------------------------------------------------------------------
import re
import webbrowser
import wx
if wx.Platform == '__WXMSW__':
# The new version of IEHTMLWindow (wx 2.8.8.0) is mostly compatible with
# the old one, but it has changed the API for handling COM events, so we
# cannot use it.
try:
import wx.lib.iewin_old as iewin
except ImportError:
import wx.lib.iewin as iewin
from traits.api \
import Bool, Event, Property, Str
from traitsui.wx.editor \
import Editor
from traitsui.basic_editor_factory \
import BasicEditorFactory
#-------------------------------------------------------------------------------
# Constants
#-------------------------------------------------------------------------------
RELATIVE_OBJECTS_PATTERN = re.compile(r'src=["\'](?!https?:)([\s\w/\.]+?)["\']',
re.IGNORECASE)
#-------------------------------------------------------------------------------
# '_IEHTMLEditor' class:
#-------------------------------------------------------------------------------
class _IEHTMLEditor ( Editor ):
""" Traits UI MS Internet Explorer editor.
"""
#---------------------------------------------------------------------------
# Trait definitions:
#---------------------------------------------------------------------------
# Is the table editor is scrollable? This value overrides the default.
scrollable = True
# External objects referenced in the HTML are relative to this url
base_url = Str
# Event fired when the browser home page should be displayed:
home = Event
# Event fired when the browser should show the previous page:
back = Event
# Event fired when the browser should show the next page:
forward = Event
# Event fired when the browser should stop loading the current page:
stop = Event
# Event fired when the browser should refresh the current page:
refresh = Event
# Event fired when the browser should search the current page:
search = Event
# The current browser status:
status = Str
# The current browser page title:
title = Str
# The URL of the page that just finished loading:
page_loaded = Str
# The current page content as HTML:
html = Property
#---------------------------------------------------------------------------
# Finishes initializing the editor by creating the underlying toolkit
# widget:
#---------------------------------------------------------------------------
def init ( self, parent ):
""" Finishes initializing the editor by creating the underlying toolkit
widget.
"""
self.control = ie = iewin.IEHtmlWindow( parent, -1,
style = wx.NO_FULL_REPAINT_ON_RESIZE )
self.set_tooltip()
factory = self.factory
self.base_url = factory.base_url
self.sync_value( factory.home, 'home', 'from' )
self.sync_value( factory.back, 'back', 'from' )
self.sync_value( factory.forward, 'forward', 'from' )
self.sync_value( factory.stop, 'stop', 'from' )
self.sync_value( factory.refresh, 'refresh', 'from' )
self.sync_value( factory.search, 'search', 'from' )
self.sync_value( factory.status, 'status', 'to' )
self.sync_value( factory.title, 'title', 'to' )
self.sync_value( factory.page_loaded, 'page_loaded', 'to' )
self.sync_value( factory.html, 'html', 'to' )
self.sync_value( factory.base_url_name, 'base_url', 'from' )
parent.Bind( iewin.EVT_StatusTextChange, self._status_modified, ie )
parent.Bind( iewin.EVT_TitleChange, self._title_modified, ie )
parent.Bind( iewin.EVT_DocumentComplete, self._page_loaded_modified,ie )
parent.Bind( iewin.EVT_NewWindow2, self._new_window_modified, ie )
parent.Bind( iewin.EVT_BeforeNavigate2, self._navigate_requested, ie )
#---------------------------------------------------------------------------
# Updates the editor when the object trait changes external to the editor:
#---------------------------------------------------------------------------
def update_editor ( self ):
""" Updates the editor when the object trait changes externally to the
editor.
"""
value = self.str_value.strip()
# We can correct URLs via the BeforeNavigate Event, but the COM
# interface provides no such option for images. Sadly, we are forced
# to take a more brute force approach.
if self.base_url:
rep = lambda m: r'src="%s%s"' % ( self.base_url, m.group( 1 ) )
value = re.sub( RELATIVE_OBJECTS_PATTERN, rep, value )
if value == '':
self.control.LoadString( '<html><body></body></html>' )
elif value[:1] == '<':
self.control.LoadString( value )
elif (value[:4] != 'http') or (value.find( '://' ) < 0):
try:
file = open( value, 'rb' )
self.control.LoadStream( file )
file.close()
except:
pass
else:
self.control.Navigate( value )
#-- Property Implementations -----------------------------------------------
def _get_html ( self ):
return self.control.GetText()
def _set_html ( self, value ):
self.control.LoadString( value )
#-- Event Handlers ---------------------------------------------------------
def _home_changed ( self ):
self.control.GoHome()
def _back_changed ( self ):
self.control.GoBack()
def _forward_changed ( self ):
self.control.GoForward()
def _stop_changed ( self ):
self.control.Stop()
def _search_changed ( self ):
self.control.GoSearch()
def _refresh_changed ( self ):
self.control.Refresh( iewin.REFRESH_COMPLETELY )
def _status_modified ( self, event ):
self.status = event.Text
def _title_modified ( self, event ):
self.title = event.Text
def _page_loaded_modified ( self, event ):
self.page_loaded = event.URL
self.trait_property_changed( 'html', '', self.html )
def _new_window_modified ( self, event ):
# If the event is cancelled, new windows can be disabled.
# At this point we've opted to allow new windows
pass
def _navigate_requested ( self, event ):
# The way NavigateToString works is to navigate to about:blank then
# load the supplied HTML into the document property. This borks
# relative URLs.
if event.URL.startswith ( 'about:' ):
base = self.base_url
if not base.endswith( '/' ):
base += '/'
event.URL = base + event.URL[6:]
if self.factory.open_externally:
event.Cancel = True
webbrowser.get( 'windows-default' ).open_new( event.URL )
#-------------------------------------------------------------------------------
# Create the editor factory object:
#-------------------------------------------------------------------------------
# wxPython editor factory for MS Internet Explorer editors:
class IEHTMLEditor ( BasicEditorFactory ):
# The editor class to be created:
klass = _IEHTMLEditor
# External objects referenced in the HTML are relative to this url
base_url = Str
# The object trait containing the base URL
base_url_name = Str
# Should links be opened in an external browser?
open_externally = Bool(False)
# Optional name of trait used to tell browser to show Home page:
home = Str
# Optional name of trait used to tell browser to view the previous page:
back = Str
# Optional name of trait used to tell browser to view the next page:
forward = Str
# Optional name of trait used to tell browser to stop loading page:
stop = Str
# Optional name of trait used to tell browser to refresh the current page:
refresh = Str
# Optional name of trait used to tell browser to search the current page:
search = Str
# Optional name of trait used to contain the current browser status:
status = Str
# Optional name of trait used to contain the current browser page title:
title = Str
# Optional name of trait used to contain the URL of the page that just
# completed loading:
page_loaded = Str
# Optional name of trait used to get/set the page content as HTML:
html = Str
|