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:
46
utils/wxPython/demo/About.py
Normal file
46
utils/wxPython/demo/About.py
Normal 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()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
@@ -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()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
@@ -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>
|
||||
|
58
utils/wxPython/demo/data/widgetTest.htm
Normal file
58
utils/wxPython/demo/data/widgetTest.htm
Normal 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>
|
||||
<center><wxp class="wxButton" width="50%">
|
||||
<param name="label" value="It works!">
|
||||
<param name="id" value="wxID_OK">
|
||||
</wxp></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>
|
49
utils/wxPython/demo/widgetTest.py
Normal file
49
utils/wxPython/demo/widgetTest.py
Normal 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()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
@@ -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:
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
@@ -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>
|
||||
'''
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user