|
From: Kevin A. <al...@se...> - 2001-12-18 18:52:46
|
As an experiment, I created an HTMLField widget yesterday. The complete
htmlfield.py file that I put in the 'components' directory is below. This is
not a complete interface to wxHtmlWindow, just a simple test.
I modified the minimal.rsrc.py file:
{ 'type':'HTMLField',
'name':'field1',
'position':(0, 0),
'size':(400, 450),
#'text':'<html><head><title>Hello</title></head><body>hello
world</body></html>' },
'text':'index.html'},
wxHtmlWindow supports loading of a URL or filename as well as setting the
HTML directly. It handles the HTTP requests internally. wxHtmlWindow is not
intended to build a full-featured browser, but it is more than adequate for
displaying non-editable/non-selectable HTML for help or any place you might
normally use a non-editable TextField or TextArea widget, but want richer
text capabilities with embedded images... There are more elaborate
capabilities such as embedding other wxPython controls in the wxHtmlWindow,
but I don't want to try dealing with that initially.
So, the question is what the component should be named? Then I'll add the
component and we can experiment with the capabilities. I'm tempted to just
name it "HtmlWindow" since once we move to directly subclassing wxPython
controls and windows, using the wxPython name, minus the "wx" prefix might
simplify reading user code and docs.
I also want to add a component for displaying MS HTML Workshop format files
which in handled by wxHtmlHelpController, but I haven't experimented with
this yet. If anyone has experience with the help file format and/or
wxPython/wxWindows classes for using them and would like to do some of the
work, please let me know.
ka
---
htmlfield.py:
from wxPython import wx, html
import sys
from PythonCardPrototype import binding, event, widget
class HTMLFieldSpec(widget.WidgetSpec):
def __init__(self):
widget.WidgetSpec.__init__(self)
self.name = 'HTMLField'
self.parent = 'Widget'
self.parentName = self.parent
self._attributes.update({
'text' : { 'presence' : 'optional', 'default' : '' },
})
self.attributes = self.parseAttributes(self._attributes)
self.requiredAttributes = self.parseRequiredAttributes()
self.optionalAttributes = self.parseOptionalAttributes()
class HTMLField(widget.Widget):
"""
An HTML window.
"""
_events = event.MOUSE_EVENTS
_spec = HTMLFieldSpec()
def __init__( self, aParent, aResource ) :
widget.Widget.__init__( self, aParent, aResource )
self._setText(aResource.text)
def _createDelegate( self, aParent, aResource ) :
return html.wxHtmlWindow( aParent._delegate,
self.getId(),
wx.wxPoint( aResource.position[ 0 ], aResource.position[ 1 ] ),
wx.wxSize( aResource.size[ 0 ], aResource.size[ 1 ] ),
#style = wx.wxHW_SCROLLBAR_AUTO | wx.wxCLIP_SIBLINGS,
name = aResource.name
)
def _bindEvents(self):
adapter = binding.wxPython_EventBinding(self)
adapter.bindEvents()
def _getText( self ) :
return self._delegate.GetOpenedPage()
def _setText( self, aString ) :
if aString == '' or aString[0] == '<':
self._delegate.SetPage(aString)
else:
# filename
self._delegate.LoadPage(aString)
#self._delegate.Refresh()
widget.WidgetRegistry['HTMLField'] = sys.modules[__name__].HTMLField
|