Merged wxPython 2.2.2 over to the main branch

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8658 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2000-10-30 21:08:42 +00:00
parent 7874bf5430
commit c368d904fc
193 changed files with 21992 additions and 4366 deletions

View File

@@ -1,5 +1,6 @@
*.pyc
.emacs.desktop
b.bat
hangman_dict.txt
setup.bat
test.out

View File

@@ -1,3 +1,4 @@
import sys, string
from wxPython.wx import *
from wxPython.html import *
@@ -12,7 +13,10 @@ class MyAboutBox(wxDialog):
<center><table bgcolor="#458154" width="100%%" cellspacing="0"
cellpadding="0" border="1">
<tr>
<td align="center"><h1>wxPython %s</h1></td>
<td align="center">
<h1>wxPython %s</h1>
Running on Python %s<br>
</td>
</tr>
</table>
@@ -40,19 +44,13 @@ demo item so you can learn how to use the classes yourself.</p>
</html>
'''
def __init__(self, parent):
wxDialog.__init__(self, parent, -1, 'About the wxPython demo',
size=wxSize(420, 380))
self.html = wxHtmlWindow(self, -1)
self.html.SetPage(self.text % wx.__version__)
self.SetAutoLayout(true)
lc = wxLayoutConstraints()
lc.top.SameAs(self, wxTop, 5)
lc.left.SameAs(self, wxLeft, 5)
lc.bottom.SameAs(self, wxBottom, 5)
lc.right.SameAs(self, wxRight, 5)
self.html.SetConstraints(lc)
self.Layout()
wxDialog.__init__(self, parent, -1, 'About the wxPython demo',)
html = wxHtmlWindow(self, -1, size=(420, -1))
py_version = string.split(sys.version)[0]
html.SetPage(self.text % (wx.__version__, py_version))
ir = html.GetInternalRepresentation()
html.SetSize( (ir.GetWidth()+5, ir.GetHeight()+5) )
self.SetClientSize(html.GetSize())
self.CentreOnParent(wxBOTH)
#---------------------------------------------------------------------------

View File

@@ -37,7 +37,7 @@ class TestPanel(wxWindow):
wxWindow.__init__(self, parent, -1)#, style=wxCLIP_CHILDREN)
self.ie = None
self.log = log
self.current = "http://alldunn.com/"
self.current = "http://wxPython.org/"
self.frame = frame
if frame:
self.titleBase = frame.GetTitle()

View File

@@ -7,6 +7,9 @@ class SimpleGrid(wxGrid):
def __init__(self, parent, log):
wxGrid.__init__(self, parent, -1)
self.log = log
self.moveTo = None
EVT_IDLE(self, self.OnIdle)
self.CreateGrid(25, 25)
@@ -113,15 +116,43 @@ class SimpleGrid(wxGrid):
(evt.GetTopLeftCoords(), evt.GetBottomRightCoords()))
evt.Skip()
def OnCellChange(self, evt):
self.log.write("OnCellChange: (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
evt.Skip()
# Show how to stay in a cell that has bad data. We can't just
# call SetGridCursor here since we are nested inside one so it
# won't have any effect. Instead, set coordinants to move to in
# idle time.
value = self.GetCellValue(evt.GetRow(), evt.GetCol())
if value == 'no good':
self.moveTo = evt.GetRow(), evt.GetCol()
def OnIdle(self, evt):
if self.moveTo != None:
self.SetGridCursor(self.moveTo[0], self.moveTo[1])
self.moveTo = None
def OnSelectCell(self, evt):
self.log.write("OnSelectCell: (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
evt.Skip()
# Another way to stay in a cell that has a bad value...
row = self.GetGridCursorRow()
col = self.GetGridCursorCol()
if self.IsCellEditControlEnabled():
self.HideCellEditControl()
self.DisableCellEditControl()
value = self.GetCellValue(row, col)
if value == 'no good 2':
return # cancels the cell selection
else:
evt.Skip()
def OnEditorShown(self, evt):
self.log.write("OnEditorShown: (%d,%d) %s\n" %
@@ -154,3 +185,5 @@ if __name__ == '__main__':
#---------------------------------------------------------------------------

View File

@@ -20,7 +20,7 @@ from wxPython.html import wxHtmlWindow
_treeList = [
('New since last release', ['PyShellWindow',
('New since last release', ['wxProcess',
]),
('Managed Windows', ['wxFrame', 'wxDialog', 'wxMiniFrame']),
@@ -43,20 +43,22 @@ _treeList = [
'wxCalendarCtrl',
]),
('Window Layout', ['wxLayoutConstraints', 'Sizers', 'OldSizers']),
('Window Layout', ['wxLayoutConstraints', 'Sizers', ]),
('Miscellaneous', [ 'DragAndDrop', 'CustomDragAndDrop', 'FontEnumerator',
'wxTimer', 'wxValidator', 'wxGLCanvas', 'DialogUnits',
'wxImage', 'wxMask', 'PrintFramework', 'wxOGL',
'PythonEvents', 'Threads',
'ActiveXWrapper_Acrobat', 'ActiveXWrapper_IE',
'wxDragImage', 'PyShellWindow',
'wxDragImage',
]),
('wxPython Library', ['Layoutf', 'wxScrolledMessageDialog',
'wxMultipleChoiceDialog', 'wxPlotCanvas', 'wxFloatBar',
'PyShell', 'wxCalendar', 'wxMVCTree', 'wxVTKRenderWindow',
'FileBrowseButton', 'GenericButtons', 'wxEditor']),
'FileBrowseButton', 'GenericButtons', 'wxEditor',
'PyShellWindow',
]),
('Cool Contribs', ['pyTree', 'hangman', 'SlashDot', 'XMLtreeview']),
@@ -65,6 +67,7 @@ _treeList = [
#---------------------------------------------------------------------------
class wxPythonDemo(wxFrame):
def __init__(self, parent, id, title):
wxFrame.__init__(self, parent, -1, title, size = (800, 600),
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
@@ -73,8 +76,17 @@ class wxPythonDemo(wxFrame):
self.curOverview = ""
if wxPlatform == '__WXMSW__':
self.icon = wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO)
self.SetIcon(self.icon)
icon = wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO)
self.SetIcon(icon)
# setup a taskbar icon, and catch some events from it
self.tbicon = wxTaskBarIcon()
self.tbicon.SetIcon(icon, "wxPython Demo")
EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarActivate)
EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu)
EVT_MENU(self.tbicon, self.TBMENU_RESTORE, self.OnTaskBarActivate)
EVT_MENU(self.tbicon, self.TBMENU_CLOSE, self.OnTaskBarClose)
self.otherWin = None
EVT_IDLE(self, self.OnIdle)
@@ -152,9 +164,25 @@ class wxPythonDemo(wxFrame):
# Create a Notebook
self.nb = wxNotebook(splitter2, -1)
# Set up a TextCtrl on the Overview Notebook page
self.ovr = wxHtmlWindow(self.nb, -1)
self.nb.AddPage(self.ovr, "Overview")
# Set up a wxHtmlWindow on the Overview Notebook page
# we put it in a panel first because there seems to be a
# refresh bug of some sort (wxGTK) when it is directly in
# the notebook...
if 0: # the old way
self.ovr = wxHtmlWindow(self.nb, -1, size=(400, 400))
self.nb.AddPage(self.ovr, "Overview")
else: # hopefully I can remove this hacky code soon
panel = wxPanel(self.nb, -1)
self.ovr = wxHtmlWindow(panel, -1, size=(400, 400))
self.nb.AddPage(panel, "Overview")
def OnOvrSize(evt, ovr=self.ovr):
ovr.SetSize(evt.GetSize())
EVT_SIZE(panel, OnOvrSize)
self.SetOverview("Overview", overview)
# Set up a TextCtrl on the Demo Code Notebook page
@@ -215,12 +243,13 @@ class wxPythonDemo(wxFrame):
def OnItemExpanded(self, event):
item = event.GetItem()
wxLogMessage("OnItemExpanded: %s" % self.tree.GetItemText(item))
event.Skip()
#---------------------------------------------
def OnItemCollapsed(self, event):
item = event.GetItem()
wxLogMessage("OnItemCollapsed: %s" % self.tree.GetItemText(item))
event.Skip()
#---------------------------------------------
def OnTreeLeftDown(self, event):
@@ -307,7 +336,7 @@ class wxPythonDemo(wxFrame):
#---------------------------------------------
# Menu methods
def OnFileExit(self, event):
def OnFileExit(self, *event):
self.Close()
@@ -323,8 +352,11 @@ class wxPythonDemo(wxFrame):
self.dying = true
self.window = None
self.mainmenu = None
if hasattr(self, "tbicon"):
del self.tbicon
self.Destroy()
#---------------------------------------------
def OnIdle(self, event):
if self.otherWin:
@@ -342,6 +374,36 @@ class wxPythonDemo(wxFrame):
self.tree.SelectItem(selectedDemo)
self.tree.EnsureVisible(selectedDemo)
#---------------------------------------------
def OnTaskBarActivate(self, evt):
if self.IsIconized():
self.Iconize(false)
if not self.IsShown():
self.Show(true)
self.Raise()
#---------------------------------------------
TBMENU_RESTORE = 1000
TBMENU_CLOSE = 1001
def OnTaskBarMenu(self, evt):
menu = wxMenu()
menu.Append(self.TBMENU_RESTORE, "Restore wxPython Demo")
menu.Append(self.TBMENU_CLOSE, "Close")
self.tbicon.PopupMenu(menu)
menu.Destroy()
#---------------------------------------------
def OnTaskBarClose(self, evt):
self.Close()
# because of the way wxTaskBarIcon.PopupMenu is implemented we have to
# prod the main idle handler a bit to get the window to actually close
wxGetApp().ProcessIdle()
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
@@ -370,7 +432,7 @@ class MyApp(wxApp):
showTip, index = eval(showTipText)
except IOError:
showTip, index = (1, 0)
print showTip, index
#print showTip, index
if showTip:
tp = wxCreateFileTipProvider("data/tips.txt", index)
showTip = wxShowTip(frame, tp)

View File

@@ -1,403 +0,0 @@
#----------------------------------------------------------------------
# sizer test code
#----------------------------------------------------------------------
from wxPython.wx import *
from wxPython.lib.sizers import *
#----------------------------------------------------------------------
def makeSimpleBox1(win):
box = wxBoxSizer(wxHORIZONTAL)
box.Add(wxButton(win, 1010, "one"), 0)
box.Add(wxButton(win, 1010, "two"), 0)
box.Add(wxButton(win, 1010, "three"), 0)
box.Add(wxButton(win, 1010, "four"), 0)
return box
#----------------------------------------------------------------------
def makeSimpleBox2(win):
box = wxBoxSizer(wxVERTICAL)
box.Add(wxButton(win, 1010, "one"), 0)
box.Add(wxButton(win, 1010, "two"), 0)
box.Add(wxButton(win, 1010, "three"), 0)
box.Add(wxButton(win, 1010, "four"), 0)
return box
#----------------------------------------------------------------------
def makeSimpleBox3(win):
box = wxBoxSizer(wxHORIZONTAL)
box.Add(wxButton(win, 1010, "one"), 0)
box.Add(wxButton(win, 1010, "two"), 0)
box.Add(wxButton(win, 1010, "three"), 0)
box.Add(wxButton(win, 1010, "four"), 0)
box.Add(wxButton(win, 1010, "five"), 1)
return box
#----------------------------------------------------------------------
def makeSimpleBox4(win):
box = wxBoxSizer(wxHORIZONTAL)
box.Add(wxButton(win, 1010, "one"), 0)
box.Add(wxButton(win, 1010, "two"), 0)
box.Add(wxButton(win, 1010, "three"), 1)
box.Add(wxButton(win, 1010, "four"), 1)
box.Add(wxButton(win, 1010, "five"), 1)
return box
#----------------------------------------------------------------------
def makeSimpleBox5(win):
box = wxBoxSizer(wxHORIZONTAL)
box.Add(wxButton(win, 1010, "one"), 0)
box.Add(wxButton(win, 1010, "two"), 0)
box.Add(wxButton(win, 1010, "three"), 3)
box.Add(wxButton(win, 1010, "four"), 1)
box.Add(wxButton(win, 1010, "five"), 1)
return box
#----------------------------------------------------------------------
def makeSimpleBox6(win):
box = wxBoxSizer(wxHORIZONTAL, wxSize(250, 50))
box.Add(wxButton(win, 1010, "10"), 10)
box.Add(wxButton(win, 1010, "20"), 20)
box.Add(wxButton(win, 1010, "30"), 30)
box.Add(wxButton(win, 1010, "15"), 15)
box.Add(wxButton(win, 1010, "5"), 5)
return box
#----------------------------------------------------------------------
def makeSimpleBorder1(win):
bdr = wxBorderSizer(wxALL)
btn = wxButton(win, 1010, "border")
btn.SetSize(wxSize(80, 80))
bdr.Add(btn, 15)
return bdr
#----------------------------------------------------------------------
def makeSimpleBorder2(win):
bdr = wxBorderSizer(wxEAST | wxWEST)
btn = wxButton(win, 1010, "border")
btn.SetSize(wxSize(80, 80))
bdr.Add(btn, 15)
return bdr
#----------------------------------------------------------------------
def makeSimpleBorder3(win):
bdr = wxBorderSizer(wxNORTH | wxWEST)
btn = wxButton(win, 1010, "border")
btn.SetSize(wxSize(80, 80))
bdr.Add(btn, 15)
return bdr
#----------------------------------------------------------------------
def makeShapes(win):
box =wxBoxSizer(wxVERTICAL)
box.Add(wxStaticLine(win, -1), 0)
for line in (
(wxANCHOR_NW, "NorthWest"),
(wxANCHOR_NORTH, "North"),
(wxANCHOR_NE, "NorthEast")
), (
(wxANCHOR_WEST, "West"),
(wxANCHOR_NONE, "Center"),
(wxANCHOR_EAST, "East")
), (
(wxANCHOR_SW, "SouthWest"),
(wxANCHOR_SOUTH, "South"),
(wxANCHOR_SE, "SouthEast")
):
linebox =wxBoxSizer(wxHORIZONTAL)
linebox.Add(wxStaticLine(win, -1, style=wxVERTICAL), 0)
for (anchor, label) in line:
sizer =wxShapeSizer(anchor)
sizer.Add(wxButton(win, -1, label, size=wxSize(100, 50)))
linebox.Add(sizer, 1)
linebox.Add(wxStaticLine(win, -1, style=wxVERTICAL), 0)
box.Add(linebox, 1)
box.Add(wxStaticLine(win, -1), 0)
return box
#----------------------------------------------------------------------
def makeBoxInBox(win):
box = wxBoxSizer(wxVERTICAL)
box.Add(wxButton(win, 1010, "one"))
box2 = wxBoxSizer(wxHORIZONTAL)
box2.AddMany([ wxButton(win, 1010, "two"),
wxButton(win, 1010, "three"),
wxButton(win, 1010, "four"),
wxButton(win, 1010, "five"),
])
box3 = wxBoxSizer(wxVERTICAL)
box3.AddMany([ (wxButton(win, 1010, "six"), 0),
(wxButton(win, 1010, "seven"), 2),
(wxButton(win, 1010, "eight"), 1),
(wxButton(win, 1010, "nine"), 1),
])
box2.Add(box3, 1)
box.Add(box2, 1)
box.Add(wxButton(win, 1010, "ten"))
return box
#----------------------------------------------------------------------
def makeBoxInBorder(win):
bdr = wxBorderSizer(wxALL)
box = makeSimpleBox3(win)
bdr.Add(box, 15)
return bdr
#----------------------------------------------------------------------
def makeBorderInBox(win):
insideBox = wxBoxSizer(wxHORIZONTAL)
box2 = wxBoxSizer(wxHORIZONTAL)
box2.AddMany([ wxButton(win, 1010, "one"),
wxButton(win, 1010, "two"),
wxButton(win, 1010, "three"),
wxButton(win, 1010, "four"),
wxButton(win, 1010, "five"),
])
insideBox.Add(box2, 0)
bdr = wxBorderSizer(wxALL)
bdr.Add(wxButton(win, 1010, "border"), 20)
insideBox.Add(bdr, 1)
box3 = wxBoxSizer(wxVERTICAL)
box3.AddMany([ (wxButton(win, 1010, "six"), 0),
(wxButton(win, 1010, "seven"), 2),
(wxButton(win, 1010, "eight"), 1),
(wxButton(win, 1010, "nine"), 1),
])
insideBox.Add(box3, 1)
outsideBox = wxBoxSizer(wxVERTICAL)
outsideBox.Add(wxButton(win, 1010, "top"))
outsideBox.Add(insideBox, 1)
outsideBox.Add(wxButton(win, 1010, "bottom"))
return outsideBox
#----------------------------------------------------------------------
theTests = [
("Simple horizontal boxes", makeSimpleBox1,
"This is a HORIZONTAL box sizer with four non-stretchable buttons held "
"within it. Notice that the buttons are added and aligned in the horizontal "
"dimension. Also notice that they are fixed size in the horizontal dimension, "
"but will stretch vertically."
),
("Simple vertical boxes", makeSimpleBox2,
"Exactly the same as the previous sample but using a VERTICAL box sizer "
"instead of a HORIZONTAL one."
),
("Add a stretchable", makeSimpleBox3,
"We've added one more button with the strechable flag turned on. Notice "
"how it grows to fill the extra space in the otherwise fixed dimension."
),
("More than one stretchable", makeSimpleBox4,
"Here there are several items that are stretchable, they all divide up the "
"extra space evenly."
),
("Weighting factor", makeSimpleBox5,
"This one shows more than one strechable, but one of them has a weighting "
"factor so it gets more of the free space."
),
# ("Percent Sizer", makeSimpleBox6,
# "You can use the wxBoxSizer like a Percent Sizer. Just make sure that all "
# "the weighting factors add up to 100!"
# ),
("", None, ""),
("Simple border sizer", makeSimpleBorder1,
"The wxBorderSizer leaves empty space around its contents. This one "
"gives a border all the way around."
),
("East and West border", makeSimpleBorder2,
"You can pick and choose which sides have borders."
),
("North and West border", makeSimpleBorder3,
"You can pick and choose which sides have borders."
),
("", None, ""),
("Proportional resize", makeShapes,
"The wxShapeSizer preserves the original proportions of the window."
),
("", None, ""),
("Boxes inside of boxes", makeBoxInBox,
"This one shows nesting of boxes within boxes within boxes, using both "
"orientations. Notice also that button seven has a greater weighting "
"factor than its siblings."
),
("Boxes inside a Border", makeBoxInBorder,
"Sizers of different types can be nested withing each other as well. "
"Here is a box sizer with several buttons embedded within a border sizer."
),
("Border in a Box", makeBorderInBox,
"Another nesting example. This one has Boxes and a Border inside another Box."
),
]
#----------------------------------------------------------------------
class TestFrame(wxFrame):
def __init__(self, parent, title, sizerFunc):
wxFrame.__init__(self, parent, -1, title)
EVT_BUTTON(self, 1010, self.OnButton)
self.sizer = sizerFunc(self)
self.CreateStatusBar()
self.SetStatusText("Resize this frame to see how the sizers respond...")
self.sizer.FitWindow(self)
EVT_CLOSE(self, self.OnCloseWindow)
EVT_SIZE(self, self.OnSize)
def OnSize(self, event):
size = self.GetClientSize()
self.sizer.Layout(size)
def OnCloseWindow(self, event):
self.MakeModal(false)
self.Destroy()
def OnButton(self, event):
self.Close(true)
#----------------------------------------------------------------------
class TestSelectionPanel(wxPanel):
def __init__(self, parent, frame=NULL):
wxPanel.__init__(self, parent, -1)
self.frame = frame
self.list = wxListBox(self, 401,
wxDLG_PNT(self, 10, 10), wxDLG_SZE(self, 100, 60),
[])
EVT_LISTBOX(self, 401, self.OnSelect)
EVT_LISTBOX_DCLICK(self, 401, self.OnDClick)
wxButton(self, 402, "Try it!", wxDLG_PNT(self, 120, 10)).SetDefault()
EVT_BUTTON(self, 402, self.OnDClick)
self.text = wxTextCtrl(self, -1, "",
wxDLG_PNT(self, 10, 80),
wxDLG_SZE(self, 200, 60),
wxTE_MULTILINE | wxTE_READONLY)
for item in theTests:
self.list.Append(item[0])
def OnSelect(self, event):
pos = self.list.GetSelection()
self.text.SetValue(theTests[pos][2])
def OnDClick(self, event):
pos = self.list.GetSelection()
title = theTests[pos][0]
func = theTests[pos][1]
if func:
win = TestFrame(self, title, func)
win.CentreOnParent(wxBOTH)
win.Show(true)
win.MakeModal(true)
#----------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestSelectionPanel(nb, frame)
return win
overview = wxSizer.__doc__ + '\n' + '-' * 80 + '\n' + \
wxBoxSizer.__doc__ + '\n' + '-' * 80 + '\n' + \
wxBorderSizer.__doc__
#----------------------------------------------------------------------
if __name__ == '__main__':
class MainFrame(wxFrame):
def __init__(self):
wxFrame.__init__(self, NULL, -1, "Testing...")
self.CreateStatusBar()
mainmenu = wxMenuBar()
menu = wxMenu()
menu.Append(200, 'E&xit', 'Get the heck outta here!')
mainmenu.Append(menu, "&File")
self.SetMenuBar(mainmenu)
EVT_MENU(self, 200, self.OnExit)
self.panel = TestSelectionPanel(self, self)
self.SetSize(wxSize(400, 380))
EVT_CLOSE(self, self.OnCloseWindow)
def OnCloseWindow(self, event):
self.Destroy()
def OnExit(self, event):
self.Close(true)
class TestApp(wxApp):
def OnInit(self):
frame = MainFrame()
frame.Show(true)
self.SetTopWindow(frame)
return true
app = TestApp(0)
app.MainLoop()
#----------------------------------------------------------------------

View File

@@ -1,20 +0,0 @@
from wxPython.wx import *
from wxPython.lib.shell import PyShell
#----------------------------------------------------------------------
def runTest(frame, nb, log):
win = PyShell(nb)
win.Show(true)
return win
#----------------------------------------------------------------------
overview = """
A simple GUI version of the interactive interpreter.
"""

View File

@@ -1,9 +1,16 @@
import string
import string, sys
py2 = sys.version[0] == '2'
from wxPython.wx import *
try:
from xml.parsers import pyexpat
if py2:
from xml.parsers import expat
parsermodule = expat
else:
from xml.parsers import pyexpat
parsermodule = pyexpat
haveXML = true
except ImportError:
haveXML = false
@@ -12,7 +19,8 @@ except ImportError:
if not haveXML:
def runTest(frame, nb, log):
dlg = wxMessageDialog(frame, 'This demo requires the XML package. See http://www.python.org/sigs/xml-sig/',
dlg = wxMessageDialog(frame, 'This demo requires the XML package. '
'See http://www.python.org/sigs/xml-sig/',
'Sorry', wxOK | wxICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
@@ -26,6 +34,8 @@ else:
# Define a handler for start element events
def StartElement(self, name, attrs ):
if py2:
name = name.encode()
id = self.AppendItem(self.nodeStack[-1], name)
self.nodeStack.append(id)
@@ -34,12 +44,14 @@ else:
def CharacterData(self, data ):
if string.strip(data):
if py2:
data = data.encode()
self.AppendItem(self.nodeStack[-1], data)
def LoadTree(self, filename):
# Create a parser
Parser = pyexpat.ParserCreate()
Parser = parsermodule.ParserCreate()
# Tell the parser what the start element handler is
Parser.StartElementHandler = self.StartElement

View File

@@ -0,0 +1,27 @@
"""
This is a simple little echo program that is used by the wxProcess
demo. It reads lines from stdin and echos them back to stdout, until
there is an EOF on stdin.
Enter text in the field below to send to the stdin of the echo
process. Clicking on 'Close Stream' will close the stream in the
demo, and then echo.py should terminate too...
"""
import sys
sys.stdout.write( __doc__)
sys.stdout.flush()
line = sys.stdin.readline()
while line:
line = line[:-1]
sys.stdout.write('\nYou typed "%s"\n' % line)
sys.stdout.flush()
line = sys.stdin.readline()
sys.stdout.write('\nExiting...\n')
sys.stdout.flush()

View File

@@ -6,7 +6,7 @@
//
// Created: 17-March-2000
// RCS-ID: $Id$
// Copyright: (c) 1998 by Total Control Software
// Copyright: (c) 2000 by Total Control Software
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
@@ -74,7 +74,7 @@
if (m_myInst.findCallback(#CBNAME)) \
m_myInst.callCallback( \
Py_BuildValue("(Oii)", \
wxPyConstructObject((void*)attr, "_wxGridCellAttr_p"), \
wxPyConstructObject((void*)attr, "wxGridCellAttr"), \
a, b)); \
else \
PCLASS::CBNAME(attr, a, b); \
@@ -92,7 +92,7 @@
if (m_myInst.findCallback(#CBNAME)) \
m_myInst.callCallback( \
Py_BuildValue("(Oi)", \
wxPyConstructObject((void*)attr, "_wxGridCellAttr_p"), \
wxPyConstructObject((void*)attr, "wxGridCellAttr"), \
val)); \
else \
PCLASS::CBNAME(attr, val); \
@@ -451,6 +451,8 @@ class wxGridCellRenderer
{
public:
void SetParameters(const wxString& params);
void IncRef();
void DecRef();
virtual void Draw(wxGrid& grid,
wxGridCellAttr& attr,
@@ -600,6 +602,8 @@ public:
void SetControl(wxControl* control);
void SetParameters(const wxString& params);
void IncRef();
void DecRef();
virtual void Create(wxWindow* parent,
wxWindowID id,
@@ -612,6 +616,7 @@ public:
virtual void SetSize(const wxRect& rect);
virtual void Show(bool show, wxGridCellAttr *attr = NULL);
virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void StartingKey(wxKeyEvent& event);
virtual void StartingClick();
virtual void HandleReturn(wxKeyEvent& event);
@@ -687,7 +692,7 @@ public:
if (m_myInst.findCallback("Show"))
m_myInst.callCallback(
Py_BuildValue("(iO)", show,
wxPyConstructObject((void*)attr, "_wxGridCellAttr_p")));
wxPyConstructObject((void*)attr, "wxGridCellAttr")));
else
wxGridCellEditor::Show(show, attr);
wxPySaveThread(doSave);
@@ -702,8 +707,8 @@ public:
if (m_myInst.findCallback("PaintBackground"))
m_myInst.callCallback(
Py_BuildValue("(OO)",
wxPyConstructObject((void*)&rectCell, "_wxRect_p"),
wxPyConstructObject((void*)attr, "_wxGridCellAttr_p")));
wxPyConstructObject((void*)&rectCell, "wxRect"),
wxPyConstructObject((void*)attr, "wxGridCellAttr")));
else
wxGridCellEditor::PaintBackground(rectCell, attr);
wxPySaveThread(doSave);
@@ -715,6 +720,7 @@ public:
DEC_PYCALLBACK___pure(Reset);
DEC_PYCALLBACK__constany(SetSize, wxRect);
DEC_PYCALLBACK_bool_any(IsAcceptedKey, wxKeyEvent);
DEC_PYCALLBACK__any(StartingKey, wxKeyEvent);
DEC_PYCALLBACK__any(HandleReturn, wxKeyEvent);
DEC_PYCALLBACK__(StartingClick);
@@ -728,6 +734,7 @@ public:
IMP_PYCALLBACK__STRING( wxPyGridCellEditor, wxGridCellEditor, SetParameters);
IMP_PYCALLBACK___pure(wxPyGridCellEditor, wxGridCellEditor, Reset);
IMP_PYCALLBACK__constany(wxPyGridCellEditor, wxGridCellEditor, SetSize, wxRect);
IMP_PYCALLBACK_bool_any(wxPyGridCellEditor, wxGridCellEditor, IsAcceptedKey, wxKeyEvent);
IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, StartingKey, wxKeyEvent);
IMP_PYCALLBACK__any(wxPyGridCellEditor, wxGridCellEditor, HandleReturn, wxKeyEvent);
IMP_PYCALLBACK__(wxPyGridCellEditor, wxGridCellEditor, StartingClick);
@@ -1269,15 +1276,14 @@ public:
int GetNumberCols();
#ifdef NOTNEEDED // ????
// ------ display update functions
//
void CalcRowLabelsExposed( wxRegion& reg );
void CalcColLabelsExposed( wxRegion& reg );
void CalcCellsExposed( wxRegion& reg );
#ifdef NOTNEEDED // ????
// ------ event handlers
//
void ProcessRowLabelMouseEvent( wxMouseEvent& event );
@@ -1338,7 +1344,7 @@ public:
void GetTextBoxSize( wxDC& dc,
wxArrayString& lines,
long *width, long *height );
long *OUTPUT, long *OUTPUT );
// ------
@@ -1559,7 +1565,8 @@ public:
void SelectRow( int row, bool addToSelected = FALSE );
void SelectCol( int col, bool addToSelected = FALSE );
void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol );
void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
bool addToSelected = FALSE );
// TODO: ??? void SelectBlock( const wxGridCellCoords& topLeft,
// TODO: ??? const wxGridCellCoords& bottomRight )
@@ -1577,10 +1584,6 @@ public:
wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
const wxGridCellCoords & bottomRight );
// This function returns the rectangle that encloses the selected cells
// in device coords and clipped to the client size of the grid window.
//
wxRect SelectionToDeviceRect();
// Access or update the selection fore/back colours
wxColour GetSelectionBackground() const;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,7 @@
import sys, string
from wxPython.wx import *
from wxPython.html import *
@@ -41,7 +43,10 @@ class TestHtmlPanel(wxPanel):
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__)
py_version = string.split(sys.version)[0]
self.html.SetPage(About.MyAboutBox.text % (wx.__version__, py_version))
ir = self.html.GetInternalRepresentation()
self.html.SetSize( (ir.GetWidth()+5, ir.GetHeight()+5) )
self.Fit()
#----------------------------------------------------------------------

View File

@@ -43,7 +43,7 @@ class TestFloatBar(wxFrame):
tb.AddTool(60, wxBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
wxBitmap('bitmaps/tog2.bmp', wxBITMAP_TYPE_BMP),
shortHelpString="Toggle with 2 bitmaps", toggle=true)
shortHelpString="Toggle with 2 bitmaps", isToggle=true)
EVT_TOOL(self, 60, self.OnToolClick)
EVT_TOOL_RCLICKED(self, 60, self.OnToolRClick)
tb.Realize()

View File

@@ -8,7 +8,7 @@ except ImportError:
try:
# The Python OpenGL package can be found at
# http://starship.python.net:9673/crew/da/Code/PyOpenGL/
# http://PyOpenGL.sourceforge.net/
from OpenGL.GL import *
from OpenGL.GLUT import *
haveOpenGL = true
@@ -28,7 +28,7 @@ elif not haveOpenGL:
def runTest(frame, nb, log):
dlg = wxMessageDialog(frame,
'The OpenGL package was not found. You can get it at\n'
'http://starship.python.net:9673/crew/da/Code/PyOpenGL/',
'http://PyOpenGL.sourceforge.net/',
'Sorry', wxOK | wxICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
@@ -57,7 +57,8 @@ else:
class CubeCanvas(wxGLCanvas):
def __init__(self, parent):
wxGLCanvas.__init__(self, parent, -1)
wxGLCanvas.__init__(self, parent, -1) #,
#attribList=[GL_RED_BITS, 4, GL_DOUBLEBUFFER] )
EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
EVT_SIZE(self, self.OnSize)
EVT_PAINT(self, self.OnPaint)

View File

@@ -9,16 +9,15 @@ class TestPanel(wxPanel):
self.log = log
self.count = 0
wxStaticText(self, -1, "This example uses the wxGauge control.",
wxStaticText(self, -1, "This example shows the wxGauge control.",
wxPoint(45, 15))
#self.g1 = wxGauge(self, -1, 50, wxPoint(40, 50), wxSize(40, 160),
# wxGA_VERTICAL)
#self.g1.SetBezelFace(3)
#self.g1.SetShadowWidth(3)
self.g1 = wxGauge(self, -1, 50, wxPoint(110, 50), wxSize(250, 25))
self.g1.SetBezelFace(3)
self.g1.SetShadowWidth(3)
self.g2 = wxGauge(self, -1, 50, wxPoint(110, 50), wxSize(250, 25),
wxGA_HORIZONTAL)
self.g2 = wxGauge(self, -1, 50, wxPoint(110, 95), wxSize(250, 25),
wxGA_HORIZONTAL|wxGA_SMOOTH)
self.g2.SetBezelFace(5)
self.g2.SetShadowWidth(5)
@@ -29,7 +28,7 @@ class TestPanel(wxPanel):
self.count = self.count + 1
if self.count >= 50:
self.count = 0
#self.g1.SetValue(self.count)
self.g1.SetValue(self.count)
self.g2.SetValue(self.count)

View File

@@ -13,6 +13,12 @@ class MyHtmlWindow(wxHtmlWindow):
def __init__(self, parent, id, log):
wxHtmlWindow.__init__(self, parent, id)
self.log = log
EVT_SCROLLWIN( self, self.OnScroll )
def OnScroll( self, event ):
print 'event.GetOrientation()',event.GetOrientation()
print 'event.GetPosition()',event.GetPosition()
event.Skip()
def OnLinkClicked(self, linkinfo):

View File

@@ -60,7 +60,7 @@ musicdata = {
class TestListCtrlPanel(wxPanel):
def __init__(self, parent, log):
wxPanel.__init__(self, parent, -1)
wxPanel.__init__(self, parent, -1, style=wxWANTS_CHARS)
self.log = log
tID = wxNewId()
@@ -68,15 +68,15 @@ class TestListCtrlPanel(wxPanel):
self.il = wxImageList(16, 16)
idx1 = self.il.Add(wxBitmap('bitmaps/smiles.bmp', wxBITMAP_TYPE_BMP))
self.list = wxListCtrl(self, tID, wxDefaultPosition, wxDefaultSize,
wxLC_REPORT|wxSUNKEN_BORDER)
self.list = wxListCtrl(self, tID,
style=wxLC_REPORT|wxSUNKEN_BORDER)
self.list.SetImageList(self.il, wxIMAGE_LIST_SMALL)
self.list.SetToolTip(wxToolTip("This is a ToolTip!"))
wxToolTip_Enable(true)
self.list.InsertColumn(0, "Artist")
self.list.InsertColumn(1, "Title")
self.list.InsertColumn(1, "Title", wxLIST_FORMAT_RIGHT)
self.list.InsertColumn(2, "Genre")
items = musicdata.items()
for x in range(len(items)):
@@ -90,11 +90,20 @@ class TestListCtrlPanel(wxPanel):
self.list.SetColumnWidth(1, wxLIST_AUTOSIZE)
##self.list.SetColumnWidth(2, wxLIST_AUTOSIZE)
self.list.SetItemState(5, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED)
self.list.SetItemState(25, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED)
#self.list.SetItemState(25, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED)
#self.list.EnsureVisible(25)
# show how to change the colour of an item
item = self.list.GetItem(1)
item.SetTextColour(wxBLUE)
self.list.SetItem(item)
self.currentItem = 0
EVT_SIZE(self, self.OnSize)
EVT_LIST_ITEM_SELECTED(self, tID, self.OnItemSelected)
EVT_LIST_ITEM_ACTIVATED(self, tID, self.OnItemActivated)
EVT_LIST_DELETE_ITEM(self, tID, self.OnItemDelete)
EVT_LIST_COL_CLICK(self, tID, self.OnColClick)
EVT_LEFT_DCLICK(self.list, self.OnDoubleClick)
@@ -117,6 +126,10 @@ class TestListCtrlPanel(wxPanel):
self.currentItem = event.m_itemIndex
self.log.WriteText("OnItemSelected: %s\n" % self.list.GetItemText(self.currentItem))
def OnItemActivated(self, event):
self.currentItem = event.m_itemIndex
self.log.WriteText("OnItemActivated: %s\n" % self.list.GetItemText(self.currentItem))
def OnItemDelete(self, event):
self.log.WriteText("OnItemDelete\n")

157
wxPython/demo/wxProcess.py Normal file
View File

@@ -0,0 +1,157 @@
from wxPython.wx import *
#----------------------------------------------------------------------
class TestPanel(wxPanel):
def __init__(self, parent, ID, log):
wxPanel.__init__(self, parent, ID)
self.log = log
self.process = None
EVT_IDLE(self, self.OnIdle)
# We can either derive from wxProcess and override OnTerminate
# or we can let wxProcess send this window an event that is
# caught in the normal way...
EVT_END_PROCESS(self, -1, self.OnProcessEnded)
# Make the controls
prompt = wxStaticText(self, -1, 'Command line:')
self.cmd = wxTextCtrl(self, -1, 'python data/echo.py')
self.exBtn = wxButton(self, -1, 'Execute')
self.out = wxTextCtrl(self, -1, '', style=wxTE_MULTILINE|wxTE_READONLY)
self.inp = wxTextCtrl(self, -1, '', style=wxTE_PROCESS_ENTER)
self.sndBtn = wxButton(self, -1, 'Send')
self.termBtn = wxButton(self, -1, 'Close Stream')
self.inp.Enable(false)
self.sndBtn.Enable(false)
self.termBtn.Enable(false)
# Hook up the events
EVT_BUTTON(self, self.exBtn.GetId(), self.OnExecuteBtn)
EVT_BUTTON(self, self.sndBtn.GetId(), self.OnSendText)
EVT_BUTTON(self, self.termBtn.GetId(), self.OnCloseStream)
EVT_TEXT_ENTER(self, self.inp.GetId(), self.OnSendText)
# Do the layout
box1 = wxBoxSizer(wxHORIZONTAL)
box1.Add(prompt, 0, wxALIGN_CENTER)
box1.Add(self.cmd, 1, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5)
box1.Add(self.exBtn, 0)
box2 = wxBoxSizer(wxHORIZONTAL)
box2.Add(self.inp, 1, wxALIGN_CENTER)
box2.Add(self.sndBtn, 0, wxLEFT, 5)
box2.Add(self.termBtn, 0, wxLEFT, 5)
sizer = wxBoxSizer(wxVERTICAL)
sizer.Add(box1, 0, wxEXPAND|wxALL, 10)
sizer.Add(self.out, 1, wxEXPAND|wxALL, 10)
sizer.Add(box2, 0, wxEXPAND|wxALL, 10)
self.SetSizer(sizer)
self.SetAutoLayout(true)
def __del__(self):
if self.process is not None:
self.process.Detach()
self.process.CloseOutput()
self.process = None
def OnExecuteBtn(self, evt):
cmd = self.cmd.GetValue()
self.process = wxProcess(self)
self.process.Redirect();
pid = wxExecute(cmd, false, self.process)
self.log.write('OnExecuteBtn: "%s" pid: %s\n' % (cmd, pid))
self.inp.Enable(true)
self.sndBtn.Enable(true)
self.termBtn.Enable(true)
self.cmd.Enable(false)
self.exBtn.Enable(false)
self.inp.SetFocus()
def OnSendText(self, evt):
text = self.inp.GetValue()
self.inp.SetValue('')
self.log.write('OnSendText: "%s"\n' % text)
self.process.GetOutputStream().write(text + '\n')
self.inp.SetFocus()
def OnCloseStream(self, evt):
self.log.write('OnCloseStream\n')
self.process.CloseOutput()
def OnIdle(self, evt):
if self.process is not None:
stream = self.process.GetInputStream()
# Yes, this is weird. For this particular stream, EOF
# simply means that there is no data available to be read,
# not truly the end of file. Also, read() just reads all
# the currently available data, not until the real EOF...
if not stream.eof():
text = stream.read()
self.out.AppendText(text)
def OnProcessEnded(self, evt):
self.log.write('OnProcessEnded, pid:%s, exitCode: %s\n' %
(evt.GetPid(), evt.GetExitCode()))
stream = self.process.GetInputStream()
if not stream.eof():
text = stream.read()
self.out.AppendText(text)
self.process.Destroy()
self.process = None
self.inp.Enable(false)
self.sndBtn.Enable(false)
self.termBtn.Enable(false)
self.cmd.Enable(true)
self.exBtn.Enable(true)
#----------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, -1, log)
return win
#----------------------------------------------------------------------
overview = """\
<html><body>
<h2>wxProcess</h2>
wxProcess lets you get notified when an asyncronous child process
started by wxExecute terminates, and also to get input/output streams
for the child process's stdout, stderr and stdin.
<p>
This demo launches a simple python script that echos back on stdout
lines that it reads from stdin. You can send text to the echo
process' stdin by typing in the lower textctrl and clicking Send.
<p>
Clicking the Close Stream button will close the demo's end of the
stdin pipe to the child process. In our case that will cause the
child process to exit its main loop.
</body><html>
"""

View File

@@ -81,6 +81,9 @@ class MyCanvas(wxScrolledWindow):
dc.DrawRectangle(50,500,50,50)
dc.DrawRectangle(100,500,50,50)
dc.SetPen(pen1)
dc.DrawEllipticArc(200, 500, 50, 75, 0, 90)
#from wxPython import dch
#dch.FillRect(dc, wxRect(50, 400, 50, 50), wxBLACK)

View File

@@ -9,9 +9,17 @@ class MySplitter(wxSplitterWindow):
wxSplitterWindow.__init__(self, parent, ID)
self.log = log
EVT_SPLITTER_SASH_POS_CHANGED(self, self.GetId(), self.OnSashChanged)
EVT_SPLITTER_SASH_POS_CHANGING(self, self.GetId(), self.OnSashChanging)
def OnSashChanged(self, evt):
self.log.WriteText("sash changed to " + str(evt.GetSashPosition()))
self.log.WriteText("sash changed to %s\n" % str(evt.GetSashPosition()))
# uncomment this to not allow the change
#evt.SetSashPosition(-1)
def OnSashChanging(self, evt):
self.log.WriteText("sash changing to %s\n" % str(evt.GetSashPosition()))
# uncomment this to not allow the change
#evt.SetSashPosition(-1)
#---------------------------------------------------------------------------

View File

@@ -10,7 +10,9 @@ class CustomStatusBar(wxStatusBar):
wxStatusBar.__init__(self, parent, -1)
self.SetFieldsCount(3)
self.log = log
self.sizeChanged = false
EVT_SIZE(self, self.OnSize)
EVT_IDLE(self, self.OnIdle)
self.SetStatusText("A Custom StatusBar...", 0)
@@ -18,12 +20,8 @@ class CustomStatusBar(wxStatusBar):
EVT_CHECKBOX(self, 1001, self.OnToggleClock)
self.cb.SetValue(true)
# figure out how tall to make it.
dc = wxClientDC(self)
dc.SetFont(self.GetFont())
(w,h) = dc.GetTextExtent('X')
h = int(h * 1.8)
self.SetSize(wxSize(100, h))
# set the initial position of the checkbox
self.Reposition()
# start our timer
self.timer = wxPyTimer(self.Notify)
@@ -38,6 +36,7 @@ class CustomStatusBar(wxStatusBar):
self.SetStatusText(st, 2)
self.log.WriteText("tick...\n")
# the checkbox was clicked
def OnToggleClock(self, event):
if self.cb.GetValue():
@@ -47,11 +46,26 @@ class CustomStatusBar(wxStatusBar):
self.timer.Stop()
def OnSize(self, evt):
self.Reposition() # for normal size events
# Set a flag so the idle time handler will also do the repositioning.
# It is done this way to get around a buglet where GetFieldRect is not
# accurate during the EVT_SIZE resulting from a frame maximize.
self.sizeChanged = true
def OnIdle(self, evt):
if self.sizeChanged:
self.Reposition()
# reposition the checkbox
def OnSize(self, event):
def Reposition(self):
rect = self.GetFieldRect(1)
self.cb.SetPosition(wxPoint(rect.x+2, rect.y+2))
self.cb.SetSize(wxSize(rect.width-4, rect.height-4))
self.sizeChanged = false
@@ -89,28 +103,4 @@ def runTest(frame, nb, log):
overview = """\
A status bar is a narrow window that can be placed along the bottom of a frame to give small amounts of status information. It can contain one or more fields, one or more of which can be variable length according to the size of the window.
wxStatusBar()
----------------------------
Default constructor.
wxStatusBar(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = "statusBar")
Constructor, creating the window.
Parameters
-------------------
parent = The window parent, usually a frame.
id = The window identifier. It may take a value of -1 to indicate a default value.
pos = The window position. A value of (-1, -1) indicates a default position, chosen by either the windowing system or wxWindows, depending on platform.
size = The window size. A value of (-1, -1) indicates a default size, chosen by either the windowing system or wxWindows, depending on platform.
style = The window style. See wxStatusBar.
name = The name of the window. This parameter is used to associate a name with the item, allowing the application user to set Motif resource values for individual windows.
"""

View File

@@ -113,15 +113,15 @@ def runTest(frame, nb, log):
# now set some text to those styles... Normally this would be
# done in an event handler that happens when text needs displayed.
ed.StartStyling(98, 0xff)
ed.SetStyleFor(6, 1) # set style for 6 characters using style 1
ed.SetStyling(6, 1) # set style for 6 characters using style 1
ed.StartStyling(190, 0xff)
ed.SetStyleFor(20, 2)
ed.SetStyling(20, 2)
ed.StartStyling(310, 0xff)
ed.SetStyleFor(4, 3)
ed.SetStyleFor(2, 0)
ed.SetStyleFor(10, 4)
ed.SetStyling(4, 3)
ed.SetStyling(2, 0)
ed.SetStyling(10, 4)
# line numbers in the margin
@@ -146,16 +146,16 @@ def runTest(frame, nb, log):
# and finally, an indicator or two
ed.IndicatorSetStyle(0, wxSTC_INDIC_SQUIGGLE)
ed.IndicatorSetColour(0, wxRED)
ed.IndicatorSetForeground(0, wxRED)
ed.IndicatorSetStyle(1, wxSTC_INDIC_DIAGONAL)
ed.IndicatorSetColour(1, wxBLUE)
ed.IndicatorSetForeground(1, wxBLUE)
ed.IndicatorSetStyle(2, wxSTC_INDIC_STRIKE)
ed.IndicatorSetColour(2, wxRED)
ed.IndicatorSetForeground(2, wxRED)
ed.StartStyling(836, wxSTC_INDICS_MASK)
ed.SetStyleFor(10, wxSTC_INDIC0_MASK)
ed.SetStyleFor(10, wxSTC_INDIC1_MASK)
ed.SetStyleFor(10, wxSTC_INDIC2_MASK | wxSTC_INDIC1_MASK)
ed.SetStyling(10, wxSTC_INDIC0_MASK)
ed.SetStyling(10, wxSTC_INDIC1_MASK)
ed.SetStyling(10, wxSTC_INDIC2_MASK | wxSTC_INDIC1_MASK)
return ed

View File

@@ -41,13 +41,13 @@ class PythonSTC(wxStyledTextCtrl):
wxStyledTextCtrl.__init__(self, parent, ID)
self.SetLexer(wxSTC_LEX_PYTHON)
self.SetKeywords(0, string.join(keyword.kwlist))
self.SetKeyWords(0, string.join(keyword.kwlist))
self.SetProperty("fold", "1")
self.SetProperty("tab.timmy.whinge.level", "1")
self.SetMargins(0,0)
self.SetViewWhitespace(false)
self.SetViewWhiteSpace(false)
#self.SetBufferedDraw(false)
self.SetEdgeMode(wxSTC_EDGE_BACKGROUND)
@@ -82,33 +82,33 @@ class PythonSTC(wxStyledTextCtrl):
# Python styles
# White space
self.StyleSetSpec(SCE_P_DEFAULT, "fore:#808080")
self.StyleSetSpec(wxSTC_P_DEFAULT, "fore:#808080")
# Comment
self.StyleSetSpec(SCE_P_COMMENTLINE, "fore:#007F00,face:%(other)s" % faces)
self.StyleSetSpec(wxSTC_P_COMMENTLINE, "fore:#007F00,face:%(other)s" % faces)
# Number
self.StyleSetSpec(SCE_P_NUMBER, "fore:#007F7F")
self.StyleSetSpec(wxSTC_P_NUMBER, "fore:#007F7F")
# String
self.StyleSetSpec(SCE_P_STRING, "fore:#7F007F,italic,face:%(times)s" % faces)
self.StyleSetSpec(wxSTC_P_STRING, "fore:#7F007F,italic,face:%(times)s" % faces)
# Single quoted string
self.StyleSetSpec(SCE_P_CHARACTER, "fore:#7F007F,italic,face:%(times)s" % faces)
self.StyleSetSpec(wxSTC_P_CHARACTER, "fore:#7F007F,italic,face:%(times)s" % faces)
# Keyword
self.StyleSetSpec(SCE_P_WORD, "fore:#00007F,bold")
self.StyleSetSpec(wxSTC_P_WORD, "fore:#00007F,bold")
# Triple quotes
self.StyleSetSpec(SCE_P_TRIPLE, "fore:#7F0000")
self.StyleSetSpec(wxSTC_P_TRIPLE, "fore:#7F0000")
# Triple double quotes
self.StyleSetSpec(SCE_P_TRIPLEDOUBLE, "fore:#7F0000")
self.StyleSetSpec(wxSTC_P_TRIPLEDOUBLE, "fore:#7F0000")
# Class name definition
self.StyleSetSpec(SCE_P_CLASSNAME, "fore:#0000FF,bold,underline")
self.StyleSetSpec(wxSTC_P_CLASSNAME, "fore:#0000FF,bold,underline")
# Function or method name definition
self.StyleSetSpec(SCE_P_DEFNAME, "fore:#007F7F,bold")
self.StyleSetSpec(wxSTC_P_DEFNAME, "fore:#007F7F,bold")
# Operators
self.StyleSetSpec(SCE_P_OPERATOR, "bold")
self.StyleSetSpec(wxSTC_P_OPERATOR, "bold")
# Identifiers
#self.StyleSetSpec(SCE_P_IDENTIFIER, "bold")#,fore:#FF00FF")
#self.StyleSetSpec(wxSTC_P_IDENTIFIER, "bold")#,fore:#FF00FF")
# Comment-blocks
self.StyleSetSpec(SCE_P_COMMENTBLOCK, "fore:#7F7F7F")
self.StyleSetSpec(wxSTC_P_COMMENTBLOCK, "fore:#7F7F7F")
# End of line where string is not closed
self.StyleSetSpec(SCE_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eolfilled" % faces)
self.StyleSetSpec(wxSTC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eolfilled" % faces)
self.SetCaretForeground("BLUE")
@@ -126,8 +126,17 @@ class PythonSTC(wxStyledTextCtrl):
self.CallTipShow(pos, 'param1, param2')
# Code completion
else:
self.AutoCompShow('I love wxPython a b c')
#lst = []
#for x in range(50000):
# lst.append('%05d' % x)
#st = string.join(lst)
#print len(st)
#self.AutoCompShow(0, st)
self.AutoCompSetIgnoreCase(true)
self.AutoCompShow(0, string.join(keyword.kwlist))
self.AutoCompSelect('br')
else:
event.Skip()
def OnUpdateUI(self, evt):
@@ -141,21 +150,21 @@ class PythonSTC(wxStyledTextCtrl):
styleBefore = self.GetStyleAt(caretPos - 1)
# check before
if charBefore and charBefore in "[]{}()" and ord(styleBefore) == SCE_P_OPERATOR:
if charBefore and chr(charBefore) in "[]{}()" and styleBefore == wxSTC_P_OPERATOR:
braceAtCaret = caretPos - 1
# check after
if braceAtCaret < 0:
charAfter = self.GetCharAt(caretPos)
styleAfter = self.GetStyleAt(caretPos)
if charAfter and charAfter in "[]{}()" and ord(styleAfter) == SCE_P_OPERATOR:
if charAfter and chr(charAfter) in "[]{}()" and styleAfter == wxSTC_P_OPERATOR:
braceAtCaret = caretPos
if braceAtCaret >= 0:
braceOpposite = self.BraceMatch(braceAtCaret)
if braceAtCaret != -1 and braceOpposite == -1:
self.BraceBadlight(braceAtCaret)
self.BraceBadLight(braceAtCaret)
else:
self.BraceHighlight(braceAtCaret, braceOpposite)
#pt = self.PointFromPosition(braceOpposite)
@@ -170,7 +179,7 @@ class PythonSTC(wxStyledTextCtrl):
if evt.GetShift() and evt.GetControl():
self.FoldAll()
else:
lineClicked = self.GetLineFromPos(evt.GetPosition())
lineClicked = self.LineFromPosition(evt.GetPosition())
if self.GetFoldLevel(lineClicked) & wxSTC_FOLDLEVELHEADERFLAG:
if evt.GetShift():
self.SetFoldExpanded(lineClicked, true)

View File

@@ -12,13 +12,16 @@ class TestPanel(wxPanel):
t = wxTextCtrl(self, 10, "Test it out and see", wxPoint(80, 25), wxSize(150, 20))
t.SetInsertionPoint(0)
EVT_TEXT(self, 10, self.EvtText)
EVT_CHAR(t, self.EvtChar)
wxStaticText(self, -1, "Passsword", wxPoint(5, 50), wxSize(75, 20))
wxTextCtrl(self, 20, "", wxPoint(80, 50), wxSize(150, 20), wxTE_PASSWORD)
EVT_TEXT(self, 20, self.EvtText)
wxStaticText(self, -1, "Multi-line", wxPoint(5, 75), wxSize(75, 20))
t = wxTextCtrl(self, 30, "How does it work with a long line of text set in the control", wxPoint(80, 75), wxSize(200, 150), wxTE_MULTILINE)
t = wxTextCtrl(self, 30, "How does it work with a long line of text set in the control",
wxPoint(80, 75), wxSize(200, 150), wxTE_MULTILINE)
t.SetInsertionPoint(0)
EVT_TEXT(self, 30, self.EvtText)
@@ -26,6 +29,10 @@ class TestPanel(wxPanel):
self.log.WriteText('EvtText: %s\n' % event.GetString())
def EvtChar(self, event):
self.log.WriteText('EvtChar: %d\n' % event.GetKeyCode())
event.Skip()
#---------------------------------------------------------------------------

View File

@@ -39,20 +39,22 @@ class TestToolBar(wxFrame):
tb.AddSeparator()
tool = tb.AddTool(50, wxBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
shortHelpString="Toggle this", toggle=true)
shortHelpString="Toggle this", isToggle=true)
EVT_TOOL(self, 50, self.OnToolClick)
EVT_TOOL_RCLICKED(self, 50, self.OnToolRClick)
tb.AddTool(60, wxBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
wxBitmap('bitmaps/tog2.bmp', wxBITMAP_TYPE_BMP),
shortHelpString="Toggle with 2 bitmaps", toggle=true)
shortHelpString="Toggle with 2 bitmaps", isToggle=true)
EVT_TOOL(self, 60, self.OnToolClick)
EVT_TOOL_RCLICKED(self, 60, self.OnToolRClick)
tb.AddSeparator()
tb.AddControl(wxComboBox(tb, -1, "", choices=["", "This", "is a", "wxComboBox"],
cbID = wxNewId()
tb.AddControl(wxComboBox(tb, cbID, "", choices=["", "This", "is a", "wxComboBox"],
size=(150,-1), style=wxCB_DROPDOWN))
EVT_COMBOBOX(self, cbID, self.OnCombo)
tb.Realize()
EVT_CLOSE(self, self.OnCloseWindow)
@@ -67,6 +69,10 @@ class TestToolBar(wxFrame):
def OnToolRClick(self, event):
self.log.WriteText("tool %s right-clicked\n" % event.GetId())
def OnCombo(self, event):
self.log.WriteText("combobox item selected: %s\n" % event.GetString())
#---------------------------------------------------------------------------
def runTest(frame, nb, log):

View File

@@ -21,7 +21,8 @@ class MyTreeCtrl(wxTreeCtrl):
class TestTreeCtrlPanel(wxPanel):
def __init__(self, parent, log):
wxPanel.__init__(self, parent, -1)
# Use the WANTS_CHARS style so the panel doesn't eat the Return key.
wxPanel.__init__(self, parent, -1, style=wxWANTS_CHARS)
EVT_SIZE(self, self.OnSize)
self.log = log
@@ -68,6 +69,7 @@ class TestTreeCtrlPanel(wxPanel):
EVT_TREE_SEL_CHANGED (self, tID, self.OnSelChanged)
EVT_TREE_BEGIN_LABEL_EDIT(self, tID, self.OnBeginEdit)
EVT_TREE_END_LABEL_EDIT (self, tID, self.OnEndEdit)
EVT_TREE_ITEM_ACTIVATED (self, tID, self.OnActivate)
EVT_LEFT_DCLICK(self.tree, self.OnLeftDClick)
EVT_RIGHT_DOWN(self.tree, self.OnRightClick)
@@ -135,10 +137,17 @@ class TestTreeCtrlPanel(wxPanel):
def OnSelChanged(self, event):
self.item = event.GetItem()
self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(self.item))
self.log.WriteText("BoundingRect: %s\n" %
self.tree.GetBoundingRect(self.item, true))
if wxPlatform == '__WXMSW__':
self.log.WriteText("BoundingRect: %s\n" %
self.tree.GetBoundingRect(self.item, true))
#items = self.tree.GetSelections()
#print map(self.tree.GetItemText, items)
event.Skip()
def OnActivate(self, evt):
self.log.WriteText("OnActivate: %s\n" % self.tree.GetItemText(self.item))
#---------------------------------------------------------------------------
@@ -160,11 +169,6 @@ def runTest(frame, nb, log):
overview = """\
A tree control presents information as a hierarchy, with items that may be expanded to show further items. Items in a tree control are referenced by wxTreeItemId handles.