New wxHtml stuff, including a TagHandler for placing wxPython widgets

on the html page.

Some other tweaks and fixes


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3691 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn 1999-09-17 05:55:00 +00:00
parent 2819545569
commit e166644c53
19 changed files with 2097 additions and 82 deletions

View File

@ -0,0 +1,46 @@
from wxPython.wx import *
from wxPython.html import *
import wxPython.lib.wxpTag
#---------------------------------------------------------------------------
class MyAboutBox(wxDialog):
text = '''
<html>
<body bgcolor="#AC76DE">
<center><table bgcolor="#458154" width="100%%" cellspacing="0" cellpadding="0" border="1">
<tr>
<td align="center"><h1>wxPython %s</h1></td>
</tr>
</table>
<p><b>wxPython</b> is a Python extension module that
encapsulates the wxWindows GUI classes.</p>
<p>This demo shows off some of the capabilities
of <b>wxPython</b>. Select items from the menu or tree control,
sit back and enjoy. Be sure to take a peek at the source code for each
demo item so you can learn how to use the classes yourself.</p>
<p><b>wxPython</b> is brought to you by <b>Robin Dunn</b> and<br>
<b>Total Control Software</b>, Copyright (c) 1998-1999.</p>
<p><font size="-1">Please see <i>license.txt</i> for licensing information.</font></p>
<p><wxp class="wxButton">
<param name="label" value="Okay">
<param name="id" value="wxID_OK">
</wxp></p>
</center>
</body>
</html>
'''
def __init__(self, parent):
wxDialog.__init__(self, parent, -1, 'About wxPython')
self.html = wxHtmlWindow(self, -1, wxPoint(5,5), wxSize(400, 350))
self.html.SetPage(self.text % wx.__version__)
self.Fit()
#---------------------------------------------------------------------------

View File

@ -133,7 +133,7 @@ class wxPythonDemo(wxFrame):
self.log = wxTextCtrl(splitter2, -1,
style = wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL)
(w, self.charHeight) = self.log.GetTextExtent('X')
#self.WriteText('wxPython Demo Log:\n')
self.WriteText('wxPython Demo Log:\n')
# add the windows to the splitter and split it.
@ -168,8 +168,9 @@ class wxPythonDemo(wxFrame):
w, h = self.log.GetClientSizeTuple()
numLines = h/self.charHeight
x, y = self.log.PositionToXY(self.log.GetLastPosition())
self.log.ShowPosition(self.log.XYToPosition(x, y-numLines))
##self.log.ShowPosition(self.log.GetLastPosition())
if y > numLines:
self.log.ShowPosition(self.log.XYToPosition(x, y-numLines))
##self.log.ShowPosition(self.log.GetLastPosition())
self.log.SetInsertionPointEnd()
def write(self, txt):
@ -265,6 +266,7 @@ class wxPythonDemo(wxFrame):
# "of wxPython.\n\n"
# " Developed by Robin Dunn",
# "About wxPython", wxOK)
from About import MyAboutBox
about = MyAboutBox(self)
about.ShowModal()
about.Destroy()
@ -296,44 +298,6 @@ class wxPythonDemo(wxFrame):
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
class MyAboutBox(wxDialog):
text = '''
<html>
<body bgcolor="#AC76DE">
<center><table bgcolor="#458154" width="100%%" cellspacing="0" cellpadding="0" border="1">
<tr>
<td align="center"><h1>wxPython %s</h1></td>
</tr>
</table>
<p><b>wxPython</b> is a Python extension module that
encapsulates the wxWindows GUI classes.</p>
<p>This demo shows off some of the capabilities
of <b>wxPython</b>. Select items from the menu or tree control,
sit back and enjoy. Be sure to take a peek at the source code for each
demo item so you can learn how to use the classes yourself.</p>
<p><b>wxPython</b> is brought to you by <b>Robin Dunn</b> and<br>
<b>Total Control Software</b>, copyright 1999.</p>
<p><font size="-1">Please see <i>license.txt</i> for licensing information.</font></p>
</center>
</body>
</html>
'''
def __init__(self, parent):
from wxPython.html import *
wxDialog.__init__(self, parent, -1, 'About wxPython')
self.html = wxHtmlWindow(self, -1, wxPoint(5,5), wxSize(400, 350))
self.html.SetPage(self.text % wx.__version__)
wxButton(self, wxID_OK, 'OK', wxPoint(5, 365)).SetDefault()
self.Fit()
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------

View File

@ -4,9 +4,9 @@
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="GENERATOR" CONTENT="Mozilla/4.06 [en] (X11; I; Linux
2.0.35 i686) [Netscape]">
<TITLE>wxHTML Test</TITLE>
<TITLE>wxPython does wxHTML!</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#006600" LINK="#0000FF" VLINK="#FF0000" ALINK="#000088">
<BODY TEXT="#000000" BGCOLOR="#008800" LINK="#0000FF" VLINK="#FF0000" ALINK="#000088">
<b><a href="tables.htm">click here to go to tables test page!</a></b>
<p>

View File

