This commit was manufactured by cvs2svn to create tag 'wxPy_2_4_0'.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/tags/wxPy_2_4_0@18275 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
@@ -1,9 +0,0 @@
|
||||
*.pyc
|
||||
.DS_Store
|
||||
.emacs.desktop
|
||||
b.bat
|
||||
hangman_dict.txt
|
||||
mimetypes_wdr
|
||||
setup.bat
|
||||
test.out
|
||||
tmphtml.txt
|
@@ -1,64 +0,0 @@
|
||||
import sys, string
|
||||
|
||||
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>
|
||||
Running on Python %s<br>
|
||||
</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) 1997-2002.</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 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))
|
||||
btn = html.FindWindowById(wxID_OK)
|
||||
btn.SetDefault()
|
||||
ir = html.GetInternalRepresentation()
|
||||
html.SetSize( (ir.GetWidth()+5, ir.GetHeight()+5) )
|
||||
self.SetClientSize(html.GetSize())
|
||||
self.CentreOnParent(wxBOTH)
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,128 +0,0 @@
|
||||
"""
|
||||
<html><body>
|
||||
This demo shows how to embed an ActiveX control in a wxPython application, (Win32 only.)
|
||||
<p>
|
||||
The MakeActiveXClass function dynamically builds a new Class on the fly, that has the
|
||||
same signature and semantics as wxWindow. This means that when you call the function
|
||||
you get back a new class that you can use just like wxWindow, (set the size and position,
|
||||
use in a sizer, etc.) except its contents will be the COM control.
|
||||
<p>
|
||||
This demo embeds the Adobe Acrobat Reader, and gives you some buttons for opening a PDF
|
||||
file, changing pages, etc. that show how to call methods on the COM object. If you don't
|
||||
have Acrobat Reader 4.0 installed it won't work.
|
||||
</body></html>
|
||||
"""
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
if wxPlatform == '__WXMSW__':
|
||||
from wxPython.lib.activexwrapper import MakeActiveXClass
|
||||
import win32com.client.gencache
|
||||
|
||||
try:
|
||||
acrobat = win32com.client.gencache.EnsureModule('{CA8A9783-280D-11CF-A24D-444553540000}', 0x0, 1, 3)
|
||||
except:
|
||||
raise ImportError("Can't load PDF.OCX, install Acrobat 4.0")
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
self.pdf = None
|
||||
|
||||
sizer = wxBoxSizer(wxVERTICAL)
|
||||
btnSizer = wxBoxSizer(wxHORIZONTAL)
|
||||
|
||||
# this function creates a new class that can be used as
|
||||
# a wxWindow, but contains the given ActiveX control.
|
||||
ActiveXWrapper = MakeActiveXClass(acrobat.Pdf)
|
||||
|
||||
# create an instance of the new class
|
||||
self.pdf = ActiveXWrapper( self, -1, style=wxSUNKEN_BORDER)
|
||||
|
||||
sizer.Add(self.pdf, 1, wxEXPAND)
|
||||
|
||||
btn = wxButton(self, wxNewId(), "Open PDF File")
|
||||
EVT_BUTTON(self, btn.GetId(), self.OnOpenButton)
|
||||
btnSizer.Add(btn, 1, wxEXPAND|wxALL, 5)
|
||||
|
||||
btn = wxButton(self, wxNewId(), "<-- Previous Page")
|
||||
EVT_BUTTON(self, btn.GetId(), self.OnPrevPageButton)
|
||||
btnSizer.Add(btn, 1, wxEXPAND|wxALL, 5)
|
||||
|
||||
btn = wxButton(self, wxNewId(), "Next Page -->")
|
||||
EVT_BUTTON(self, btn.GetId(), self.OnNextPageButton)
|
||||
btnSizer.Add(btn, 1, wxEXPAND|wxALL, 5)
|
||||
|
||||
|
||||
btnSizer.Add(50, -1, 2, wxEXPAND)
|
||||
sizer.Add(btnSizer, 0, wxEXPAND)
|
||||
|
||||
self.SetSizer(sizer)
|
||||
self.SetAutoLayout(true)
|
||||
|
||||
EVT_WINDOW_DESTROY(self, self.OnDestroy)
|
||||
|
||||
|
||||
def OnDestroy(self, evt):
|
||||
if self.pdf:
|
||||
self.pdf.Cleanup()
|
||||
self.pdf = None
|
||||
|
||||
|
||||
|
||||
def OnOpenButton(self, event):
|
||||
dlg = wxFileDialog(self, wildcard="*.pdf")
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
wxBeginBusyCursor()
|
||||
self.pdf.LoadFile(dlg.GetPath())
|
||||
wxEndBusyCursor()
|
||||
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
def OnPrevPageButton(self, event):
|
||||
self.pdf.gotoPreviousPage()
|
||||
|
||||
|
||||
def OnNextPageButton(self, event):
|
||||
self.pdf.gotoNextPage()
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
if wxPlatform == '__WXMSW__':
|
||||
win = TestPanel(nb, log)
|
||||
return win
|
||||
else:
|
||||
dlg = wxMessageDialog(frame, 'This demo only works on MSW.',
|
||||
'Sorry', wxOK | wxICON_INFORMATION)
|
||||
dlg.ShowModal()
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
overview = __doc__
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
class TestFrame(wxFrame):
|
||||
def __init__(self):
|
||||
wxFrame.__init__(self, None, -1, "ActiveX test -- Acrobat", size=(640, 480),
|
||||
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
|
||||
self.tp = TestPanel(self, sys.stdout)
|
||||
|
||||
|
||||
app = wxPySimpleApp()
|
||||
frame = TestFrame()
|
||||
frame.Show(true)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
@@ -1,231 +0,0 @@
|
||||
"""
|
||||
<html><body>
|
||||
This demo shows how to embed an ActiveX control in a wxPython
|
||||
application, (Win32 only.)
|
||||
|
||||
<p>
|
||||
The MakeActiveXClass function dynamically builds a new Class on the
|
||||
fly, that has the same signature and semantics as wxWindow. This
|
||||
means that when you call the function you get back a new class that
|
||||
you can use just like wxWindow, (set the size and position, use in a
|
||||
sizer, etc.) except its contents will be the COM control.
|
||||
|
||||
<p>
|
||||
This demo embeds the Internet Exploer WebBrowser control, and shows
|
||||
how to receive events from the COM control. (The title bar and status
|
||||
bar are updated as pages change, in addition to the log messages being
|
||||
shown.)
|
||||
</body></html>
|
||||
"""
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
if wxPlatform == '__WXMSW__':
|
||||
from wxPython.lib.activexwrapper import MakeActiveXClass
|
||||
import win32com.client.gencache
|
||||
|
||||
try:
|
||||
browserModule = win32com.client.gencache.EnsureModule("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1)
|
||||
except:
|
||||
raise ImportError("IE4 or greater does not appear to be installed.")
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestPanel(wxWindow):
|
||||
def __init__(self, parent, log, frame=None):
|
||||
wxWindow.__init__(self, parent, -1,
|
||||
style=wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE)
|
||||
self.ie = None
|
||||
self.log = log
|
||||
self.current = "http://wxPython.org/"
|
||||
self.frame = frame
|
||||
if frame:
|
||||
self.titleBase = frame.GetTitle()
|
||||
|
||||
|
||||
sizer = wxBoxSizer(wxVERTICAL)
|
||||
btnSizer = wxBoxSizer(wxHORIZONTAL)
|
||||
|
||||
# Make a new class that derives from the WebBrowser class in the
|
||||
# COM module imported above. This class also derives from wxWindow and
|
||||
# implements the machinery needed to integrate the two worlds.
|
||||
theClass = MakeActiveXClass(browserModule.WebBrowser,
|
||||
eventObj = self)
|
||||
|
||||
# Create an instance of that class
|
||||
self.ie = theClass(self, -1) ##, style=wxSUNKEN_BORDER)
|
||||
|
||||
|
||||
btn = wxButton(self, wxNewId(), "Open", style=wxBU_EXACTFIT)
|
||||
EVT_BUTTON(self, btn.GetId(), self.OnOpenButton)
|
||||
btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
|
||||
|
||||
btn = wxButton(self, wxNewId(), "Home", style=wxBU_EXACTFIT)
|
||||
EVT_BUTTON(self, btn.GetId(), self.OnHomeButton)
|
||||
btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
|
||||
|
||||
btn = wxButton(self, wxNewId(), "<--", style=wxBU_EXACTFIT)
|
||||
EVT_BUTTON(self, btn.GetId(), self.OnPrevPageButton)
|
||||
btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
|
||||
|
||||
btn = wxButton(self, wxNewId(), "-->", style=wxBU_EXACTFIT)
|
||||
EVT_BUTTON(self, btn.GetId(), self.OnNextPageButton)
|
||||
btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
|
||||
|
||||
btn = wxButton(self, wxNewId(), "Stop", style=wxBU_EXACTFIT)
|
||||
EVT_BUTTON(self, btn.GetId(), self.OnStopButton)
|
||||
btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
|
||||
|
||||
btn = wxButton(self, wxNewId(), "Search", style=wxBU_EXACTFIT)
|
||||
EVT_BUTTON(self, btn.GetId(), self.OnSearchPageButton)
|
||||
btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
|
||||
|
||||
btn = wxButton(self, wxNewId(), "Refresh", style=wxBU_EXACTFIT)
|
||||
EVT_BUTTON(self, btn.GetId(), self.OnRefreshPageButton)
|
||||
btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
|
||||
|
||||
txt = wxStaticText(self, -1, "Location:")
|
||||
btnSizer.Add(txt, 0, wxCENTER|wxALL, 2)
|
||||
|
||||
self.location = wxComboBox(self, wxNewId(), "", style=wxCB_DROPDOWN)
|
||||
EVT_COMBOBOX(self, self.location.GetId(), self.OnLocationSelect)
|
||||
EVT_KEY_UP(self.location, self.OnLocationKey)
|
||||
EVT_CHAR(self.location, self.IgnoreReturn)
|
||||
btnSizer.Add(self.location, 1, wxEXPAND|wxALL, 2)
|
||||
|
||||
sizer.Add(btnSizer, 0, wxEXPAND)
|
||||
sizer.Add(self.ie, 1, wxEXPAND)
|
||||
|
||||
self.ie.Navigate(self.current)
|
||||
self.location.Append(self.current)
|
||||
|
||||
self.SetSizer(sizer)
|
||||
self.SetAutoLayout(true)
|
||||
EVT_SIZE(self, self.OnSize)
|
||||
|
||||
EVT_WINDOW_DESTROY(self, self.OnDestroy)
|
||||
|
||||
|
||||
def OnDestroy(self, evt):
|
||||
if self.ie:
|
||||
self.ie.Cleanup()
|
||||
self.ie = None
|
||||
self.frame = None
|
||||
|
||||
|
||||
def OnSize(self, evt):
|
||||
self.Layout()
|
||||
|
||||
|
||||
def OnLocationSelect(self, evt):
|
||||
url = self.location.GetStringSelection()
|
||||
self.log.write('OnLocationSelect: %s\n' % url)
|
||||
self.ie.Navigate(url)
|
||||
|
||||
def OnLocationKey(self, evt):
|
||||
if evt.KeyCode() == WXK_RETURN:
|
||||
URL = self.location.GetValue()
|
||||
self.location.Append(URL)
|
||||
self.ie.Navigate(URL)
|
||||
else:
|
||||
evt.Skip()
|
||||
|
||||
def IgnoreReturn(self, evt):
|
||||
print 'IgnoreReturn'
|
||||
if evt.KeyCode() != WXK_RETURN:
|
||||
evt.Skip()
|
||||
|
||||
def OnOpenButton(self, event):
|
||||
dlg = wxTextEntryDialog(self, "Open Location",
|
||||
"Enter a full URL or local path",
|
||||
self.current, wxOK|wxCANCEL)
|
||||
dlg.CentreOnParent()
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
self.current = dlg.GetValue()
|
||||
self.ie.Navigate(self.current)
|
||||
dlg.Destroy()
|
||||
|
||||
def OnHomeButton(self, event):
|
||||
self.ie.GoHome() ## ET Phone Home!
|
||||
|
||||
def OnPrevPageButton(self, event):
|
||||
self.ie.GoBack()
|
||||
|
||||
def OnNextPageButton(self, event):
|
||||
self.ie.GoForward()
|
||||
|
||||
def OnStopButton(self, evt):
|
||||
self.ie.Stop()
|
||||
|
||||
def OnSearchPageButton(self, evt):
|
||||
self.ie.GoSearch()
|
||||
|
||||
def OnRefreshPageButton(self, evt):
|
||||
self.ie.Refresh2(3)
|
||||
|
||||
|
||||
|
||||
# The following event handlers are called by the web browser COM
|
||||
# control since we passed self to MakeActiveXClass. It will look
|
||||
# here for matching attributes and call them if they exist. See the
|
||||
# module generated by makepy for details of method names, etc.
|
||||
def OnBeforeNavigate2(self, pDisp, URL, *args):
|
||||
self.log.write('OnBeforeNavigate2: %s\n' % URL)
|
||||
|
||||
def OnNavigateComplete2(self, pDisp, URL):
|
||||
self.log.write('OnNavigateComplete2: %s\n' % URL)
|
||||
self.current = URL
|
||||
self.location.SetValue(URL)
|
||||
|
||||
def OnTitleChange(self, text):
|
||||
self.log.write('OnTitleChange: %s\n' % text)
|
||||
if self.frame:
|
||||
self.frame.SetTitle(self.titleBase + ' -- ' + text)
|
||||
|
||||
def OnStatusTextChange(self, text):
|
||||
self.log.write('OnStatusTextChange: %s\n' % text)
|
||||
if self.frame:
|
||||
self.frame.SetStatusText(text)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# for the demo framework...
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
if wxPlatform == '__WXMSW__':
|
||||
win = TestPanel(nb, log, frame)
|
||||
return win
|
||||
else:
|
||||
dlg = wxMessageDialog(frame, 'This demo only works on MSW.',
|
||||
'Sorry', wxOK | wxICON_INFORMATION)
|
||||
dlg.ShowModal()
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
overview = __doc__
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
class TestFrame(wxFrame):
|
||||
def __init__(self):
|
||||
wxFrame.__init__(self, None, -1, "ActiveX test -- Internet Explorer",
|
||||
size=(640, 480),
|
||||
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
|
||||
self.CreateStatusBar()
|
||||
self.tp = TestPanel(self, sys.stdout, self)
|
||||
EVT_CLOSE(self, self.OnCloseWindow)
|
||||
|
||||
def OnCloseWindow(self, evt):
|
||||
self.tp.Destroy()
|
||||
self.Destroy()
|
||||
|
||||
app = wxPySimpleApp()
|
||||
frame = TestFrame()
|
||||
frame.Show(true)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
@@ -1,12 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class ColoredPanel(wxWindow):
|
||||
def __init__(self, parent, color):
|
||||
wxWindow.__init__(self, parent, -1, style = wxSIMPLE_BORDER) #wxRAISED_BORDER)
|
||||
self.SetBackgroundColour(color)
|
||||
|
||||
#---------------------------------------------------------------------------
|
@@ -1,129 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib import colourdb
|
||||
|
||||
import images
|
||||
|
||||
|
||||
# This loads a whole bunch of new color names and values
|
||||
# into wxTheColourDatabase
|
||||
|
||||
colourdb.updateColourDB()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestWindow(wxScrolledWindow):
|
||||
def __init__(self, parent):
|
||||
wxScrolledWindow.__init__(self, parent, -1)
|
||||
|
||||
self.clrList = colourdb.getColourList()
|
||||
#self.clrList.sort()
|
||||
self.bg_bmp = images.getGridBGBitmap()
|
||||
|
||||
EVT_PAINT(self, self.OnPaint)
|
||||
EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
|
||||
#self.SetBackgroundColour("WHITE")
|
||||
|
||||
self.font = wxFont(10, wxSWISS, wxNORMAL, wxNORMAL)
|
||||
dc = wxClientDC(self)
|
||||
dc.SetFont(self.font)
|
||||
|
||||
w,h,d,e = dc.GetFullTextExtent("Wy") # a wide character and one that decends
|
||||
self.textHeight = h + d
|
||||
self.lineHeight = self.textHeight + 5
|
||||
self.cellWidth = w
|
||||
|
||||
numCells = 24
|
||||
self.SetScrollbars(self.cellWidth, self.lineHeight, numCells, len(self.clrList) + 2)
|
||||
|
||||
|
||||
def TileBackground(self, dc):
|
||||
# tile the background bitmap
|
||||
sz = self.GetClientSize()
|
||||
w = self.bg_bmp.GetWidth()
|
||||
h = self.bg_bmp.GetHeight()
|
||||
|
||||
# adjust for scrolled position
|
||||
spx, spy = self.GetScrollPixelsPerUnit()
|
||||
vsx, vsy = self.GetViewStart()
|
||||
dx, dy = (spx * vsx) % w, (spy * vsy) % h
|
||||
|
||||
x = -dx
|
||||
while x < sz.width:
|
||||
y = -dy
|
||||
while y < sz.height:
|
||||
dc.DrawBitmap(self.bg_bmp, x, y)
|
||||
y = y + h
|
||||
x = x + w
|
||||
|
||||
|
||||
def OnEraseBackground(self, evt):
|
||||
dc = evt.GetDC()
|
||||
if not dc:
|
||||
dc = wxClientDC(self)
|
||||
rect = self.GetUpdateRegion().GetBox()
|
||||
dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height)
|
||||
self.TileBackground(dc)
|
||||
|
||||
|
||||
def OnPaint(self, evt):
|
||||
dc = wxPaintDC(self)
|
||||
self.PrepareDC(dc)
|
||||
self.Draw(dc, self.GetUpdateRegion(), self.GetViewStart())
|
||||
|
||||
|
||||
def Draw(self, dc, rgn=None, vs=None):
|
||||
dc.BeginDrawing()
|
||||
dc.SetTextForeground("BLACK")
|
||||
dc.SetPen(wxPen("BLACK", 1, wxSOLID))
|
||||
dc.SetFont(self.font)
|
||||
colours = self.clrList
|
||||
numColours = len(colours)
|
||||
|
||||
if rgn:
|
||||
# determine the subset that has been exposed and needs drawn
|
||||
rect = rgn.GetBox()
|
||||
pixStart = vs[1]*self.lineHeight + rect.y
|
||||
pixStop = pixStart + rect.height
|
||||
start = pixStart / self.lineHeight - 1
|
||||
stop = pixStop / self.lineHeight
|
||||
else:
|
||||
start = 0
|
||||
stop = numColours
|
||||
|
||||
for line in range(max(0,start), min(stop,numColours)):
|
||||
clr = colours[line]
|
||||
y = (line+1) * self.lineHeight + 2
|
||||
dc.DrawText(clr, self.cellWidth, y)
|
||||
|
||||
brush = wxBrush(clr, wxSOLID)
|
||||
dc.SetBrush(brush)
|
||||
dc.DrawRectangle(12 * self.cellWidth, y, 6 * self.cellWidth, self.textHeight)
|
||||
|
||||
dc.EndDrawing()
|
||||
|
||||
|
||||
# On wxGTK there needs to be a panel under wxScrolledWindows if they are
|
||||
# going to be in a wxNotebook...
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
self.win = TestWindow(self)
|
||||
EVT_SIZE(self, self.OnSize)
|
||||
|
||||
def OnSize(self, evt):
|
||||
self.win.SetSize(evt.GetSize())
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPanel(nb)
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
overview = """
|
||||
"""
|
@@ -1,116 +0,0 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: ColourSelect.py
|
||||
# Purpose: Colour Selection control display testing on panel for wxPython demo
|
||||
#
|
||||
# Author: Lorne White (email: lorne.white@telusplanet.net)
|
||||
#
|
||||
# Version 0.6
|
||||
# Date: Nov 14, 2001
|
||||
# Licence: wxWindows license
|
||||
#
|
||||
# Change Log: Add Label parameter to accommodate updated library code
|
||||
#
|
||||
# Cliff Wells (logiplexsoftware@earthlink.net) 2002/03/11
|
||||
# - added code to demonstrate EVT_COLOURSELECT
|
||||
# - use sizers
|
||||
# - other minor "improvements"
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.colourselect import *
|
||||
import string
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
class TestColourSelect(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
self.log = log
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
self.SetAutoLayout(true)
|
||||
mainSizer = wxBoxSizer(wxVERTICAL)
|
||||
self.SetSizer(mainSizer)
|
||||
t = wxStaticText(self, -1,
|
||||
"This example uses a colour selection control based on the wxButton\n"
|
||||
"and wxColourDialog Classes. Click Button to get Colour Values")
|
||||
mainSizer.Add(t, 0, wxALL, 3)
|
||||
|
||||
b = wxButton(self, -1, "Show All Colours")
|
||||
EVT_BUTTON(self, b.GetId(), self.OnShowAll)
|
||||
mainSizer.Add(b, 0, wxALL, 3)
|
||||
|
||||
buttonSizer = wxFlexGridSizer(1, 2) # sizer to contain all the example buttons
|
||||
|
||||
# show a button with all default values
|
||||
self.colourDefaults = ColourSelect(self, -1)
|
||||
EVT_COLOURSELECT(self.colourDefaults, self.colourDefaults.GetId(), self.OnSelectColour)
|
||||
buttonSizer.AddMany([
|
||||
(wxStaticText(self, -1, "Default Colour/Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL),
|
||||
(self.colourDefaults, 0, wxALL, 3),
|
||||
])
|
||||
|
||||
# build several examples of buttons with different colours and sizes
|
||||
buttonData = [
|
||||
("Default Size", (255, 255, 0), wxDefaultSize, ""),
|
||||
("Another Size", (255, 0, 255), (60, 20), ""),
|
||||
("Another Colour", (0, 255, 0), wxDefaultSize, ""),
|
||||
("Larger Size", (0, 0, 255), (60, 60), ""),
|
||||
("With a Label", (127, 0, 255), wxDefaultSize, "Colour..."),
|
||||
("Another Colour/Label", (255, 100, 130), (120, -1), "Choose Colour..."),
|
||||
]
|
||||
|
||||
self.buttonRefs = [] # for saving references to buttons
|
||||
|
||||
# build each button and save a reference to it
|
||||
for name, color, size, label in buttonData:
|
||||
b = ColourSelect(self, -1, label, color, size = size)
|
||||
EVT_COLOURSELECT(b, b.GetId(), self.OnSelectColour)
|
||||
self.buttonRefs.append((name, b)) # store reference to button
|
||||
buttonSizer.AddMany([
|
||||
(wxStaticText(self, -1, name), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL),
|
||||
(b, 0, wxALL, 3),
|
||||
])
|
||||
|
||||
mainSizer.Add(buttonSizer, 0, wxALL, 3)
|
||||
self.Layout()
|
||||
|
||||
def OnSelectColour(self, event):
|
||||
self.log.WriteText("Colour selected: %s" % str(event.GetValue()))
|
||||
|
||||
def OnShowAll(self, event):
|
||||
# show the state of each button
|
||||
result = []
|
||||
colour = self.colourDefaults.GetColour() # default control value
|
||||
result.append("Default Colour/Size: " + str(colour))
|
||||
|
||||
for name, button in self.buttonRefs:
|
||||
colour = button.GetColour() # get the colour selection button result
|
||||
result.append(name + ": " + str(colour)) # create string list for easy viewing of results
|
||||
|
||||
out_result = string.joinfields(result, ', ')
|
||||
self.log.WriteText("Colour Results: " + out_result + "\n")
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestColourSelect(nb, log)
|
||||
return win
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
overview = """\
|
||||
|
||||
"""
|
@@ -1,92 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.help import *
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# We first have to set an application-wide help provider. Normally you
|
||||
# would do this in your app's OnInit or in other startup code...
|
||||
|
||||
provider = wxSimpleHelpProvider()
|
||||
wxHelpProvider_Set(provider)
|
||||
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
self.log = log
|
||||
|
||||
self.SetHelpText("This is a wxPanel.")
|
||||
sizer = wxBoxSizer(wxVERTICAL)
|
||||
|
||||
cBtn = wxContextHelpButton(self)
|
||||
cBtn.SetHelpText("wxContextHelpButton")
|
||||
cBtnText = wxStaticText(self, -1, "This is a wxContextHelpButton. Clicking it puts the\n"
|
||||
"app into context sensitive help mode.")
|
||||
cBtnText.SetHelpText("Some helpful text...")
|
||||
|
||||
s = wxBoxSizer(wxHORIZONTAL)
|
||||
s.Add(cBtn, 0, wxALL, 5)
|
||||
s.Add(cBtnText, 0, wxALL, 5)
|
||||
sizer.Add(20,20)
|
||||
sizer.Add(s)
|
||||
|
||||
text = wxTextCtrl(self, -1, "Each sub-window can have its own help message",
|
||||
size=(240, 60), style = wxTE_MULTILINE)
|
||||
text.SetHelpText("This is my very own help message. This is a really long long long long long long long long long long long long long long long long long long long long message!")
|
||||
sizer.Add(20,20)
|
||||
sizer.Add(text)
|
||||
|
||||
text = wxTextCtrl(self, -1, "You can also intercept the help event if you like. Watch the log window when you click here...",
|
||||
size=(240, 60), style = wxTE_MULTILINE)
|
||||
text.SetHelpText("Yet another context help message.")
|
||||
sizer.Add(20,20)
|
||||
sizer.Add(text)
|
||||
EVT_HELP(text, text.GetId(), self.OnCtxHelp)
|
||||
|
||||
text = wxTextCtrl(self, -1, "This one displays the tip itself...",
|
||||
size=(240, 60), style = wxTE_MULTILINE)
|
||||
sizer.Add(20,20)
|
||||
sizer.Add(text)
|
||||
EVT_HELP(text, text.GetId(), self.OnCtxHelp2)
|
||||
|
||||
|
||||
border = wxBoxSizer(wxVERTICAL)
|
||||
border.Add(sizer, 0, wxALL, 25)
|
||||
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(border)
|
||||
self.Layout()
|
||||
|
||||
|
||||
def OnCtxHelp(self, evt):
|
||||
self.log.write("OnCtxHelp: %s" % evt)
|
||||
evt.Skip()
|
||||
|
||||
|
||||
def OnCtxHelp2(self, evt):
|
||||
self.log.write("OnCtxHelp: %s\n" % evt)
|
||||
tip = wxTipWindow(self, "This is a wxTipWindow")
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPanel(nb, log)
|
||||
return win
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
overview = """
|
||||
This demo shows how to encorporate Context Sensitive
|
||||
help into your applicaiton using the wxSimpleHelpProvider class.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
@@ -1,346 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
import cPickle
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
class DoodlePad(wxWindow):
|
||||
def __init__(self, parent, log):
|
||||
wxWindow.__init__(self, parent, -1, style=wxSUNKEN_BORDER)
|
||||
self.log = log
|
||||
self.SetBackgroundColour(wxWHITE)
|
||||
self.lines = []
|
||||
self.x = self.y = 0
|
||||
self.SetMode("Draw")
|
||||
|
||||
EVT_LEFT_DOWN(self, self.OnLeftDown)
|
||||
EVT_LEFT_UP(self, self.OnLeftUp)
|
||||
EVT_RIGHT_UP(self, self.OnRightUp)
|
||||
EVT_MOTION(self, self.OnMotion)
|
||||
EVT_PAINT(self, self.OnPaint)
|
||||
|
||||
|
||||
def SetMode(self, mode):
|
||||
self.mode = mode
|
||||
if self.mode == "Draw":
|
||||
self.SetCursor(wxStockCursor(wxCURSOR_PENCIL))
|
||||
else:
|
||||
self.SetCursor(wxSTANDARD_CURSOR)
|
||||
|
||||
|
||||
def OnPaint(self, event):
|
||||
dc = wxPaintDC(self)
|
||||
self.DrawSavedLines(dc)
|
||||
|
||||
def DrawSavedLines(self, dc):
|
||||
dc.BeginDrawing()
|
||||
dc.SetPen(wxPen(wxBLUE, 3))
|
||||
for line in self.lines:
|
||||
for coords in line:
|
||||
apply(dc.DrawLine, coords)
|
||||
dc.EndDrawing()
|
||||
|
||||
|
||||
def OnLeftDown(self, event):
|
||||
if self.mode == "Drag":
|
||||
self.StartDragOpperation()
|
||||
elif self.mode == "Draw":
|
||||
self.curLine = []
|
||||
self.x, self.y = event.GetPositionTuple()
|
||||
self.CaptureMouse()
|
||||
else:
|
||||
wxBell()
|
||||
self.log.write("unknown mode!\n")
|
||||
|
||||
|
||||
def OnLeftUp(self, event):
|
||||
self.lines.append(self.curLine)
|
||||
self.curLine = []
|
||||
self.ReleaseMouse()
|
||||
|
||||
def OnRightUp(self, event):
|
||||
self.lines = []
|
||||
self.Refresh()
|
||||
|
||||
def OnMotion(self, event):
|
||||
if event.Dragging() and not self.mode == "Drag":
|
||||
dc = wxClientDC(self)
|
||||
dc.BeginDrawing()
|
||||
dc.SetPen(wxPen(wxBLUE, 3))
|
||||
coords = (self.x, self.y) + event.GetPositionTuple()
|
||||
self.curLine.append(coords)
|
||||
apply(dc.DrawLine, coords)
|
||||
self.x, self.y = event.GetPositionTuple()
|
||||
dc.EndDrawing()
|
||||
|
||||
|
||||
def StartDragOpperation(self):
|
||||
# pickle the lines list
|
||||
linesdata = cPickle.dumps(self.lines, 1)
|
||||
|
||||
# create our own data format and use it in a
|
||||
# custom data object
|
||||
ldata = wxCustomDataObject(wxCustomDataFormat("DoodleLines"))
|
||||
ldata.SetData(linesdata)
|
||||
|
||||
# Also create a Bitmap version of the drawing
|
||||
size = self.GetSize()
|
||||
bmp = wxEmptyBitmap(size.width, size.height)
|
||||
dc = wxMemoryDC()
|
||||
dc.SelectObject(bmp)
|
||||
dc.SetBackground(wxWHITE_BRUSH)
|
||||
dc.Clear()
|
||||
self.DrawSavedLines(dc)
|
||||
dc.SelectObject(wxNullBitmap)
|
||||
|
||||
# Now make a data object for the bitmap and also a composite
|
||||
# data object holding both of the others.
|
||||
bdata = wxBitmapDataObject(bmp)
|
||||
data = wxDataObjectComposite()
|
||||
data.Add(ldata)
|
||||
data.Add(bdata)
|
||||
|
||||
# And finally, create the drop source and begin the drag
|
||||
# and drop opperation
|
||||
dropSource = wxDropSource(self)
|
||||
dropSource.SetData(data)
|
||||
self.log.WriteText("Begining DragDrop\n")
|
||||
result = dropSource.DoDragDrop(wxDrag_AllowMove)
|
||||
self.log.WriteText("DragDrop completed: %d\n" % result)
|
||||
if result == wxDragMove:
|
||||
self.lines = []
|
||||
self.Refresh()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
class DoodleDropTarget(wxPyDropTarget):
|
||||
def __init__(self, window, log):
|
||||
wxPyDropTarget.__init__(self)
|
||||
self.log = log
|
||||
self.dv = window
|
||||
|
||||
# specify the type of data we will accept
|
||||
self.df = wxCustomDataFormat("DoodleLines")
|
||||
self.data = wxCustomDataObject(self.df)
|
||||
self.SetDataObject(self.data)
|
||||
|
||||
|
||||
# some virtual methods that track the progress of the drag
|
||||
def OnEnter(self, x, y, d):
|
||||
self.log.WriteText("OnEnter: %d, %d, %d\n" % (x, y, d))
|
||||
return d
|
||||
|
||||
def OnLeave(self):
|
||||
self.log.WriteText("OnLeave\n")
|
||||
|
||||
def OnDrop(self, x, y):
|
||||
self.log.WriteText("OnDrop: %d %d\n" % (x, y))
|
||||
return true
|
||||
|
||||
def OnDragOver(self, x, y, d):
|
||||
#self.log.WriteText("OnDragOver: %d, %d, %d\n" % (x, y, d))
|
||||
|
||||
# The value returned here tells the source what kind of visual
|
||||
# feedback to give. For example, if wxDragCopy is returned then
|
||||
# only the copy cursor will be shown, even if the source allows
|
||||
# moves. You can use the passed in (x,y) to determine what kind
|
||||
# of feedback to give. In this case we return the suggested value
|
||||
# which is based on whether the Ctrl key is pressed.
|
||||
return d
|
||||
|
||||
|
||||
|
||||
# Called when OnDrop returns true. We need to get the data and
|
||||
# do something with it.
|
||||
def OnData(self, x, y, d):
|
||||
self.log.WriteText("OnData: %d, %d, %d\n" % (x, y, d))
|
||||
|
||||
# copy the data from the drag source to our data object
|
||||
if self.GetData():
|
||||
# convert it back to a list of lines and give it to the viewer
|
||||
linesdata = self.data.GetData()
|
||||
lines = cPickle.loads(linesdata)
|
||||
self.dv.SetLines(lines)
|
||||
return d # what is returned signals the source what to do
|
||||
# with the original data (move, copy, etc.) In this
|
||||
# case we just return the suggested value given to us.
|
||||
|
||||
|
||||
|
||||
|
||||
class DoodleViewer(wxWindow):
|
||||
def __init__(self, parent, log):
|
||||
wxWindow.__init__(self, parent, -1, style=wxSUNKEN_BORDER)
|
||||
self.log = log
|
||||
self.SetBackgroundColour(wxWHITE)
|
||||
self.lines = []
|
||||
self.x = self.y = 0
|
||||
dt = DoodleDropTarget(self, log)
|
||||
self.SetDropTarget(dt)
|
||||
EVT_PAINT(self, self.OnPaint)
|
||||
|
||||
|
||||
def SetLines(self, lines):
|
||||
self.lines = lines
|
||||
self.Refresh()
|
||||
|
||||
def OnPaint(self, event):
|
||||
dc = wxPaintDC(self)
|
||||
self.DrawSavedLines(dc)
|
||||
|
||||
def DrawSavedLines(self, dc):
|
||||
dc.BeginDrawing()
|
||||
dc.SetPen(wxPen(wxRED, 3))
|
||||
for line in self.lines:
|
||||
for coords in line:
|
||||
apply(dc.DrawLine, coords)
|
||||
dc.EndDrawing()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class CustomDnDPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
|
||||
self.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD, false))
|
||||
|
||||
# Make the controls
|
||||
text1 = wxStaticText(self, -1,
|
||||
"Draw a little picture in this window\n"
|
||||
"then switch the mode below and drag the\n"
|
||||
"picture to the lower window or to another\n"
|
||||
"application that accepts BMP's as a drop\n"
|
||||
"target.\n"
|
||||
)
|
||||
|
||||
rb1 = wxRadioButton(self, -1, "Draw", style=wxRB_GROUP)
|
||||
rb1.SetValue(true)
|
||||
rb2 = wxRadioButton(self, -1, "Drag")
|
||||
rb2.SetValue(false)
|
||||
|
||||
text2 = wxStaticText(self, -1,
|
||||
"The lower window is accepting a\n"
|
||||
"custom data type that is a pickled\n"
|
||||
"Python list of lines data.")
|
||||
|
||||
self.pad = DoodlePad(self, log)
|
||||
view = DoodleViewer(self, log)
|
||||
|
||||
# put them in sizers
|
||||
sizer = wxBoxSizer(wxHORIZONTAL)
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
rbox = wxBoxSizer(wxHORIZONTAL)
|
||||
|
||||
rbox.Add(rb1)
|
||||
rbox.Add(rb2)
|
||||
box.Add(text1, 0, wxALL, 10)
|
||||
box.Add(rbox, 0, wxALIGN_CENTER)
|
||||
box.Add(10,90)
|
||||
box.Add(text2, 0, wxALL, 10)
|
||||
|
||||
sizer.Add(box)
|
||||
|
||||
dndsizer = wxBoxSizer(wxVERTICAL)
|
||||
dndsizer.Add(self.pad, 1, wxEXPAND|wxALL, 5)
|
||||
dndsizer.Add(view, 1, wxEXPAND|wxALL, 5)
|
||||
|
||||
sizer.Add(dndsizer, 1, wxEXPAND)
|
||||
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
# Events
|
||||
EVT_RADIOBUTTON(self, rb1.GetId(), self.OnRadioButton)
|
||||
EVT_RADIOBUTTON(self, rb2.GetId(), self.OnRadioButton)
|
||||
|
||||
|
||||
def OnRadioButton(self, evt):
|
||||
rb = self.FindWindowById(evt.GetId())
|
||||
self.pad.SetMode(rb.GetLabel())
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
|
||||
self.SetAutoLayout(true)
|
||||
sizer = wxBoxSizer(wxVERTICAL)
|
||||
|
||||
msg = "Custom Drag-And-Drop"
|
||||
text = wxStaticText(self, -1, "", style=wxALIGN_CENTRE)
|
||||
text.SetFont(wxFont(24, wxSWISS, wxNORMAL, wxBOLD, false))
|
||||
text.SetLabel(msg)
|
||||
w,h = text.GetTextExtent(msg)
|
||||
text.SetSize(wxSize(w,h+1))
|
||||
text.SetForegroundColour(wxBLUE)
|
||||
sizer.Add(text, 0, wxEXPAND|wxALL, 5)
|
||||
sizer.Add(wxStaticLine(self, -1), 0, wxEXPAND)
|
||||
|
||||
sizer.Add(CustomDnDPanel(self, log), 1, wxEXPAND)
|
||||
|
||||
self.SetSizer(sizer)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
#win = TestPanel(nb, log)
|
||||
win = CustomDnDPanel(nb, log)
|
||||
return win
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
class DummyLog:
|
||||
def WriteText(self, text):
|
||||
sys.stdout.write(text)
|
||||
|
||||
class TestApp(wxApp):
|
||||
def OnInit(self):
|
||||
self.MakeFrame()
|
||||
return true
|
||||
|
||||
def MakeFrame(self, event=None):
|
||||
frame = wxFrame(None, -1, "Custom Drag and Drop", size=(550,400))
|
||||
menu = wxMenu()
|
||||
menu.Append(6543, "Window")
|
||||
mb = wxMenuBar()
|
||||
mb.Append(menu, "New")
|
||||
frame.SetMenuBar(mb)
|
||||
EVT_MENU(frame, 6543, self.MakeFrame)
|
||||
panel = TestPanel(frame, DummyLog())
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
|
||||
|
||||
|
||||
app = TestApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
overview = """<html><body>
|
||||
This demo shows Drag and Drop using a custom data type and a custom
|
||||
data object. A type called "DoodleLines" is created and a Python
|
||||
Pickle of a list is actually transfered in the drag and drop
|
||||
opperation.
|
||||
|
||||
A second data object is also created containing a bitmap of the image
|
||||
and is made available to any drop target that accepts bitmaps, such as
|
||||
MS Word.
|
||||
|
||||
The two data objects are combined in a wxDataObjectComposite and the
|
||||
rest is handled by the framework.
|
||||
</body></html>
|
||||
"""
|
||||
|
||||
|
||||
|
@@ -1,127 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: DialogUnits.py
|
||||
# Purpose: A minimal wxPython program that is a bit smarter than test1.
|
||||
#
|
||||
# Author: Robin Dunn
|
||||
#
|
||||
# Created: A long time ago, in a galaxy far, far away...
|
||||
# RCS-ID: $Id$
|
||||
# Copyright: (c) 1998 by Total Control Software
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
## import all of the wxPython GUI package
|
||||
from wxPython.wx import *
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
## Create a new frame class, derived from the wxPython Frame.
|
||||
class MyFrame(wxFrame):
|
||||
|
||||
def __init__(self, parent, id, title):
|
||||
# First, call the base class' __init__ method to create the frame
|
||||
wxFrame.__init__(self, parent, id, title,
|
||||
wxPoint(100, 100), wxSize(160, 100))
|
||||
|
||||
# Associate some events with methods of this class
|
||||
EVT_SIZE(self, self.OnSize)
|
||||
EVT_MOVE(self, self.OnMove)
|
||||
EVT_CLOSE(self, self.OnCloseWindow)
|
||||
|
||||
# Add a panel and some controls to display the size and position
|
||||
panel = wxPanel(self, -1)
|
||||
wxStaticText(panel, -1, "Size:",
|
||||
wxDLG_PNT(panel, wxPoint(4, 4)), wxDefaultSize)
|
||||
wxStaticText(panel, -1, "Pos:",
|
||||
wxDLG_PNT(panel, wxPoint(4, 16)), wxDefaultSize)
|
||||
self.sizeCtrl = wxTextCtrl(panel, -1, "",
|
||||
wxDLG_PNT(panel, wxPoint(24, 4)),
|
||||
wxDLG_SZE(panel, wxSize(36, -1)),
|
||||
wxTE_READONLY)
|
||||
|
||||
self.posCtrl = wxTextCtrl(panel, -1, "",
|
||||
wxDLG_PNT(panel, wxPoint(24, 16)),
|
||||
wxDLG_SZE(panel, wxSize(36, -1)),
|
||||
wxTE_READONLY)
|
||||
|
||||
#print wxDLG_PNT(panel, wxPoint(24, 4)), wxDLG_SZE(panel, wxSize(36, -1))
|
||||
#print wxDLG_PNT(panel, wxPoint(24, 16)),wxDLG_SZE(panel, wxSize(36, -1))
|
||||
|
||||
|
||||
# This method is called automatically when the CLOSE event is
|
||||
# sent to this window
|
||||
def OnCloseWindow(self, event):
|
||||
# tell the window to kill itself
|
||||
self.Destroy()
|
||||
|
||||
|
||||
# This method is called by the System when the window is resized,
|
||||
# because of the association above.
|
||||
def OnSize(self, event):
|
||||
size = event.GetSize()
|
||||
self.sizeCtrl.SetValue("%s, %s" % (size.width, size.height))
|
||||
|
||||
# tell the event system to continue looking for an event handler,
|
||||
# so the default handler will get called.
|
||||
event.Skip()
|
||||
|
||||
# This method is called by the System when the window is moved,
|
||||
# because of the association above.
|
||||
def OnMove(self, event):
|
||||
pos = event.GetPosition()
|
||||
self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# if running standalone
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Every wxWindows application must have a class derived from wxApp
|
||||
class MyApp(wxApp):
|
||||
|
||||
# wxWindows calls this method to initialize the application
|
||||
def OnInit(self):
|
||||
|
||||
# Create an instance of our customized Frame class
|
||||
frame = MyFrame(None, -1, "This is a test")
|
||||
frame.Show(true)
|
||||
|
||||
# Tell wxWindows that this is our main window
|
||||
self.SetTopWindow(frame)
|
||||
|
||||
# Return a success flag
|
||||
return true
|
||||
|
||||
|
||||
app = MyApp(0) # Create an instance of the application class
|
||||
app.MainLoop() # Tell it to start processing events
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# if running as part of the Demo Framework...
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = MyFrame(frame, -1, "This is a test")
|
||||
frame.otherWin = win
|
||||
win.Show(true)
|
||||
|
||||
|
||||
overview = """\
|
||||
A simple example that shows how to use Dialog Units.
|
||||
"""
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,216 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class ClipTextPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
self.log = log
|
||||
|
||||
#self.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD, false))
|
||||
|
||||
sizer = wxBoxSizer(wxVERTICAL)
|
||||
sizer.Add(wxStaticText(self, -1,
|
||||
"Copy/Paste text to/from\n"
|
||||
"this window and other apps"), 0, wxEXPAND|wxALL, 2)
|
||||
|
||||
self.text = wxTextCtrl(self, -1, "", style=wxTE_MULTILINE|wxHSCROLL)
|
||||
sizer.Add(self.text, 1, wxEXPAND)
|
||||
|
||||
hsz = wxBoxSizer(wxHORIZONTAL)
|
||||
hsz.Add(wxButton(self, 6050, " Copy "), 1, wxEXPAND|wxALL, 2)
|
||||
hsz.Add(wxButton(self, 6051, " Paste "), 1, wxEXPAND|wxALL, 2)
|
||||
sizer.Add(hsz, 0, wxEXPAND)
|
||||
sizer.Add(wxButton(self, 6052, " Copy Bitmap "), 0, wxEXPAND|wxALL, 2)
|
||||
|
||||
EVT_BUTTON(self, 6050, self.OnCopy)
|
||||
EVT_BUTTON(self, 6051, self.OnPaste)
|
||||
EVT_BUTTON(self, 6052, self.OnCopyBitmap)
|
||||
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
|
||||
def OnCopy(self, evt):
|
||||
self.do = wxTextDataObject()
|
||||
self.do.SetText(self.text.GetValue())
|
||||
wxTheClipboard.Open()
|
||||
wxTheClipboard.SetData(self.do)
|
||||
wxTheClipboard.Close()
|
||||
|
||||
|
||||
def OnPaste(self, evt):
|
||||
do = wxTextDataObject()
|
||||
wxTheClipboard.Open()
|
||||
success = wxTheClipboard.GetData(do)
|
||||
wxTheClipboard.Close()
|
||||
if success:
|
||||
self.text.SetValue(do.GetText())
|
||||
else:
|
||||
wxMessageBox("There is no data in the clipboard in the required format",
|
||||
"Error")
|
||||
|
||||
def OnCopyBitmap(self, evt):
|
||||
dlg = wxFileDialog(self, "Choose a bitmap to copy", wildcard="*.bmp")
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
bmp = wxBitmap(dlg.GetFilename(), wxBITMAP_TYPE_BMP)
|
||||
bmpdo = wxBitmapDataObject(bmp)
|
||||
wxTheClipboard.Open()
|
||||
wxTheClipboard.SetData(bmpdo)
|
||||
wxTheClipboard.Close()
|
||||
|
||||
wxMessageBox("The bitmap is now in the Clipboard. Switch to a graphics\n"
|
||||
"editor and try pasting it in...")
|
||||
dlg.Destroy()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class OtherDropTarget(wxPyDropTarget):
|
||||
def __init__(self, window, log):
|
||||
wxPyDropTarget.__init__(self)
|
||||
self.log = log
|
||||
self.do = wxFileDataObject()
|
||||
self.SetDataObject(self.do)
|
||||
|
||||
def OnEnter(self, x, y, d):
|
||||
self.log.WriteText("OnEnter: %d, %d, %d\n" % (x, y, d))
|
||||
return wxDragCopy
|
||||
|
||||
#def OnDragOver(self, x, y, d):
|
||||
# self.log.WriteText("OnDragOver: %d, %d, %d\n" % (x, y, d))
|
||||
# return wxDragCopy
|
||||
|
||||
def OnLeave(self):
|
||||
self.log.WriteText("OnLeave\n")
|
||||
|
||||
def OnDrop(self, x, y):
|
||||
self.log.WriteText("OnDrop: %d %d\n" % (x, y))
|
||||
return true
|
||||
|
||||
def OnData(self, x, y, d):
|
||||
self.log.WriteText("OnData: %d, %d, %d\n" % (x, y, d))
|
||||
self.GetData()
|
||||
self.log.WriteText("%s\n" % self.do.GetFilenames())
|
||||
return d
|
||||
|
||||
|
||||
|
||||
|
||||
class MyFileDropTarget(wxFileDropTarget):
|
||||
def __init__(self, window, log):
|
||||
wxFileDropTarget.__init__(self)
|
||||
self.window = window
|
||||
self.log = log
|
||||
|
||||
def OnDropFiles(self, x, y, filenames):
|
||||
self.window.SetInsertionPointEnd()
|
||||
self.window.WriteText("\n%d file(s) dropped at %d,%d:\n" %
|
||||
(len(filenames), x, y))
|
||||
for file in filenames:
|
||||
self.window.WriteText(file + '\n')
|
||||
|
||||
|
||||
class MyTextDropTarget(wxTextDropTarget):
|
||||
def __init__(self, window, log):
|
||||
wxTextDropTarget.__init__(self)
|
||||
self.window = window
|
||||
self.log = log
|
||||
|
||||
def OnDropText(self, x, y, text):
|
||||
self.window.WriteText("(%d, %d)\n%s\n" % (x, y, text))
|
||||
|
||||
def OnDragOver(self, x, y, d):
|
||||
return wxDragCopy
|
||||
|
||||
|
||||
class FileDropPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
|
||||
#self.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD, false))
|
||||
|
||||
sizer = wxBoxSizer(wxVERTICAL)
|
||||
sizer.Add(wxStaticText(self, -1, " \nDrag some files here:"),
|
||||
0, wxEXPAND|wxALL, 2)
|
||||
|
||||
self.text = wxTextCtrl(self, -1, "",
|
||||
style = wxTE_MULTILINE|wxHSCROLL|wxTE_READONLY)
|
||||
dt = MyFileDropTarget(self, log)
|
||||
self.text.SetDropTarget(dt)
|
||||
sizer.Add(self.text, 1, wxEXPAND)
|
||||
|
||||
sizer.Add(wxStaticText(self, -1, " \nDrag some text here:"),
|
||||
0, wxEXPAND|wxALL, 2)
|
||||
self.text2 = wxTextCtrl(self, -1, "",
|
||||
style = wxTE_MULTILINE|wxHSCROLL|wxTE_READONLY)
|
||||
dt = MyTextDropTarget(self.text2, log)
|
||||
self.text2.SetDropTarget(dt)
|
||||
sizer.Add(self.text2, 1, wxEXPAND)
|
||||
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
|
||||
def WriteText(self, text):
|
||||
self.text.WriteText(text)
|
||||
|
||||
def SetInsertionPointEnd(self):
|
||||
self.text.SetInsertionPointEnd()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
|
||||
self.SetAutoLayout(true)
|
||||
outsideSizer = wxBoxSizer(wxVERTICAL)
|
||||
|
||||
msg = "Clipboard / Drag-And-Drop"
|
||||
text = wxStaticText(self, -1, "", style=wxALIGN_CENTRE)
|
||||
text.SetFont(wxFont(24, wxSWISS, wxNORMAL, wxBOLD, false))
|
||||
text.SetLabel(msg)
|
||||
w,h = text.GetTextExtent(msg)
|
||||
text.SetSize(wxSize(w,h+1))
|
||||
text.SetForegroundColour(wxBLUE)
|
||||
outsideSizer.Add(text, 0, wxEXPAND|wxALL, 5)
|
||||
outsideSizer.Add(wxStaticLine(self, -1), 0, wxEXPAND)
|
||||
|
||||
inSizer = wxBoxSizer(wxHORIZONTAL)
|
||||
inSizer.Add(ClipTextPanel(self, log), 1, wxEXPAND)
|
||||
inSizer.Add(FileDropPanel(self, log), 1, wxEXPAND)
|
||||
|
||||
outsideSizer.Add(inSizer, 1, wxEXPAND)
|
||||
self.SetSizer(outsideSizer)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPanel(nb, log)
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
overview = """\
|
||||
This demo shows some examples of data transfer through clipboard or drag and drop. In wxWindows, these two ways to transfer data (either between different applications or inside one and the same) are very similar which allows to implement both of them using almost the same code - or, in other words, if you implement drag and drop support for your application, you get clipboard support for free and vice versa.
|
||||
|
||||
At the heart of both clipboard and drag and drop operations lies the wxDataObject class. The objects of this class (or, to be precise, classes derived from it) represent the data which is being carried by the mouse during drag and drop operation or copied to or pasted from the clipboard. wxDataObject is a "smart" piece of data because it knows which formats it supports (see GetFormatCount and GetAllFormats) and knows how to render itself in any of them (see GetDataHere). It can also receive its value from the outside in a format it supports if it implements the SetData method. Please see the documentation of this class for more details.
|
||||
|
||||
Both clipboard and drag and drop operations have two sides: the source and target, the data provider and the data receiver. These which may be in the same application and even the same window when, for example, you drag some text from one position to another in a word processor. Let us describe what each of them should do.
|
||||
|
||||
"""
|
@@ -1,139 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
import whrandom, time
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
colours = [
|
||||
"BLACK",
|
||||
"BLUE",
|
||||
"BLUE VIOLET",
|
||||
"BROWN",
|
||||
"CYAN",
|
||||
"DARK GREY",
|
||||
"DARK GREEN",
|
||||
"GOLD",
|
||||
"GREY",
|
||||
"GREEN",
|
||||
"MAGENTA",
|
||||
"NAVY",
|
||||
"PINK",
|
||||
"RED",
|
||||
"SKY BLUE",
|
||||
"VIOLET",
|
||||
"YELLOW",
|
||||
]
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeRandomPoints(num, w, h):
|
||||
pnts = []
|
||||
for i in range(num):
|
||||
x = whrandom.randint(0, w)
|
||||
y = whrandom.randint(0, h)
|
||||
pnts.append( (x,y) )
|
||||
return pnts
|
||||
|
||||
|
||||
def makeRandomLines(num, w, h):
|
||||
pnts = []
|
||||
for i in range(num):
|
||||
x1 = whrandom.randint(0, w)
|
||||
y1 = whrandom.randint(0, h)
|
||||
x2 = whrandom.randint(0, w)
|
||||
y2 = whrandom.randint(0, h)
|
||||
pnts.append( (x1,y1, x2,y2) )
|
||||
return pnts
|
||||
|
||||
|
||||
def makeRandomPens(num, cache):
|
||||
pens = []
|
||||
for i in range(num):
|
||||
c = whrandom.choice(colours)
|
||||
t = whrandom.randint(1, 4)
|
||||
if not cache.has_key( (c, t) ):
|
||||
cache[(c, t)] = wxPen(c, t)
|
||||
pens.append( cache[(c, t)] )
|
||||
return pens
|
||||
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent, size, log):
|
||||
wxPanel.__init__(self, parent, -1, size=size)
|
||||
self.log = log
|
||||
self.SetBackgroundColour(wxWHITE)
|
||||
|
||||
w = size.width
|
||||
h = size.height
|
||||
pencache = {}
|
||||
|
||||
# make some lists of random points
|
||||
self.pnts1 = makeRandomPoints(1000, w, h)
|
||||
self.pnts2 = makeRandomPoints(1000, w, h)
|
||||
self.pnts3 = makeRandomPoints(1000, w, h)
|
||||
self.pens1 = makeRandomPens(1000, pencache)
|
||||
|
||||
# and now some lines
|
||||
self.lines1 = makeRandomLines(500, w, h)
|
||||
self.lines2 = makeRandomLines(500, w, h)
|
||||
self.lines3 = makeRandomLines(500, w, h)
|
||||
self.pens2 = makeRandomPens(500, pencache)
|
||||
|
||||
EVT_PAINT(self, self.OnPaint)
|
||||
|
||||
|
||||
def OnPaint(self, evt):
|
||||
dc = wxPaintDC(self)
|
||||
dc.BeginDrawing()
|
||||
start = time.time()
|
||||
|
||||
dc.SetPen(wxPen("BLACK", 1))
|
||||
dc.DrawPointList(self.pnts1)
|
||||
dc.DrawPointList(self.pnts2, wxPen("RED", 2))
|
||||
dc.DrawPointList(self.pnts3, self.pens1)
|
||||
|
||||
dc.SetPen(wxPen("BLACK", 1))
|
||||
dc.DrawLineList(self.lines1)
|
||||
dc.DrawLineList(self.lines2, wxPen("RED", 2))
|
||||
dc.DrawLineList(self.lines3, self.pens2)
|
||||
|
||||
dc.EndDrawing()
|
||||
self.log.write("DrawTime: %s seconds\n" % (time.time() - start))
|
||||
self.log.write("GetBoundingBox: %s\n" % (dc.GetBoundingBox(), ))
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
w = nb.GetClientSize().width
|
||||
h = nb.GetClientSize().height
|
||||
if w < 300: w = 300
|
||||
if h < 300: h = 300
|
||||
win = wxPanel(nb, -1)
|
||||
tp = TestPanel(win, wxSize(w, h), log)
|
||||
def OnPanelSize(evt, tp=tp):
|
||||
tp.SetSize(evt.GetSize())
|
||||
EVT_SIZE(win, OnPanelSize)
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
overview = """\
|
||||
|
||||
Some methods have been added to wxDC to help with optimization of
|
||||
drawing routines. Currently they are:
|
||||
|
||||
<pre>
|
||||
DrawPointList(sequence, pens=None)
|
||||
</pre>
|
||||
Where sequence is a tuple, list, whatever of 2 element tuples
|
||||
(x, y) and pens is either None, a single pen or a list of pens.
|
||||
|
||||
<pre>
|
||||
DrawLineList(sequence, pens=None)
|
||||
</pre>
|
||||
Where sequence is a tuple, list, whatever of 4 element tuples
|
||||
(x1,y1, x2,y2) andd pens is either None, a single pen or a list
|
||||
of pens.
|
||||
|
||||
"""
|
@@ -1,178 +0,0 @@
|
||||
# demo for ErrorDialogs.py
|
||||
# usual wxWindows license stuff here.
|
||||
# by Chris Fama, with thanks to Robin Dunn, and others on the wxPython-users
|
||||
# mailing list.
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.ErrorDialogs import *
|
||||
_debug = 0
|
||||
ID_TEXT = 10000
|
||||
ID_BUTTON_wxPyNonFatalError = 10001
|
||||
ID_BUTTON_wxPyFatalError = 10002
|
||||
ID_BUTTON_wxPyFatalErrorDialog = 10003
|
||||
ID_BUTTON_wxPyNonFatalErrorDialog = 10004
|
||||
ID_BUTTON_wxPyFatalErrorDialogWithTraceback = 10005
|
||||
ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback = 10006
|
||||
|
||||
def ErrorDialogsDemoPanelFunc( parent, call_fit = true, set_sizer = true ):
|
||||
item0 = wxBoxSizer( wxVERTICAL )
|
||||
|
||||
item1 = wxStaticText( parent, ID_TEXT, "Please select one of the buttons below for an example using explicit errors...", wxDefaultPosition, wxDefaultSize, 0 )
|
||||
item0.AddWindow( item1, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
|
||||
item2 = wxFlexGridSizer( 0, 2, 0, 0 )
|
||||
|
||||
item3 = wxButton( parent, ID_BUTTON_wxPyNonFatalError, "wxPyNonFatalError", wxDefaultPosition, wxDefaultSize, 0 )
|
||||
item2.AddWindow( item3, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
|
||||
item4 = wxButton( parent, ID_BUTTON_wxPyFatalError, "wxPyFatalError", wxDefaultPosition, wxDefaultSize, 0 )
|
||||
item2.AddWindow( item4, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
|
||||
item0.AddSizer( item2, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
|
||||
item5 = wxStaticText( parent, ID_TEXT, "Please select one of the buttons below for interpreter errors...", wxDefaultPosition, wxDefaultSize, 0 )
|
||||
item0.AddWindow( item5, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
|
||||
item6 = wxFlexGridSizer( 0, 2, 0, 0 )
|
||||
|
||||
item7 = wxButton( parent, ID_BUTTON_wxPyFatalErrorDialog, "wxPyFatalErrorDialog", wxDefaultPosition, wxDefaultSize, 0 )
|
||||
item6.AddWindow( item7, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
|
||||
item8 = wxButton( parent, ID_BUTTON_wxPyNonFatalErrorDialog, "wxPyNonFatalErrorDialog", wxDefaultPosition, wxDefaultSize, 0 )
|
||||
item6.AddWindow( item8, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
|
||||
item9 = wxButton( parent, ID_BUTTON_wxPyFatalErrorDialogWithTraceback, "wxPyFatalErrorDialogWithTraceback", wxDefaultPosition, wxDefaultSize, 0 )
|
||||
item6.AddWindow( item9, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
|
||||
item10 = wxButton( parent, ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback, "wxPyNonFatalErrorDialogWithTraceback", wxDefaultPosition, wxDefaultSize, 0 )
|
||||
item10.SetDefault()
|
||||
item6.AddWindow( item10, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
|
||||
item0.AddSizer( item6, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
|
||||
item11 = wxFlexGridSizer( 0, 2, 0, 0 )
|
||||
|
||||
item0.AddSizer( item11, 0, wxALIGN_CENTRE|wxALL, 5 )
|
||||
|
||||
if set_sizer == true:
|
||||
parent.SetAutoLayout( true )
|
||||
parent.SetSizer( item0 )
|
||||
if call_fit == true:
|
||||
item0.Fit( parent )
|
||||
item0.SetSizeHints( parent )
|
||||
|
||||
return item0
|
||||
|
||||
# Menu bar functions
|
||||
|
||||
# Bitmap functions
|
||||
|
||||
|
||||
# End of generated file
|
||||
|
||||
class MyPanel(wxPanel):
|
||||
def __init__(self,parent=None):
|
||||
wxPanel.__init__(self,parent,-1)
|
||||
args = (None, -1)
|
||||
kwargs = {
|
||||
'programname': "sumthing",
|
||||
'mailto': "me@sumwear",
|
||||
'whendismissed': "from wxPython.wx import * ; wxBell()"}
|
||||
self.dialogs = map(apply,
|
||||
[wxPyNonFatalErrorDialogWithTraceback,
|
||||
wxPyNonFatalErrorDialog,#WithTraceback
|
||||
wxPyFatalErrorDialogWithTraceback,
|
||||
wxPyFatalErrorDialog],#WithTraceback
|
||||
(args,) * 4,
|
||||
(kwargs,) * 4)
|
||||
ErrorDialogsDemoPanelFunc(self)
|
||||
|
||||
EVT_BUTTON(self,
|
||||
ID_BUTTON_wxPyFatalErrorDialog,
|
||||
self.DoDialog)
|
||||
EVT_BUTTON(self,
|
||||
ID_BUTTON_wxPyNonFatalError,
|
||||
self.DoDialog)
|
||||
EVT_BUTTON(self,
|
||||
ID_BUTTON_wxPyFatalError,
|
||||
self.DoDialog)
|
||||
EVT_BUTTON(self,
|
||||
ID_BUTTON_wxPyFatalErrorDialogWithTraceback,
|
||||
self.DoDialog)
|
||||
EVT_BUTTON(self,
|
||||
ID_BUTTON_wxPyNonFatalErrorDialog,
|
||||
self.DoDialog)
|
||||
EVT_BUTTON(self,
|
||||
ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback,
|
||||
self.DoDialog)
|
||||
EVT_CLOSE(self,self.OnClose)
|
||||
|
||||
IndexFromID = {
|
||||
ID_BUTTON_wxPyFatalErrorDialog: 3,
|
||||
ID_BUTTON_wxPyFatalErrorDialogWithTraceback: 2,
|
||||
ID_BUTTON_wxPyNonFatalErrorDialog: 1,
|
||||
ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback: 0
|
||||
}
|
||||
|
||||
def DoDialog(self,event):
|
||||
id = event.GetId()
|
||||
if id in [ID_BUTTON_wxPyFatalError,ID_BUTTON_wxPyNonFatalError]:
|
||||
if id == ID_BUTTON_wxPyFatalError:
|
||||
print "%s.DoDialog(): testing explicit wxPyFatalError..."\
|
||||
% self
|
||||
wxPyFatalError(self,"Test Non-fatal error.<p>"
|
||||
"Nearly arbitrary HTML (i.e., that which is"
|
||||
" understood by <B><I>wxHtmlWindow</i></b>)."
|
||||
"<p><table border=\"2\"><tr><td>This</td><td>is</td></tr>"
|
||||
"<tr><td>a</td><td>table</td></tr></table></p>")
|
||||
else:
|
||||
print "%s.DoDialog(): testing explicit wxPyNonFatalError..."\
|
||||
% self
|
||||
wxPyNonFatalError(self,"Test Non-fatal error.<p>"
|
||||
"Nearly arbitrary HTML (i.e., that which is"
|
||||
" understood by <B><I>wxHtmlWindow</i></b>)."
|
||||
"<p><table border=\"2\"><tr><td>This</td><td>is</td></tr>"
|
||||
"<tr><td>a</td><td>table</td></tr></table></p>")
|
||||
else:
|
||||
sys.stderr = self.dialogs[self.IndexFromID[id]]
|
||||
print "%s.DoDialog(): testing %s..." % (self,sys.stderr)
|
||||
this_will_generate_a_NameError_exception
|
||||
|
||||
def OnClose(self,evt):
|
||||
for d in self.dialogs:
|
||||
d.Destroy ()
|
||||
self.Destroy ()
|
||||
|
||||
class MyFrame(wxFrame):
|
||||
def __init__(self,parent=None):
|
||||
wxFrame.__init__(self,parent,-1,
|
||||
"Please make a selection...",
|
||||
)
|
||||
self. panel = MyPanel(self)
|
||||
EVT_CLOSE (self,self.OnCloseWindow)
|
||||
|
||||
def OnCloseWindow(self,event):
|
||||
self.panel.Close()
|
||||
self.Destroy()
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame = MyFrame()
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
|
||||
def runTest(pframe, nb, log):
|
||||
panel = MyPanel(nb)
|
||||
return panel
|
||||
|
||||
from wxPython.lib import ErrorDialogs
|
||||
ErrorDialogs._debug = 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.stderr = wxPyNonWindowingErrorHandler()
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
sys.exit()
|
||||
else:
|
||||
overview = ErrorDialogs.__doc__
|
@@ -1,41 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib import fancytext
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
test_str = ('<font style="italic" family="swiss" color="red" weight="bold" >'
|
||||
'some |<sup>23</sup> <angle/>text<sub>with <angle/> subscript</sub>'
|
||||
'</font> some other text')
|
||||
|
||||
test_str2 = '<font family="swiss" color="dark green" size="40">big green text</font>'
|
||||
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
EVT_PAINT(self, self.OnPaint)
|
||||
|
||||
|
||||
def OnPaint(self, evt):
|
||||
dc = wxPaintDC(self)
|
||||
|
||||
sz = fancytext.getExtent(test_str, dc)
|
||||
fancytext.renderToDC(test_str, dc, 20, 20)
|
||||
|
||||
fancytext.renderToDC(test_str2, dc, 20, 20 + sz.height + 10)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPanel(nb)
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
import string
|
||||
overview = string.replace(fancytext.__doc__, "<", "<")
|
||||
|
@@ -1,76 +0,0 @@
|
||||
""" Demonstrate filebrowsebutton module of the wxPython.lib Library.
|
||||
|
||||
14.1.2001 Bernhard Reiter <bernhard@intevation.de>
|
||||
Added demo for DirBrowseButton and improved overview text.
|
||||
"""
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.filebrowsebutton import FileBrowseButton, FileBrowseButtonWithHistory,DirBrowseButton
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent, ID, log):
|
||||
wxPanel.__init__(self, parent, ID)
|
||||
self.log = log
|
||||
self.fbb = FileBrowseButton(self, -1, wxPoint(20,20), wxSize(450, -1),
|
||||
changeCallback = self.fbbCallback)
|
||||
self.fbbh = FileBrowseButtonWithHistory(self, -1, wxPoint(20, 50),
|
||||
wxSize(450, -1),
|
||||
#changeCallback = self.fbbhCallback
|
||||
)
|
||||
self.dbb = DirBrowseButton(self, -1, wxPoint(20,80), wxSize(450,-1),
|
||||
changeCallback = self.dbbCallback)
|
||||
|
||||
|
||||
self.fbbh.SetHistory(['You', 'can', 'put', 'some', 'file', 'names', 'here'])
|
||||
|
||||
|
||||
def fbbCallback(self, evt):
|
||||
self.log.write('FileBrowseButton: %s\n' % evt.GetString())
|
||||
|
||||
|
||||
|
||||
def fbbhCallback(self, evt):
|
||||
if hasattr(self, 'fbbh'):
|
||||
value = evt.GetString()
|
||||
self.log.write('FileBrowseButtonWithHistory: %s\n' % value)
|
||||
history = self.fbbh.GetHistory()
|
||||
history.append(value)
|
||||
self.fbbh.SetHistory(history)
|
||||
|
||||
def dbbCallback(self, evt):
|
||||
self.log.write('DirBrowseButton: %s\n' % evt.GetString())
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPanel(nb, -1, log)
|
||||
return win
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
overview = """<html><body>
|
||||
<h2>class FileBrowseButton:</h2>
|
||||
<small><pre>
|
||||
%s
|
||||
</pre></small>
|
||||
|
||||
<h2>class FileBrowseButtonWithHistory(FileBrowseButton):</h2>
|
||||
<small><pre>
|
||||
%s
|
||||
</pre></small>
|
||||
|
||||
<h2>class DirBrowseButton(FileBrowseButton):</h2>
|
||||
<small><pre>
|
||||
%s
|
||||
</pre></small>
|
||||
|
||||
</body><</html>
|
||||
""" % ( FileBrowseButton.__doc__,
|
||||
FileBrowseButtonWithHistory.__doc__ ,
|
||||
str(DirBrowseButton.__doc__) )
|
@@ -1,77 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
## class MyFontEnumerator(wxFontEnumerator):
|
||||
## def __init__(self, list):
|
||||
## wxFontEnumerator.__init__(self)
|
||||
## self.list = list
|
||||
|
||||
## def OnFacename(self, face):
|
||||
## self.list.append(face)
|
||||
## return true
|
||||
|
||||
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
|
||||
## list = []
|
||||
## e = MyFontEnumerator(list)
|
||||
## e.EnumerateFacenames()
|
||||
|
||||
e = wxFontEnumerator()
|
||||
e.EnumerateFacenames()
|
||||
list = e.GetFacenames()
|
||||
|
||||
list.sort()
|
||||
|
||||
wxStaticText(self, -1, "Face names:", (15, 50), (65, 18))
|
||||
self.lb1 = wxListBox(self, -1, (80, 50), (200, 250),
|
||||
list, wxLB_SINGLE)
|
||||
EVT_LISTBOX(self, self.lb1.GetId(), self.OnSelect)
|
||||
|
||||
self.txt = wxStaticText(self, -1, "Sample text...", (285, 50))
|
||||
|
||||
self.lb1.SetSelection(0)
|
||||
|
||||
|
||||
def OnSelect(self, evt):
|
||||
face = self.lb1.GetStringSelection()
|
||||
font = wxFont(28, wxDEFAULT, wxNORMAL, wxNORMAL, false, face)
|
||||
self.txt.SetFont(font)
|
||||
self.txt.SetSize(self.txt.GetBestSize())
|
||||
|
||||
## st = font.GetNativeFontInfo().ToString()
|
||||
## ni2 = wxNativeFontInfo()
|
||||
## ni2.FromString(st)
|
||||
## font2 = wxFontFromNativeInfo(ni2)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPanel(nb, log)
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
overview = """\
|
||||
wxFontEnumerator enumerates either all available fonts on the system or only the ones with given attributes - either only fixed-width (suited for use in programs such as terminal emulators and the like) or the fonts available in the given encoding.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys,os
|
||||
import run
|
||||
run.main(['', os.path.basename(sys.argv[0])])
|
||||
|
@@ -1,143 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.buttons import *
|
||||
|
||||
import images
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
self.log = log
|
||||
|
||||
sizer = wxFlexGridSizer(1, 3, 20, 20)
|
||||
b = wxButton(self, -1, "A real button")
|
||||
b.SetDefault()
|
||||
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
||||
sizer.Add(b)
|
||||
|
||||
b = wxButton(self, -1, "non-default")
|
||||
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
||||
sizer.Add(b)
|
||||
sizer.Add(10,10)
|
||||
|
||||
b = wxGenButton(self, -1, 'Hello')
|
||||
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
||||
sizer.Add(b)
|
||||
|
||||
b = wxGenButton(self, -1, 'disabled')
|
||||
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
||||
b.Enable(false)
|
||||
sizer.Add(b)
|
||||
|
||||
b = wxGenButton(self, -1, 'bigger')
|
||||
EVT_BUTTON(self, b.GetId(), self.OnBiggerButton)
|
||||
b.SetFont(wxFont(20, wxSWISS, wxNORMAL, wxBOLD, false))
|
||||
b.SetBezelWidth(5)
|
||||
###b.SetBestSize()
|
||||
b.SetBackgroundColour("Navy")
|
||||
b.SetForegroundColour(wxWHITE)
|
||||
b.SetToolTipString("This is a BIG button...")
|
||||
sizer.Add(b, flag=wxADJUST_MINSIZE) # let the sizer set best size
|
||||
|
||||
bmp = images.getTest2Bitmap()
|
||||
b = wxGenBitmapButton(self, -1, bmp)
|
||||
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
||||
sizer.Add(b)
|
||||
|
||||
bmp = images.getTest2Bitmap()
|
||||
b = wxGenBitmapButton(self, -1, bmp)
|
||||
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
||||
sizer.Add(b)
|
||||
b.Enable(FALSE)
|
||||
|
||||
b = wxGenBitmapButton(self, -1, None)
|
||||
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
||||
bmp = images.getBulb1Bitmap()
|
||||
mask = wxMaskColour(bmp, wxBLUE)
|
||||
bmp.SetMask(mask)
|
||||
b.SetBitmapLabel(bmp)
|
||||
bmp = images.getBulb2Bitmap()
|
||||
mask = wxMaskColour(bmp, wxBLUE)
|
||||
bmp.SetMask(mask)
|
||||
b.SetBitmapSelected(bmp)
|
||||
b.SetBestSize()
|
||||
sizer.Add(b)
|
||||
|
||||
b = wxGenToggleButton(self, -1, "Toggle Button")
|
||||
EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
|
||||
sizer.Add(b)
|
||||
|
||||
b = wxGenBitmapToggleButton(self, -1, None)
|
||||
EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
|
||||
bmp = images.getBulb1Bitmap()
|
||||
mask = wxMaskColour(bmp, wxBLUE)
|
||||
bmp.SetMask(mask)
|
||||
b.SetBitmapLabel(bmp)
|
||||
bmp = images.getBulb2Bitmap()
|
||||
mask = wxMaskColour(bmp, wxBLUE)
|
||||
bmp.SetMask(mask)
|
||||
b.SetBitmapSelected(bmp)
|
||||
b.SetToggle(true)
|
||||
b.SetBestSize()
|
||||
sizer.Add(b)
|
||||
|
||||
b = wxGenBitmapTextButton(self, -1, None, "Bitmapped Text", size = (200, 45))
|
||||
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
||||
bmp = images.getBulb1Bitmap()
|
||||
mask = wxMaskColour(bmp, wxBLUE)
|
||||
bmp.SetMask(mask)
|
||||
b.SetBitmapLabel(bmp)
|
||||
bmp = images.getBulb2Bitmap()
|
||||
mask = wxMaskColour(bmp, wxBLUE)
|
||||
bmp.SetMask(mask)
|
||||
b.SetBitmapSelected(bmp)
|
||||
b.SetUseFocusIndicator(false)
|
||||
b.SetBestSize()
|
||||
sizer.Add(b)
|
||||
|
||||
border = wxBoxSizer(wxVERTICAL)
|
||||
border.Add(sizer, 0, wxALL, 25)
|
||||
self.SetSizer(border)
|
||||
|
||||
|
||||
def OnButton(self, event):
|
||||
self.log.WriteText("Button Clicked: %d\n" % event.GetId())
|
||||
|
||||
|
||||
def OnBiggerButton(self, event):
|
||||
self.log.WriteText("Bigger Button Clicked: %d\n" % event.GetId())
|
||||
b = event.GetEventObject()
|
||||
txt = "big " + b.GetLabel()
|
||||
b.SetLabel(txt)
|
||||
self.GetSizer().Layout()
|
||||
|
||||
|
||||
def OnToggleButton(self, event):
|
||||
msg = (event.GetIsDown() and "on") or "off"
|
||||
self.log.WriteText("Button %d Toggled: %s\n" % (event.GetId(), msg))
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPanel(nb, log)
|
||||
return win
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
import wxPython.lib.buttons
|
||||
overview = wxPython.lib.buttons.__doc__
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys,os
|
||||
import run
|
||||
run.main(['', os.path.basename(sys.argv[0])])
|
||||
|
@@ -1,233 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.grid import *
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
class MyCellEditor(wxPyGridCellEditor):
|
||||
"""
|
||||
This is a sample GridCellEditor that shows you how to make your own custom
|
||||
grid editors. All the methods that can be overridden are show here. The
|
||||
ones that must be overridden are marked with "*Must Override*" in the
|
||||
docstring.
|
||||
|
||||
Notice that in order to call the base class version of these special
|
||||
methods we use the method name preceded by "base_". This is because these
|
||||
methods are "virtual" in C++ so if we try to call wxGridCellEditor.Create
|
||||
for example, then when the wxPython extension module tries to call
|
||||
ptr->Create(...) then it actually calls the derived class version which
|
||||
looks up the method in this class and calls it, causing a recursion loop.
|
||||
If you don't understand any of this, don't worry, just call the "base_"
|
||||
version instead.
|
||||
"""
|
||||
def __init__(self, log):
|
||||
self.log = log
|
||||
self.log.write("MyCellEditor ctor\n")
|
||||
wxPyGridCellEditor.__init__(self)
|
||||
|
||||
|
||||
def Create(self, parent, id, evtHandler):
|
||||
"""
|
||||
Called to create the control, which must derive from wxControl.
|
||||
*Must Override*
|
||||
"""
|
||||
self.log.write("MyCellEditor: Create\n")
|
||||
self._tc = wxTextCtrl(parent, id, "")
|
||||
self._tc.SetInsertionPoint(0)
|
||||
self.SetControl(self._tc)
|
||||
if evtHandler:
|
||||
self._tc.PushEventHandler(evtHandler)
|
||||
|
||||
|
||||
def SetSize(self, rect):
|
||||
"""
|
||||
Called to position/size the edit control within the cell rectangle.
|
||||
If you don't fill the cell (the rect) then be sure to override
|
||||
PaintBackground and do something meaningful there.
|
||||
"""
|
||||
self.log.write("MyCellEditor: SetSize %s\n" % rect)
|
||||
self._tc.SetDimensions(rect.x, rect.y, rect.width+2, rect.height+2,
|
||||
wxSIZE_ALLOW_MINUS_ONE)
|
||||
|
||||
|
||||
def Show(self, show, attr):
|
||||
"""
|
||||
Show or hide the edit control. You can use the attr (if not None)
|
||||
to set colours or fonts for the control.
|
||||
"""
|
||||
self.log.write("MyCellEditor: Show(self, %s, %s)\n" % (show, attr))
|
||||
self.base_Show(show, attr)
|
||||
|
||||
|
||||
def PaintBackground(self, rect, attr):
|
||||
"""
|
||||
Draws the part of the cell not occupied by the edit control. The
|
||||
base class version just fills it with background colour from the
|
||||
attribute. In this class the edit control fills the whole cell so
|
||||
don't do anything at all in order to reduce flicker.
|
||||
"""
|
||||
self.log.write("MyCellEditor: PaintBackground\n")
|
||||
|
||||
|
||||
def BeginEdit(self, row, col, grid):
|
||||
"""
|
||||
Fetch the value from the table and prepare the edit control
|
||||
to begin editing. Set the focus to the edit control.
|
||||
*Must Override*
|
||||
"""
|
||||
self.log.write("MyCellEditor: BeginEdit (%d,%d)\n" % (row, col))
|
||||
self.startValue = grid.GetTable().GetValue(row, col)
|
||||
self._tc.SetValue(self.startValue)
|
||||
self._tc.SetInsertionPointEnd()
|
||||
self._tc.SetFocus()
|
||||
|
||||
# For this example, select the text
|
||||
self._tc.SetSelection(0, self._tc.GetLastPosition())
|
||||
|
||||
|
||||
def EndEdit(self, row, col, grid):
|
||||
"""
|
||||
Complete the editing of the current cell. Returns true if the value
|
||||
has changed. If necessary, the control may be destroyed.
|
||||
*Must Override*
|
||||
"""
|
||||
self.log.write("MyCellEditor: EndEdit (%d,%d)\n" % (row, col))
|
||||
changed = false
|
||||
|
||||
val = self._tc.GetValue()
|
||||
if val != self.startValue:
|
||||
changed = true
|
||||
grid.GetTable().SetValue(row, col, val) # update the table
|
||||
|
||||
self.startValue = ''
|
||||
self._tc.SetValue('')
|
||||
return changed
|
||||
|
||||
|
||||
def Reset(self):
|
||||
"""
|
||||
Reset the value in the control back to its starting value.
|
||||
*Must Override*
|
||||
"""
|
||||
self.log.write("MyCellEditor: Reset\n")
|
||||
self._tc.SetValue(self.startValue)
|
||||
self._tc.SetInsertionPointEnd()
|
||||
|
||||
|
||||
def IsAcceptedKey(self, evt):
|
||||
"""
|
||||
Return TRUE to allow the given key to start editing: the base class
|
||||
version only checks that the event has no modifiers. F2 is special
|
||||
and will always start the editor.
|
||||
"""
|
||||
self.log.write("MyCellEditor: IsAcceptedKey: %d\n" % (evt.GetKeyCode()))
|
||||
|
||||
## Oops, there's a bug here, we'll have to do it ourself..
|
||||
##return self.base_IsAcceptedKey(evt)
|
||||
|
||||
return (not (evt.ControlDown() or evt.AltDown()) and
|
||||
evt.GetKeyCode() != WXK_SHIFT)
|
||||
|
||||
|
||||
def StartingKey(self, evt):
|
||||
"""
|
||||
If the editor is enabled by pressing keys on the grid, this will be
|
||||
called to let the editor do something about that first key if desired.
|
||||
"""
|
||||
self.log.write("MyCellEditor: StartingKey %d\n" % evt.GetKeyCode())
|
||||
key = evt.GetKeyCode()
|
||||
ch = None
|
||||
if key in [WXK_NUMPAD0, WXK_NUMPAD1, WXK_NUMPAD2, WXK_NUMPAD3, WXK_NUMPAD4,
|
||||
WXK_NUMPAD5, WXK_NUMPAD6, WXK_NUMPAD7, WXK_NUMPAD8, WXK_NUMPAD9]:
|
||||
ch = ch = chr(ord('0') + key - WXK_NUMPAD0)
|
||||
|
||||
elif key < 256 and key >= 0 and chr(key) in string.printable:
|
||||
ch = chr(key)
|
||||
if not evt.ShiftDown():
|
||||
ch = string.lower(ch)
|
||||
|
||||
if ch is not None:
|
||||
# For this example, replace the text. Normally we would append it.
|
||||
#self._tc.AppendText(ch)
|
||||
self._tc.SetValue(ch)
|
||||
self._tc.SetInsertionPointEnd()
|
||||
else:
|
||||
evt.Skip()
|
||||
|
||||
|
||||
def StartingClick(self):
|
||||
"""
|
||||
If the editor is enabled by clicking on the cell, this method will be
|
||||
called to allow the editor to simulate the click on the control if
|
||||
needed.
|
||||
"""
|
||||
self.log.write("MyCellEditor: StartingClick\n")
|
||||
|
||||
|
||||
def Destroy(self):
|
||||
"""final cleanup"""
|
||||
self.log.write("MyCellEditor: Destroy\n")
|
||||
self.base_Destroy()
|
||||
|
||||
|
||||
def Clone(self):
|
||||
"""
|
||||
Create a new object which is the copy of this one
|
||||
*Must Override*
|
||||
"""
|
||||
self.log.write("MyCellEditor: Clone\n")
|
||||
return MyCellEditor(self.log)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
class GridEditorTest(wxGrid):
|
||||
def __init__(self, parent, log):
|
||||
wxGrid.__init__(self, parent, -1)
|
||||
self.log = log
|
||||
|
||||
self.CreateGrid(10, 3)
|
||||
|
||||
# Somebody changed the grid so the type registry takes precedence
|
||||
# over the default attribute set for editors and renderers, so we
|
||||
# have to set null handlers for the type registry before the
|
||||
# default editor will get used otherwise...
|
||||
#self.RegisterDataType(wxGRID_VALUE_STRING, None, None)
|
||||
#self.SetDefaultEditor(MyCellEditor(self.log))
|
||||
|
||||
# Or we could just do it like this:
|
||||
#self.RegisterDataType(wxGRID_VALUE_STRING,
|
||||
# wxGridCellStringRenderer(),
|
||||
# MyCellEditor(self.log))
|
||||
|
||||
# but for this example, we'll just set the custom editor on one cell
|
||||
self.SetCellEditor(1, 0, MyCellEditor(self.log))
|
||||
self.SetCellValue(1, 0, "Try to edit this box")
|
||||
|
||||
# and on a column
|
||||
attr = wxGridCellAttr()
|
||||
attr.SetEditor(MyCellEditor(self.log))
|
||||
self.SetColAttr(2, attr)
|
||||
self.SetCellValue(1, 2, "or any in this column")
|
||||
|
||||
self.SetColSize(0, 150)
|
||||
self.SetColSize(1, 150)
|
||||
self.SetColSize(2, 150)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class TestFrame(wxFrame):
|
||||
def __init__(self, parent, log):
|
||||
wxFrame.__init__(self, parent, -1, "Custom Grid Cell Editor Test",
|
||||
size=(640,480))
|
||||
grid = GridEditorTest(self, log)
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
app = wxPySimpleApp()
|
||||
frame = TestFrame(None, sys.stdout)
|
||||
frame.Show(true)
|
||||
app.MainLoop()
|
||||
|
||||
|
@@ -1,172 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
from wxPython.grid import *
|
||||
|
||||
import string
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class CustomDataTable(wxPyGridTableBase):
|
||||
"""
|
||||
"""
|
||||
|
||||
def __init__(self, log):
|
||||
wxPyGridTableBase.__init__(self)
|
||||
self.log = log
|
||||
|
||||
self.colLabels = ['ID', 'Description', 'Severity', 'Priority', 'Platform',
|
||||
'Opened?', 'Fixed?', 'Tested?', 'TestFloat']
|
||||
|
||||
self.dataTypes = [wxGRID_VALUE_NUMBER,
|
||||
wxGRID_VALUE_STRING,
|
||||
wxGRID_VALUE_CHOICE + ':only in a million years!,wish list,minor,normal,major,critical',
|
||||
wxGRID_VALUE_NUMBER + ':1,5',
|
||||
wxGRID_VALUE_CHOICE + ':all,MSW,GTK,other',
|
||||
wxGRID_VALUE_BOOL,
|
||||
wxGRID_VALUE_BOOL,
|
||||
wxGRID_VALUE_BOOL,
|
||||
wxGRID_VALUE_FLOAT + ':6,2',
|
||||
]
|
||||
|
||||
self.data = [
|
||||
[1010, "The foo doesn't bar", "major", 1, 'MSW', 1, 1, 1, 1.12],
|
||||
[1011, "I've got a wicket in my wocket", "wish list", 2, 'other', 0, 0, 0, 1.50],
|
||||
[1012, "Rectangle() returns a triangle", "critical", 5, 'all', 0, 0, 0, 1.56]
|
||||
|
||||
]
|
||||
|
||||
|
||||
#--------------------------------------------------
|
||||
# required methods for the wxPyGridTableBase interface
|
||||
|
||||
def GetNumberRows(self):
|
||||
return len(self.data) + 1
|
||||
|
||||
def GetNumberCols(self):
|
||||
return len(self.data[0])
|
||||
|
||||
def IsEmptyCell(self, row, col):
|
||||
try:
|
||||
return not self.data[row][col]
|
||||
except IndexError:
|
||||
return true
|
||||
|
||||
# Get/Set values in the table. The Python version of these
|
||||
# methods can handle any data-type, (as long as the Editor and
|
||||
# Renderer understands the type too,) not just strings as in the
|
||||
# C++ version.
|
||||
def GetValue(self, row, col):
|
||||
try:
|
||||
return self.data[row][col]
|
||||
except IndexError:
|
||||
return ''
|
||||
|
||||
def SetValue(self, row, col, value):
|
||||
try:
|
||||
self.data[row][col] = value
|
||||
except IndexError:
|
||||
# add a new row
|
||||
self.data.append([''] * self.GetNumberCols())
|
||||
self.SetValue(row, col, value)
|
||||
|
||||
# tell the grid we've added a row
|
||||
msg = wxGridTableMessage(self, # The table
|
||||
wxGRIDTABLE_NOTIFY_ROWS_APPENDED, # what we did to it
|
||||
1) # how many
|
||||
|
||||
self.GetView().ProcessTableMessage(msg)
|
||||
|
||||
|
||||
#--------------------------------------------------
|
||||
# Some optional methods
|
||||
|
||||
# Called when the grid needs to display labels
|
||||
def GetColLabelValue(self, col):
|
||||
return self.colLabels[col]
|
||||
|
||||
# Called to determine the kind of editor/renderer to use by
|
||||
# default, doesn't necessarily have to be the same type used
|
||||
# nativly by the editor/renderer if they know how to convert.
|
||||
def GetTypeName(self, row, col):
|
||||
return self.dataTypes[col]
|
||||
|
||||
# Called to determine how the data can be fetched and stored by the
|
||||
# editor and renderer. This allows you to enforce some type-safety
|
||||
# in the grid.
|
||||
def CanGetValueAs(self, row, col, typeName):
|
||||
colType = string.split(self.dataTypes[col], ':')[0]
|
||||
if typeName == colType:
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
def CanSetValueAs(self, row, col, typeName):
|
||||
return self.CanGetValueAs(row, col, typeName)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
class CustTableGrid(wxGrid):
|
||||
def __init__(self, parent, log):
|
||||
wxGrid.__init__(self, parent, -1)
|
||||
|
||||
table = CustomDataTable(log)
|
||||
|
||||
# The second parameter means that the grid is to take ownership of the
|
||||
# table and will destroy it when done. Otherwise you would need to keep
|
||||
# a reference to it and call it's Destroy method later.
|
||||
self.SetTable(table, true)
|
||||
|
||||
self.SetRowLabelSize(0)
|
||||
self.SetMargins(0,0)
|
||||
self.AutoSizeColumns(false)
|
||||
|
||||
EVT_GRID_CELL_LEFT_DCLICK(self, self.OnLeftDClick)
|
||||
|
||||
|
||||
|
||||
# I do this because I don't like the default behaviour of not starting the
|
||||
# cell editor on double clicks, but only a second click.
|
||||
def OnLeftDClick(self, evt):
|
||||
if self.CanEnableCellControl():
|
||||
self.EnableCellEditControl()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class TestFrame(wxFrame):
|
||||
def __init__(self, parent, log):
|
||||
wxFrame.__init__(self, parent, -1, "Custom Table, data driven Grid Demo", size=(640,480))
|
||||
p = wxPanel(self, -1, style=0)
|
||||
grid = CustTableGrid(p, log)
|
||||
b = wxButton(p, -1, "Another Control...")
|
||||
b.SetDefault()
|
||||
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
||||
EVT_SET_FOCUS(b, self.OnButtonFocus)
|
||||
bs = wxBoxSizer(wxVERTICAL)
|
||||
bs.Add(grid, 1, wxGROW|wxALL, 5)
|
||||
bs.Add(b)
|
||||
p.SetSizer(bs)
|
||||
|
||||
def OnButton(self, evt):
|
||||
print "button selected"
|
||||
|
||||
def OnButtonFocus(self, evt):
|
||||
print "button focus"
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
app = wxPySimpleApp()
|
||||
frame = TestFrame(None, sys.stdout)
|
||||
frame.Show(true)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
@@ -1,193 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
from wxPython.grid import *
|
||||
from wxPython.lib.gridmovers import wxGridColMover, EVT_GRID_COL_MOVE
|
||||
from wxPython.lib.gridmovers import wxGridRowMover, EVT_GRID_ROW_MOVE
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class CustomDataTable(wxPyGridTableBase):
|
||||
"""
|
||||
"""
|
||||
|
||||
def __init__(self, log):
|
||||
wxPyGridTableBase.__init__(self)
|
||||
self.log = log
|
||||
|
||||
self.identifiers = ['id','ds','sv','pr','pl','op','fx','ts']
|
||||
|
||||
self.rowLabels = ['Row1','Row2','Row3']
|
||||
|
||||
self.colLabels = {'id':'ID','ds':'Description','sv':'Severity',
|
||||
'pr':'Priority','pl':'Platform','op':'Opened?',
|
||||
'fx':'Fixed?','ts':'Tested?'}
|
||||
|
||||
self.data = [{'id':1010,
|
||||
'ds':"The foo doesn't bar",
|
||||
'sv':"major",
|
||||
'pr':1,
|
||||
'pl':'MSW',
|
||||
'op':1,
|
||||
'fx':1,
|
||||
'ts':1
|
||||
},
|
||||
{'id':1011,
|
||||
'ds':"I've got a wicket in my wocket",
|
||||
'sv':"wish list",
|
||||
'pr':2,
|
||||
'pl':'other',
|
||||
'op':0,
|
||||
'fx':0,
|
||||
'ts':0
|
||||
},
|
||||
{'id':1012,
|
||||
'ds':"Rectangle() returns a triangle",
|
||||
'sv':"critical",
|
||||
'pr':5,
|
||||
'pl':'all',
|
||||
'op':0,
|
||||
'fx':0,
|
||||
'ts':0
|
||||
}
|
||||
]
|
||||
|
||||
#--------------------------------------------------
|
||||
# required methods for the wxPyGridTableBase interface
|
||||
|
||||
def GetNumberRows(self):
|
||||
return len(self.data)
|
||||
|
||||
def GetNumberCols(self):
|
||||
return len(self.identifiers)
|
||||
|
||||
def IsEmptyCell(self, row, col):
|
||||
id = self.identifiers[col]
|
||||
return not self.data[row][id]
|
||||
|
||||
def GetValue(self, row, col):
|
||||
id = self.identifiers[col]
|
||||
return self.data[row][id]
|
||||
|
||||
def SetValue(self, row, col, value):
|
||||
id = self.identifiers[col]
|
||||
self.data[row][id] = value
|
||||
|
||||
#--------------------------------------------------
|
||||
# Some optional methods
|
||||
|
||||
# Called when the grid needs to display column labels
|
||||
def GetColLabelValue(self, col):
|
||||
id = self.identifiers[col]
|
||||
return self.colLabels[id]
|
||||
|
||||
# Called when the grid needs to display row labels
|
||||
def GetRowLabelValue(self,row):
|
||||
return self.rowLabels[row]
|
||||
|
||||
#--------------------------------------------------
|
||||
# Methods added for demo purposes.
|
||||
|
||||
# The physical moving of the cols/rows is left to the implementer.
|
||||
# Because of the dynamic nature of a wxGrid the physical moving of
|
||||
# columns differs from implementation to implementation
|
||||
|
||||
# Move the column
|
||||
def MoveColumn(self,frm,to):
|
||||
grid = self.GetView()
|
||||
if grid:
|
||||
# Move the identifiers
|
||||
old = self.identifiers[frm]
|
||||
del self.identifiers[frm]
|
||||
if to > frm:
|
||||
self.identifiers.insert(to-1,old)
|
||||
else:
|
||||
self.identifiers.insert(to,old)
|
||||
|
||||
# Notify the grid
|
||||
grid.BeginBatch()
|
||||
msg = wxGridTableMessage(self,wxGRIDTABLE_NOTIFY_COLS_DELETED,
|
||||
frm,1)
|
||||
grid.ProcessTableMessage(msg)
|
||||
msg = wxGridTableMessage(self,wxGRIDTABLE_NOTIFY_COLS_INSERTED,
|
||||
to,1)
|
||||
grid.ProcessTableMessage(msg)
|
||||
grid.EndBatch()
|
||||
|
||||
# Move the row
|
||||
def MoveRow(self,frm,to):
|
||||
grid = self.GetView()
|
||||
if grid:
|
||||
# Move the rowLabels and data rows
|
||||
oldLabel = self.rowLabels[frm]
|
||||
oldData = self.data[frm]
|
||||
del self.rowLabels[frm]
|
||||
del self.data[frm]
|
||||
if to > frm:
|
||||
self.rowLabels.insert(to-1,oldLabel)
|
||||
self.data.insert(to-1,oldData)
|
||||
else:
|
||||
self.rowLabels.insert(to,oldLabel)
|
||||
self.data.insert(to,oldData)
|
||||
|
||||
# Notify the grid
|
||||
grid.BeginBatch()
|
||||
msg = wxGridTableMessage(self,wxGRIDTABLE_NOTIFY_ROWS_DELETED,
|
||||
frm,1)
|
||||
grid.ProcessTableMessage(msg)
|
||||
msg = wxGridTableMessage(self,wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
|
||||
to,1)
|
||||
grid.ProcessTableMessage(msg)
|
||||
grid.EndBatch()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class DragableGrid(wxGrid):
|
||||
def __init__(self, parent, log):
|
||||
wxGrid.__init__(self, parent, -1)
|
||||
|
||||
table = CustomDataTable(log)
|
||||
|
||||
# The second parameter means that the grid is to take ownership of the
|
||||
# table and will destroy it when done. Otherwise you would need to keep
|
||||
# a reference to it and call it's Destroy method later.
|
||||
self.SetTable(table, true)
|
||||
|
||||
# Enable Column moving
|
||||
wxGridColMover(self)
|
||||
EVT_GRID_COL_MOVE(self,self.GetId(),self.OnColMove)
|
||||
|
||||
# Enable Row moving
|
||||
wxGridRowMover(self)
|
||||
EVT_GRID_ROW_MOVE(self,self.GetId(),self.OnRowMove)
|
||||
|
||||
# Event method called when a column move needs to take place
|
||||
def OnColMove(self,evt):
|
||||
frm = evt.GetMoveColumn() # Column being moved
|
||||
to = evt.GetBeforeColumn() # Before which column to insert
|
||||
self.GetTable().MoveColumn(frm,to)
|
||||
|
||||
# Event method called when a row move needs to take place
|
||||
def OnRowMove(self,evt):
|
||||
frm = evt.GetMoveRow() # Row being moved
|
||||
to = evt.GetBeforeRow() # Before which row to insert
|
||||
self.GetTable().MoveRow(frm,to)
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class TestFrame(wxFrame):
|
||||
def __init__(self, parent, log):
|
||||
wxFrame.__init__(self, parent, -1, "Custom Table, data driven Grid Demo", size=(640,480))
|
||||
grid = DragableGrid(self, log)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
app = wxPySimpleApp()
|
||||
frame = TestFrame(None, sys.stdout)
|
||||
frame.Show(true)
|
||||
app.MainLoop()
|
||||
|
||||
#---------------------------------------------------------------------------
|
@@ -1,62 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
from wxPython.grid import *
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class NewEnterHandlingGrid(wxGrid):
|
||||
def __init__(self, parent, log):
|
||||
wxGrid.__init__(self, parent, -1)
|
||||
self.log = log
|
||||
|
||||
self.CreateGrid(20, 6)
|
||||
|
||||
self.SetCellValue(0, 0, "Enter moves to the right")
|
||||
self.SetCellValue(0, 5, "Enter wraps to next row")
|
||||
self.SetColSize(0, 150)
|
||||
self.SetColSize(5, 150)
|
||||
|
||||
EVT_KEY_DOWN(self, self.OnKeyDown)
|
||||
|
||||
|
||||
def OnKeyDown(self, evt):
|
||||
if evt.KeyCode() != WXK_RETURN:
|
||||
evt.Skip()
|
||||
return
|
||||
|
||||
if evt.ControlDown(): # the edit control needs this key
|
||||
evt.Skip()
|
||||
return
|
||||
|
||||
self.DisableCellEditControl()
|
||||
success = self.MoveCursorRight(evt.ShiftDown())
|
||||
if not success:
|
||||
newRow = self.GetGridCursorRow() + 1
|
||||
if newRow < self.GetTable().GetNumberRows():
|
||||
self.SetGridCursor(newRow, 0)
|
||||
self.MakeCellVisible(newRow, 0)
|
||||
else:
|
||||
# this would be a good place to add a new row if your app
|
||||
# needs to do that
|
||||
pass
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class TestFrame(wxFrame):
|
||||
def __init__(self, parent, log):
|
||||
wxFrame.__init__(self, parent, -1, "Simple Grid Demo", size=(640,480))
|
||||
grid = NewEnterHandlingGrid(self, log)
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
app = wxPySimpleApp()
|
||||
frame = TestFrame(None, sys.stdout)
|
||||
frame.Show(true)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
@@ -1,71 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
from wxPython.grid import *
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class HugeTable(wxPyGridTableBase):
|
||||
|
||||
"""
|
||||
This is all it takes to make a custom data table to plug into a
|
||||
wxGrid. There are many more methods that can be overridden, but
|
||||
the ones shown below are the required ones. This table simply
|
||||
provides strings containing the row and column values.
|
||||
"""
|
||||
|
||||
def __init__(self, log):
|
||||
wxPyGridTableBase.__init__(self)
|
||||
self.log = log
|
||||
|
||||
def GetNumberRows(self):
|
||||
return 10000
|
||||
|
||||
def GetNumberCols(self):
|
||||
return 10000
|
||||
|
||||
def IsEmptyCell(self, row, col):
|
||||
return false
|
||||
|
||||
def GetValue(self, row, col):
|
||||
return str( (row, col) )
|
||||
|
||||
def SetValue(self, row, col, value):
|
||||
self.log.write('SetValue(%d, %d, "%s") ignored.\n' % (row, col, value))
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
class HugeTableGrid(wxGrid):
|
||||
def __init__(self, parent, log):
|
||||
wxGrid.__init__(self, parent, -1)
|
||||
|
||||
table = HugeTable(log)
|
||||
|
||||
# The second parameter means that the grid is to take ownership of the
|
||||
# table and will destroy it when done. Otherwise you would need to keep
|
||||
# a reference to it and call it's Destroy method later.
|
||||
self.SetTable(table, true)
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class TestFrame(wxFrame):
|
||||
def __init__(self, parent, log):
|
||||
wxFrame.__init__(self, parent, -1, "Huge (virtual) Table Demo", size=(640,480))
|
||||
grid = HugeTableGrid(self, log)
|
||||
|
||||
grid.SetReadOnly(5,5, true)
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
app = wxPySimpleApp()
|
||||
frame = TestFrame(None, sys.stdout)
|
||||
frame.Show(true)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
@@ -1,233 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
from wxPython.grid import *
|
||||
from wxPython.lib.mixins.grid import wxGridAutoEditMixin
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin):
|
||||
def __init__(self, parent, log):
|
||||
wxGrid.__init__(self, parent, -1)
|
||||
##wxGridAutoEditMixin.__init__(self)
|
||||
self.log = log
|
||||
self.moveTo = None
|
||||
|
||||
EVT_IDLE(self, self.OnIdle)
|
||||
|
||||
self.CreateGrid(25, 25)
|
||||
##self.EnableEditing(false)
|
||||
|
||||
# simple cell formatting
|
||||
self.SetColSize(3, 200)
|
||||
self.SetRowSize(4, 45)
|
||||
self.SetCellValue(0, 0, "First cell")
|
||||
self.SetCellValue(1, 1, "Another cell")
|
||||
self.SetCellValue(2, 2, "Yet another cell")
|
||||
self.SetCellValue(3, 3, "This cell is read-only")
|
||||
self.SetCellFont(0, 0, wxFont(12, wxROMAN, wxITALIC, wxNORMAL))
|
||||
self.SetCellTextColour(1, 1, wxRED)
|
||||
self.SetCellBackgroundColour(2, 2, wxCYAN)
|
||||
self.SetReadOnly(3, 3, true)
|
||||
|
||||
self.SetCellEditor(5, 0, wxGridCellNumberEditor(1,1000))
|
||||
self.SetCellValue(5, 0, "123")
|
||||
self.SetCellEditor(6, 0, wxGridCellFloatEditor())
|
||||
self.SetCellValue(6, 0, "123.34")
|
||||
self.SetCellEditor(7, 0, wxGridCellNumberEditor())
|
||||
|
||||
self.SetCellValue(6, 3, "You can veto editing this cell")
|
||||
|
||||
|
||||
# attribute objects let you keep a set of formatting values
|
||||
# in one spot, and reuse them if needed
|
||||
attr = wxGridCellAttr()
|
||||
attr.SetTextColour(wxBLACK)
|
||||
attr.SetBackgroundColour(wxRED)
|
||||
attr.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD))
|
||||
|
||||
# you can set cell attributes for the whole row (or column)
|
||||
self.SetRowAttr(5, attr)
|
||||
|
||||
self.SetColLabelValue(0, "Custom")
|
||||
self.SetColLabelValue(1, "column")
|
||||
self.SetColLabelValue(2, "labels")
|
||||
|
||||
self.SetColLabelAlignment(wxALIGN_LEFT, wxALIGN_BOTTOM)
|
||||
|
||||
# overflow cells
|
||||
self.SetCellValue( 9, 1, "This default cell will overflow into neighboring cells, but not if you turn overflow off.");
|
||||
self.SetCellSize(11, 1, 3, 3);
|
||||
self.SetCellAlignment(11, 1, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
||||
self.SetCellValue(11, 1, "This cell is set to span 3 rows and 3 columns");
|
||||
|
||||
|
||||
|
||||
# test all the events
|
||||
EVT_GRID_CELL_LEFT_CLICK(self, self.OnCellLeftClick)
|
||||
EVT_GRID_CELL_RIGHT_CLICK(self, self.OnCellRightClick)
|
||||
EVT_GRID_CELL_LEFT_DCLICK(self, self.OnCellLeftDClick)
|
||||
EVT_GRID_CELL_RIGHT_DCLICK(self, self.OnCellRightDClick)
|
||||
|
||||
EVT_GRID_LABEL_LEFT_CLICK(self, self.OnLabelLeftClick)
|
||||
EVT_GRID_LABEL_RIGHT_CLICK(self, self.OnLabelRightClick)
|
||||
EVT_GRID_LABEL_LEFT_DCLICK(self, self.OnLabelLeftDClick)
|
||||
EVT_GRID_LABEL_RIGHT_DCLICK(self, self.OnLabelRightDClick)
|
||||
|
||||
EVT_GRID_ROW_SIZE(self, self.OnRowSize)
|
||||
EVT_GRID_COL_SIZE(self, self.OnColSize)
|
||||
|
||||
EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect)
|
||||
EVT_GRID_CELL_CHANGE(self, self.OnCellChange)
|
||||
EVT_GRID_SELECT_CELL(self, self.OnSelectCell)
|
||||
|
||||
EVT_GRID_EDITOR_SHOWN(self, self.OnEditorShown)
|
||||
EVT_GRID_EDITOR_HIDDEN(self, self.OnEditorHidden)
|
||||
EVT_GRID_EDITOR_CREATED(self, self.OnEditorCreated)
|
||||
|
||||
|
||||
|
||||
def OnCellLeftClick(self, evt):
|
||||
self.log.write("OnCellLeftClick: (%d,%d) %s\n" %
|
||||
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
|
||||
evt.Skip()
|
||||
|
||||
def OnCellRightClick(self, evt):
|
||||
self.log.write("OnCellRightClick: (%d,%d) %s\n" %
|
||||
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
|
||||
evt.Skip()
|
||||
|
||||
def OnCellLeftDClick(self, evt):
|
||||
self.log.write("OnCellLeftDClick: (%d,%d) %s\n" %
|
||||
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
|
||||
evt.Skip()
|
||||
|
||||
def OnCellRightDClick(self, evt):
|
||||
self.log.write("OnCellRightDClick: (%d,%d) %s\n" %
|
||||
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
|
||||
evt.Skip()
|
||||
|
||||
def OnLabelLeftClick(self, evt):
|
||||
self.log.write("OnLabelLeftClick: (%d,%d) %s\n" %
|
||||
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
|
||||
evt.Skip()
|
||||
|
||||
def OnLabelRightClick(self, evt):
|
||||
self.log.write("OnLabelRightClick: (%d,%d) %s\n" %
|
||||
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
|
||||
evt.Skip()
|
||||
|
||||
def OnLabelLeftDClick(self, evt):
|
||||
self.log.write("OnLabelLeftDClick: (%d,%d) %s\n" %
|
||||
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
|
||||
evt.Skip()
|
||||
|
||||
def OnLabelRightDClick(self, evt):
|
||||
self.log.write("OnLabelRightDClick: (%d,%d) %s\n" %
|
||||
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
|
||||
evt.Skip()
|
||||
|
||||
|
||||
def OnRowSize(self, evt):
|
||||
self.log.write("OnRowSize: row %d, %s\n" %
|
||||
(evt.GetRowOrCol(), evt.GetPosition()))
|
||||
evt.Skip()
|
||||
|
||||
def OnColSize(self, evt):
|
||||
self.log.write("OnColSize: col %d, %s\n" %
|
||||
(evt.GetRowOrCol(), evt.GetPosition()))
|
||||
evt.Skip()
|
||||
|
||||
def OnRangeSelect(self, evt):
|
||||
if evt.Selecting():
|
||||
self.log.write("OnRangeSelect: top-left %s, bottom-right %s\n" %
|
||||
(evt.GetTopLeftCoords(), evt.GetBottomRightCoords()))
|
||||
evt.Skip()
|
||||
|
||||
|
||||
def OnCellChange(self, evt):
|
||||
self.log.write("OnCellChange: (%d,%d) %s\n" %
|
||||
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
|
||||
|
||||
# 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
|
||||
evt.Skip()
|
||||
|
||||
|
||||
def OnSelectCell(self, evt):
|
||||
self.log.write("OnSelectCell: (%d,%d) %s\n" %
|
||||
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
|
||||
|
||||
# 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
|
||||
evt.Skip()
|
||||
|
||||
|
||||
def OnEditorShown(self, evt):
|
||||
if evt.GetRow() == 6 and evt.GetCol() == 3 and \
|
||||
wxMessageBox("Are you sure you wish to edit this cell?",
|
||||
"Checking", wxYES_NO) == wxNO:
|
||||
evt.Veto()
|
||||
return
|
||||
|
||||
self.log.write("OnEditorShown: (%d,%d) %s\n" %
|
||||
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
|
||||
evt.Skip()
|
||||
|
||||
|
||||
def OnEditorHidden(self, evt):
|
||||
if evt.GetRow() == 6 and evt.GetCol() == 3 and \
|
||||
wxMessageBox("Are you sure you wish to finish editing this cell?",
|
||||
"Checking", wxYES_NO) == wxNO:
|
||||
evt.Veto()
|
||||
return
|
||||
|
||||
self.log.write("OnEditorHidden: (%d,%d) %s\n" %
|
||||
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
|
||||
evt.Skip()
|
||||
|
||||
|
||||
def OnEditorCreated(self, evt):
|
||||
self.log.write("OnEditorCreated: (%d, %d) %s\n" %
|
||||
(evt.GetRow(), evt.GetCol(), evt.GetControl()))
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class TestFrame(wxFrame):
|
||||
def __init__(self, parent, log):
|
||||
wxFrame.__init__(self, parent, -1, "Simple Grid Demo", size=(640,480))
|
||||
grid = SimpleGrid(self, log)
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
app = wxPySimpleApp()
|
||||
frame = TestFrame(None, sys.stdout)
|
||||
frame.Show(true)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
@@ -1,181 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
from wxPython.grid import *
|
||||
|
||||
import string, random
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class MyCustomRenderer(wxPyGridCellRenderer):
|
||||
def __init__(self):
|
||||
wxPyGridCellRenderer.__init__(self)
|
||||
|
||||
def Draw(self, grid, attr, dc, rect, row, col, isSelected):
|
||||
dc.SetBackgroundMode(wxSOLID)
|
||||
dc.SetBrush(wxBrush(wxBLACK, wxSOLID))
|
||||
dc.SetPen(wxTRANSPARENT_PEN)
|
||||
dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height)
|
||||
|
||||
dc.SetBackgroundMode(wxTRANSPARENT)
|
||||
dc.SetFont(attr.GetFont())
|
||||
|
||||
text = grid.GetCellValue(row, col)
|
||||
colors = [wxRED, wxWHITE, wxCYAN]
|
||||
x = rect.x + 1
|
||||
y = rect.y + 1
|
||||
for ch in text:
|
||||
dc.SetTextForeground(random.choice(colors))
|
||||
dc.DrawText(ch, x, y)
|
||||
w, h = dc.GetTextExtent(ch)
|
||||
x = x + w
|
||||
if x > rect.right - 5:
|
||||
break
|
||||
|
||||
|
||||
def GetBestSize(self, grid, attr, dc, row, col):
|
||||
text = grid.GetCellValue(row, col)
|
||||
dc.SetFont(attr.GetFont())
|
||||
w, h = dc.GetTextExtent(text)
|
||||
return wxSize(w, h)
|
||||
|
||||
|
||||
def Clone(self):
|
||||
return MyCustomRenderer()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
rendererDemoData = [
|
||||
('wxGridCellStringRenderer\n(the default)', 'this is a text value', wxGridCellStringRenderer, ()),
|
||||
('wxGridCellNumberRenderer', '12345', wxGridCellNumberRenderer, ()),
|
||||
('wxGridCellFloatRenderer', '1234.5678', wxGridCellFloatRenderer, (6,2)),
|
||||
('wxGridCellBoolRenderer', '1', wxGridCellBoolRenderer, ()),
|
||||
('MyCustomRenderer', 'This is my renderer', MyCustomRenderer, ()),
|
||||
]
|
||||
|
||||
editorDemoData = [
|
||||
('wxGridCellTextEditor\n(the default)', 'Here is some more text', wxGridCellTextEditor, ()),
|
||||
('wxGridCellNumberEditor\nwith min,max', '101', wxGridCellNumberEditor, (5, 10005)),
|
||||
('wxGridCellNumberEditor\nwithout bounds', '101', wxGridCellNumberEditor, ()),
|
||||
('wxGridCellFloatEditor', '1234.5678', wxGridCellFloatEditor, ()),
|
||||
('wxGridCellBoolEditor', '1', wxGridCellBoolEditor, ()),
|
||||
('wxGridCellChoiceEditor', 'one', wxGridCellChoiceEditor, (['one', 'two', 'three', 'four',
|
||||
'kick', 'Microsoft', 'out the',
|
||||
'door'], false)),
|
||||
]
|
||||
|
||||
|
||||
comboDemoData = [
|
||||
('wxGridCellNumberRenderer\nwxGridCellNumberEditor', '20792', wxGridCellNumberRenderer, wxGridCellNumberEditor),
|
||||
('wxGridCellBoolRenderer\nwxGridCellBoolEditor', '1', wxGridCellBoolRenderer, wxGridCellBoolEditor),
|
||||
]
|
||||
|
||||
|
||||
class EditorsAndRenderersGrid(wxGrid):
|
||||
def __init__(self, parent, log):
|
||||
wxGrid.__init__(self, parent, -1)
|
||||
self.log = log
|
||||
|
||||
self.CreateGrid(25, 8)
|
||||
renCol = 1
|
||||
edCol = 4
|
||||
|
||||
|
||||
self.SetCellValue(0, renCol, '''\
|
||||
Cell Renderers are used to draw
|
||||
the contents of the cell when they
|
||||
need to be refreshed. Different
|
||||
types of Renderers can be plugged in
|
||||
to different cells in the grid, it can
|
||||
even be automatically determined based
|
||||
on the type of data in the cell.
|
||||
''')
|
||||
|
||||
self.SetCellValue(0, edCol, '''\
|
||||
Cell Editors are used when the
|
||||
value of the cell is edited by
|
||||
the user. An editor class is
|
||||
wrapped around a an object
|
||||
derived from wxControl and it
|
||||
implements some methods required
|
||||
to integrate with the grid.
|
||||
''')
|
||||
|
||||
self.SetCellValue(16, renCol, '''\
|
||||
Here are some combinations of Editors and
|
||||
Renderers used together.
|
||||
''')
|
||||
|
||||
row = 2
|
||||
for label, value, renderClass, args in rendererDemoData:
|
||||
renderer = apply(renderClass, args)
|
||||
self.SetCellValue(row, renCol, label)
|
||||
self.SetCellValue(row, renCol+1, value)
|
||||
self.SetCellRenderer(row, renCol+1, renderer)
|
||||
row = row + 2
|
||||
|
||||
|
||||
row = 2
|
||||
for label, value, editorClass, args in editorDemoData:
|
||||
editor = apply(editorClass, args)
|
||||
self.SetCellValue(row, edCol, label)
|
||||
self.SetCellValue(row, edCol+1, value)
|
||||
self.SetCellEditor(row, edCol+1, editor)
|
||||
row = row + 2
|
||||
|
||||
|
||||
row = 18
|
||||
for label, value, renClass, edClass in comboDemoData:
|
||||
self.SetCellValue(row, renCol, label)
|
||||
self.SetCellValue(row, renCol+1, value)
|
||||
editor = apply(edClass, ()) #args)
|
||||
renderer = apply(renClass, ()) #args)
|
||||
self.SetCellEditor(row, renCol+1, editor)
|
||||
self.SetCellRenderer(row, renCol+1, renderer)
|
||||
row = row + 2
|
||||
|
||||
|
||||
font = self.GetFont()
|
||||
font.SetWeight(wxBOLD)
|
||||
attr = wxGridCellAttr()
|
||||
attr.SetFont(font)
|
||||
attr.SetBackgroundColour(wxLIGHT_GREY)
|
||||
attr.SetReadOnly(true)
|
||||
attr.SetAlignment(wxRIGHT, -1)
|
||||
self.SetColAttr(renCol, attr)
|
||||
attr.IncRef()
|
||||
self.SetColAttr(edCol, attr)
|
||||
|
||||
# There is a bug in wxGTK for this method...
|
||||
self.AutoSizeColumns(true)
|
||||
self.AutoSizeRows(true)
|
||||
|
||||
EVT_GRID_CELL_LEFT_DCLICK(self, self.OnLeftDClick)
|
||||
|
||||
|
||||
# I do this because I don't like the default behaviour of not starting the
|
||||
# cell editor on double clicks, but only a second click.
|
||||
def OnLeftDClick(self, evt):
|
||||
if self.CanEnableCellControl():
|
||||
self.EnableCellEditControl()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class TestFrame(wxFrame):
|
||||
def __init__(self, parent, log):
|
||||
wxFrame.__init__(self, parent, -1, "Editors and Renderers Demo", size=(640,480))
|
||||
grid = EditorsAndRenderersGrid(self, log)
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
app = wxPySimpleApp()
|
||||
frame = TestFrame(None, sys.stdout)
|
||||
frame.Show(true)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
@@ -1,40 +0,0 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: ImageBrowser.py
|
||||
# Purpose: Image Selection dialog for wxPython demo
|
||||
#
|
||||
# Author: Lorne White (email: lorne.white@telusplanet.net)
|
||||
#
|
||||
# Version 0.5
|
||||
# Date: Feb 26, 2001
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.imagebrowser import *
|
||||
import os
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
dir = os.getcwd() # get working directory
|
||||
initial_dir = os.path.join(dir, 'bitmaps') # set the initial directory for the demo bitmaps
|
||||
win = ImageDialog(frame, initial_dir) # open the image browser dialog
|
||||
win.Centre()
|
||||
if win.ShowModal() == wxID_OK:
|
||||
log.WriteText("You Selected File: " + win.GetFile()) # show the selected file
|
||||
else:
|
||||
log.WriteText("You pressed Cancel\n")
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
overview = """\
|
||||
"""
|
@@ -1,140 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.anchors import LayoutAnchors
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
[wxID_ANCHORSDEMOFRAMEANCHOREDPANEL, wxID_ANCHORSDEMOFRAMEHELPSTATICTEXT,
|
||||
wxID_ANCHORSDEMOFRAMEMAINPANEL, wxID_ANCHORSDEMOFRAMEBACKGROUNDPANEL,
|
||||
wxID_ANCHORSDEMOFRAMERIGHTCHECKBOX, wxID_ANCHORSDEMOFRAMEOKBUTTON,
|
||||
wxID_ANCHORSDEMOFRAMETOPCHECKBOX, wxID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX,
|
||||
wxID_ANCHORSDEMOFRAME, wxID_ANCHORSDEMOFRAMELEFTCHECKBOX,
|
||||
] = map(lambda _init_ctrls: wxNewId(), range(10))
|
||||
|
||||
class AnchorsDemoFrame(wxFrame):
|
||||
def _init_utils(self):
|
||||
pass
|
||||
|
||||
def _init_ctrls(self, prnt):
|
||||
wxFrame.__init__(self, size = wxSize(328, 187), id = wxID_ANCHORSDEMOFRAME, title = 'LayoutAnchors Demonstration', parent = prnt, name = 'AnchorsDemoFrame', style = wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN, pos = wxPoint(261, 123))
|
||||
self._init_utils()
|
||||
|
||||
self.mainPanel = wxPanel(size = wxSize(320, 160), parent = self, id = wxID_ANCHORSDEMOFRAMEMAINPANEL, name = 'panel1', style = wxTAB_TRAVERSAL | wxCLIP_CHILDREN, pos = wxPoint(0, 0))
|
||||
self.mainPanel.SetAutoLayout(true)
|
||||
|
||||
self.okButton = wxButton(label = 'OK', id = wxID_ANCHORSDEMOFRAMEOKBUTTON, parent = self.mainPanel, name = 'okButton', size = wxSize(72, 24), style = 0, pos = wxPoint(240, 128))
|
||||
self.okButton.SetConstraints(LayoutAnchors(self.okButton, false, false, true, true))
|
||||
EVT_BUTTON(self.okButton, wxID_ANCHORSDEMOFRAMEOKBUTTON, self.OnOkButtonButton)
|
||||
|
||||
self.backgroundPanel = wxPanel(size = wxSize(304, 80), parent = self.mainPanel, id = wxID_ANCHORSDEMOFRAMEBACKGROUNDPANEL, name = 'backgroundPanel', style = wxSIMPLE_BORDER | wxCLIP_CHILDREN, pos = wxPoint(8, 40))
|
||||
self.backgroundPanel.SetBackgroundColour(wxColour(255, 255, 255))
|
||||
self.backgroundPanel.SetConstraints(LayoutAnchors(self.backgroundPanel, true, true, true, true))
|
||||
|
||||
self.anchoredPanel = wxPanel(size = wxSize(88, 48), id = wxID_ANCHORSDEMOFRAMEANCHOREDPANEL, parent = self.backgroundPanel, name = 'anchoredPanel', style = wxSIMPLE_BORDER, pos = wxPoint(104, 16))
|
||||
self.anchoredPanel.SetBackgroundColour(wxColour(0, 0, 222))
|
||||
self.anchoredPanel.SetConstraints(LayoutAnchors(self.anchoredPanel, false, false, false, false))
|
||||
|
||||
self.leftCheckBox = wxCheckBox(label = 'Left', id = wxID_ANCHORSDEMOFRAMELEFTCHECKBOX, parent = self.mainPanel, name = 'leftCheckBox', size = wxSize(40, 16), style = 0, pos = wxPoint(8, 8))
|
||||
self.leftCheckBox.SetConstraints(LayoutAnchors(self.leftCheckBox, false, true, false, false))
|
||||
EVT_CHECKBOX(self.leftCheckBox, wxID_ANCHORSDEMOFRAMELEFTCHECKBOX, self.OnCheckboxCheckbox)
|
||||
|
||||
self.topCheckBox = wxCheckBox(label = 'Top', id = wxID_ANCHORSDEMOFRAMETOPCHECKBOX, parent = self.mainPanel, name = 'topCheckBox', size = wxSize(40, 16), style = 0, pos = wxPoint(88, 8))
|
||||
self.topCheckBox.SetConstraints(LayoutAnchors(self.topCheckBox, false, true, false, false))
|
||||
EVT_CHECKBOX(self.topCheckBox, wxID_ANCHORSDEMOFRAMETOPCHECKBOX, self.OnCheckboxCheckbox)
|
||||
|
||||
self.rightCheckBox = wxCheckBox(label = 'Right', id = wxID_ANCHORSDEMOFRAMERIGHTCHECKBOX, parent = self.mainPanel, name = 'rightCheckBox', size = wxSize(48, 16), style = 0, pos = wxPoint(168, 8))
|
||||
self.rightCheckBox.SetConstraints(LayoutAnchors(self.rightCheckBox, false, true, false, false))
|
||||
EVT_CHECKBOX(self.rightCheckBox, wxID_ANCHORSDEMOFRAMERIGHTCHECKBOX, self.OnCheckboxCheckbox)
|
||||
|
||||
self.bottomCheckBox = wxCheckBox(label = 'Bottom', id = wxID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX, parent = self.mainPanel, name = 'bottomCheckBox', size = wxSize(56, 16), style = 0, pos = wxPoint(248, 8))
|
||||
self.bottomCheckBox.SetConstraints(LayoutAnchors(self.bottomCheckBox, false, true, false, false))
|
||||
EVT_CHECKBOX(self.bottomCheckBox, wxID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX, self.OnCheckboxCheckbox)
|
||||
|
||||
self.helpStaticText = wxStaticText(label = 'Select anchor options above, then resize window to see the effect', id = wxID_ANCHORSDEMOFRAMEHELPSTATICTEXT, parent = self.mainPanel, name = 'helpStaticText', size = wxSize(224, 24), style = wxST_NO_AUTORESIZE, pos = wxPoint(8, 128))
|
||||
self.helpStaticText.SetConstraints(LayoutAnchors(self.helpStaticText, true, false, true, true))
|
||||
|
||||
def __init__(self, parent):
|
||||
self._init_ctrls(parent)
|
||||
|
||||
def OnCheckboxCheckbox(self, event):
|
||||
self.anchoredPanel.SetConstraints(
|
||||
LayoutAnchors(self.anchoredPanel,
|
||||
self.leftCheckBox.GetValue(), self.topCheckBox.GetValue(),
|
||||
self.rightCheckBox.GetValue(), self.bottomCheckBox.GetValue()) )
|
||||
|
||||
def OnOkButtonButton(self, event):
|
||||
self.Close()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = AnchorsDemoFrame(frame)
|
||||
frame.otherWin = win
|
||||
win.Show(true)
|
||||
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
overview = """<html><body>
|
||||
<h2>LayoutAnchors</h2>
|
||||
A class that implements Delphi's Anchors with wxLayoutConstraints.
|
||||
<p>
|
||||
Anchored sides maintain the distance from the edge of the
|
||||
control to the same edge of the parent.
|
||||
When neither side is selected, the control keeps the same
|
||||
relative position to both sides.
|
||||
<p>
|
||||
The current position and size of the control and it's parent
|
||||
is used when setting up the constraints. To change the size or
|
||||
position of an already anchored control, set the constraints to
|
||||
None, reposition or resize and reapply the anchors.
|
||||
<p>
|
||||
Examples:
|
||||
<p>
|
||||
Let's anchor the right and bottom edge of a control and
|
||||
resize it's parent.
|
||||
<p>
|
||||
<pre>
|
||||
ctrl.SetConstraints(LayoutAnchors(ctrl, left=0, top=0, right=1, bottom=1))
|
||||
|
||||
+=========+ +===================+
|
||||
| +-----+ | | |
|
||||
| | * | -> | |
|
||||
| +--*--+ | | +-----+ |
|
||||
+---------+ | | * |
|
||||
| +--*--+ |
|
||||
+-------------------+
|
||||
* = anchored edge
|
||||
</pre>
|
||||
<p>
|
||||
When anchored on both sides the control will stretch horizontally.
|
||||
<p>
|
||||
<pre>
|
||||
ctrl.SetConstraints(LayoutAnchors(ctrl, 1, 0, 1, 1))
|
||||
|
||||
+=========+ +===================+
|
||||
| +-----+ | | |
|
||||
| * * | -> | |
|
||||
| +--*--+ | | +---------------+ |
|
||||
+---------+ | * ctrl * |
|
||||
| +-------*-------+ |
|
||||
+-------------------+
|
||||
* = anchored edge
|
||||
</pre>
|
||||
</html></body>
|
||||
"""
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,62 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.layoutf import Layoutf
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class TestLayoutf(wxPanel):
|
||||
def __init__(self, parent):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
|
||||
self.SetAutoLayout(true)
|
||||
EVT_BUTTON(self, 100, self.OnButton)
|
||||
|
||||
self.panelA = wxWindow(self, -1, wxPyDefaultPosition, wxPyDefaultSize, wxSIMPLE_BORDER)
|
||||
self.panelA.SetBackgroundColour(wxBLUE)
|
||||
self.panelA.SetConstraints(Layoutf('t=t10#1;l=l10#1;b=b10#1;r%r50#1',(self,)))
|
||||
|
||||
self.panelB = wxWindow(self, -1, wxPyDefaultPosition, wxPyDefaultSize, wxSIMPLE_BORDER)
|
||||
self.panelB.SetBackgroundColour(wxRED)
|
||||
self.panelB.SetConstraints(Layoutf('t=t10#1;r=r10#1;b%b30#1;l>10#2', (self,self.panelA)))
|
||||
|
||||
self.panelC = wxWindow(self, -1, wxPyDefaultPosition, wxPyDefaultSize, wxSIMPLE_BORDER)
|
||||
self.panelC.SetBackgroundColour(wxWHITE)
|
||||
self.panelC.SetConstraints(Layoutf('t_10#3;r=r10#1;b=b10#1;l>10#2', (self,self.panelA,self.panelB)))
|
||||
|
||||
b = wxButton(self.panelA, 100, ' Panel A ')
|
||||
b.SetConstraints(Layoutf('X=X#1;Y=Y#1;h*;w%w50#1', (self.panelA,)))
|
||||
|
||||
b = wxButton(self.panelB, 100, ' Panel B ')
|
||||
b.SetConstraints(Layoutf('t=t2#1;r=r4#1;h*;w*', (self.panelB,)))
|
||||
|
||||
self.panelD = wxWindow(self.panelC, -1, wxPyDefaultPosition, wxPyDefaultSize, wxSIMPLE_BORDER)
|
||||
self.panelD.SetBackgroundColour(wxGREEN)
|
||||
self.panelD.SetConstraints(Layoutf('b%h50#1;r%w50#1;h=h#2;w=w#2', (self.panelC, b)))
|
||||
|
||||
b = wxButton(self.panelC, 100, ' Panel C ')
|
||||
b.SetConstraints(Layoutf('t_#1;l>#1;h*;w*', (self.panelD,)))
|
||||
|
||||
wxStaticText(self.panelD, -1, "Panel D", wxPoint(4, 4)).SetBackgroundColour(wxGREEN)
|
||||
|
||||
def OnButton(self, event):
|
||||
wxBell()
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestLayoutf(nb)
|
||||
return win
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
overview = Layoutf.__doc__
|
@@ -1,55 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxScrolledWindow import MyCanvas
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class MyParentFrame(wxMDIParentFrame):
|
||||
def __init__(self):
|
||||
wxMDIParentFrame.__init__(self, None, -1, "MDI Parent", size=(600,400))
|
||||
|
||||
self.winCount = 0
|
||||
menu = wxMenu()
|
||||
menu.Append(5000, "&New Window")
|
||||
menu.AppendSeparator()
|
||||
menu.Append(5001, "E&xit")
|
||||
|
||||
menubar = wxMenuBar()
|
||||
menubar.Append(menu, "&File")
|
||||
self.SetMenuBar(menubar)
|
||||
|
||||
self.CreateStatusBar()
|
||||
|
||||
EVT_MENU(self, 5000, self.OnNewWindow)
|
||||
EVT_MENU(self, 5001, self.OnExit)
|
||||
|
||||
|
||||
def OnExit(self, evt):
|
||||
self.Close(true)
|
||||
|
||||
|
||||
def OnNewWindow(self, evt):
|
||||
self.winCount = self.winCount + 1
|
||||
win = wxMDIChildFrame(self, -1, "Child Window: %d" % self.winCount)
|
||||
canvas = MyCanvas(win)
|
||||
win.Show(true)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
if __name__ == '__main__':
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
wxInitAllImageHandlers()
|
||||
frame = MyParentFrame()
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
|
||||
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
@@ -1,142 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxScrolledWindow import MyCanvas
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class MyParentFrame(wxMDIParentFrame):
|
||||
ID_WINDOW_TOP = 5100
|
||||
ID_WINDOW_LEFT1 = 5101
|
||||
ID_WINDOW_LEFT2 = 5102
|
||||
ID_WINDOW_BOTTOM = 5103
|
||||
|
||||
def __init__(self):
|
||||
wxMDIParentFrame.__init__(self, None, -1, "MDI Parent", size=(600,400),
|
||||
style = wxDEFAULT_FRAME_STYLE | wxHSCROLL | wxVSCROLL)
|
||||
|
||||
self.winCount = 0
|
||||
menu = wxMenu()
|
||||
menu.Append(5000, "&New Window")
|
||||
menu.AppendSeparator()
|
||||
menu.Append(5001, "E&xit")
|
||||
|
||||
menubar = wxMenuBar()
|
||||
menubar.Append(menu, "&File")
|
||||
self.SetMenuBar(menubar)
|
||||
|
||||
#self.CreateStatusBar()
|
||||
|
||||
EVT_MENU(self, 5000, self.OnNewWindow)
|
||||
EVT_MENU(self, 5001, self.OnExit)
|
||||
|
||||
|
||||
EVT_SASH_DRAGGED_RANGE(self,
|
||||
self.ID_WINDOW_TOP, self.ID_WINDOW_BOTTOM,
|
||||
self.OnSashDrag)
|
||||
EVT_SIZE(self, self.OnSize)
|
||||
|
||||
|
||||
# Create some layout windows
|
||||
# A window like a toolbar
|
||||
win = wxSashLayoutWindow(self, self.ID_WINDOW_TOP, style = wxNO_BORDER|wxSW_3D)
|
||||
win.SetDefaultSize((1000, 30))
|
||||
win.SetOrientation(wxLAYOUT_HORIZONTAL)
|
||||
win.SetAlignment(wxLAYOUT_TOP)
|
||||
win.SetBackgroundColour(wxColour(255, 0, 0))
|
||||
win.SetSashVisible(wxSASH_BOTTOM, true)
|
||||
|
||||
self.topWindow = win
|
||||
|
||||
|
||||
# A window like a statusbar
|
||||
win = wxSashLayoutWindow(self, self.ID_WINDOW_BOTTOM, style = wxNO_BORDER|wxSW_3D)
|
||||
win.SetDefaultSize((1000, 30))
|
||||
win.SetOrientation(wxLAYOUT_HORIZONTAL)
|
||||
win.SetAlignment(wxLAYOUT_BOTTOM)
|
||||
win.SetBackgroundColour(wxColour(0, 0, 255))
|
||||
win.SetSashVisible(wxSASH_TOP, true)
|
||||
|
||||
self.bottomWindow = win
|
||||
|
||||
|
||||
# A window to the left of the client window
|
||||
win = wxSashLayoutWindow(self, self.ID_WINDOW_LEFT1, style = wxNO_BORDER|wxSW_3D)
|
||||
win.SetDefaultSize((120, 1000))
|
||||
win.SetOrientation(wxLAYOUT_VERTICAL)
|
||||
win.SetAlignment(wxLAYOUT_LEFT)
|
||||
win.SetBackgroundColour(wxColour(0, 255, 0))
|
||||
win.SetSashVisible(wxSASH_RIGHT, TRUE)
|
||||
win.SetExtraBorderSize(10)
|
||||
textWindow = wxTextCtrl(win, -1, "", wxDefaultPosition, wxDefaultSize,
|
||||
wxTE_MULTILINE|wxSUNKEN_BORDER)
|
||||
textWindow.SetValue("A sub window")
|
||||
|
||||
self.leftWindow1 = win
|
||||
|
||||
|
||||
# Another window to the left of the client window
|
||||
win = wxSashLayoutWindow(self, self.ID_WINDOW_LEFT2, style = wxNO_BORDER|wxSW_3D)
|
||||
win.SetDefaultSize((120, 1000))
|
||||
win.SetOrientation(wxLAYOUT_VERTICAL)
|
||||
win.SetAlignment(wxLAYOUT_LEFT)
|
||||
win.SetBackgroundColour(wxColour(0, 255, 255))
|
||||
win.SetSashVisible(wxSASH_RIGHT, TRUE)
|
||||
|
||||
self.leftWindow2 = win
|
||||
|
||||
|
||||
def OnSashDrag(self, event):
|
||||
if event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE:
|
||||
return
|
||||
|
||||
eID = event.GetId()
|
||||
if eID == self.ID_WINDOW_TOP:
|
||||
self.topWindow.SetDefaultSize(wxSize(1000, event.GetDragRect().height))
|
||||
|
||||
elif eID == self.ID_WINDOW_LEFT1:
|
||||
self.leftWindow1.SetDefaultSize(wxSize(event.GetDragRect().width, 1000))
|
||||
|
||||
|
||||
elif eID == self.ID_WINDOW_LEFT2:
|
||||
self.leftWindow2.SetDefaultSize(wxSize(event.GetDragRect().width, 1000))
|
||||
|
||||
elif eID == self.ID_WINDOW_BOTTOM:
|
||||
self.bottomWindow.SetDefaultSize(wxSize(1000, event.GetDragRect().height))
|
||||
|
||||
wxLayoutAlgorithm().LayoutMDIFrame(self)
|
||||
self.GetClientWindow().Refresh()
|
||||
|
||||
|
||||
def OnSize(self, event):
|
||||
wxLayoutAlgorithm().LayoutMDIFrame(self)
|
||||
|
||||
|
||||
def OnExit(self, evt):
|
||||
self.Close(true)
|
||||
|
||||
|
||||
def OnNewWindow(self, evt):
|
||||
self.winCount = self.winCount + 1
|
||||
win = wxMDIChildFrame(self, -1, "Child Window: %d" % self.winCount)
|
||||
canvas = MyCanvas(win)
|
||||
win.Show(true)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
if __name__ == '__main__':
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
wxInitAllImageHandlers()
|
||||
frame = MyParentFrame()
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
|
||||
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
@@ -1,751 +0,0 @@
|
||||
#!/bin/env python
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: Main.py
|
||||
# Purpose: Testing lots of stuff, controls, window types, etc.
|
||||
#
|
||||
# Author: Robin Dunn
|
||||
#
|
||||
# Created: A long time ago, in a galaxy far, far away...
|
||||
# RCS-ID: $Id$
|
||||
# Copyright: (c) 1999 by Total Control Software
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
import sys, os, time, string
|
||||
from wxPython.wx import *
|
||||
from wxPython.html import wxHtmlWindow
|
||||
|
||||
##from wxPython.stc import *
|
||||
|
||||
import images
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
_treeList = [
|
||||
# new stuff
|
||||
('New since last release', [
|
||||
'wxRadioButton',
|
||||
'Throbber',
|
||||
'wxPopupControl',
|
||||
'wxMultiSash',
|
||||
]),
|
||||
|
||||
# managed windows == things with a caption you can close
|
||||
('Base Frames and Dialogs', [
|
||||
'wxDialog',
|
||||
'wxFrame',
|
||||
'wxMDIWindows',
|
||||
'wxMiniFrame',
|
||||
'wxWizard',
|
||||
]),
|
||||
|
||||
# the common dialogs
|
||||
('Common Dialogs', [
|
||||
'wxColourDialog',
|
||||
'wxDirDialog',
|
||||
'wxFileDialog',
|
||||
'wxFindReplaceDialog',
|
||||
'wxFontDialog',
|
||||
'wxMessageDialog',
|
||||
'wxPageSetupDialog',
|
||||
'wxPrintDialog',
|
||||
'wxProgressDialog',
|
||||
'wxSingleChoiceDialog',
|
||||
'wxTextEntryDialog',
|
||||
]),
|
||||
|
||||
# dialogs from libraries
|
||||
('More Dialogs', [
|
||||
'ErrorDialogs',
|
||||
'ImageBrowser',
|
||||
'wxMultipleChoiceDialog',
|
||||
'wxScrolledMessageDialog',
|
||||
]),
|
||||
|
||||
# core controls
|
||||
('Core Windows/Controls', [
|
||||
'wxButton',
|
||||
'wxCheckBox',
|
||||
'wxCheckListBox',
|
||||
'wxChoice',
|
||||
'wxComboBox',
|
||||
'wxGauge',
|
||||
'wxGenericDirCtrl',
|
||||
'wxGrid',
|
||||
'wxListBox',
|
||||
'wxListCtrl',
|
||||
'wxListCtrl_virtual',
|
||||
'wxMenu',
|
||||
'wxNotebook',
|
||||
'wxPopupWindow',
|
||||
'wxRadioBox',
|
||||
'wxRadioButton',
|
||||
'wxSashWindow',
|
||||
'wxScrolledWindow',
|
||||
'wxSlider',
|
||||
'wxSpinButton',
|
||||
'wxSpinCtrl',
|
||||
'wxSplitterWindow',
|
||||
'wxStaticBitmap',
|
||||
'wxStaticText',
|
||||
'wxStatusBar',
|
||||
'wxTextCtrl',
|
||||
'wxToggleButton',
|
||||
'wxToolBar',
|
||||
'wxTreeCtrl',
|
||||
'wxValidator',
|
||||
]),
|
||||
|
||||
# controls coming from other librairies
|
||||
('More Windows/Controls', [
|
||||
#'wxFloatBar', deprecated
|
||||
#'wxMVCTree', deprecated
|
||||
'ColourSelect',
|
||||
'ContextHelp',
|
||||
'FancyText',
|
||||
'FileBrowseButton',
|
||||
'GenericButtons',
|
||||
'PyCrust',
|
||||
'PyCrustWithFilling',
|
||||
'SplitTree',
|
||||
'TablePrint',
|
||||
'Throbber',
|
||||
'wxCalendar',
|
||||
'wxCalendarCtrl',
|
||||
'wxDynamicSashWindow',
|
||||
'wxEditableListBox',
|
||||
'wxEditor',
|
||||
'wxHtmlWindow',
|
||||
'wxIEHtmlWin',
|
||||
'wxLEDNumberCtrl',
|
||||
'wxMimeTypesManager',
|
||||
'wxMultiSash',
|
||||
'wxPopupControl',
|
||||
'wxRightTextCtrl',
|
||||
'wxStyledTextCtrl_1',
|
||||
'wxStyledTextCtrl_2',
|
||||
'wxTimeCtrl',
|
||||
]),
|
||||
|
||||
# How to lay out the controls in a frame/dialog
|
||||
('Window Layout', [
|
||||
'LayoutAnchors',
|
||||
'Layoutf',
|
||||
'RowColSizer',
|
||||
'ScrolledPanel',
|
||||
'Sizers',
|
||||
'wxLayoutConstraints',
|
||||
'wxXmlResource',
|
||||
'wxXmlResourceHandler',
|
||||
]),
|
||||
|
||||
# ditto
|
||||
('Process and Events', [
|
||||
'infoframe',
|
||||
'OOR',
|
||||
'PythonEvents',
|
||||
'Threads',
|
||||
'wxProcess',
|
||||
'wxTimer',
|
||||
'wxKeyEvents',
|
||||
]),
|
||||
|
||||
# Clipboard and DnD
|
||||
('Clipboard and DnD', [
|
||||
'CustomDragAndDrop',
|
||||
'DragAndDrop',
|
||||
'URLDragAndDrop',
|
||||
]),
|
||||
|
||||
# Images
|
||||
('Images', [
|
||||
'Throbber',
|
||||
'wxDragImage',
|
||||
'wxImage',
|
||||
'wxImageFromStream',
|
||||
'wxMask',
|
||||
'wxArtProvider',
|
||||
]),
|
||||
|
||||
# Other stuff
|
||||
('Miscellaneous', [
|
||||
'ColourDB',
|
||||
'DialogUnits',
|
||||
'DrawXXXList',
|
||||
'FontEnumerator',
|
||||
'PrintFramework',
|
||||
'Throbber',
|
||||
'Unicode',
|
||||
'wxFileHistory',
|
||||
'wxJoystick',
|
||||
'wxOGL',
|
||||
'wxWave',
|
||||
]),
|
||||
|
||||
# need libs not coming with the demo
|
||||
('Objects using an external library', [
|
||||
'ActiveXWrapper_Acrobat',
|
||||
'ActiveXWrapper_IE',
|
||||
'wxGLCanvas',
|
||||
'wxPlotCanvas',
|
||||
]),
|
||||
|
||||
|
||||
('Check out the samples dir too', [
|
||||
]),
|
||||
|
||||
]
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class MyLog(wxPyLog):
|
||||
def __init__(self, textCtrl, logTime=0):
|
||||
wxPyLog.__init__(self)
|
||||
self.tc = textCtrl
|
||||
self.logTime = logTime
|
||||
|
||||
def DoLogString(self, message, timeStamp):
|
||||
if self.logTime:
|
||||
message = time.strftime("%X", time.localtime(timeStamp)) + \
|
||||
": " + message
|
||||
if self.tc:
|
||||
self.tc.AppendText(message + '\n')
|
||||
|
||||
|
||||
class MyTP(wxPyTipProvider):
|
||||
def GetTip(self):
|
||||
return "This is my tip"
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
def opj(path):
|
||||
"""Convert paths to the platform-specific separator"""
|
||||
return apply(os.path.join, tuple(string.split(path, '/')))
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class wxPythonDemo(wxFrame):
|
||||
overviewText = "wxPython Overview"
|
||||
|
||||
def __init__(self, parent, id, title):
|
||||
wxFrame.__init__(self, parent, -1, title, size = (800, 600),
|
||||
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
|
||||
|
||||
self.cwd = os.getcwd()
|
||||
self.curOverview = ""
|
||||
|
||||
icon = images.getMondrianIcon()
|
||||
self.SetIcon(icon)
|
||||
|
||||
if wxPlatform == '__WXMSW__':
|
||||
# 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
|
||||
self.showTip = true
|
||||
EVT_IDLE(self, self.OnIdle)
|
||||
EVT_CLOSE(self, self.OnCloseWindow)
|
||||
EVT_ICONIZE(self, self.OnIconfiy)
|
||||
EVT_MAXIMIZE(self, self.OnMaximize)
|
||||
|
||||
self.Centre(wxBOTH)
|
||||
self.CreateStatusBar(1, wxST_SIZEGRIP)
|
||||
|
||||
splitter = wxSplitterWindow(self, -1, style=wxNO_3D|wxSP_3D)
|
||||
splitter2 = wxSplitterWindow(splitter, -1, style=wxNO_3D|wxSP_3D)
|
||||
|
||||
def EmptyHandler(evt): pass
|
||||
EVT_ERASE_BACKGROUND(splitter, EmptyHandler)
|
||||
EVT_ERASE_BACKGROUND(splitter2, EmptyHandler)
|
||||
|
||||
# Prevent TreeCtrl from displaying all items after destruction when true
|
||||
self.dying = false
|
||||
|
||||
# Make a File menu
|
||||
self.mainmenu = wxMenuBar()
|
||||
menu = wxMenu()
|
||||
exitID = wxNewId()
|
||||
menu.Append(exitID, 'E&xit\tAlt-X', 'Get the heck outta here!')
|
||||
EVT_MENU(self, exitID, self.OnFileExit)
|
||||
self.mainmenu.Append(menu, '&File')
|
||||
|
||||
# Make a Demo menu
|
||||
menu = wxMenu()
|
||||
for item in _treeList:
|
||||
submenu = wxMenu()
|
||||
for childItem in item[1]:
|
||||
mID = wxNewId()
|
||||
submenu.Append(mID, childItem)
|
||||
EVT_MENU(self, mID, self.OnDemoMenu)
|
||||
menu.AppendMenu(wxNewId(), item[0], submenu)
|
||||
self.mainmenu.Append(menu, '&Demo')
|
||||
|
||||
|
||||
# Make a Help menu
|
||||
helpID = wxNewId()
|
||||
menu = wxMenu()
|
||||
menu.Append(helpID, '&About\tCtrl-H', 'wxPython RULES!!!')
|
||||
EVT_MENU(self, helpID, self.OnHelpAbout)
|
||||
self.mainmenu.Append(menu, '&Help')
|
||||
self.SetMenuBar(self.mainmenu)
|
||||
|
||||
# set the menu accellerator table...
|
||||
aTable = wxAcceleratorTable([(wxACCEL_ALT, ord('X'), exitID),
|
||||
(wxACCEL_CTRL, ord('H'), helpID)])
|
||||
self.SetAcceleratorTable(aTable)
|
||||
|
||||
|
||||
# Create a TreeCtrl
|
||||
tID = wxNewId()
|
||||
self.treeMap = {}
|
||||
self.tree = wxTreeCtrl(splitter, tID,
|
||||
style=wxTR_HAS_BUTTONS |
|
||||
wxTR_HAS_VARIABLE_ROW_HEIGHT
|
||||
)
|
||||
|
||||
#self.tree.SetBackgroundColour(wxNamedColour("Pink"))
|
||||
root = self.tree.AddRoot("wxPython Overview")
|
||||
firstChild = None
|
||||
for item in _treeList:
|
||||
child = self.tree.AppendItem(root, item[0])
|
||||
if not firstChild: firstChild = child
|
||||
for childItem in item[1]:
|
||||
theDemo = self.tree.AppendItem(child, childItem)
|
||||
self.treeMap[childItem] = theDemo
|
||||
|
||||
self.tree.Expand(root)
|
||||
self.tree.Expand(firstChild)
|
||||
EVT_TREE_ITEM_EXPANDED (self.tree, tID, self.OnItemExpanded)
|
||||
EVT_TREE_ITEM_COLLAPSED (self.tree, tID, self.OnItemCollapsed)
|
||||
EVT_TREE_SEL_CHANGED (self.tree, tID, self.OnSelChanged)
|
||||
EVT_LEFT_DOWN (self.tree, self.OnTreeLeftDown)
|
||||
|
||||
# Create a Notebook
|
||||
self.nb = wxNotebook(splitter2, -1, style=wxCLIP_CHILDREN)
|
||||
|
||||
# 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, self.overviewText)
|
||||
|
||||
else: # hopefully I can remove this hacky code soon, see bug #216861
|
||||
panel = wxPanel(self.nb, -1, style=wxCLIP_CHILDREN)
|
||||
self.ovr = wxHtmlWindow(panel, -1, size=(400, 400))
|
||||
self.nb.AddPage(panel, self.overviewText)
|
||||
|
||||
def OnOvrSize(evt, ovr=self.ovr):
|
||||
ovr.SetSize(evt.GetSize())
|
||||
|
||||
EVT_SIZE(panel, OnOvrSize)
|
||||
EVT_ERASE_BACKGROUND(panel, EmptyHandler)
|
||||
|
||||
|
||||
self.SetOverview(self.overviewText, overview)
|
||||
|
||||
|
||||
# Set up a TextCtrl on the Demo Code Notebook page
|
||||
self.txt = wxTextCtrl(self.nb, -1,
|
||||
style = wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL|wxTE_RICH2)
|
||||
self.nb.AddPage(self.txt, "Demo Code")
|
||||
|
||||
|
||||
# Set up a log on the View Log Notebook page
|
||||
self.log = wxTextCtrl(splitter2, -1,
|
||||
style = wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL)
|
||||
|
||||
# Set the wxWindows log target to be this textctrl
|
||||
#wxLog_SetActiveTarget(wxLogTextCtrl(self.log))
|
||||
|
||||
# But instead of the above we want to show how to use our own wxLog class
|
||||
wxLog_SetActiveTarget(MyLog(self.log))
|
||||
|
||||
# for serious debugging
|
||||
#wxLog_SetActiveTarget(wxLogStderr())
|
||||
#wxLog_SetTraceMask(wxTraceMessages)
|
||||
|
||||
self.Show(true)
|
||||
|
||||
|
||||
# add the windows to the splitter and split it.
|
||||
splitter2.SplitHorizontally(self.nb, self.log)
|
||||
splitter.SplitVertically(self.tree, splitter2)
|
||||
|
||||
splitter.SetSashPosition(180, true)
|
||||
splitter.SetMinimumPaneSize(20)
|
||||
splitter2.SetSashPosition(450, true)
|
||||
splitter2.SetMinimumPaneSize(20)
|
||||
|
||||
|
||||
|
||||
# select initial items
|
||||
self.nb.SetSelection(0)
|
||||
self.tree.SelectItem(root)
|
||||
|
||||
if len(sys.argv) == 2:
|
||||
try:
|
||||
selectedDemo = self.treeMap[sys.argv[1]]
|
||||
except:
|
||||
selectedDemo = None
|
||||
if selectedDemo:
|
||||
self.tree.SelectItem(selectedDemo)
|
||||
self.tree.EnsureVisible(selectedDemo)
|
||||
|
||||
|
||||
wxLogMessage('window handle: %s' % self.GetHandle())
|
||||
|
||||
|
||||
#---------------------------------------------
|
||||
def WriteText(self, text):
|
||||
if text[-1:] == '\n':
|
||||
text = text[:-1]
|
||||
wxLogMessage(text)
|
||||
|
||||
|
||||
def write(self, txt):
|
||||
self.WriteText(txt)
|
||||
|
||||
#---------------------------------------------
|
||||
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):
|
||||
pt = event.GetPosition();
|
||||
item, flags = self.tree.HitTest(pt)
|
||||
if item == self.tree.GetSelection():
|
||||
self.SetOverview(self.tree.GetItemText(item)+" Overview", self.curOverview)
|
||||
event.Skip()
|
||||
|
||||
#---------------------------------------------
|
||||
def OnSelChanged(self, event):
|
||||
if self.dying:
|
||||
return
|
||||
|
||||
item = event.GetItem()
|
||||
itemText = self.tree.GetItemText(item)
|
||||
self.RunDemo(itemText)
|
||||
|
||||
|
||||
#---------------------------------------------
|
||||
def RunDemo(self, itemText):
|
||||
os.chdir(self.cwd)
|
||||
if self.nb.GetPageCount() == 3:
|
||||
if self.nb.GetSelection() == 2:
|
||||
self.nb.SetSelection(0)
|
||||
wxSafeYield() # in case the page has pending events
|
||||
self.nb.DeletePage(2)
|
||||
|
||||
if itemText == self.overviewText:
|
||||
self.GetDemoFile('Main.py')
|
||||
self.SetOverview(self.overviewText, overview)
|
||||
self.nb.Refresh();
|
||||
self.window = None
|
||||
|
||||
else:
|
||||
if os.path.exists(itemText + '.py'):
|
||||
wxBeginBusyCursor()
|
||||
wxLogMessage("Running demo %s.py..." % itemText)
|
||||
try:
|
||||
self.GetDemoFile(itemText + '.py')
|
||||
module = __import__(itemText, globals())
|
||||
self.SetOverview(itemText + " Overview", module.overview)
|
||||
finally:
|
||||
wxEndBusyCursor()
|
||||
self.tree.Refresh()
|
||||
|
||||
# in case runTest is modal, make sure things look right...
|
||||
self.nb.Refresh();
|
||||
wxSafeYield()
|
||||
|
||||
self.window = module.runTest(self, self.nb, self) ###
|
||||
if self.window:
|
||||
self.nb.AddPage(self.window, 'Demo')
|
||||
self.nb.SetSelection(2)
|
||||
self.nb.Refresh() # without this wxMac has troubles showing the just added page
|
||||
|
||||
else:
|
||||
self.ovr.SetPage("")
|
||||
self.txt.Clear()
|
||||
self.window = None
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------
|
||||
# Get the Demo files
|
||||
def GetDemoFile(self, filename):
|
||||
self.txt.Clear()
|
||||
try:
|
||||
self.txt.SetValue(open(filename).read())
|
||||
except IOError:
|
||||
self.txt.WriteText("Cannot open %s file." % filename)
|
||||
|
||||
self.txt.SetInsertionPoint(0)
|
||||
self.txt.ShowPosition(0)
|
||||
|
||||
#---------------------------------------------
|
||||
def SetOverview(self, name, text):
|
||||
self.curOverview = text
|
||||
lead = text[:6]
|
||||
if lead != '<html>' and lead != '<HTML>':
|
||||
text = string.join(string.split(text, '\n'), '<br>')
|
||||
self.ovr.SetPage(text)
|
||||
self.nb.SetPageText(0, name)
|
||||
|
||||
#---------------------------------------------
|
||||
# Menu methods
|
||||
def OnFileExit(self, *event):
|
||||
self.Close()
|
||||
|
||||
|
||||
def OnHelpAbout(self, event):
|
||||
from About import MyAboutBox
|
||||
about = MyAboutBox(self)
|
||||
about.ShowModal()
|
||||
about.Destroy()
|
||||
|
||||
|
||||
#---------------------------------------------
|
||||
def OnCloseWindow(self, event):
|
||||
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:
|
||||
self.otherWin.Raise()
|
||||
self.window = self.otherWin
|
||||
self.otherWin = None
|
||||
|
||||
if self.showTip:
|
||||
self.ShowTip()
|
||||
self.showTip = false
|
||||
|
||||
|
||||
#---------------------------------------------
|
||||
def ShowTip(self):
|
||||
try:
|
||||
showTipText = open(opj("data/showTips")).read()
|
||||
showTip, index = eval(showTipText)
|
||||
except IOError:
|
||||
showTip, index = (1, 0)
|
||||
if showTip:
|
||||
tp = wxCreateFileTipProvider(opj("data/tips.txt"), index)
|
||||
##tp = MyTP(0)
|
||||
showTip = wxShowTip(self, tp)
|
||||
index = tp.GetCurrentTip()
|
||||
open(opj("data/showTips"), "w").write(str( (showTip, index) ))
|
||||
|
||||
|
||||
#---------------------------------------------
|
||||
def OnDemoMenu(self, event):
|
||||
try:
|
||||
selectedDemo = self.treeMap[self.mainmenu.GetLabel(event.GetId())]
|
||||
except:
|
||||
selectedDemo = None
|
||||
if selectedDemo:
|
||||
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()
|
||||
|
||||
|
||||
#---------------------------------------------
|
||||
def OnIconfiy(self, evt):
|
||||
wxLogMessage("OnIconfiy")
|
||||
evt.Skip()
|
||||
|
||||
#---------------------------------------------
|
||||
def OnMaximize(self, evt):
|
||||
wxLogMessage("OnMaximize")
|
||||
evt.Skip()
|
||||
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class MySplashScreen(wxSplashScreen):
|
||||
def __init__(self):
|
||||
bmp = wxImage(opj("bitmaps/splash.gif")).ConvertToBitmap()
|
||||
wxSplashScreen.__init__(self, bmp,
|
||||
wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT,
|
||||
4000, None, -1,
|
||||
style = wxSIMPLE_BORDER|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP)
|
||||
EVT_CLOSE(self, self.OnClose)
|
||||
|
||||
def OnClose(self, evt):
|
||||
frame = wxPythonDemo(None, -1, "wxPython: (A Demonstration)")
|
||||
frame.Show(true)
|
||||
evt.Skip() # Make sure the default handler runs too...
|
||||
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
"""
|
||||
Create and show the splash screen. It will then create and show
|
||||
the main frame when it is time to do so.
|
||||
"""
|
||||
wxInitAllImageHandlers()
|
||||
splash = MySplashScreen()
|
||||
splash.Show()
|
||||
return true
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
def main():
|
||||
try:
|
||||
demoPath = os.path.dirname(__file__)
|
||||
os.chdir(demoPath)
|
||||
except:
|
||||
pass
|
||||
app = MyApp(wxPlatform == "__WXMAC__")
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
overview = """<html><body>
|
||||
<h2>Python</h2>
|
||||
|
||||
Python is an interpreted, interactive, object-oriented programming
|
||||
language often compared to Tcl, Perl, Scheme, or Java.
|
||||
|
||||
<p> Python combines remarkable power with very clear syntax. It has
|
||||
modules, classes, exceptions, very high level dynamic data types, and
|
||||
dynamic typing. There are interfaces to many system calls and
|
||||
libraries, and new built-in modules are easily written in C or
|
||||
C++. Python is also usable as an extension language for applications
|
||||
that need a programmable interface. <p>
|
||||
|
||||
<h2>wxWindows</h2>
|
||||
|
||||
wxWindows is a free C++ framework designed to make cross-platform
|
||||
programming child's play. Well, almost. wxWindows 2 supports Windows
|
||||
3.1/95/98/NT, Unix with GTK/Motif/Lesstif, with a Mac version
|
||||
underway. Other ports are under consideration. <p>
|
||||
|
||||
wxWindows is a set of libraries that allows C++ applications to
|
||||
compile and run on several different types of computers, with minimal
|
||||
source code changes. There is one library per supported GUI (such as
|
||||
Motif, or Windows). As well as providing a common API (Application
|
||||
Programming Interface) for GUI functionality, it provides
|
||||
functionality for accessing some commonly-used operating system
|
||||
facilities, such as copying or deleting files. wxWindows is a
|
||||
'framework' in the sense that it provides a lot of built-in
|
||||
functionality, which the application can use or replace as required,
|
||||
thus saving a great deal of coding effort. Basic data structures such
|
||||
as strings, linked lists and hash tables are also supported.
|
||||
|
||||
<p>
|
||||
<h2>wxPython</h2>
|
||||
|
||||
wxPython is a Python extension module that encapsulates the wxWindows
|
||||
GUI classes. Currently it is only available for the Win32 and GTK
|
||||
ports of wxWindows, but as soon as the other ports are brought up to
|
||||
the same level as Win32 and GTK, it should be fairly trivial to
|
||||
enable wxPython to be used with the new GUI.
|
||||
|
||||
<p>
|
||||
|
||||
The wxPython extension module attempts to mirror the class heiarchy
|
||||
of wxWindows as closely as possible. This means that there is a
|
||||
wxFrame class in wxPython that looks, smells, tastes and acts almost
|
||||
the same as the wxFrame class in the C++ version. Unfortunately,
|
||||
because of differences in the languages, wxPython doesn't match
|
||||
wxWindows exactly, but the differences should be easy to absorb
|
||||
because they are natural to Python. For example, some methods that
|
||||
return multiple values via argument pointers in C++ will return a
|
||||
tuple of values in Python.
|
||||
|
||||
<p>
|
||||
|
||||
There is still much to be done for wxPython, many classes still need
|
||||
to be mirrored. Also, wxWindows is still somewhat of a moving target
|
||||
so it is a bit of an effort just keeping wxPython up to date. On the
|
||||
other hand, there are enough of the core classes completed that
|
||||
useful applications can be written.
|
||||
|
||||
<p>
|
||||
|
||||
wxPython is close enough to the C++ version that the majority of
|
||||
the wxPython documentation is actually just notes attached to the C++
|
||||
documents that describe the places where wxPython is different. There
|
||||
is also a series of sample programs included, and a series of
|
||||
documentation pages that assist the programmer in getting started
|
||||
with wxPython.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,138 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.html import *
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
BTN1 = wxNewId()
|
||||
BTN2 = wxNewId()
|
||||
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
self.log = log
|
||||
|
||||
sizer = wxBoxSizer(wxVERTICAL)
|
||||
html = wxHtmlWindow(self, -1)
|
||||
html.SetPage(overview)
|
||||
sizer.Add(html, 1, wxEXPAND|wxALL, 5)
|
||||
|
||||
btns = wxBoxSizer(wxHORIZONTAL)
|
||||
btns.Add(50, -1, 1, wxEXPAND)
|
||||
btn1 = wxButton(self, BTN1, "Find My Alter-ego") # don't save a ref to this one
|
||||
btns.Add(btn1)
|
||||
btns.Add(50, -1, 1, wxEXPAND)
|
||||
self.btn2 = wxButton(self, BTN2, "Find Myself")
|
||||
btns.Add(self.btn2)
|
||||
btns.Add(50, -1, 1, wxEXPAND)
|
||||
|
||||
sizer.Add(btns, 0, wxEXPAND|wxALL, 15)
|
||||
|
||||
self.SetSizer(sizer)
|
||||
self.SetAutoLayout(true)
|
||||
|
||||
self.sizer = sizer # save it for testing later
|
||||
|
||||
EVT_BUTTON(self, BTN1, self.OnFindButton1)
|
||||
EVT_BUTTON(self, BTN2, self.OnFindButton2)
|
||||
|
||||
|
||||
def OnFindButton1(self, evt):
|
||||
win = self.FindWindowById(BTN1)
|
||||
if win is None:
|
||||
self.log.write("***** OOPS! None returned...\n")
|
||||
return
|
||||
className = win.__class__.__name__
|
||||
if className in ["wxButton", "wxButtonPtr"]:
|
||||
self.log.write("The types are the same! <grin>\n")
|
||||
else:
|
||||
self.log.write("Got %s, expected wxButton or wxButtonPtr\n" % className)
|
||||
|
||||
|
||||
|
||||
def OnFindButton2(self, evt):
|
||||
win = self.FindWindowById(BTN2)
|
||||
if win is None:
|
||||
self.log.write("***** OOPS! None returned...\n")
|
||||
return
|
||||
if win is self.btn2:
|
||||
self.log.write("The objects are the same! <grin>\n")
|
||||
else:
|
||||
self.log.write("The objects are NOT the same! <frown>\n")
|
||||
|
||||
win = evt.GetEventObject()
|
||||
if win is None:
|
||||
self.log.write("***** OOPS! None returned...\n")
|
||||
return
|
||||
if win is self.btn2:
|
||||
self.log.write("The objects are the same! <grin>\n")
|
||||
else:
|
||||
self.log.write("The objects are NOT the same! <frown>\n")
|
||||
|
||||
sizer = self.GetSizer()
|
||||
if sizer is None:
|
||||
self.log.write("***** OOPS! None returned...\n")
|
||||
return
|
||||
if sizer is self.sizer:
|
||||
self.log.write("The objects are the same! <grin>\n")
|
||||
else:
|
||||
self.log.write("The objects are NOT the same! <frown>\n")
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPanel(nb, log)
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
overview = """\
|
||||
<html><body>
|
||||
<h2>Original Object Return</h2>
|
||||
|
||||
<p>Several methods in wxWindows return pointers to base class objects,
|
||||
when in fact the actual object pointed to is of a derived type. Since
|
||||
SWIG isn't able to tell the actual type it just creates a new Python
|
||||
shadow object of the base type to wrap around the base type pointer
|
||||
and returns it.
|
||||
|
||||
<p>In wxPython prior to 2.3.0 this could cause annoying issues. For
|
||||
example if you called:
|
||||
|
||||
<pre>
|
||||
|
||||
myText = someWindow.FindWindowById(txtID)
|
||||
</pre>
|
||||
|
||||
expecting to get a wxTextCtrl you would actually get a wxWindow object
|
||||
instead. If you then try to call SetValue on that object you'll get
|
||||
an exception since there is no such method. This is the reason for
|
||||
the wxPyTypeCast hack that has been in wxPython for so long.
|
||||
|
||||
<p>Even with wxPyTypeCast there was the issue that the object returned
|
||||
was not the same one that was created in Python originally, but a new
|
||||
object of the same type that wraps the same C++ pointer. If the
|
||||
programmer has set additional attributes of that original object they
|
||||
will not exist in the new object.
|
||||
|
||||
<p>For a long time now I have wanted to do away with wxPyTypeCast and
|
||||
also find a way to return the original Python object from methods like
|
||||
FindWindowById. This project naturally divides into two phases:
|
||||
|
||||
<p><ol>
|
||||
|
||||
<li>Teach the wrapper methods how to return objects of the right type,
|
||||
and be able to then turn wxPyTypeCast in to a no-op.
|
||||
|
||||
<li>Be able to return the original Python shadow object if it still exists.
|
||||
|
||||
</ol>
|
||||
|
||||
<p>The first button below shows the first of these phases (<i>working</i>)
|
||||
and the second will show #2 (<i>working as of 2.3.2</i>)
|
||||
|
||||
</body></html>
|
||||
"""
|
@@ -1,178 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxScrolledWindow import MyCanvas
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class MyPrintout(wxPrintout):
|
||||
def __init__(self, canvas, log):
|
||||
wxPrintout.__init__(self)
|
||||
self.canvas = canvas
|
||||
self.log = log
|
||||
|
||||
def OnBeginDocument(self, start, end):
|
||||
self.log.WriteText("wxPrintout.OnBeginDocument\n")
|
||||
return self.base_OnBeginDocument(start, end)
|
||||
|
||||
def OnEndDocument(self):
|
||||
self.log.WriteText("wxPrintout.OnEndDocument\n")
|
||||
self.base_OnEndDocument()
|
||||
|
||||
def OnBeginPrinting(self):
|
||||
self.log.WriteText("wxPrintout.OnBeginPrinting\n")
|
||||
self.base_OnBeginPrinting()
|
||||
|
||||
def OnEndPrinting(self):
|
||||
self.log.WriteText("wxPrintout.OnEndPrinting\n")
|
||||
self.base_OnEndPrinting()
|
||||
|
||||
def OnPreparePrinting(self):
|
||||
self.log.WriteText("wxPrintout.OnPreparePrinting\n")
|
||||
self.base_OnPreparePrinting()
|
||||
|
||||
def HasPage(self, page):
|
||||
self.log.WriteText("wxPrintout.HasPage: %d\n" % page)
|
||||
if page <= 2:
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
def GetPageInfo(self):
|
||||
self.log.WriteText("wxPrintout.GetPageInfo\n")
|
||||
return (1, 2, 1, 2)
|
||||
|
||||
def OnPrintPage(self, page):
|
||||
self.log.WriteText("wxPrintout.OnPrintPage: %d\n" % page)
|
||||
dc = self.GetDC()
|
||||
|
||||
#-------------------------------------------
|
||||
# One possible method of setting scaling factors...
|
||||
|
||||
maxX = self.canvas.getWidth()
|
||||
maxY = self.canvas.getHeight()
|
||||
|
||||
# Let's have at least 50 device units margin
|
||||
marginX = 50
|
||||
marginY = 50
|
||||
|
||||
# Add the margin to the graphic size
|
||||
maxX = maxX + (2 * marginX)
|
||||
maxY = maxY + (2 * marginY)
|
||||
|
||||
# Get the size of the DC in pixels
|
||||
(w, h) = dc.GetSizeTuple()
|
||||
|
||||
# Calculate a suitable scaling factor
|
||||
scaleX = float(w) / maxX
|
||||
scaleY = float(h) / maxY
|
||||
|
||||
# Use x or y scaling factor, whichever fits on the DC
|
||||
actualScale = min(scaleX, scaleY)
|
||||
|
||||
# Calculate the position on the DC for centring the graphic
|
||||
posX = (w - (self.canvas.getWidth() * actualScale)) / 2.0
|
||||
posY = (h - (self.canvas.getHeight() * actualScale)) / 2.0
|
||||
|
||||
# Set the scale and origin
|
||||
dc.SetUserScale(actualScale, actualScale)
|
||||
dc.SetDeviceOrigin(int(posX), int(posY))
|
||||
|
||||
#-------------------------------------------
|
||||
|
||||
self.canvas.DoDrawing(dc)
|
||||
dc.DrawText("Page: %d" % page, marginX/2, maxY-marginY)
|
||||
|
||||
return true
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
class TestPrintPanel(wxPanel):
|
||||
def __init__(self, parent, frame, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
self.log = log
|
||||
self.frame = frame
|
||||
|
||||
|
||||
self.printData = wxPrintData()
|
||||
self.printData.SetPaperId(wxPAPER_LETTER)
|
||||
|
||||
self.box = wxBoxSizer(wxVERTICAL)
|
||||
self.canvas = MyCanvas(self)
|
||||
self.box.Add(self.canvas, 1, wxGROW)
|
||||
|
||||
subbox = wxBoxSizer(wxHORIZONTAL)
|
||||
btn = wxButton(self, 1201, "Print Setup")
|
||||
EVT_BUTTON(self, 1201, self.OnPrintSetup)
|
||||
subbox.Add(btn, 1, wxGROW | wxALL, 2)
|
||||
|
||||
btn = wxButton(self, 1202, "Print Preview")
|
||||
EVT_BUTTON(self, 1202, self.OnPrintPreview)
|
||||
subbox.Add(btn, 1, wxGROW | wxALL, 2)
|
||||
|
||||
btn = wxButton(self, 1203, "Print")
|
||||
EVT_BUTTON(self, 1203, self.OnDoPrint)
|
||||
subbox.Add(btn, 1, wxGROW | wxALL, 2)
|
||||
|
||||
self.box.Add(subbox, 0, wxGROW)
|
||||
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(self.box)
|
||||
|
||||
|
||||
def OnPrintSetup(self, event):
|
||||
printerDialog = wxPrintDialog(self)
|
||||
printerDialog.GetPrintDialogData().SetPrintData(self.printData)
|
||||
printerDialog.GetPrintDialogData().SetSetupDialog(true)
|
||||
printerDialog.ShowModal();
|
||||
self.printData = printerDialog.GetPrintDialogData().GetPrintData()
|
||||
printerDialog.Destroy()
|
||||
|
||||
|
||||
def OnPrintPreview(self, event):
|
||||
self.log.WriteText("OnPrintPreview\n")
|
||||
printout = MyPrintout(self.canvas, self.log)
|
||||
printout2 = MyPrintout(self.canvas, self.log)
|
||||
self.preview = wxPrintPreview(printout, printout2, self.printData)
|
||||
if not self.preview.Ok():
|
||||
self.log.WriteText("Houston, we have a problem...\n")
|
||||
return
|
||||
|
||||
frame = wxPreviewFrame(self.preview, self.frame, "This is a print preview")
|
||||
|
||||
frame.Initialize()
|
||||
frame.SetPosition(self.frame.GetPosition())
|
||||
frame.SetSize(self.frame.GetSize())
|
||||
frame.Show(true)
|
||||
|
||||
|
||||
|
||||
def OnDoPrint(self, event):
|
||||
pdd = wxPrintDialogData()
|
||||
pdd.SetPrintData(self.printData)
|
||||
printer = wxPrinter(pdd)
|
||||
printout = MyPrintout(self.canvas, self.log)
|
||||
if not printer.Print(self.frame, printout):
|
||||
wxMessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wxOK)
|
||||
else:
|
||||
self.printData = printer.GetPrintDialogData().GetPrintData()
|
||||
printout.Destroy()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPrintPanel(nb, frame, log)
|
||||
return win
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
overview = """\
|
||||
"""
|
||||
|
@@ -1,23 +0,0 @@
|
||||
|
||||
|
||||
from wxPython.lib.PyCrust import shell, version
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
intro = 'Welcome To PyCrust %s - The Flakiest Python Shell' % version.VERSION
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = shell.Shell(nb, -1, introText=intro)
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
overview = shell.__doc__
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys,os
|
||||
import run
|
||||
run.main(['', os.path.basename(sys.argv[0])])
|
||||
|
@@ -1,28 +0,0 @@
|
||||
|
||||
from wxPython.wx import wxSplitterWindow
|
||||
from wxPython.lib.PyCrust import shell, version, filling
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
intro = 'Welcome To PyCrust %s - The Flakiest Python Shell' % version.VERSION
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = wxSplitterWindow(nb, -1, size=(640, 480))
|
||||
shellWin = shell.Shell(win, -1, introText=intro)
|
||||
fillingWin = filling.Filling(win, -1, size=(640, 480),
|
||||
rootObject=shellWin.interp.locals,
|
||||
rootIsNamespace=1
|
||||
)
|
||||
win.SplitHorizontally(shellWin, fillingWin)
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
overview = filling.__doc__
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys,os
|
||||
import run
|
||||
run.main(['', os.path.basename(sys.argv[0])])
|
||||
|
@@ -1,85 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
import sys
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
myEVT_BUTTON_CLICKPOS = wxNewEventType()
|
||||
|
||||
def EVT_BUTTON_CLICKPOS(win, id, func):
|
||||
win.Connect(id, -1, myEVT_BUTTON_CLICKPOS, func)
|
||||
|
||||
|
||||
|
||||
class MyEvent(wxPyCommandEvent):
|
||||
def __init__(self, evtType, id):
|
||||
wxPyCommandEvent.__init__(self, evtType, id)
|
||||
self.myVal = None
|
||||
|
||||
#def __del__(self):
|
||||
# print '__del__'
|
||||
# wxPyCommandEvent.__del__(self)
|
||||
|
||||
def SetMyVal(self, val):
|
||||
self.myVal = val
|
||||
|
||||
def GetMyVal(self):
|
||||
return self.myVal
|
||||
|
||||
|
||||
|
||||
class MyButton(wxButton):
|
||||
def __init__(self, parent, id, txt, pos):
|
||||
wxButton.__init__(self, parent, id, txt, pos)
|
||||
EVT_LEFT_DOWN(self, self.OnLeftDown)
|
||||
|
||||
def OnLeftDown(self, event):
|
||||
pt = event.GetPosition()
|
||||
evt = MyEvent(myEVT_BUTTON_CLICKPOS, self.GetId())
|
||||
evt.SetMyVal(pt)
|
||||
#print id(evt), sys.getrefcount(evt)
|
||||
self.GetEventHandler().ProcessEvent(evt)
|
||||
#print id(evt), sys.getrefcount(evt)
|
||||
event.Skip()
|
||||
|
||||
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
self.log = log
|
||||
|
||||
b = MyButton(self, -1, " Click me ", wxPoint(30,30))
|
||||
EVT_BUTTON(self, b.GetId(), self.OnClick)
|
||||
EVT_BUTTON_CLICKPOS(self, b.GetId(), self.OnMyEvent)
|
||||
|
||||
wxStaticText(self, -1, "Please see the Overview and Demo Code for details...",
|
||||
wxPoint(30, 80))
|
||||
|
||||
|
||||
def OnClick(self, event):
|
||||
self.log.WriteText("OnClick\n")
|
||||
|
||||
def OnMyEvent(self, event):
|
||||
#print id(event), sys.getrefcount(event)
|
||||
self.log.WriteText("MyEvent: %s\n" % (event.GetMyVal(), ) )
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPanel(nb, log)
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
overview = """\
|
||||
This demo is a contrived example of defining an event class in wxPython and sending it up the containment heirachy for processing.
|
||||
"""
|
||||
|
||||
|
||||
|
||||
|
@@ -1,7 +0,0 @@
|
||||
To run the main demo in this directory, execute demo.py. In other
|
||||
words, one of the following commands should do it:
|
||||
|
||||
demo.py
|
||||
python demo.py
|
||||
pythonw demo.py
|
||||
|
@@ -1,69 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.rcsizer import RowColSizer
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
|
||||
sizer = RowColSizer()
|
||||
text = "This sizer lays out it's items by row and column "\
|
||||
"that are specified explicitly when the item is \n"\
|
||||
"added to the sizer. Grid cells with nothing in "\
|
||||
"them are supported and column- or row-spanning is \n"\
|
||||
"handled as well. Growable rows and columns are "\
|
||||
"specified just like the wxFlexGridSizer."
|
||||
|
||||
sizer.Add(wxStaticText(self, -1, text), row=1, col=1, colspan=5)
|
||||
|
||||
sizer.Add(wxTextCtrl(self, -1, "(3,1)"), flag=wxEXPAND, row=3, col=1)
|
||||
sizer.Add(wxTextCtrl(self, -1, "(3,2)"), row=3, col=2)
|
||||
sizer.Add(wxTextCtrl(self, -1, "(3,3)"), row=3, col=3)
|
||||
sizer.Add(wxTextCtrl(self, -1, "(3,4)"), row=3, col=4)
|
||||
sizer.Add(wxTextCtrl(self, -1, "(4,2) span:(2,2)"), flag=wxEXPAND,
|
||||
row=4, col=2, rowspan=2, colspan=2)
|
||||
sizer.Add(wxTextCtrl(self, -1, "(6,4)"), row=6, col=4)
|
||||
sizer.Add(wxTextCtrl(self, -1, "(7,2)"), row=7, col=2)
|
||||
sizer.Add(wxTextCtrl(self, -1, "(8,3)"), row=8, col=3)
|
||||
sizer.Add(wxTextCtrl(self, -1, "(10,1) colspan: 4"), flag=wxEXPAND, pos=(10,1), colspan=4)
|
||||
sizer.Add(wxTextCtrl(self, -1, "(3,5) rowspan: 8, growable col", style=wxTE_MULTILINE),
|
||||
flag=wxEXPAND, pos=(3,5), size=(8,1))
|
||||
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
box.Add(wxButton(self, -1, "A vertical box"), flag=wxEXPAND)
|
||||
box.Add(wxButton(self, -1, "sizer put in the"), flag=wxEXPAND)
|
||||
box.Add(wxButton(self, -1, "RowColSizer at (12,1)"), flag=wxEXPAND)
|
||||
sizer.Add(box, pos=(12,1))
|
||||
|
||||
sizer.Add(wxTextCtrl(self, -1, "(12,2) align bottom"), flag=wxALIGN_BOTTOM, pos=(12,2))
|
||||
sizer.Add(wxTextCtrl(self, -1, "(12,3) align center"), flag=wxALIGN_CENTER_VERTICAL, pos=(12,3))
|
||||
sizer.Add(wxTextCtrl(self, -1, "(12,4)"),pos=(12,4))
|
||||
sizer.Add(wxTextCtrl(self, -1, "(12,5) full border"), flag=wxEXPAND|wxALL, border=15, pos=(12,5))
|
||||
|
||||
sizer.AddGrowableCol(5)
|
||||
sizer.AddGrowableRow(9)
|
||||
|
||||
sizer.AddSpacer(10,10, pos=(1,6))
|
||||
sizer.AddSpacer(10,10, pos=(13,1))
|
||||
|
||||
self.SetSizer(sizer)
|
||||
self.SetAutoLayout(true)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPanel(nb)
|
||||
return win
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
import wxPython.lib.rcsizer
|
||||
overview = wxPython.lib.rcsizer.__doc__
|
||||
|
||||
|
@@ -1,97 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
text = "one two buckle my shoe three four shut the door five six pick up sticks seven eight lay them straight nine ten big fat hen"
|
||||
|
||||
|
||||
class ScrolledPanel(wxScrolledWindow):
|
||||
def __init__(self, parent, log):
|
||||
self.log = log
|
||||
wxScrolledWindow.__init__(self, parent, -1,
|
||||
style = wxTAB_TRAVERSAL)
|
||||
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
box.Add(wxStaticText(self, -1,
|
||||
"This sample shows how to make a scrollable data entry \n"
|
||||
"form by using a wxSizer in a wxScrolledWindow."),
|
||||
0, wxCENTER|wxALL, 5)
|
||||
box.Add(wxStaticLine(self, -1), 0, wxEXPAND|wxALL, 5)
|
||||
|
||||
fgs = wxFlexGridSizer(cols=2, vgap=4, hgap=4)
|
||||
fgs.AddGrowableCol(1)
|
||||
|
||||
# Add some spacers
|
||||
fgs.Add(75, 10)
|
||||
fgs.Add(150, 10)
|
||||
|
||||
for word in text.split():
|
||||
label = wxStaticText(self, -1, word+":")
|
||||
tc = wxTextCtrl(self, -1, word)
|
||||
fgs.Add(label, flag=wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL)
|
||||
fgs.Add(tc, flag=wxEXPAND)
|
||||
|
||||
box.Add(fgs, 1)
|
||||
box.Add(10, 40) # some more empty space at the bottom
|
||||
self.SetSizer(box)
|
||||
|
||||
|
||||
# The following is all that is needed to integrate the sizer and the
|
||||
# scrolled window. In this case we will only support vertical scrolling.
|
||||
self.EnableScrolling(false, true)
|
||||
self.SetScrollRate(0, 20)
|
||||
box.SetVirtualSizeHints(self)
|
||||
EVT_CHILD_FOCUS(self, self.OnChildFocus)
|
||||
|
||||
wxCallAfter(self.Scroll, 0, 0) # scroll back to top after initial events
|
||||
|
||||
|
||||
def OnChildFocus(self, evt):
|
||||
# If the child window that gets the focus is not visible,
|
||||
# this handler will try to scroll enough to see it. If you
|
||||
# need to handle horizontal auto-scrolling too then this will
|
||||
# need adapted.
|
||||
evt.Skip()
|
||||
child = evt.GetWindow()
|
||||
|
||||
sppu_y = self.GetScrollPixelsPerUnit()[1]
|
||||
vs_y = self.GetViewStart()[1]
|
||||
cpos = child.GetPosition()
|
||||
csz = child.GetSize()
|
||||
|
||||
# is it above the top?
|
||||
if cpos.y < 0:
|
||||
new_vs = cpos.y / sppu_y
|
||||
self.Scroll(-1, new_vs)
|
||||
|
||||
# is it below the bottom ?
|
||||
if cpos.y + csz.height > self.GetClientSize().height:
|
||||
diff = (cpos.y + csz.height - self.GetClientSize().height) / sppu_y
|
||||
self.Scroll(-1, vs_y + diff + 1)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = ScrolledPanel(nb, log)
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
overview = """<html><body>
|
||||
This sample shows how to make a scrollable data entry form by
|
||||
using a wxSizer in a wxScrolledWindow.
|
||||
</body></html>
|
||||
"""
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys,os
|
||||
import run
|
||||
run.main(['', os.path.basename(sys.argv[0])])
|
||||
|
@@ -1,587 +0,0 @@
|
||||
#----------------------------------------------------------------------
|
||||
# sizer test code
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.grids import wxGridSizer, wxFlexGridSizer
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox1(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "three"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "four"), 0, wxEXPAND)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox2(win):
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "three"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "four"), 0, wxEXPAND)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox3(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "three"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "four"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "five"), 1, wxEXPAND)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox4(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "three"), 1, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "four"), 1, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "five"), 1, wxEXPAND)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox5(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "three"), 3, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "four"), 1, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "five"), 1, wxEXPAND)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox6(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 1, wxALIGN_TOP)
|
||||
box.Add(wxButton(win, 1010, "two"), 1, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "three"), 1, wxALIGN_CENTER)
|
||||
box.Add(wxButton(win, 1010, "four"), 1, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "five"), 1, wxALIGN_BOTTOM)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox7(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "three"), 0, wxEXPAND)
|
||||
box.Add(60, 20, 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "five"), 1, wxEXPAND)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBox8(win):
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
|
||||
box.Add(0,0, 1)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxALIGN_CENTER)
|
||||
box.Add(0,0, 1)
|
||||
box.Add(wxButton(win, 1010, "three"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "four"), 0, wxEXPAND)
|
||||
# box.Add(wxButton(win, 1010, "five"), 1, wxEXPAND)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBorder1(win):
|
||||
bdr = wxBoxSizer(wxHORIZONTAL)
|
||||
btn = wxButton(win, 1010, "border")
|
||||
btn.SetSize(wxSize(80, 80))
|
||||
bdr.Add(btn, 1, wxEXPAND|wxALL, 15)
|
||||
|
||||
return bdr
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBorder2(win):
|
||||
bdr = wxBoxSizer(wxHORIZONTAL)
|
||||
btn = wxButton(win, 1010, "border")
|
||||
btn.SetSize(wxSize(80, 80))
|
||||
bdr.Add(btn, 1, wxEXPAND | wxEAST | wxWEST, 15)
|
||||
|
||||
return bdr
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBorder3(win):
|
||||
bdr = wxBoxSizer(wxHORIZONTAL)
|
||||
btn = wxButton(win, 1010, "border")
|
||||
btn.SetSize(wxSize(80, 80))
|
||||
bdr.Add(btn, 1, wxEXPAND | wxNORTH | wxWEST, 15)
|
||||
|
||||
return bdr
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeBoxInBox(win):
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
|
||||
|
||||
box2 = wxBoxSizer(wxHORIZONTAL)
|
||||
box2.AddMany([ (wxButton(win, 1010, "two"), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, "three"), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, "four"), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, "five"), 0, wxEXPAND),
|
||||
])
|
||||
|
||||
box3 = wxBoxSizer(wxVERTICAL)
|
||||
box3.AddMany([ (wxButton(win, 1010, "six"), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, "seven"), 2, wxEXPAND),
|
||||
(wxButton(win, 1010, "eight"), 1, wxEXPAND),
|
||||
(wxButton(win, 1010, "nine"), 1, wxEXPAND),
|
||||
])
|
||||
|
||||
box2.Add(box3, 1, wxEXPAND)
|
||||
box.Add(box2, 1, wxEXPAND)
|
||||
|
||||
box.Add(wxButton(win, 1010, "ten"), 0, wxEXPAND)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeBoxInBorder(win):
|
||||
bdr = wxBoxSizer(wxHORIZONTAL)
|
||||
box = makeSimpleBox3(win)
|
||||
bdr.Add(box, 1, wxEXPAND | wxALL, 15)
|
||||
|
||||
return bdr
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeBorderInBox(win):
|
||||
insideBox = wxBoxSizer(wxHORIZONTAL)
|
||||
|
||||
box2 = wxBoxSizer(wxHORIZONTAL)
|
||||
box2.AddMany([ (wxButton(win, 1010, "one"), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, "two"), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, "three"), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, "four"), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, "five"), 0, wxEXPAND),
|
||||
])
|
||||
|
||||
insideBox.Add(box2, 0, wxEXPAND)
|
||||
|
||||
bdr = wxBoxSizer(wxHORIZONTAL)
|
||||
bdr.Add(wxButton(win, 1010, "border"), 1, wxEXPAND | wxALL)
|
||||
insideBox.Add(bdr, 1, wxEXPAND | wxALL, 20)
|
||||
|
||||
box3 = wxBoxSizer(wxVERTICAL)
|
||||
box3.AddMany([ (wxButton(win, 1010, "six"), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, "seven"), 2, wxEXPAND),
|
||||
(wxButton(win, 1010, "eight"), 1, wxEXPAND),
|
||||
(wxButton(win, 1010, "nine"), 1, wxEXPAND),
|
||||
])
|
||||
insideBox.Add(box3, 1, wxEXPAND)
|
||||
|
||||
outsideBox = wxBoxSizer(wxVERTICAL)
|
||||
outsideBox.Add(wxButton(win, 1010, "top"), 0, wxEXPAND)
|
||||
outsideBox.Add(insideBox, 1, wxEXPAND)
|
||||
outsideBox.Add(wxButton(win, 1010, "bottom"), 0, wxEXPAND)
|
||||
|
||||
return outsideBox
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeGrid1(win):
|
||||
gs = wxGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
|
||||
|
||||
gs.AddMany([ (wxButton(win, 1010, 'one'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'two'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'three'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'four'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'five'), 0, wxEXPAND),
|
||||
#(75, 50),
|
||||
(wxButton(win, 1010, 'six'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'seven'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'eight'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'nine'), 0, wxEXPAND),
|
||||
])
|
||||
|
||||
return gs
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeGrid2(win):
|
||||
gs = wxGridSizer(3, 3) # rows, cols, hgap, vgap
|
||||
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
box.Add(wxButton(win, 1010, 'A'), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, 'B'), 1, wxEXPAND)
|
||||
|
||||
gs2 = wxGridSizer(2,2, 4, 4)
|
||||
gs2.AddMany([ (wxButton(win, 1010, 'C'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'E'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'F'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'G'), 0, wxEXPAND)])
|
||||
|
||||
gs.AddMany([ (wxButton(win, 1010, 'one'), 0, wxALIGN_RIGHT | wxALIGN_BOTTOM),
|
||||
(wxButton(win, 1010, 'two'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'three'), 0, wxALIGN_LEFT | wxALIGN_BOTTOM),
|
||||
(wxButton(win, 1010, 'four'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'five'), 0, wxALIGN_CENTER),
|
||||
(wxButton(win, 1010, 'six'), 0, wxEXPAND),
|
||||
(box, 0, wxEXPAND | wxALL, 10),
|
||||
(wxButton(win, 1010, 'eight'), 0, wxEXPAND),
|
||||
(gs2, 0, wxEXPAND | wxALL, 4),
|
||||
])
|
||||
|
||||
return gs
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeGrid3(win):
|
||||
gs = wxFlexGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
|
||||
|
||||
gs.AddMany([ (wxButton(win, 1010, 'one'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'two'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'three'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'four'), 0, wxEXPAND),
|
||||
#(wxButton(win, 1010, 'five'), 0, wxEXPAND),
|
||||
(175, 50),
|
||||
(wxButton(win, 1010, 'six'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'seven'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'eight'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'nine'), 0, wxEXPAND),
|
||||
])
|
||||
|
||||
gs.AddGrowableRow(0)
|
||||
gs.AddGrowableRow(2)
|
||||
gs.AddGrowableCol(1)
|
||||
return gs
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeGrid4(win):
|
||||
bpos = wxDefaultPosition
|
||||
bsize = wxSize(100, 50)
|
||||
gs = wxGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
|
||||
|
||||
gs.AddMany([ (wxButton(win, 1010, 'one', bpos, bsize),
|
||||
0, wxALIGN_TOP | wxALIGN_LEFT ),
|
||||
(wxButton(win, 1010, 'two', bpos, bsize),
|
||||
0, wxALIGN_TOP | wxALIGN_CENTER_HORIZONTAL ),
|
||||
(wxButton(win, 1010, 'three', bpos, bsize),
|
||||
0, wxALIGN_TOP | wxALIGN_RIGHT ),
|
||||
(wxButton(win, 1010, 'four', bpos, bsize),
|
||||
0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT ),
|
||||
(wxButton(win, 1010, 'five', bpos, bsize),
|
||||
0, wxALIGN_CENTER ),
|
||||
(wxButton(win, 1010, 'six', bpos, bsize),
|
||||
0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT ),
|
||||
(wxButton(win, 1010, 'seven', bpos, bsize),
|
||||
0, wxALIGN_BOTTOM | wxALIGN_LEFT ),
|
||||
(wxButton(win, 1010, 'eight', bpos, bsize),
|
||||
0, wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL ),
|
||||
(wxButton(win, 1010, 'nine', bpos, bsize),
|
||||
0, wxALIGN_BOTTOM | wxALIGN_RIGHT ),
|
||||
])
|
||||
|
||||
return gs
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeShapes(win):
|
||||
bpos = wxDefaultPosition
|
||||
bsize = wxSize(100, 50)
|
||||
gs = wxGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
|
||||
|
||||
gs.AddMany([ (wxButton(win, 1010, 'one', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_TOP | wxALIGN_LEFT ),
|
||||
(wxButton(win, 1010, 'two', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_TOP | wxALIGN_CENTER_HORIZONTAL ),
|
||||
(wxButton(win, 1010, 'three', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_TOP | wxALIGN_RIGHT ),
|
||||
(wxButton(win, 1010, 'four', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT ),
|
||||
(wxButton(win, 1010, 'five', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_CENTER ),
|
||||
(wxButton(win, 1010, 'six', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT ),
|
||||
(wxButton(win, 1010, 'seven', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_BOTTOM | wxALIGN_LEFT ),
|
||||
(wxButton(win, 1010, 'eight', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL ),
|
||||
(wxButton(win, 1010, 'nine', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_BOTTOM | wxALIGN_RIGHT ),
|
||||
])
|
||||
|
||||
return gs
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBoxShaped(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "three"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "four"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "five"), 1, wxSHAPED)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
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."
|
||||
),
|
||||
|
||||
("Edge Affinity", makeSimpleBox6,
|
||||
"For items that don't completly fill their allotted space, and don't "
|
||||
"stretch, you can specify which side (or the center) they should stay "
|
||||
"attached to."
|
||||
),
|
||||
|
||||
("Spacer", makeSimpleBox7,
|
||||
"You can add empty space to be managed by a Sizer just as if it were a "
|
||||
"window or another Sizer."
|
||||
),
|
||||
|
||||
("Centering in available space", makeSimpleBox8,
|
||||
"This one shows an item that does not expand to fill it's space, but rather"
|
||||
"stays centered within it."
|
||||
),
|
||||
|
||||
# ("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 wxBoxSizer can leave 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, ""),
|
||||
|
||||
("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."
|
||||
),
|
||||
|
||||
("", None, ""),
|
||||
|
||||
("Simple Grid", makeGrid1,
|
||||
"This is an example of the wxGridSizer. In this case all row heights "
|
||||
"and column widths are kept the same as all the others and all items "
|
||||
"fill their available space. The horzontal and vertical gaps are set to "
|
||||
"2 pixels each."
|
||||
),
|
||||
|
||||
("More Grid Features", makeGrid2,
|
||||
"This is another example of the wxGridSizer. This one has no gaps in the grid, "
|
||||
"but various cells are given different alignment options and some of them "
|
||||
"hold nested sizers."
|
||||
),
|
||||
|
||||
("Flexible Grid", makeGrid3,
|
||||
"This grid allows the rows to have different heights and the columns to have "
|
||||
"different widths. You can also specify rows and columns that are growable, "
|
||||
"which we have done for the first and last row and the middle column for "
|
||||
"this example.\n"
|
||||
"\nThere is also a spacer in the middle cell instead of an actual window."
|
||||
),
|
||||
|
||||
("Grid with Alignment", makeGrid4,
|
||||
"New alignment flags allow for the positioning of items in any corner or centered "
|
||||
"position."
|
||||
),
|
||||
|
||||
("", None, ""),
|
||||
|
||||
("Proportional resize", makeSimpleBoxShaped,
|
||||
"Managed items can preserve their original aspect ratio. The last item has the "
|
||||
"wxSHAPED flag set and will resize proportional to its origingal size."
|
||||
),
|
||||
|
||||
("Proportional resize with Alignments", makeShapes,
|
||||
"This one shows various alignments as well as proportional resizing for all items."
|
||||
),
|
||||
|
||||
]
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
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.Fit(self)
|
||||
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(self.sizer)
|
||||
EVT_CLOSE(self, self.OnCloseWindow)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.MakeModal(false)
|
||||
self.Destroy()
|
||||
|
||||
def OnButton(self, event):
|
||||
self.Close(true)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
class TestSelectionPanel(wxPanel):
|
||||
def __init__(self, parent, frame):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
self.frame = frame
|
||||
|
||||
self.list = wxListBox(self, 401,
|
||||
wxDLG_PNT(self, 10, 10), wxDLG_SZE(self, 100, 100),
|
||||
[])
|
||||
EVT_LISTBOX(self, 401, self.OnSelect)
|
||||
EVT_LISTBOX_DCLICK(self, 401, self.OnDClick)
|
||||
|
||||
self.btn = 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, 115),
|
||||
wxDLG_SZE(self, 200, 50),
|
||||
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, None, -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()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
@@ -1,379 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
"""This is SlashDot 1.2
|
||||
|
||||
It's the obligatory Slashdot.org headlines reader that
|
||||
any modern widget set/library must have in order to be taken
|
||||
seriously :-)
|
||||
|
||||
Usage is quite simple; wxSlash attempts to download the
|
||||
'ultramode.txt' file from http://slashdot.org, which
|
||||
contains the headlines in a computer friendly format. It
|
||||
then displays said headlines in a wxWindows list control.
|
||||
|
||||
You can read articles using either Python's html library
|
||||
or an external browser. Uncheck the 'browser->internal' menu
|
||||
item to use the latter option. Use the settings dialog box
|
||||
to set which external browser is started.
|
||||
|
||||
This code is available under the wxWindows license, see
|
||||
elsewhere. If you modify this code, be aware of the fact
|
||||
that slashdot.org's maintainer, CmdrTaco, explicitly asks
|
||||
'ultramode.txt' downloaders not to do this automatically
|
||||
more than twice per hour. If this feature is abused,
|
||||
CmdrTaco may remove the ultramode file completely and that
|
||||
will make a *lot* of people unhappy.
|
||||
|
||||
I want to thank Alex Shnitman whose slashes.pl
|
||||
(Perl/GTK) script gave me the idea for this applet.
|
||||
|
||||
Have fun with it,
|
||||
|
||||
Harm van der Heijden (H.v.d.Heijden@phys.tue.nl)
|
||||
"""
|
||||
|
||||
from wxPython.wx import *
|
||||
from httplib import HTTP
|
||||
from htmllib import HTMLParser
|
||||
import os
|
||||
import re
|
||||
import formatter
|
||||
|
||||
class HTMLTextView(wxFrame):
|
||||
def __init__(self, parent, id, title='HTMLTextView', url=None):
|
||||
wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition,
|
||||
wxSize(600,400))
|
||||
|
||||
EVT_CLOSE(self, self.OnCloseWindow)
|
||||
self.mainmenu = wxMenuBar()
|
||||
|
||||
menu = wxMenu()
|
||||
menu.Append(201, '&Open URL...', 'Open URL')
|
||||
EVT_MENU(self, 201, self.OnFileOpen)
|
||||
menu.Append(209, 'E&xit', 'Exit viewer')
|
||||
EVT_MENU(self, 209, self.OnFileExit)
|
||||
|
||||
self.mainmenu.Append(menu, '&File')
|
||||
self.SetMenuBar(self.mainmenu)
|
||||
self.CreateStatusBar(1)
|
||||
|
||||
self.text = wxTextCtrl(self, -1, "", wxPyDefaultPosition,
|
||||
wxPyDefaultSize, wxTE_MULTILINE | wxTE_READONLY)
|
||||
|
||||
if (url):
|
||||
self.OpenURL(url)
|
||||
|
||||
def logprint(self, x):
|
||||
self.SetStatusText(x)
|
||||
|
||||
def OpenURL(self, url):
|
||||
self.url = url
|
||||
m = re.match('file:(\S+)\s*', url)
|
||||
if m:
|
||||
f = open(m.groups()[0],'r')
|
||||
else:
|
||||
m = re.match('http://([^/]+)(/\S*)\s*', url)
|
||||
if m:
|
||||
host = m.groups()[0]
|
||||
path = m.groups()[1]
|
||||
else:
|
||||
m = re.match('http://(\S+)\s*', url)
|
||||
if not m:
|
||||
# Invalid URL
|
||||
self.logprint("Invalid or unsupported URL: %s" % (url))
|
||||
return
|
||||
host = m.groups()[0]
|
||||
path = ''
|
||||
f = RetrieveAsFile(host,path,self.logprint)
|
||||
if not f:
|
||||
self.logprint("Could not open %s" % (url))
|
||||
return
|
||||
self.logprint("Receiving data...")
|
||||
data = f.read()
|
||||
tmp = open('tmphtml.txt','w')
|
||||
fmt = formatter.AbstractFormatter(formatter.DumbWriter(tmp))
|
||||
p = HTMLParser(fmt)
|
||||
self.logprint("Parsing data...")
|
||||
p.feed(data)
|
||||
p.close()
|
||||
tmp.close()
|
||||
tmp = open('tmphtml.txt', 'r')
|
||||
self.text.SetValue(tmp.read())
|
||||
self.SetTitle(url)
|
||||
self.logprint(url)
|
||||
|
||||
def OnFileOpen(self, event):
|
||||
dlg = wxTextEntryDialog(self, "Enter URL to open:", "")
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
url = dlg.GetValue()
|
||||
else:
|
||||
url = None
|
||||
if url:
|
||||
self.OpenURL(url)
|
||||
|
||||
def OnFileExit(self, event):
|
||||
self.Close()
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
|
||||
def ParseSlashdot(f):
|
||||
art_sep = re.compile('%%\r?\n')
|
||||
line_sep = re.compile('\r?\n')
|
||||
data = f.read()
|
||||
list = art_sep.split(data)
|
||||
art_list = []
|
||||
for i in range(1,len(list)-1):
|
||||
art_list.append(line_sep.split(list[i]))
|
||||
return art_list
|
||||
|
||||
def myprint(x):
|
||||
print x
|
||||
|
||||
def RetrieveAsFile(host, path='', logprint = myprint):
|
||||
try:
|
||||
h = HTTP(host)
|
||||
except:
|
||||
logprint("Failed to create HTTP connection to %s... is the network available?" % (host))
|
||||
return None
|
||||
h.putrequest('GET',path)
|
||||
h.putheader('Accept','text/html')
|
||||
h.putheader('Accept','text/plain')
|
||||
h.endheaders()
|
||||
errcode, errmsg, headers = h.getreply()
|
||||
if errcode != 200:
|
||||
logprint("HTTP error code %d: %s" % (errcode, errmsg))
|
||||
return None
|
||||
f = h.getfile()
|
||||
# f = open('/home/harm/ultramode.txt','r')
|
||||
return f
|
||||
|
||||
|
||||
class AppStatusBar(wxStatusBar):
|
||||
def __init__(self, parent):
|
||||
wxStatusBar.__init__(self,parent, -1)
|
||||
self.SetFieldsCount(2)
|
||||
self.SetStatusWidths([-1, 100])
|
||||
self.but = wxButton(self, 1001, "Refresh")
|
||||
EVT_BUTTON(self, 1001, parent.OnViewRefresh)
|
||||
EVT_SIZE(self, self.OnSize)
|
||||
self.OnSize(None)
|
||||
|
||||
def logprint(self,x):
|
||||
self.SetStatusText(x,0)
|
||||
|
||||
def OnSize(self, event):
|
||||
rect = self.GetFieldRect(1)
|
||||
self.but.SetPosition(wxPoint(rect.x+2, rect.y+2))
|
||||
self.but.SetSize(wxSize(rect.width-4, rect.height-4))
|
||||
|
||||
# This is a simple timer class to start a function after a short delay;
|
||||
class QuickTimer(wxTimer):
|
||||
def __init__(self, func, wait=100):
|
||||
wxTimer.__init__(self)
|
||||
self.callback = func
|
||||
self.Start(wait); # wait .1 second (.001 second doesn't work. why?)
|
||||
def Notify(self):
|
||||
self.Stop();
|
||||
apply(self.callback, ());
|
||||
|
||||
class AppFrame(wxFrame):
|
||||
def __init__(self, parent, id, title):
|
||||
wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition,
|
||||
wxSize(650, 250))
|
||||
|
||||
# if the window manager closes the window:
|
||||
EVT_CLOSE(self, self.OnCloseWindow);
|
||||
|
||||
# Now Create the menu bar and items
|
||||
self.mainmenu = wxMenuBar()
|
||||
|
||||
menu = wxMenu()
|
||||
menu.Append(209, 'E&xit', 'Enough of this already!')
|
||||
EVT_MENU(self, 209, self.OnFileExit)
|
||||
self.mainmenu.Append(menu, '&File')
|
||||
menu = wxMenu()
|
||||
menu.Append(210, '&Refresh', 'Refresh headlines')
|
||||
EVT_MENU(self, 210, self.OnViewRefresh)
|
||||
menu.Append(211, '&Slashdot Index', 'View Slashdot index')
|
||||
EVT_MENU(self, 211, self.OnViewIndex)
|
||||
menu.Append(212, 'Selected &Article', 'View selected article')
|
||||
EVT_MENU(self, 212, self.OnViewArticle)
|
||||
self.mainmenu.Append(menu, '&View')
|
||||
menu = wxMenu()
|
||||
menu.Append(220, '&Internal', 'Use internal text browser',TRUE)
|
||||
menu.Check(220, true)
|
||||
self.UseInternal = 1;
|
||||
EVT_MENU(self, 220, self.OnBrowserInternal)
|
||||
menu.Append(222, '&Settings...', 'External browser Settings')
|
||||
EVT_MENU(self, 222, self.OnBrowserSettings)
|
||||
self.mainmenu.Append(menu, '&Browser')
|
||||
menu = wxMenu()
|
||||
menu.Append(230, '&About', 'Some documentation');
|
||||
EVT_MENU(self, 230, self.OnAbout)
|
||||
self.mainmenu.Append(menu, '&Help')
|
||||
|
||||
self.SetMenuBar(self.mainmenu)
|
||||
|
||||
if wxPlatform == '__WXGTK__':
|
||||
# I like lynx. Also Netscape 4.5 doesn't react to my cmdline opts
|
||||
self.BrowserSettings = "xterm -e lynx %s &"
|
||||
elif wxPlatform == '__WXMSW__':
|
||||
# netscape 4.x likes to hang out here...
|
||||
self.BrowserSettings = '\\progra~1\\Netscape\\Communicator\\Program\\netscape.exe %s'
|
||||
else:
|
||||
# a wild guess...
|
||||
self.BrowserSettings = 'netscape %s'
|
||||
|
||||
# A status bar to tell people what's happening
|
||||
self.sb = AppStatusBar(self)
|
||||
self.SetStatusBar(self.sb)
|
||||
|
||||
self.list = wxListCtrl(self, 1100, style=wxLC_REPORT)
|
||||
self.list.InsertColumn(0, 'Subject')
|
||||
self.list.InsertColumn(1, 'Date')
|
||||
self.list.InsertColumn(2, 'Posted by')
|
||||
self.list.InsertColumn(3, 'Comments')
|
||||
self.list.SetColumnWidth(0, 300)
|
||||
self.list.SetColumnWidth(1, 150)
|
||||
self.list.SetColumnWidth(2, 100)
|
||||
self.list.SetColumnWidth(3, 100)
|
||||
|
||||
EVT_LIST_ITEM_SELECTED(self, 1100, self.OnItemSelected)
|
||||
EVT_LEFT_DCLICK(self.list, self.OnLeftDClick)
|
||||
|
||||
self.logprint("Connecting to slashdot... Please wait.")
|
||||
# wxYield doesn't yet work here. That's why we use a timer
|
||||
# to make sure that we see some GUI stuff before the slashdot
|
||||
# file is transfered.
|
||||
self.timer = QuickTimer(self.DoRefresh, 1000)
|
||||
|
||||
def logprint(self, x):
|
||||
self.sb.logprint(x)
|
||||
|
||||
def OnFileExit(self, event):
|
||||
self.Destroy()
|
||||
|
||||
def DoRefresh(self):
|
||||
f = RetrieveAsFile('slashdot.org','/ultramode.txt',self.sb.logprint)
|
||||
art_list = ParseSlashdot(f)
|
||||
self.list.DeleteAllItems()
|
||||
self.url = []
|
||||
self.current = -1
|
||||
i = 0;
|
||||
for article in art_list:
|
||||
self.list.InsertStringItem(i, article[0])
|
||||
self.list.SetStringItem(i, 1, article[2])
|
||||
self.list.SetStringItem(i, 2, article[3])
|
||||
self.list.SetStringItem(i, 3, article[6])
|
||||
self.url.append(article[1])
|
||||
i = i + 1
|
||||
self.logprint("File retrieved OK.")
|
||||
|
||||
def OnViewRefresh(self, event):
|
||||
self.logprint("Connecting to slashdot... Please wait.");
|
||||
wxYield()
|
||||
self.DoRefresh()
|
||||
|
||||
def DoViewIndex(self):
|
||||
if self.UseInternal:
|
||||
self.view = HTMLTextView(self, -1, 'slashdot.org',
|
||||
'http://slashdot.org')
|
||||
self.view.Show(true)
|
||||
else:
|
||||
self.logprint(self.BrowserSettings % ('http://slashdot.org'))
|
||||
#os.system(self.BrowserSettings % ('http://slashdot.org'))
|
||||
wxExecute(self.BrowserSettings % ('http://slashdot.org'))
|
||||
self.logprint("OK")
|
||||
|
||||
def OnViewIndex(self, event):
|
||||
self.logprint("Starting browser... Please wait.")
|
||||
wxYield()
|
||||
self.DoViewIndex()
|
||||
|
||||
def DoViewArticle(self):
|
||||
if self.current<0: return
|
||||
url = self.url[self.current]
|
||||
if self.UseInternal:
|
||||
self.view = HTMLTextView(self, -1, url, url)
|
||||
self.view.Show(true)
|
||||
else:
|
||||
self.logprint(self.BrowserSettings % (url))
|
||||
os.system(self.BrowserSettings % (url))
|
||||
self.logprint("OK")
|
||||
|
||||
def OnViewArticle(self, event):
|
||||
self.logprint("Starting browser... Please wait.")
|
||||
wxYield()
|
||||
self.DoViewArticle()
|
||||
|
||||
def OnBrowserInternal(self, event):
|
||||
if self.mainmenu.Checked(220):
|
||||
self.UseInternal = 1
|
||||
else:
|
||||
self.UseInternal = 0
|
||||
|
||||
def OnBrowserSettings(self, event):
|
||||
dlg = wxTextEntryDialog(self, "Enter command to view URL.\nUse %s as a placeholder for the URL.", "", self.BrowserSettings);
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
self.BrowserSettings = dlg.GetValue()
|
||||
|
||||
def OnAbout(self, event):
|
||||
dlg = wxMessageDialog(self, __doc__, "wxSlash", wxOK | wxICON_INFORMATION)
|
||||
dlg.ShowModal()
|
||||
|
||||
def OnItemSelected(self, event):
|
||||
self.current = event.m_itemIndex
|
||||
self.logprint("URL: %s" % (self.url[self.current]))
|
||||
|
||||
def OnLeftDClick(self, event):
|
||||
(x,y) = event.Position();
|
||||
# Actually, we should convert x,y to logical coords using
|
||||
# a dc, but only for a wxScrolledWindow widget.
|
||||
# Now wxGTK derives wxListCtrl from wxScrolledWindow,
|
||||
# and wxMSW from wxControl... So that doesn't work.
|
||||
#dc = wxClientDC(self.list)
|
||||
##self.list.PrepareDC(dc)
|
||||
#x = dc.DeviceToLogicalX( event.GetX() )
|
||||
#y = dc.DeviceToLogicalY( event.GetY() )
|
||||
id = self.list.HitTest(wxPoint(x,y))
|
||||
#print "Double click at %d %d" % (x,y), id
|
||||
# Okay, we got a double click. Let's assume it's the current selection
|
||||
wxYield()
|
||||
self.OnViewArticle(event)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# if running standalone
|
||||
|
||||
if __name__ == '__main__':
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame = AppFrame(None, -1, "Slashdot Breaking News")
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# if running as part of the Demo Framework...
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = AppFrame(None, -1, "Slashdot Breaking News")
|
||||
frame.otherWin = win
|
||||
win.Show(true)
|
||||
|
||||
|
||||
overview = __doc__
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
@@ -1,120 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
from wxPython.gizmos import *
|
||||
|
||||
import images
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestTree(wxRemotelyScrolledTreeCtrl):
|
||||
def __init__(self, parent, ID, pos=wxDefaultPosition, size=wxDefaultSize,
|
||||
style=wxTR_HAS_BUTTONS):
|
||||
wxRemotelyScrolledTreeCtrl.__init__(self, parent, ID, pos, size, style)
|
||||
|
||||
# make an image list
|
||||
im1 = im2 = -1
|
||||
self.il = wxImageList(16, 16)
|
||||
im1 = self.il.Add(images.getFolder1Bitmap())
|
||||
im2 = self.il.Add(images.getFile1Bitmap())
|
||||
self.SetImageList(self.il)
|
||||
|
||||
# Add some items
|
||||
root = self.AddRoot("Root")
|
||||
for i in range(30):
|
||||
item = self.AppendItem(root, "Item %d" % i, im1)
|
||||
for j in range(10):
|
||||
child = self.AppendItem(item, "Child %d" % j, im2)
|
||||
|
||||
self.Expand(root)
|
||||
|
||||
|
||||
|
||||
class TestValueWindow(wxTreeCompanionWindow):
|
||||
def __init__(self, parent, ID, pos=wxDefaultPosition, size=wxDefaultSize, style=0):
|
||||
wxTreeCompanionWindow.__init__(self, parent, ID, pos, size, style)
|
||||
self.SetBackgroundColour("WHITE")
|
||||
EVT_ERASE_BACKGROUND(self, self.OEB)
|
||||
|
||||
def OEB(self, evt):
|
||||
pass
|
||||
|
||||
# This method is called to draw each item in the value window
|
||||
def DrawItem(self, dc, itemId, rect):
|
||||
tree = self.GetTreeCtrl()
|
||||
if tree:
|
||||
text = "This is "
|
||||
parent = tree.GetItemParent(itemId)
|
||||
if parent.IsOk():
|
||||
ptext = tree.GetItemText(parent)
|
||||
text = text + ptext + " --> "
|
||||
text = text + tree.GetItemText(itemId)
|
||||
pen = wxPen(wxSystemSettings_GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID)
|
||||
dc.SetPen(pen)
|
||||
dc.SetBrush(wxBrush(self.GetBackgroundColour(), wxSOLID))
|
||||
dc.DrawRectangle(rect.x, rect.y, rect.width+1, rect.height+1)
|
||||
dc.SetTextForeground("BLACK")
|
||||
dc.SetBackgroundMode(wxTRANSPARENT)
|
||||
tw, th = dc.GetTextExtent(text)
|
||||
x = 5
|
||||
y = rect.y + max(0, (rect.height - th) / 2)
|
||||
dc.DrawText(text, x, y)
|
||||
|
||||
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
self.log = log
|
||||
|
||||
scroller = wxSplitterScrolledWindow(self, -1, #(50,50), (350, 250),
|
||||
style=wxNO_BORDER | wxCLIP_CHILDREN | wxVSCROLL)
|
||||
splitter = wxThinSplitterWindow(scroller, -1, style=wxSP_3DBORDER | wxCLIP_CHILDREN)
|
||||
splitter.SetSashSize(2)
|
||||
tree = TestTree(splitter, -1, style = wxTR_HAS_BUTTONS |
|
||||
wxTR_NO_LINES |
|
||||
wxTR_ROW_LINES |
|
||||
#wxTR_HIDE_ROOT |
|
||||
wxNO_BORDER )
|
||||
valueWindow = TestValueWindow(splitter, -1, style=wxNO_BORDER)
|
||||
|
||||
splitter.SplitVertically(tree, valueWindow)
|
||||
splitter.SetSashPosition(150)
|
||||
scroller.SetTargetWindow(tree)
|
||||
scroller.EnableScrolling(FALSE, FALSE)
|
||||
|
||||
valueWindow.SetTreeCtrl(tree)
|
||||
tree.SetCompanionWindow(valueWindow)
|
||||
|
||||
sizer = wxBoxSizer(wxVERTICAL)
|
||||
sizer.Add(scroller, 1, wxEXPAND|wxALL, 25)
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPanel(nb, log)
|
||||
return win
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
overview = """\
|
||||
This demo shows a collection of classes that were designed to operate
|
||||
together and provide a tree control with additional columns for each
|
||||
item. The classes are wxRemotelyScrolledTreeCtrl, wxTreeCompanionWindow,
|
||||
wxThinSplitterWindow, and wxSplitterScrolledWindow, some of which may
|
||||
also be useful by themselves.
|
||||
"""
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys,os
|
||||
import run
|
||||
run.main(['', os.path.basename(sys.argv[0])])
|
||||
|
@@ -1,207 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.printout import PrintTable
|
||||
|
||||
import os
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
buttonDefs = {
|
||||
814 : ('PreviewWide', 'Preview print of a wide table'),
|
||||
815 : ('PreviewNarrow', 'Preview print of a narrow table with color highlights'),
|
||||
818 : ('OnPreviewMatrix', 'Preview print of a narrow column grid without a table header'),
|
||||
817 : ('PreviewLine', 'Preview print to demonstrate the use of line breaks'),
|
||||
819 : ('PrintWide', 'Direct print (no preview) of a wide table'),
|
||||
}
|
||||
|
||||
|
||||
class TablePanel(wxPanel):
|
||||
def __init__(self, parent, log, frame):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
self.log = log
|
||||
self.frame = frame
|
||||
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
box.Add(20, 30)
|
||||
keys = buttonDefs.keys()
|
||||
keys.sort()
|
||||
for k in keys:
|
||||
text = buttonDefs[k][1]
|
||||
btn = wxButton(self, k, text)
|
||||
box.Add(btn, 0, wxALIGN_CENTER|wxALL, 15)
|
||||
EVT_BUTTON(self, k, self.OnButton)
|
||||
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(box)
|
||||
|
||||
def OnButton(self, evt):
|
||||
funct = buttonDefs[evt.GetId()][0]
|
||||
code = 'self.' + funct + '()'
|
||||
eval(code)
|
||||
|
||||
def ReadData(self):
|
||||
test_file = "./data/testtable.txt"
|
||||
file = open(test_file,'r',1)
|
||||
i = 0
|
||||
|
||||
data = []
|
||||
while 1:
|
||||
text = file.readline()
|
||||
text = string.strip(text)
|
||||
if not text:
|
||||
break
|
||||
|
||||
list_val = string.splitfields(text,'\t')
|
||||
data.append(list_val)
|
||||
file.close()
|
||||
|
||||
self.header = data[0]
|
||||
self.data = data[1:]
|
||||
|
||||
def PreviewWide(self):
|
||||
self.ReadData()
|
||||
prt = PrintTable(self.frame)
|
||||
prt.data = self.data
|
||||
prt.left_margin = 0.5
|
||||
prt.set_column = [1.0, 1.0, 1.0, 1.5, 1.0, 3.0]
|
||||
prt.label = self.header
|
||||
prt.SetLandscape()
|
||||
|
||||
prt.SetColumnLineSize(2, 3)
|
||||
prt.SetColumnLineColour(3, wxNamedColour('RED'))
|
||||
|
||||
prt.SetRowLineSize(1, 3)
|
||||
prt.SetRowLineColour(5, wxNamedColour('RED'))
|
||||
|
||||
prt.SetHeader("wxWindows Applications")
|
||||
prt.SetFooter()
|
||||
prt.SetFooter("Date: ", type = "Date", align=wxALIGN_RIGHT, indent = -2, colour = wxNamedColour('RED'))
|
||||
prt.Preview()
|
||||
|
||||
def PreviewNarrow(self):
|
||||
self.ReadData()
|
||||
new_data = []
|
||||
for val in self.data:
|
||||
new_data.append([val[0], val[1], val[2], val[4], val[5]])
|
||||
|
||||
val = self.header
|
||||
new_header = [val[0], val[1], val[2], val[4], val[5]]
|
||||
|
||||
prt = PrintTable(self.frame)
|
||||
prt.data = new_data
|
||||
prt.set_column = [ 1, 1, 1, 1, 2]
|
||||
prt.label = new_header
|
||||
prt.SetColAlignment(1, wxALIGN_CENTRE)
|
||||
prt.SetColBackgroundColour(0, wxNamedColour('RED'))
|
||||
prt.SetColTextColour(0, wxNamedColour('WHITE'))
|
||||
prt.SetCellColour(4, 0, wxNamedColour('LIGHT BLUE'))
|
||||
prt.SetCellColour(4, 1, wxNamedColour('LIGHT BLUE'))
|
||||
prt.SetCellColour(17, 1, wxNamedColour('LIGHT BLUE'))
|
||||
|
||||
prt.SetColBackgroundColour(2, wxNamedColour('LIGHT BLUE'))
|
||||
prt.SetCellText(4, 2, wxNamedColour('RED'))
|
||||
|
||||
prt.SetColTextColour(3, wxNamedColour('RED'))
|
||||
prt.label_font_colour = wxNamedColour('WHITE')
|
||||
prt.SetHeader("wxWindows Applications", colour = wxNamedColour('RED'))
|
||||
|
||||
prt.SetHeader("Printed: ", type = "Date & Time", align=wxALIGN_RIGHT, indent = -2, colour = wxNamedColour('BLUE'))
|
||||
prt.SetFooter("Page No", colour = wxNamedColour('RED'), type ="Num")
|
||||
prt.Preview()
|
||||
|
||||
def OnPreviewMatrix(self):
|
||||
total_col = 45
|
||||
total_row = 10
|
||||
hsize = 0.2
|
||||
vsize = 0.2
|
||||
|
||||
data = []
|
||||
startx = 1.0
|
||||
columns = []
|
||||
for val in range(total_col):
|
||||
columns.append(hsize)
|
||||
|
||||
prt = PrintTable(self.frame)
|
||||
|
||||
for row in range(total_row):
|
||||
value = []
|
||||
for col in range(total_col):
|
||||
value.append(str(col))
|
||||
data.append(value)
|
||||
|
||||
for col in range(total_col):
|
||||
prt.SetColAlignment(col, wxALIGN_CENTRE)
|
||||
|
||||
prt.SetLandscape()
|
||||
prt.text_font_size = 8
|
||||
prt.cell_left_margin = 0
|
||||
|
||||
prt.data = data
|
||||
prt.set_column = columns
|
||||
prt.SetHeader("Test of Small Grid Size")
|
||||
prt.Preview()
|
||||
|
||||
def PreviewLine(self):
|
||||
prt = PrintTable(self.frame)
|
||||
prt.label = ["Header 1", "Header 2", "Header 3"]
|
||||
prt.set_column = []
|
||||
prt.data = [["Row 1", "1", "2"], ["Row 2", "3", "4\nNew Line to see if it also can wrap around the cell region properly\nAnother new line"]]
|
||||
prt.SetFooter()
|
||||
prt.Preview()
|
||||
|
||||
def PrintWide(self):
|
||||
self.ReadData()
|
||||
prt = PrintTable(self.frame)
|
||||
prt.data = self.data
|
||||
|
||||
prt.left_margin = 0.5
|
||||
prt.set_columns = [ 1, 1, 1, 1, 2, 1, 3 ]
|
||||
prt.label = self.header
|
||||
prt.SetLandscape()
|
||||
prt.Print()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TablePanel(nb, log, frame)
|
||||
return win
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import os
|
||||
import wxPython.lib.printout
|
||||
|
||||
|
||||
|
||||
|
||||
overview = """\
|
||||
<html><body>
|
||||
<h2>Table Printing</h2>
|
||||
|
||||
This demo shows various ways of using the <b><i>new
|
||||
</i></b> PrintOut class. To understand the class you need to examine the demo examples
|
||||
and the library <a href="%s">printout.py</a> module classes.
|
||||
<p>
|
||||
The initial class primarily contains a Table preview/printing class. There is alot of flexibility
|
||||
in manipulating the placement, sizing, colours, alignment of the table text and cell background colors.
|
||||
There are also a number of options for printing Header and Footer information on the page.
|
||||
<p>
|
||||
There is also a class to extract the parameters from a wxGrid and easily recreate a Table printout.
|
||||
<p>
|
||||
The data is printed from a list object containing the column and row values. The label or table header
|
||||
can be defined and will be repeated for all pages.
|
||||
<p>
|
||||
The correct "Total Page" does get calculated and used in the print out Footer.
|
||||
<p>
|
||||
There is still problems with the print framework to properly get the total pages in the preview unless
|
||||
the program knows it before trying to parse through the available pages. This will be fixed
|
||||
when the framework allows for it.
|
||||
|
||||
|
||||
""" % os.path.join(os.path.dirname(wxPython.lib.printout.__file__), "printout.py")
|
||||
|
@@ -1,38 +0,0 @@
|
||||
Name Type Platform Location Availability Description
|
||||
WebReuser Development Windows 95, Windows NT, HPUX 9.05 and 10.2, Solaris 2.4 and 2.5 http://www.stablesoft.com Evaluation WebReuser is a re-use tool from Hitachi Europe Limited. WebReuser is a tool that simplifies software reuse. Its ability to track, schematize and search documents makes it the ideal way to understand C++ code. These features also make WebReuser an ideal tool to classify any Web resource. WebReuser can even be used for more general documentation management tasks.
|
||||
MacAnova Development Windows, Motif, Mac http://www.stat.umn.edu/~gary/macanova/macanova.home.html Free A large statistical application from the School of Statistics, University of Minnesota. It is based on a modified version of wxWindows 1.65.
|
||||
Hardy Development Win 3.1, WIN32, Motif (Sun only) http://www.aiai.ed.ac.uk/~hardy/ Freeware for personal and academic use A hypertext-based diagramming and knowledge-based system development tool, with NASA's CLIPS built-in. It is a superset of wxCLIPS.
|
||||
wxCLIPS Development Win 3.1, WIN32, Motif, XView http://web.ukonline.co.uk/julian.smart/wxclips Freeware A GUI development environment for CLIPS applications.
|
||||
wxPython Development wxWindows 2 for the new version http://alldunn.com/wxPython/ Freeware Python/wxWindows combination by Robin Dunn and Harri Pasanen. Python is an elegant object-oriented, interpreted language that runs on many platforms.
|
||||
MrEd Development Win 3.1, WIN32, Motif, XView http://www.cs.rice.edu/CS/PLT/packages/mred/ Freeware MrEd is a combined editor and Scheme development environment by Matthew Flatt.
|
||||
WXLisp Development Win 3.1, WIN32, Motif, XView http://www.cadlab.de/~lipuser/wxlisp/wxlisp.html Freeware A combination of wxWindows and XLisp.
|
||||
Scriptum Development Motif http://www.isoft.com.ar/eng/products/system/scriptum.html Freeware Graphical editor with visual highlighting, navigation/browsing, undo, class browser for C++ and Java, source code management, file locking, remote editing using ftp, configurable.
|
||||
WipeOut Development XView/Linux http://www.softwarebuero.de/wipeout-eng.html Giftware WipeOut is an integrated development environment for C++ projects, available for Linux/XView. The authors are working on versions for SunOS/Solaris. Source is available for porting to other platforms.
|
||||
OPL Development Win 3.1, WIN32, Motif, XView http://www.ozemail.com.au/~adavison/ Freeware Object Prolog is a portable implementation of Prolog by Andrew Davison, with object-oriented extensions, entirely written in C++. In the initial version, a binding to wxWindows is available. In the revamped version, this binding has not been written yet.
|
||||
Dataplore Graphics and sound Windows, other? http://www.datan.de/dataplore Commercial Data visualisation tool, from Datan
|
||||
VCG Tool Graphics and sound Win 3.1, WIN32, Motif, XView http://www.cs.uni-sb.de:80/RW/users/sander/html/gsvcg1.html Freeware A graph layout tool similar to GraphPlace, but with extensions. Very nice indeed!
|
||||
Y.E.S. Graphics and sound Win 3.1, WIN32, XView (Linux) ftp://ftp.musik.uni-essen.de/pub/EsAC/program/ Shareware Monophonic notation program.
|
||||
JAZZ Graphics and sound XView (Linux) http://rokke.aug.hiagder.no/per/jazz.html Freeware A MIDI sequencer for Linux.
|
||||
ISP Graphics and sound Win 3.1, WIN32, Motif, XView ftp://www.remstar.com/pub/wxwin/contrib/isp-100/ Freeware Image and sound player educational tool.
|
||||
ClockWorks Graphics and sound Win 3.1, WIN32, Motif, XView http://web.ukonline.co.uk/Members/julian.smart/freesoft.html#clockworks Freeware A configurable analogue clock, with a collection of 'fine art' faces. By Julian Smart.
|
||||
M Miscellaneous Windows 95, Windows NT, Linux http://www.phy.hw.ac.uk/~karsten/M/index.html GPL M is a cross-platform e-mail application. It will be available for X11/Unix and Windows platforms, supporting a wide range of e-mail transfer protocols as well as including full MIME support. M's wealth of features and ease of use make it one of the most powerful MUAs available, providing a consistent and intuitive interface across all platforms.
|
||||
Boolean Miscellaneous Windows 95, Windows NT, Solaris http://www.xs4all.nl/~kholwerd/bool.html Freeware A GDSII CAD file format viewer, and program to perform boolean operations on sets of 2D polygons. By Klaas Holwerda.
|
||||
TimeMan Miscellaneous wxGTK, Unix http://www.bgif.no/neureka/TimeMan/ Freeware A time manager, written using wxGTK
|
||||
Forty Thieves Miscellaneous Motif, Windows apps/forty/forty.htm Freeware A fiendish patience game, by Chris Breeze. A nice demo of what's possible with wxWindows.
|
||||
Lean Integration Platform Miscellaneous Windows NT, various flavours of UNIX http://www.c-lab.de/~lipuser/lip To be decided LIP is a workflow-oriented tool integration system which uses wxLisp (and thus wxWindows) as an implementation basis. Lisp combined with the wxWindows bindings make up the compatible extension language platform of the system.
|
||||
wxWeb Miscellaneous Win 3.1, WIN32, Motif ftp://www.remstar.com/pub/wxwin/contrib/wxweb Freeware Andrew Davison's Web browser, with SimSock portable socket library and wxHtml canvas. Includes an http server for UNIX and Windows.
|
||||
SANTIS Miscellaneous Win 3.1, Windows 95, Linux, Solaris OpenLook and Motif, Silicon Graphics http://www.physiology.rwth-aachen.de/bs/santis/ Free for non-commercial use SANTIS is a software tool designed for the analysis of signals and time series data of any kind, in particular for scientific purposes. It was developed at the Laboratory of Biomedical Systems Analysis, Institute of Physiology at the University of Aachen, Germany.
|
||||
Xbaies Miscellaneous Win 3.1, WIN32, Motif, XView xbaies.htm Freeware A shell for building Bayesian network models, by Robert Cowell.
|
||||
wxTinyBB Miscellaneous Win 3.1, WIN32, Motif, XView ftp://www.remstar.com/pub/wxwin/contrib/wxtinybb Freeware/commercial A tiny blackboard shell demo showing an embedded (commercial) Prolog engine. Demo written by Arvindra Sehmi. A good example of a nice interface using wxWindows.
|
||||
Gambit Miscellaneous Win 3.1, WIN32, Motif, XView http://www.hss.caltech.edu/~gambit/Gambit.html Freeware A large wxWindows application with source, and features such as a table control with printing.
|
||||
Tex2RTF Miscellaneous Win 3.1, WIN32, Motif, XView http://web.ukonline.co.uk/julian.smart/tex2rtf Freeware Converts subset of LaTeX syntax to WinHelp, wordprocessor RTF, HTML, and wxHelp. As used for wxWindows documentation.
|
||||
wxPoem Miscellaneous Win 3.1, WIN32, Motif, XView none.htm Freeware A poetry display program for wxWindows. Included as a sample in the wxWindows distribution.
|
||||
Sonar tracking software Miscellaneous See Web site http://www.desertstar.com Demonstration Miscellaneous sonar tracking software from Desert Star Systems, who use wxWindows for all their Windows-based software.
|
||||
Name Research software Platform Location Availability Description
|
||||
DisCo Research software N/A http://www.cs.tut.fi/laitos/DisCo/tool.fm.html N/A A tool for specification of reactive systems.
|
||||
CAFE Research software N/A cafe.htm N/A Cellular Analysis of Fire and Extinction
|
||||
CODA Research software See Web site http://www.ozemail.com.au/~mbedward/coda/coda.html See Web site CODA assists in the design of networks of nature reserves or protected areas. It has been used for major reserve planning studies, as a teaching resource and for research into conservation planning methods.<2E>
|
||||
EGRESS Research software N/A http://www.aiai.ed.ac.uk/~jimd/Egress2/projInfo_contents.html N/A An evacuation decision model.
|
||||
ACT Research software N/A none.htm N/A A general process and tracker and automator being built at NASA.
|
||||
Rectangular nesting program Research software N/A http://www.elec-eng.leeds.ac.uk/een5mpd/research.html N/A Optimized layout of rectangles on a page.
|
||||
Finite element post processor Research software N/A http://www.ime.auc.dk/afd3/odessy/manuals/index.htm N/A Finite element postprocessor, produced at Aalborg University in Denmark by John Rasmussen and Erik Lund.
|
@@ -1,246 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
import thread
|
||||
import time
|
||||
from whrandom import random
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
wxEVT_UPDATE_BARGRAPH = wxNewEventType()
|
||||
|
||||
def EVT_UPDATE_BARGRAPH(win, func):
|
||||
win.Connect(-1, -1, wxEVT_UPDATE_BARGRAPH, func)
|
||||
|
||||
|
||||
class UpdateBarEvent(wxPyEvent):
|
||||
def __init__(self, barNum, value):
|
||||
wxPyEvent.__init__(self)
|
||||
self.SetEventType(wxEVT_UPDATE_BARGRAPH)
|
||||
self.barNum = barNum
|
||||
self.value = value
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class CalcBarThread:
|
||||
def __init__(self, win, barNum, val):
|
||||
self.win = win
|
||||
self.barNum = barNum
|
||||
self.val = val
|
||||
|
||||
def Start(self):
|
||||
self.keepGoing = self.running = true
|
||||
thread.start_new_thread(self.Run, ())
|
||||
|
||||
def Stop(self):
|
||||
self.keepGoing = false
|
||||
|
||||
def IsRunning(self):
|
||||
return self.running
|
||||
|
||||
def Run(self):
|
||||
while self.keepGoing:
|
||||
evt = UpdateBarEvent(self.barNum, int(self.val))
|
||||
wxPostEvent(self.win, evt)
|
||||
#del evt
|
||||
|
||||
sleeptime = (random() * 2) + 0.5
|
||||
time.sleep(sleeptime/4)
|
||||
|
||||
sleeptime = sleeptime * 5
|
||||
if int(random() * 2):
|
||||
self.val = self.val + sleeptime
|
||||
else:
|
||||
self.val = self.val - sleeptime
|
||||
|
||||
if self.val < 0: self.val = 0
|
||||
if self.val > 300: self.val = 300
|
||||
|
||||
self.running = false
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
class GraphWindow(wxWindow):
|
||||
def __init__(self, parent, labels):
|
||||
wxWindow.__init__(self, parent, -1)
|
||||
|
||||
self.values = []
|
||||
for label in labels:
|
||||
self.values.append((label, 0))
|
||||
|
||||
font = wxFont(12, wxSWISS, wxNORMAL, wxBOLD)
|
||||
self.SetFont(font)
|
||||
|
||||
self.colors = [ wxRED, wxGREEN, wxBLUE, wxCYAN,
|
||||
"Yellow", "Navy" ]
|
||||
|
||||
EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
|
||||
EVT_PAINT(self, self.OnPaint)
|
||||
|
||||
|
||||
def SetValue(self, index, value):
|
||||
assert index < len(self.values)
|
||||
cur = self.values[index]
|
||||
self.values[index:index+1] = [(cur[0], value)]
|
||||
|
||||
|
||||
def SetFont(self, font):
|
||||
wxWindow.SetFont(self, font)
|
||||
wmax = hmax = 0
|
||||
for label, val in self.values:
|
||||
w,h = self.GetTextExtent(label)
|
||||
if w > wmax: wmax = w
|
||||
if h > hmax: hmax = h
|
||||
self.linePos = wmax + 10
|
||||
self.barHeight = hmax
|
||||
|
||||
|
||||
def GetBestHeight(self):
|
||||
return 2 * (self.barHeight + 1) * len(self.values)
|
||||
|
||||
|
||||
def Draw(self, dc, size):
|
||||
dc.SetFont(self.GetFont())
|
||||
dc.SetTextForeground(wxBLUE)
|
||||
dc.SetBackground(wxBrush(self.GetBackgroundColour()))
|
||||
dc.Clear()
|
||||
dc.SetPen(wxPen(wxBLACK, 3, wxSOLID))
|
||||
dc.DrawLine(self.linePos, 0, self.linePos, size.height-10)
|
||||
|
||||
bh = ypos = self.barHeight
|
||||
for x in range(len(self.values)):
|
||||
label, val = self.values[x]
|
||||
dc.DrawText(label, 5, ypos)
|
||||
|
||||
if val:
|
||||
color = self.colors[ x % len(self.colors) ]
|
||||
dc.SetPen(wxPen(color))
|
||||
dc.SetBrush(wxBrush(color))
|
||||
dc.DrawRectangle(self.linePos+3, ypos, val, bh)
|
||||
|
||||
ypos = ypos + 2*bh
|
||||
if ypos > size.height-10:
|
||||
break
|
||||
|
||||
|
||||
def OnPaint(self, evt):
|
||||
size = self.GetSize()
|
||||
bmp = wxEmptyBitmap(size.width, size.height)
|
||||
dc = wxMemoryDC()
|
||||
dc.SelectObject(bmp)
|
||||
self.Draw(dc, size)
|
||||
|
||||
wdc = wxPaintDC(self)
|
||||
wdc.BeginDrawing()
|
||||
wdc.Blit(0,0, size.width, size.height, dc, 0,0)
|
||||
wdc.EndDrawing()
|
||||
|
||||
dc.SelectObject(wxNullBitmap)
|
||||
|
||||
|
||||
def OnEraseBackground(self, evt):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestFrame(wxFrame):
|
||||
def __init__(self, parent, log):
|
||||
wxFrame.__init__(self, parent, -1, "Thread Test", size=(450,300))
|
||||
self.log = log
|
||||
|
||||
#self.CenterOnParent()
|
||||
|
||||
panel = wxPanel(self, -1)
|
||||
panel.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD))
|
||||
wxStaticText(panel, -1,
|
||||
"This demo shows multiple threads interacting with this\n"
|
||||
"window by sending events to it, one thread for each bar.",
|
||||
wxPoint(5,5))
|
||||
panel.Fit()
|
||||
|
||||
self.graph = GraphWindow(self, ['Zero', 'One', 'Two', 'Three', 'Four',
|
||||
'Five', 'Six', 'Seven'])
|
||||
self.graph.SetSize((450, self.graph.GetBestHeight()))
|
||||
|
||||
sizer = wxBoxSizer(wxVERTICAL)
|
||||
sizer.Add(panel, 0, wxEXPAND)
|
||||
sizer.Add(self.graph, 1, wxEXPAND)
|
||||
|
||||
self.SetSizer(sizer)
|
||||
self.SetAutoLayout(true)
|
||||
sizer.Fit(self)
|
||||
|
||||
EVT_UPDATE_BARGRAPH(self, self.OnUpdate)
|
||||
self.threads = []
|
||||
self.threads.append(CalcBarThread(self, 0, 50))
|
||||
self.threads.append(CalcBarThread(self, 1, 75))
|
||||
self.threads.append(CalcBarThread(self, 2, 100))
|
||||
self.threads.append(CalcBarThread(self, 3, 150))
|
||||
self.threads.append(CalcBarThread(self, 4, 225))
|
||||
self.threads.append(CalcBarThread(self, 5, 300))
|
||||
self.threads.append(CalcBarThread(self, 6, 250))
|
||||
self.threads.append(CalcBarThread(self, 7, 175))
|
||||
|
||||
for t in self.threads:
|
||||
t.Start()
|
||||
|
||||
EVT_CLOSE(self, self.OnCloseWindow)
|
||||
|
||||
|
||||
def OnUpdate(self, evt):
|
||||
self.graph.SetValue(evt.barNum, evt.value)
|
||||
self.graph.Refresh(false)
|
||||
|
||||
|
||||
def OnCloseWindow(self, evt):
|
||||
busy = wxBusyInfo("One moment please, waiting for threads to die...")
|
||||
wxYield()
|
||||
for t in self.threads:
|
||||
t.Stop()
|
||||
running = 1
|
||||
while running:
|
||||
running = 0
|
||||
for t in self.threads:
|
||||
running = running + t.IsRunning()
|
||||
time.sleep(0.1)
|
||||
self.Destroy()
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestFrame(frame, log)
|
||||
frame.otherWin = win
|
||||
win.Show(true)
|
||||
return None
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
overview = """\
|
||||
The main issue with multi-threaded GUI programming is the thread safty
|
||||
of the GUI itself. On most platforms the GUI is not thread safe and
|
||||
so any cross platform GUI Toolkit and applications written with it
|
||||
need to take that into account.
|
||||
|
||||
The solution is to only allow interaction with the GUI from a single
|
||||
thread, but this often severly limits what can be done in an
|
||||
application and makes it difficult to use additional threads at all.
|
||||
|
||||
Since wxPython already makes extensive use of event handlers, it is a
|
||||
logical extension to allow events to be sent to GUI objects from
|
||||
alternate threads. A function called wxPostEvent allows you to do
|
||||
this. It accepts an event and an event handler (window) and instead
|
||||
of sending the event immediately in the current context like
|
||||
ProcessEvent does, it processes it later from the context of the GUI
|
||||
thread.
|
||||
|
||||
"""
|
@@ -1,171 +0,0 @@
|
||||
#
|
||||
# Throbber.py - Cliff Wells <clifford.wells@attbi.com>
|
||||
#
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.rcsizer import RowColSizer
|
||||
from wxPython.lib.throbber import Throbber, __doc__ as docString
|
||||
import throbImages # this was created using a modified version of img2py
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
self.log = log
|
||||
|
||||
# create the throbbers
|
||||
self.throbbers = {
|
||||
'plain': { 'throbber': None,
|
||||
'text': "Plain throbber." },
|
||||
'reverse': { 'throbber': None,
|
||||
'text': "This throbber runs in reverse and faster." },
|
||||
'autoreverse': { 'throbber': None,
|
||||
'text': "This throbber switches direction." },
|
||||
'label': { 'throbber': None,
|
||||
'text': "With a label." },
|
||||
'overlay': { 'throbber': None,
|
||||
'text': "With an overlayed image." },
|
||||
'overlay+text': { 'throbber': None,
|
||||
'text': "With a label and an overlayed image." },
|
||||
}
|
||||
|
||||
images = [throbImages.catalog[i].getBitmap()
|
||||
for i in throbImages.index
|
||||
if i not in ['eclouds', 'logo']]
|
||||
|
||||
self.throbbers['plain']['throbber'] = Throbber(self, -1,
|
||||
images, #size=(36, 36),
|
||||
frameDelay = 0.1)
|
||||
self.throbbers['reverse']['throbber'] = Throbber(self, -1, images, #size=(36, 36),
|
||||
frameDelay = 0.07)
|
||||
self.throbbers['reverse']['throbber'].Reverse()
|
||||
self.throbbers['autoreverse']['throbber'] = Throbber(self, -1,
|
||||
images, #size=(36, 36),
|
||||
frameDelay = 0.1,
|
||||
reverse = true)
|
||||
self.throbbers['autoreverse']['throbber'].sequence.append(0)
|
||||
self.throbbers['label']['throbber'] = Throbber(self, -1,
|
||||
images, #size=(36, 36),
|
||||
frameDelay = 0.1,
|
||||
label = 'Label')
|
||||
self.throbbers['label']['throbber'].SetFont(wxFont(pointSize = 10,
|
||||
family = wxDEFAULT,
|
||||
style = wxNORMAL,
|
||||
weight = wxBOLD))
|
||||
self.throbbers['overlay']['throbber'] = Throbber(self, -1,
|
||||
images, #size=(36, 36),
|
||||
frameDelay = 0.1,
|
||||
overlay = throbImages.catalog['logo'].getBitmap())
|
||||
self.throbbers['overlay+text']['throbber'] = Throbber(self, -1,
|
||||
images, #size=(36, 36),
|
||||
frameDelay = 0.1,
|
||||
overlay = throbImages.catalog['logo'].getBitmap(),
|
||||
label = "Python!")
|
||||
self.throbbers['overlay+text']['throbber'].SetFont(wxFont(pointSize = 8,
|
||||
family = wxDEFAULT,
|
||||
style = wxNORMAL,
|
||||
weight = wxBOLD))
|
||||
|
||||
|
||||
# this throbber is created using a single, composite image
|
||||
self.otherThrobber = Throbber(self, -1,
|
||||
throbImages.catalog['eclouds'].getBitmap(), #size=(48, 48),
|
||||
frameDelay = 0.15,
|
||||
frames = 12,
|
||||
frameWidth = 48,
|
||||
label = "Stop")
|
||||
|
||||
|
||||
EVT_LEFT_DOWN(self.otherThrobber, self.OnClickThrobber)
|
||||
|
||||
staticBox = wxStaticBox(self, -1, "")
|
||||
box = wxStaticBoxSizer(staticBox)
|
||||
sizer = RowColSizer()
|
||||
box.Add(sizer, 1, wxEXPAND|wxALL, 5)
|
||||
sizer.AddGrowableCol(1)
|
||||
|
||||
sizer.Add(self.otherThrobber, row = 0, col = 2, rowspan = 4, flag = wxALIGN_CENTER_VERTICAL)
|
||||
|
||||
row = 2
|
||||
# use a list so we can keep our order
|
||||
for t in ['plain', 'reverse', 'autoreverse', 'label', 'overlay', 'overlay+text']:
|
||||
sizer.Add(self.throbbers[t]['throbber'], row = row, col = 0, flag = wxALIGN_CENTER|wxALL, border=2)
|
||||
sizer.Add(wxStaticText(self, -1, self.throbbers[t]['text']), row = row, col = 1,
|
||||
flag = wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT)
|
||||
row += 1
|
||||
|
||||
# start and stop buttons
|
||||
startButton = wxButton(self, -1, "Start")
|
||||
EVT_BUTTON(self, startButton.GetId(), self.OnStartAnimation)
|
||||
stopButton = wxButton(self, -1, "Stop")
|
||||
EVT_BUTTON(self, stopButton.GetId(), self.OnStopAnimation)
|
||||
|
||||
buttonBox = wxBoxSizer(wxHORIZONTAL)
|
||||
buttonBox.AddMany([
|
||||
(startButton, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5),
|
||||
(stopButton, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5),
|
||||
])
|
||||
|
||||
sizer.Add(buttonBox,
|
||||
row = len(self.throbbers) + 3,
|
||||
col = 0,
|
||||
colspan = 3,
|
||||
flag = wxALIGN_CENTER)
|
||||
|
||||
self.SetSizer(box)
|
||||
self.SetAutoLayout(true)
|
||||
self.Layout()
|
||||
sizer.SetSizeHints(self)
|
||||
sizer.Fit(self)
|
||||
|
||||
for t in self.throbbers:
|
||||
self.throbbers[t]['throbber'].Start()
|
||||
self.otherThrobber.Start()
|
||||
self.otherThrobber.Reverse()
|
||||
|
||||
EVT_WINDOW_DESTROY(self, self.OnDestroy)
|
||||
|
||||
def OnDestroy(self, event):
|
||||
self.log.write("got it")
|
||||
event.Skip()
|
||||
|
||||
def OnStartAnimation(self, event):
|
||||
for t in self.throbbers:
|
||||
self.throbbers[t]['throbber'].Start()
|
||||
|
||||
def OnStopAnimation(self, event):
|
||||
for t in self.throbbers:
|
||||
self.throbbers[t]['throbber'].Rest()
|
||||
|
||||
def OnClickThrobber(self, event):
|
||||
if self.otherThrobber.Running():
|
||||
self.otherThrobber.Rest()
|
||||
self.otherThrobber.SetLabel("Start")
|
||||
else:
|
||||
self.otherThrobber.Start()
|
||||
self.otherThrobber.SetLabel("Stop")
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPanel(nb, log)
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
overview = """<html><body>
|
||||
<h4><center>Throbber</center></h4>
|
||||
<p>%s</p>
|
||||
</body></html>
|
||||
""" % docString
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys,os
|
||||
import run
|
||||
run.main(['', os.path.basename(sys.argv[0])])
|
@@ -1,123 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class MyURLDropTarget(wxPyDropTarget):
|
||||
def __init__(self, window):
|
||||
wxPyDropTarget.__init__(self)
|
||||
self.window = window
|
||||
|
||||
self.data = wxURLDataObject();
|
||||
self.SetDataObject(self.data)
|
||||
|
||||
def OnDragOver(self, x, y, d):
|
||||
return wxDragLink
|
||||
|
||||
def OnData(self, x, y, d):
|
||||
if not self.GetData():
|
||||
return wxDragNone
|
||||
|
||||
url = self.data.GetURL()
|
||||
self.window.AppendText(url + "\n")
|
||||
|
||||
return d
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
|
||||
self.SetAutoLayout(true)
|
||||
outsideSizer = wxBoxSizer(wxVERTICAL)
|
||||
|
||||
msg = "Drag-And-Drop of URLs"
|
||||
text = wxStaticText(self, -1, "", style=wxALIGN_CENTRE)
|
||||
text.SetFont(wxFont(24, wxSWISS, wxNORMAL, wxBOLD, false))
|
||||
text.SetLabel(msg)
|
||||
w,h = text.GetTextExtent(msg)
|
||||
text.SetSize(wxSize(w,h+1))
|
||||
text.SetForegroundColour(wxBLUE)
|
||||
outsideSizer.Add(text, 0, wxEXPAND|wxALL, 5)
|
||||
outsideSizer.Add(wxStaticLine(self, -1), 0, wxEXPAND)
|
||||
outsideSizer.Add(20,20)
|
||||
|
||||
self.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD, false))
|
||||
|
||||
inSizer = wxFlexGridSizer(2, 2, 5, 5)
|
||||
inSizer.AddGrowableCol(0)
|
||||
|
||||
inSizer.Add(20,20)
|
||||
inSizer.Add(20,20)
|
||||
inSizer.Add(wxStaticText(self, -1,
|
||||
"Drag URLs from your browser to\nthis window:",
|
||||
style = wxALIGN_RIGHT),
|
||||
0, wxALIGN_RIGHT )
|
||||
self.dropText = wxTextCtrl(self, -1, "", size=(380, 180),
|
||||
style=wxTE_MULTILINE|wxTE_READONLY)
|
||||
inSizer.Add(self.dropText, 0, wxEXPAND)
|
||||
|
||||
|
||||
inSizer.Add(wxStaticText(self, -1,
|
||||
"Drag this URL to your browser:",
|
||||
style = wxALIGN_RIGHT),
|
||||
0, wxALIGN_RIGHT )
|
||||
self.dragText = wxTextCtrl(self, -1, "http://wxPython.org/")
|
||||
inSizer.Add(self.dragText, 0, wxEXPAND)
|
||||
EVT_MOTION(self.dragText, self.OnStartDrag)
|
||||
|
||||
|
||||
## inSizer.Add(wxStaticText(self, -1,
|
||||
## "Drag this TEXT to your browser:",
|
||||
## style = wxALIGN_RIGHT),
|
||||
## 0, wxALIGN_RIGHT )
|
||||
## self.dragText2 = wxTextCtrl(self, -1, "http://wxPython.org/")
|
||||
## inSizer.Add(self.dragText2, 0, wxEXPAND)
|
||||
## EVT_MOTION(self.dragText2, self.OnStartDrag2)
|
||||
|
||||
|
||||
outsideSizer.Add(inSizer, 1, wxEXPAND)
|
||||
self.SetSizer(outsideSizer)
|
||||
|
||||
|
||||
self.dropText.SetDropTarget(MyURLDropTarget(self.dropText))
|
||||
|
||||
|
||||
|
||||
def OnStartDrag(self, evt):
|
||||
if evt.Dragging():
|
||||
url = self.dragText.GetValue()
|
||||
data = wxURLDataObject()
|
||||
data.SetURL(url)
|
||||
|
||||
dropSource = wxDropSource(self.dragText)
|
||||
dropSource.SetData(data)
|
||||
result = dropSource.DoDragDrop()
|
||||
|
||||
|
||||
def OnStartDrag2(self, evt):
|
||||
if evt.Dragging():
|
||||
url = self.dragText2.GetValue()
|
||||
data = wxTextDataObject()
|
||||
data.SetText(url)
|
||||
|
||||
dropSource = wxDropSource(self.dragText2)
|
||||
dropSource.SetData(data)
|
||||
result = dropSource.DoDragDrop()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPanel(nb, log)
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
overview = """\
|
||||
"""
|
@@ -1,141 +0,0 @@
|
||||
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
# Some unicode strings
|
||||
chi_uni = (u'Python \u662f\u6700\u597d\u7684\u7de8\u7a0b\u8a9e\u8a00\uff01',
|
||||
'Python is the best\nprogramming language!')
|
||||
|
||||
lt1_uni = (u'Pythonas yra \u017eaviausia \u0161neka',
|
||||
'Python is the best')
|
||||
lt2_uni = (u'A\u0161 m\u0117gstu \u0161okolad\u0105',
|
||||
'I like chocolate')
|
||||
|
||||
kor_uni = (u'\ud30c\uc774\uc36c\uc740 \ucd5c\uace0\uc758 \ud504\ub85c\uadf8\ub798\ubc0d \uc5b8\uc5b4\uc774\ub2e4!',
|
||||
'Python is the best\nprogramming language!')
|
||||
|
||||
bul_uni = (u'\u041f\u0438\u0442\u043e\u043d \u0435 \u043d\u0430\u0439-\u0434\u043e\u0431\u0440\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u0435\u043d \u0435\u0437\u0438\u043a!',
|
||||
'Python is the best\nprogramming language!')
|
||||
rus_uni = (u'\u041f\u0438\u0442\u043e\u043d - \u043b\u0443\u0447\u0448\u0438\u0439 \u044f\u0437\u044b\u043a \n\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f!',
|
||||
'Python is the best\nprogramming language!')
|
||||
|
||||
|
||||
# Equivalents in UTF-8. Should I demo these somehow???
|
||||
chi_utf8 = ('Python \xe6\x98\xaf\xe6\x9c\x80\xe5\xa5\xbd\xe7\x9a\x84\xe7\xb7\xa8\xe7\xa8\x8b\xe8\xaa\x9e\xe8\xa8\x80\xef\xbc\x81',
|
||||
'Python is the best programming language')
|
||||
|
||||
lt1_utf8 = ('Pythonas yra \xc5\xbeaviausia \xc5\xa1neka',
|
||||
'Python is the best')
|
||||
lt2_utf8 = ('A\xc5\xa1 m\xc4\x97gstu \xc5\xa1okolad\xc4\x85',
|
||||
'I like chocolate')
|
||||
|
||||
kor_utf8 = ('\xed\x8c\x8c\xec\x9d\xb4\xec\x8d\xac\xec\x9d\x80 \xec\xb5\x9c\xea\xb3\xa0\xec\x9d\x98 \xed\x94\x84\xeb\xa1\x9c\xea\xb7\xb8\xeb\x9e\x98\xeb\xb0\x8d \xec\x96\xb8\xec\x96\xb4\xec\x9d\xb4\xeb\x8b\xa4!',
|
||||
'Python is the best programming language!')
|
||||
|
||||
bul_utf8 = ('\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd \xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9-\xd0\xb4\xd0\xbe\xd0\xb1\xd1\x80\xd0\xb8\xd1\x8f \xd0\xbf\xd1\x80\xd0\xbe\xd0\xb3\xd1\x80\xd0\xb0\xd0\xbc\xd0\xb5\xd0\xbd \xd0\xb5\xd0\xb7\xd0\xb8\xd0\xba!',
|
||||
'Python is the best programming language!')
|
||||
rus_utf8 = ('\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd - \xd0\xbb\xd1\x83\xd1\x87\xd1\x88\xd0\xb8\xd0\xb9 \xd1\x8f\xd0\xb7\xd1\x8b\xd0\xba \xd0\xbf\xd1\x80\xd0\xbe\xd0\xb3\xd1\x80\xd0\xb0\xd0\xbc\xd0\xbc\xd0\xb8\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb0\xd0\xbd\xd0\xb8\xd1\x8f!',
|
||||
'Python is the best programming language!')
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestPanel(wxPanel):
|
||||
def __init__(self, parent, log):
|
||||
self.log = log
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
|
||||
if not wxUSE_UNICODE:
|
||||
self.AddLine(box)
|
||||
self.AddText(box, "Sorry, this wxPython was not built with Unicode support.",
|
||||
font = wxFont(12, wxSWISS, wxNORMAL, wxBOLD))
|
||||
self.AddLine(box)
|
||||
|
||||
else:
|
||||
f = self.GetFont()
|
||||
font = wxFont(14, f.GetFamily(), f.GetStyle(), wxBOLD, false,
|
||||
f.GetFaceName(), f.GetEncoding())
|
||||
|
||||
self.AddLine(box)
|
||||
self.AddText(box, chi_uni[0], chi_uni[1], 'Chinese:', font)
|
||||
self.AddLine(box)
|
||||
|
||||
self.AddText(box, lt1_uni[0], lt1_uni[1], 'Lithuanian:', font)
|
||||
self.AddLine(box)
|
||||
self.AddText(box, lt2_uni[0], lt2_uni[1], 'Lithuanian:', font)
|
||||
self.AddLine(box)
|
||||
|
||||
self.AddText(box, kor_uni[0], kor_uni[1], 'Korean:', font)
|
||||
self.AddLine(box)
|
||||
|
||||
self.AddText(box, bul_uni[0], bul_uni[1], 'Bulgarian:', font)
|
||||
self.AddLine(box)
|
||||
self.AddText(box, rus_uni[0], rus_uni[1], 'Russian:', font)
|
||||
self.AddLine(box)
|
||||
|
||||
|
||||
border = wxBoxSizer(wxVERTICAL)
|
||||
border.Add(box, 1, wxEXPAND|wxALL, 10)
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(border)
|
||||
|
||||
|
||||
def AddLine(self, sizer):
|
||||
sizer.Add(wxStaticLine(self, -1), 0, wxEXPAND)
|
||||
|
||||
def AddText(self, sizer, text1, text2='', lang='', font=None):
|
||||
# create some controls
|
||||
lang = wxStaticText(self, -1, lang)
|
||||
text1 = wxStaticText(self, -1, text1)
|
||||
text2 = wxStaticText(self, -1, text2, style=wxALIGN_RIGHT)
|
||||
if font is not None:
|
||||
text1.SetFont(font)
|
||||
|
||||
# put them in a sizer
|
||||
row = wxBoxSizer(wxHORIZONTAL)
|
||||
row.Add(lang)
|
||||
row.Add(15,10)
|
||||
row.Add(text1, 1, wxEXPAND)
|
||||
row.Add(text2)
|
||||
|
||||
# put the row in the main sizer
|
||||
sizer.Add(row, 0, wxEXPAND|wxALL, 5)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = TestPanel(nb, log)
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
overview = """<html><body>
|
||||
<h2><center>wxPython Unicode Support</center></h2>
|
||||
|
||||
wxWindows and wxPython can be compiled with unicode support enabled or
|
||||
disabled. Previous to wxPython 2.3.3 non-unicode mode was always
|
||||
used. Starting with 2.3.3 either mode is supported, but only if it is
|
||||
also available in wxWindow on the platform. Currently wxWindows only
|
||||
supports unicode on MS Windows platforms, but with the recent release
|
||||
of GTK+ 2.0 it is only a matter of time until it can be done on wxGTK
|
||||
(Linux and other unixes) as well.
|
||||
<p>
|
||||
When unicode is enabled, then all functions and methods in wxPython
|
||||
that return a wxString from the C++ function will return a Python
|
||||
unicode object, and parameters to C++ functions/methods that expect a
|
||||
wxString can accept either a Python string or unicode object. If a
|
||||
string object is passed then it will be decoded into unicode using the
|
||||
converter pointed to by wxConvCurrent, which will use the default
|
||||
system encoding. If you need to use string in some other encoding
|
||||
then you should convert it to unicode using the Python codecs first
|
||||
and then pass the unicode to the wxPython method.
|
||||
|
||||
|
||||
</body></html>
|
||||
"""
|
@@ -1,112 +0,0 @@
|
||||
|
||||
import string, sys
|
||||
|
||||
py2 = sys.version[0] == '2'
|
||||
|
||||
from wxPython.wx import *
|
||||
try:
|
||||
if py2:
|
||||
from xml.parsers import expat
|
||||
parsermodule = expat
|
||||
else:
|
||||
from xml.parsers import pyexpat
|
||||
parsermodule = pyexpat
|
||||
haveXML = true
|
||||
except ImportError:
|
||||
haveXML = false
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
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/',
|
||||
'Sorry', wxOK | wxICON_INFORMATION)
|
||||
dlg.ShowModal()
|
||||
dlg.Destroy()
|
||||
|
||||
else:
|
||||
|
||||
class XMLTree(wxTreeCtrl):
|
||||
def __init__(self, parent, ID):
|
||||
wxTreeCtrl.__init__(self, parent, ID)
|
||||
self.nodeStack = [self.AddRoot("Root")]
|
||||
|
||||
# Trees need an image list to do DnD...
|
||||
self.il = wxImageList(16,16)
|
||||
self.SetImageList(self.il)
|
||||
|
||||
# event handlers for DnD
|
||||
EVT_TREE_BEGIN_DRAG(self, ID, self.OnBeginDrag)
|
||||
EVT_TREE_END_DRAG(self, ID, self.OnEndDrag)
|
||||
|
||||
|
||||
def OnBeginDrag(self, event):
|
||||
item = event.GetItem()
|
||||
if item != self.GetRootItem():
|
||||
self.draggingItem = item
|
||||
event.Allow() # if DnD of this item is okay Allow it.
|
||||
|
||||
|
||||
def OnEndDrag(self, evt):
|
||||
itemSrc = self.draggingItem
|
||||
itemDst = evt.GetItem()
|
||||
self.draggingItem = None
|
||||
|
||||
if not itemDst.IsOk():
|
||||
print "Can't drag to here..."
|
||||
return
|
||||
|
||||
# For this simple example just take the text of the source item
|
||||
# and append it to the destination item. In real life you would
|
||||
# possibly want to copy subtrees...
|
||||
text = self.GetItemText(itemSrc)
|
||||
self.AppendItem(itemDst, text)
|
||||
self.Delete(itemSrc)
|
||||
|
||||
|
||||
# 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)
|
||||
|
||||
def EndElement(self, name ):
|
||||
self.nodeStack = self.nodeStack[:-1]
|
||||
|
||||
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 = parsermodule.ParserCreate()
|
||||
|
||||
# Tell the parser what the start element handler is
|
||||
Parser.StartElementHandler = self.StartElement
|
||||
Parser.EndElementHandler = self.EndElement
|
||||
Parser.CharacterDataHandler = self.CharacterData
|
||||
|
||||
# Parse the XML File
|
||||
ParserStatus = Parser.Parse(open(filename,'r').read(), 1)
|
||||
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
win = XMLTree(nb, -1)
|
||||
win.LoadTree("paper.xml")
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
overview = """\
|
||||
"""
|
||||
|
@@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
cd ..
|
||||
. b $*
|
||||
cd -
|
@@ -1 +0,0 @@
|
||||
new.bmp.test
|
Before Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 766 B |
Before Width: | Height: | Size: 82 KiB |
Before Width: | Height: | Size: 545 B |
Before Width: | Height: | Size: 990 B |
Before Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 630 B |
Before Width: | Height: | Size: 630 B |
Before Width: | Height: | Size: 630 B |
Before Width: | Height: | Size: 630 B |
Before Width: | Height: | Size: 681 B |
Before Width: | Height: | Size: 630 B |
Before Width: | Height: | Size: 630 B |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 238 B |
Before Width: | Height: | Size: 246 B |
Before Width: | Height: | Size: 246 B |
Before Width: | Height: | Size: 246 B |
Before Width: | Height: | Size: 246 B |
Before Width: | Height: | Size: 246 B |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 766 B |
Before Width: | Height: | Size: 238 B |
Before Width: | Height: | Size: 255 B |
Before Width: | Height: | Size: 238 B |
Before Width: | Height: | Size: 238 B |
Before Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 246 B |
Before Width: | Height: | Size: 246 B |
Before Width: | Height: | Size: 246 B |
Before Width: | Height: | Size: 822 B |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 238 B |
Before Width: | Height: | Size: 238 B |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 15 KiB |
@@ -1,2 +0,0 @@
|
||||
*.pdf
|
||||
showTips
|
@@ -1,25 +0,0 @@
|
||||
|
||||
|
||||
"""
|
||||
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)
|
||||
line = sys.stdin.readline()
|
||||
|
||||
|
||||
sys.stdout.write('\nExiting...\n')
|
@@ -1,20 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>ImageMap Test</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#FFFFFF">
|
||||
This is test.
|
||||
<img src="imagemap.png" width="269" height="249" border="0" usemap="#mymap">
|
||||
<map name="mymap">
|
||||
<area shape="poly" coords="187,85,160,121,163,153,180,129,166,225,241,223,230,155,201,121,187,86" href="test.htm">
|
||||
<area shape="circle" coords="96,89,36" href="fft.html">
|
||||
<area shape="rect" coords="43,168,124,213" href="tables.htm">
|
||||
</map>
|
||||
|
||||
|
||||
<img src="imagemap.png" usemap="#mymap">
|
||||
|
||||
</body>
|
||||
</html>
|
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 31 KiB |