@ -0,0 +1,58 @@
<html>
<head>
<title>wxHTML does wxPython!</title>
</head>
<body bgcolor="#00CCFF">
<h2>Mixing wxPython and wxHTML</h2>
The widgets on this page were created dynamically on the fly by a custom
wxTagHandler found in wxPython.lib.wxpTag. You can look at the sources
and doc-string <a href="../../lib/wxpTag.py">here</a>.
<p>
The button below is added to the page like this:
<pre>
&lt;center>&lt;wxp class="wxButton" width="50%">
&lt;param name="label" value="It works!">
&lt;param name="id" value="wxID_OK">
&lt;/wxp>&lt;/center>
</pre>
<hr>
<center>
<wxp class="wxButton" width="50%">
<param name="label" value="It works!">
<param name="id" value="wxID_OK">
</wxp>
</center>
<p>
Notice that the <b>button click</b> event is actually caught by the panel
that contains this window, which then logs it in the window below.
<p>
<hr>
<p>
This is the same widget reused three times, each with a different
parameter value. Source code is <a href="../widgetTest.py">here</a>.
<p>
<wxp module="widgetTest" class="TestPanel" width=180 height=100>
</wxp>
<wxp module="widgetTest" class="TestPanel" width=180 height=100>
<param name="bgcolor" value="#00CCFF">
</wxp>
<wxp module="widgetTest" class="TestPanel" width=180 height=100>
<param name="bgcolor" value="#0000FF">
</wxp>
<p><hr><p>
Recognize this one?<br>
<wxp module="wxScrolledWindow" class="MyCanvas" height=300 width=100%>
</wxp>
<p><hr><p>
You can also embed other wxHtmlWindows!<br>
<center>
<wxp module="widgetTest" class="TestHtmlPanel">
</wxp>
</center>
</body></html>

View File

@ -0,0 +1,49 @@
from wxPython.wx import *
from wxPython.html import *
#----------------------------------------------------------------------
class TestPanel(wxPanel):
def __init__(self, parent, id=-1, size=wxDefaultSize, bgcolor=None):
wxPanel.__init__(self, parent, id, size=size)
if bgcolor:
self.SetBackgroundColour(bgcolor)
wxStaticText(self, -1, 'Name:', wxPoint(10, 10))
wxStaticText(self, -1, 'Email:', wxPoint(10, 40))
self.name = wxTextCtrl(self, -1, '', wxPoint(50, 10), wxSize(100, -1))
self.email = wxTextCtrl(self, -1, '', wxPoint(50, 40), wxSize(100, -1))
wxButton(self, 12121, 'Okay', wxPoint(50, 70))
EVT_BUTTON(self, 12121, self.OnButton)
def OnButton(self, event):
name = self.name.GetValue()
email = self.email.GetValue()
dlg = wxMessageDialog(self,
'You entered:\n %s\n %s' % (name, email),
'Results', style = wxOK | wxICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
#----------------------------------------------------------------------
class TestHtmlPanel(wxPanel):
def __init__(self, parent, id=-1, size=wxDefaultSize):
import About
wxPanel.__init__(self, parent, id, size=size)
self.html = wxHtmlWindow(self, -1, wxPoint(5,5), wxSize(400, 350))
self.html.SetPage(About.MyAboutBox.text % wx.__version__)
self.Fit()
#----------------------------------------------------------------------

View File

@ -20,6 +20,7 @@ else:
def runTest(frame, nb, log):
#win = TestGLCanvas(nb)
#win.SetFocus()
#return win
win = wxFrame(frame, -1, "GL Cube", wxDefaultPosition, wxSize(400,300))
canvas = TestGLCanvas(win)
@ -34,6 +35,10 @@ else:
wxGLCanvas.__init__(self, parent, -1)
EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
self.init = false
EVT_CHAR(self, self.MyOnChar)
def MyOnChar(self, event):
print "MyOnChar"
def OnEraseBackground(self, event):
pass # Do nothing, to avoid flashing.
@ -50,7 +55,7 @@ else:
dc = wxPaintDC(self)
ctx = self.GetContext()
if ctx == "NULL": return
if not ctx: return
self.SetCurrent()
@ -125,6 +130,7 @@ else:
#----------------------------------------------------------------------

View File

@ -1,7 +1,10 @@
from wxPython.wx import *
from wxPython.html import *
from wxPython.lib.sizers import *
import sys, os
from wxPython.wx import *
from wxPython.html import *
from wxPython.lib.sizers import *
import wxPython.lib.wxpTag
#----------------------------------------------------------------------
@ -55,35 +58,64 @@ class TestHtmlPanel(wxPanel):
EVT_BUTTON(self, 1205, self.OnForward)
subbox.Add(btn, 1)
btn = wxButton(self, 1206, "View Source")
EVT_BUTTON(self, 1206, self.OnViewSource)
subbox.Add(btn, 1)
self.box.Add(subbox)
# A button with this ID is created on the widget test page.
EVT_BUTTON(self, wxID_OK, self.OnOk)
self.OnShowDefault(None)
def OnSize(self, event):
size = self.GetClientSize()
self.box.Layout(size)
def OnShowDefault(self, event):
self.html.LoadPage("data/test.htm")
name = os.path.join(os.path.split(sys.argv[0])[0], 'data/test.htm')
self.html.LoadPage(name)
def OnLoadFile(self, event):
pass
dlg = wxFileDialog(self, wildcard = '*.htm*', style=wxOPEN)
if dlg.ShowModal():
path = dlg.GetPath()
self.html.LoadPage(path)
dlg.Destroy()
def OnWithWidgets(self, event):
pass
os.chdir(os.path.split(sys.argv[0])[0])
name = os.path.join(os.path.split(sys.argv[0])[0], 'data/widgetTest.htm')
self.html.LoadPage(name)
#self.html.SetPage(_widgetTest)
def OnOk(self, event):
self.log.WriteText("It works!\n")
def OnBack(self, event):
if not self.html.HistoryBack():
wxMessageBox("No more items in history!")
def OnForward(self, event):
if not self.html.HistoryForward():
wxMessageBox("No more items in history!")
def OnViewSource(self, event):
from wxPython.lib.dialogs import wxScrolledMessageDialog
source = self.html.GetParser().GetSource()
dlg = wxScrolledMessageDialog(self, source, 'HTML Source')
dlg.ShowModal()
dlg.Destroy()
#----------------------------------------------------------------------
def runTest(frame, nb, log):
@ -104,3 +136,28 @@ It is not intended to be a high-end HTML browser. If you're looking for somethi
"""
_widgetTest = '''\
<html><body>
The widgets on this page were created dynamically on the fly by a custom
wxTagHandler found in wxPython.lib.wxpTag.
<hr>
<center>
<wxp class="wxButton" width="50%">
<param name="label" value="It works!">
<param name="id" value="wxID_OK">
</wxp>
</center>
<hr>
after
</body></html>
'''

View File

@ -39,6 +39,7 @@ class TestListCtrlPanel(wxPanel):
self.list.InsertImageStringItem(x, "This is item %d" % x, idx1)
self.list.SetStringItem(x, 1, "Col 1, item %d" % x)
self.list.SetStringItem(x, 2, "item %d in column 2" % x)
self.list.SetItemData(x, x*2)
self.list.SetColumnWidth(0, wxLIST_AUTOSIZE)
self.list.SetColumnWidth(1, wxLIST_AUTOSIZE)
@ -79,20 +80,24 @@ class TestListCtrlPanel(wxPanel):
def OnRightClick(self, event):
self.log.WriteText("OnRightClick %s\n" % self.list.GetItemText(self.currentItem))
self.menu = wxMenu()
menu = wxMenu()
tPopupID1 = 0
tPopupID2 = 1
tPopupID3 = 2
tPopupID4 = 3
self.menu.Append(tPopupID1, "One")
self.menu.Append(tPopupID2, "Two")
self.menu.Append(tPopupID3, "Three")
self.menu.Append(tPopupID4, "DeleteAllItems")
tPopupID5 = 5
menu.Append(tPopupID1, "One")
menu.Append(tPopupID2, "Two")
menu.Append(tPopupID3, "Three")
menu.Append(tPopupID4, "DeleteAllItems")
menu.Append(tPopupID5, "GetItem")
EVT_MENU(self, tPopupID1, self.OnPopupOne)
EVT_MENU(self, tPopupID2, self.OnPopupTwo)
EVT_MENU(self, tPopupID3, self.OnPopupThree)
EVT_MENU(self, tPopupID4, self.OnPopupFour)
self.PopupMenu(self.menu, wxPoint(self.x, self.y))
EVT_MENU(self, tPopupID5, self.OnPopupFive)
self.PopupMenu(menu, wxPoint(self.x, self.y))
menu.Destroy()
def OnPopupOne(self, event):
self.log.WriteText("Popup one\n")
@ -106,6 +111,10 @@ class TestListCtrlPanel(wxPanel):
def OnPopupFour(self, event):
self.list.DeleteAllItems()
def OnPopupFive(self, event):
item = self.list.GetItem(self.currentItem)
print item.m_text, item.m_itemId, self.list.GetItemData(self.currentItem)
def OnSize(self, event):
w,h = self.GetClientSizeTuple()
self.list.SetDimensions(0, 0, w, h)

View File

@ -4,8 +4,8 @@ from wxPython.wx import *
#---------------------------------------------------------------------------
class MyCanvas(wxScrolledWindow):
def __init__(self, parent):
wxScrolledWindow.__init__(self, parent, -1, wxPoint(0, 0), wxPyDefaultSize, wxSUNKEN_BORDER)
def __init__(self, parent, id = -1, size = wxDefaultSize):
wxScrolledWindow.__init__(self, parent, id, wxPoint(0, 0), size, wxSUNKEN_BORDER)
self.lines = []
self.maxWidth = 1000

View File

@ -0,0 +1,278 @@
#----------------------------------------------------------------------
# Name: wxPython.lib.wxpTag
# Purpose: A wxHtmlTagHandler that knows how to build and place
# wxPython widgets onto web pages.
#
# Author: Robin Dunn
#
# Created: 13-Sept-1999
# RCS-ID: $Id$
# Copyright: (c) 1999 by Total Control Software
# Licence: wxWindows license
#----------------------------------------------------------------------
'''
wxPython.lib.wxpTag
This module contains a wxHtmlTagHandler that knows how to build
and place wxPython widgets onto wxHtmlWindow web pages.
You don\'t need to use anything in this module directly, just
importing it will create the tag handler and add it to any
wxHtmlWinParsers created from that time forth.
Tags of the following form are recognised:
<WXP class="classname" [module="modulename"] [width="num"] [height="num"]>
<PARAM name="parameterName" value="parameterValue>
...
</WXP>
where modulename is the name of a module (possibly in package
notation) to import and classname is the name of a class in that
module to create an instance of. If the module tag-attribute is not
given or is an empty string, then wxPython.wx is used. The width and
height attributes are expected to be integers and will be passed to
the __init__ method of the class as a wxSize object named size.
However, if the width attribute ends with the percent (%) symbol then
the value will be used as a percentage of the available width and the
wxHtmlWindow will manage the size.
The name-value pairs in all the nested PARAM tags are packaged up as
strings into a python dictionary and passed to the __init__ method of
the class as keyword arguments. This means that they are all
accessible from the __init__ method as regular parameters, or you use
the special Python **kw syntax in your __init__ method to get the
dictionary directly.
Some parameter values are special and if they are present then they will
be converted from strings to alternate datatypes. They are:
id If the value of id can be converted to an integer, it will
be. Otherwise it is assumed to be the name of an integer
variable in the module.
colours Any value of the form "#123ABC" will automatically be
converted to a wxColour object.
Py Types Any value begining with "(", "[" or "{" are expected to
be a Python tuple, list, or dictionary and eval()
will be used to convert them to that type. If the
eval() fails then the original string value will be
preserved.
wx Types Any value begining with "wx" is expected to be an attempt
to create a wxPython object, such as a wxSize, etc.
The eval() will be used to try and construct the
object and if it fails then the original string value
will be used instead.
An example:
<wxp module="" class="wxButton">
<param name="label" value="Click here">
<param name="id" value="wxID_OK">
</wxp>
Both the begining and ending WXP tags are required.
In the future support will be added for another tag that can be
embedded between the two begining and ending WXP tags and will
facilitate calling methods of the widget to help initialize it.
Additionally, support may be added to fetch the module from a web
server as is done with java applets.
'''
#----------------------------------------------------------------------
from wxPython.wx import *
from wxPython.html import *
import wxPython.wx
import string
import types
#----------------------------------------------------------------------
WXPTAG = 'WXP'
PARAMTAG = 'PARAM'
#----------------------------------------------------------------------
class wxpTagHandler(wxHtmlWinTagHandler):
def __init__(self):
wxHtmlWinTagHandler.__init__(self)
self.ctx = None
def GetSupportedTags(self):
return WXPTAG+','+PARAMTAG
def HandleTag(self, tag):
name = tag.GetName()
if name == WXPTAG:
return self.HandleWxpTag(tag)
elif name == PARAMTAG:
return self.HandleParamTag(tag)
else:
raise ValueError, 'unknown tag: ' + name
def HandleWxpTag(self, tag):
if tag.IsEnding():
return false
# create a new context object
self.ctx = _Context()
# find and import the module
modName = ''
if tag.HasParam('MODULE'):
modName = tag.GetParam('MODULE')
if modName:
self.ctx.classMod = _my_import(modName)
else:
self.ctx.classMod = wxPython.wx
# find and verify the class
if not tag.HasParam('CLASS'):
raise AttributeError, "WXP tag requires a CLASS attribute"
className = tag.GetParam('CLASS')
self.ctx.classObj = getattr(self.ctx.classMod, className)
if type(self.ctx.classObj) != types.ClassType:
raise TypeError, "WXP tag attribute CLASS must name a class"
# now look for width and height
width = -1
height = -1
if tag.HasParam('WIDTH'):
width = tag.GetParam('WIDTH')
if width[-1] == '%':
self.ctx.floatWidth = string.atoi(width[:-1], 0)
width = self.ctx.floatWidth
else:
width = string.atoi(width)
if tag.HasParam('HEIGHT'):
height = string.atoi(tag.GetParam('HEIGHT'))
self.ctx.kwargs['size'] = wxSize(width, height)
self.ParseInner(tag)
# create the object
obj = apply(self.ctx.classObj,
(self.GetParser().GetWindow(),),
self.ctx.kwargs)
obj.Show(true)
# add it to the HtmlWindow
self.GetParser().GetContainer().InsertCell(wxHtmlWidgetCell(obj, self.ctx.floatWidth))
self.ctx = None
return true
def HandleParamTag(self, tag):
if tag.IsEnding():
return false
if not tag.HasParam('NAME'):
return false
name = tag.GetParam('NAME')
value = ""
if tag.HasParam('VALUE'):
value = tag.GetParam('VALUE')
# check for a param named 'id'
if name == 'id':
theID = -1
try:
theID = string.atoi(value)
except ValueError:
theID = getattr(self.ctx.classMod, value)
value = theID
# check for something that should be evaluated
elif value[0] in '[{(' or value[:2] == 'wx':
saveVal = value
try:
value = eval(value, self.ctx.classMod.__dict__)
except:
value = saveValue
# convert to wxColour
elif value[0] == '#':
#try:
red = string.atoi('0x'+value[1:3], 16)
green = string.atoi('0x'+value[3:5], 16)
blue = string.atoi('0x'+value[5:], 16)
value = wxColor(red, green, blue)
#except:
# pass
self.ctx.kwargs[name] = value
return false
#----------------------------------------------------------------------
# just a place to hold some values
class _Context:
def __init__(self):
self.kwargs = {}
self.width = -1
self.height = -1
self.classMod = None
self.classObj = None
self.floatWidth = 0
#----------------------------------------------------------------------
# Function to assist with importing packages
def _my_import(name):
mod = __import__(name)
components = string.split(name, '.')
for comp in components[1:]:
mod = getattr(mod, comp)
return mod
#----------------------------------------------------------------------
# Function to parse a param string (of the form 'item=value item2="value etc"'
# and creates a dictionary
def _param2dict(param):
i = 0; j = 0; s = len(param); d = {}
while 1:
while i<s and param[i] == " " : i = i+1
if i>=s: break
j = i
while j<s and param[j] != "=": j=j+1
if j+1>=s:
break
word = param[i:j]
i=j+1
if (param[i] == '"'):
j=i+1
while j<s and param[j] != '"' : j=j+1
if j == s: break
val = param[i+1:j]
elif (param[i] != " "):
j=i+1
while j<s and param[j] != " " : j=j+1
val = param[i:j]
else:
val = ""
i=j+1
d[word] = val
return d
#----------------------------------------------------------------------
wxHtmlWinParser_AddTagHandler(wxpTagHandler)

View File

@ -0,0 +1,13 @@
# Stuff these names into the wx namespace so wxPyConstructObject can find them
import wx
wx.wxHtmlTagPtr = wxHtmlTag
wx.wxHtmlParserPtr = wxHtmlParserPtr
wx.wxHtmlWinParserPtr = wxHtmlWinParserPtr
wx.wxHtmlTagHandlerPtr = wxHtmlTagHandlerPtr
wx.wxHtmlWinTagHandlerPtr = wxHtmlWinTagHandlerPtr
wx.wxHtmlCellPtr = wxHtmlCellPtr
wx.wxHtmlContainerCellPtr = wxHtmlContainerCellPtr
wx.wxHtmlWidgetCellPtr = wxHtmlWidgetCellPtr
wx.HtmlHistoryItemPtr = HtmlHistoryItemPtr
wx.wxHtmlWindowPtr = wxHtmlWindowPtr

View File

@ -12,3 +12,4 @@ OTHERCFLAGS = "-I%s/src/html" % (WXDIR,)
# There are no platform differences so we don't need separate code directories
GENCODEDIR='.'
SWIGTOOLKITFLAG=''

File diff suppressed because it is too large Load Diff

View File

@ -52,6 +52,7 @@ wxSize wxPyDefaultSize(wxDefaultSize);
%{
#if 0
static PyObject* mod_dict = NULL; // will be set by init
#include <wx/html/mod_templ.h>
@ -129,15 +130,44 @@ TAGS_MODULE_BEGIN(PythonTag)
TAGS_MODULE_END(PythonTag)
// Note: see also the init function where we add the module!
#endif
%}
//---------------------------------------------------------------------------
enum {
HTML_ALIGN_LEFT,
HTML_ALIGN_CENTER,
HTML_ALIGN_RIGHT,
HTML_ALIGN_BOTTOM,
HTML_ALIGN_TOP,
HTML_CLR_FOREGROUND,
HTML_CLR_BACKGROUND,
HTML_UNITS_PIXELS,
HTML_UNITS_PERCENT,
HTML_INDENT_LEFT,
HTML_INDENT_RIGHT,
HTML_INDENT_TOP,
HTML_INDENT_BOTTOM,
HTML_INDENT_HORIZONTAL,
HTML_INDENT_VERTICAL,
HTML_INDENT_ALL,
HTML_COND_ISANCHOR,
HTML_COND_ISIMAGEMAP,
HTML_COND_USER,
};
//---------------------------------------------------------------------------
class wxHtmlTag {
public:
// Never need to create a new tag...
// Never need to create a new tag from Python...
//wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
wxString GetName();
@ -236,7 +266,6 @@ public:
IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
%}
@ -272,7 +301,6 @@ public:
IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
%}
@ -315,9 +343,11 @@ public:
// Wave our magic wand... (if it works it's a miracle! ;-)
// First, make a new instance of the tag handler
bool doSave = wxPyRestoreThread();
PyObject* arg = Py_BuildValue("()");
PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
Py_DECREF(arg);
wxPySaveThread(doSave);
// now figure out where it's C++ object is...
wxPyHtmlWinTagHandler* thPtr;
@ -348,6 +378,63 @@ private:
}
%}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
class wxHtmlCell {
public:
wxHtmlCell();
void SetParent(wxHtmlContainerCell *p);
wxHtmlContainerCell* GetParent();
int GetPosX();
int GetPosY();
int GetWidth();
int GetHeight();
int GetDescent();
wxString GetLink(int x = 0, int y = 0);
wxHtmlCell* GetNext();
void SetPos(int x, int y);
void SetLink(const wxString& link);
void SetNext(wxHtmlCell *cell);
void Layout(int w);
void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
void DrawInvisible(wxDC& dc, int x, int y);
const wxHtmlCell* Find(int condition, const void* param);
};
class wxHtmlContainerCell : public wxHtmlCell {
public:
wxHtmlContainerCell(wxHtmlContainerCell *parent);
void InsertCell(wxHtmlCell *cell);
void SetAlignHor(int al);
int GetAlignHor();
void SetAlignVer(int al);
int GetAlignVer();
void SetIndent(int i, int what, int units = HTML_UNITS_PIXELS);
int GetIndent(int ind);
int GetIndentUnits(int ind);
void SetAlign(const wxHtmlTag& tag);
void SetWidthFloat(int w, int units);
%name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
void SetMinHeight(int h, int align = HTML_ALIGN_TOP);
int GetMaxLineWidth();
void SetBackgroundColour(const wxColour& clr);
void SetBorder(const wxColour& clr1, const wxColour& clr2);
wxHtmlCell* GetFirstCell();
};
class wxHtmlWidgetCell : public wxHtmlCell {
public:
wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
};
//---------------------------------------------------------------------------
@ -461,6 +548,8 @@ public:
// Returns pointer to conteiners/cells structure.
// It should be used ONLY when printing
wxHtmlWinParser* GetParser();
void base_OnLinkClicked(const char* link);
// called when users clicked on hypertext link. Default behavior is to
@ -486,18 +575,22 @@ public:
%init %{
#if 0
/* This is a bit cheesy. SWIG happens to call the dictionary d...
* I save it here, 'cause I don't know how to get it back later! */
mod_dict = d;
#endif
//inithtmlhelpc();
wxClassInfo::CleanUpClasses();
wxClassInfo::InitializeClasses();
#if 0
/* specifically add our python tag handler; it doesn't seem to
* happen by itself... */
wxHtmlWinParser::AddModule(new HTML_ModulePythonTag());
#endif
// Until wxFileSystem is wrapped...
#if wxUSE_FS_ZIP
@ -505,4 +598,11 @@ public:
#endif
%}
//----------------------------------------------------------------------
// And this gets appended to the shadow class file.
//----------------------------------------------------------------------
%pragma(python) include="_extras.py";
//---------------------------------------------------------------------------

View File

@ -135,12 +135,15 @@ class wxHtmlWinParserPtr(wxHtmlParserPtr):
return val
def GetContainer(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlWinParser_GetContainer,(self,) + _args, _kwargs)
if val: val = wxHtmlContainerCellPtr(val)
return val
def OpenContainer(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlWinParser_OpenContainer,(self,) + _args, _kwargs)
if val: val = wxHtmlContainerCellPtr(val)
return val
def CloseContainer(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlWinParser_CloseContainer,(self,) + _args, _kwargs)
if val: val = wxHtmlContainerCellPtr(val)
return val
def GetFontSize(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlWinParser_GetFontSize,(self,) + _args, _kwargs)
@ -268,6 +271,148 @@ class wxHtmlWinTagHandler(wxHtmlWinTagHandlerPtr):
class wxHtmlCellPtr :
def __init__(self,this):
self.this = this
self.thisown = 0
def SetParent(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_SetParent,(self,) + _args, _kwargs)
return val
def GetParent(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_GetParent,(self,) + _args, _kwargs)
if val: val = wxHtmlContainerCellPtr(val)
return val
def GetPosX(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_GetPosX,(self,) + _args, _kwargs)
return val
def GetPosY(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_GetPosY,(self,) + _args, _kwargs)
return val
def GetWidth(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_GetWidth,(self,) + _args, _kwargs)
return val
def GetHeight(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_GetHeight,(self,) + _args, _kwargs)
return val
def GetDescent(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_GetDescent,(self,) + _args, _kwargs)
return val
def GetLink(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_GetLink,(self,) + _args, _kwargs)
return val
def GetNext(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_GetNext,(self,) + _args, _kwargs)
if val: val = wxHtmlCellPtr(val)
return val
def SetPos(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_SetPos,(self,) + _args, _kwargs)
return val
def SetLink(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_SetLink,(self,) + _args, _kwargs)
return val
def SetNext(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_SetNext,(self,) + _args, _kwargs)
return val
def Layout(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_Layout,(self,) + _args, _kwargs)
return val
def Draw(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_Draw,(self,) + _args, _kwargs)
return val
def DrawInvisible(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_DrawInvisible,(self,) + _args, _kwargs)
return val
def Find(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlCell_Find,(self,) + _args, _kwargs)
if val: val = wxHtmlCellPtr(val)
return val
def __repr__(self):
return "<C wxHtmlCell instance at %s>" % (self.this,)
class wxHtmlCell(wxHtmlCellPtr):
def __init__(self,*_args,**_kwargs):
self.this = apply(htmlc.new_wxHtmlCell,_args,_kwargs)
self.thisown = 1
class wxHtmlContainerCellPtr(wxHtmlCellPtr):
def __init__(self,this):
self.this = this
self.thisown = 0
def InsertCell(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_InsertCell,(self,) + _args, _kwargs)
return val
def SetAlignHor(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_SetAlignHor,(self,) + _args, _kwargs)
return val
def GetAlignHor(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_GetAlignHor,(self,) + _args, _kwargs)
return val
def SetAlignVer(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_SetAlignVer,(self,) + _args, _kwargs)
return val
def GetAlignVer(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_GetAlignVer,(self,) + _args, _kwargs)
return val
def SetIndent(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_SetIndent,(self,) + _args, _kwargs)
return val
def GetIndent(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_GetIndent,(self,) + _args, _kwargs)
return val
def GetIndentUnits(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_GetIndentUnits,(self,) + _args, _kwargs)
return val
def SetAlign(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_SetAlign,(self,) + _args, _kwargs)
return val
def SetWidthFloat(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_SetWidthFloat,(self,) + _args, _kwargs)
return val
def SetWidthFloatFromTag(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_SetWidthFloatFromTag,(self,) + _args, _kwargs)
return val
def SetMinHeight(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_SetMinHeight,(self,) + _args, _kwargs)
return val
def GetMaxLineWidth(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_GetMaxLineWidth,(self,) + _args, _kwargs)
return val
def SetBackgroundColour(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_SetBackgroundColour,(self,) + _args, _kwargs)
return val
def SetBorder(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_SetBorder,(self,) + _args, _kwargs)
return val
def GetFirstCell(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlContainerCell_GetFirstCell,(self,) + _args, _kwargs)
if val: val = wxHtmlCellPtr(val)
return val
def __repr__(self):
return "<C wxHtmlContainerCell instance at %s>" % (self.this,)
class wxHtmlContainerCell(wxHtmlContainerCellPtr):
def __init__(self,*_args,**_kwargs):
self.this = apply(htmlc.new_wxHtmlContainerCell,_args,_kwargs)
self.thisown = 1
class wxHtmlWidgetCellPtr(wxHtmlCellPtr):
def __init__(self,this):
self.this = this
self.thisown = 0
def __repr__(self):
return "<C wxHtmlWidgetCell instance at %s>" % (self.this,)
class wxHtmlWidgetCell(wxHtmlWidgetCellPtr):
def __init__(self,*_args,**_kwargs):
self.this = apply(htmlc.new_wxHtmlWidgetCell,_args,_kwargs)
self.thisown = 1
class HtmlHistoryItemPtr :
def __init__(self,this):
self.this = this
@ -346,6 +491,11 @@ class wxHtmlWindowPtr(wxScrolledWindowPtr):
return val
def GetInternalRepresentation(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlWindow_GetInternalRepresentation,(self,) + _args, _kwargs)
if val: val = wxHtmlContainerCellPtr(val)
return val
def GetParser(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlWindow_GetParser,(self,) + _args, _kwargs)
if val: val = wxHtmlWinParserPtr(val)
return val
def base_OnLinkClicked(self, *_args, **_kwargs):
val = apply(htmlc.wxHtmlWindow_base_OnLinkClicked,(self,) + _args, _kwargs)
@ -375,3 +525,39 @@ wxHtmlWindow_AddFilter = htmlc.wxHtmlWindow_AddFilter
#-------------- VARIABLE WRAPPERS ------------------
HTML_ALIGN_LEFT = htmlc.HTML_ALIGN_LEFT
HTML_ALIGN_CENTER = htmlc.HTML_ALIGN_CENTER
HTML_ALIGN_RIGHT = htmlc.HTML_ALIGN_RIGHT
HTML_ALIGN_BOTTOM = htmlc.HTML_ALIGN_BOTTOM
HTML_ALIGN_TOP = htmlc.HTML_ALIGN_TOP
HTML_CLR_FOREGROUND = htmlc.HTML_CLR_FOREGROUND
HTML_CLR_BACKGROUND = htmlc.HTML_CLR_BACKGROUND
HTML_UNITS_PIXELS = htmlc.HTML_UNITS_PIXELS
HTML_UNITS_PERCENT = htmlc.HTML_UNITS_PERCENT
HTML_INDENT_LEFT = htmlc.HTML_INDENT_LEFT
HTML_INDENT_RIGHT = htmlc.HTML_INDENT_RIGHT
HTML_INDENT_TOP = htmlc.HTML_INDENT_TOP
HTML_INDENT_BOTTOM = htmlc.HTML_INDENT_BOTTOM
HTML_INDENT_HORIZONTAL = htmlc.HTML_INDENT_HORIZONTAL
HTML_INDENT_VERTICAL = htmlc.HTML_INDENT_VERTICAL
HTML_INDENT_ALL = htmlc.HTML_INDENT_ALL
HTML_COND_ISANCHOR = htmlc.HTML_COND_ISANCHOR
HTML_COND_ISIMAGEMAP = htmlc.HTML_COND_ISIMAGEMAP
HTML_COND_USER = htmlc.HTML_COND_USER
#-------------- USER INCLUDE -----------------------
# Stuff these names into the wx namespace so wxPyConstructObject can find them
import wx
wx.wxHtmlTagPtr = wxHtmlTag
wx.wxHtmlParserPtr = wxHtmlParserPtr
wx.wxHtmlWinParserPtr = wxHtmlWinParserPtr
wx.wxHtmlTagHandlerPtr = wxHtmlTagHandlerPtr
wx.wxHtmlWinTagHandlerPtr = wxHtmlWinTagHandlerPtr
wx.wxHtmlCellPtr = wxHtmlCellPtr
wx.wxHtmlContainerCellPtr = wxHtmlContainerCellPtr
wx.wxHtmlWidgetCellPtr = wxHtmlWidgetCellPtr
wx.HtmlHistoryItemPtr = HtmlHistoryItemPtr
wx.wxHtmlWindowPtr = wxHtmlWindowPtr

View File

@ -33,3 +33,4 @@ wx.wxPyPolygonShapePtr = wxPyPolygonShapePtr
wx.wxPyTextShapePtr = wxPyTextShapePtr
wx.wxShapeRegionPtr = wxShapeRegionPtr
wx.wxOGLConstraintPtr = wxOGLConstraintPtr
wx.wxControlPointPtr = wxControlPointPtr

View File

@ -158,9 +158,10 @@ public:
long GetItemData(long item);
%addmethods {
%new wxListItem* GetItem(long itemId) {
%new wxListItem* GetItem(long itemId, int col=0) {
wxListItem* info = new wxListItem;
info->m_itemId = itemId;
info->m_col = col;
self->GetItem(*info);
return info;
}

View File

@ -663,10 +663,9 @@ HELPEREXPORT wxBitmap** wxBitmap_LIST_helper(PyObject* source) {
}
for (int x=0; x<count; x++) {
PyObject* o = PyList_GetItem(source, x);
if (PyString_Check(o)) {
char* st = PyString_AsString(o);
if (PyInstance_Check(o)) {
wxBitmap* pt;
if (SWIG_GetPtr(st,(void **) &pt,"_wxBitmap_p")) {
if (SWIG_GetPtrObj(o, (void **) &pt,"_wxBitmap_p")) {
PyErr_SetString(PyExc_TypeError,"Expected _wxBitmap_p.");
return NULL;
}
@ -718,10 +717,9 @@ HELPEREXPORT wxAcceleratorEntry* wxAcceleratorEntry_LIST_helper(PyObject* source
}
for (int x=0; x<count; x++) {
PyObject* o = PyList_GetItem(source, x);
if (PyString_Check(o)) {
char* st = PyString_AsString(o);
if (PyInstance_Check(o)) {
wxAcceleratorEntry* ae;
if (SWIG_GetPtr(st,(void **) &ae,"_wxAcceleratorEntry_p")) {
if (SWIG_GetPtrObj(o, (void **) &ae,"_wxAcceleratorEntry_p")) {
PyErr_SetString(PyExc_TypeError,"Expected _wxAcceleratorEntry_p.");
return NULL;
}

View File

@ -1861,9 +1861,10 @@ static PyObject *_wrap_wxListCtrl_GetItemData(PyObject *self, PyObject *args, Py
return _resultobj;
}
static wxListItem * wxListCtrl_GetItem(wxListCtrl *self,long itemId) {
static wxListItem * wxListCtrl_GetItem(wxListCtrl *self,long itemId,int col) {
wxListItem* info = new wxListItem;
info->m_itemId = itemId;
info->m_col = col;
self->GetItem(*info);
return info;
}
@ -1872,12 +1873,13 @@ static PyObject *_wrap_wxListCtrl_GetItem(PyObject *self, PyObject *args, PyObje
wxListItem * _result;
wxListCtrl * _arg0;
long _arg1;
int _arg2 = (int ) 0;
PyObject * _argo0 = 0;
char *_kwnames[] = { "self","itemId", NULL };
char *_kwnames[] = { "self","itemId","col", NULL };
char _ptemp[128];
self = self;
if(!PyArg_ParseTupleAndKeywords(args,kwargs,"Ol:wxListCtrl_GetItem",_kwnames,&_argo0,&_arg1))
if(!PyArg_ParseTupleAndKeywords(args,kwargs,"Ol|i:wxListCtrl_GetItem",_kwnames,&_argo0,&_arg1,&_arg2))
return NULL;
if (_argo0) {
if (_argo0 == Py_None) { _arg0 = NULL; }
@ -1888,7 +1890,7 @@ static PyObject *_wrap_wxListCtrl_GetItem(PyObject *self, PyObject *args, PyObje
}
{
wxPy_BEGIN_ALLOW_THREADS;
_result = (wxListItem *)wxListCtrl_GetItem(_arg0,_arg1);
_result = (wxListItem *)wxListCtrl_GetItem(_arg0,_arg1,_arg2);
wxPy_END_ALLOW_THREADS;
} if (_result) {