A huge glob of changes in the 2.4 branch merged over to HEAD
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24050 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -11,7 +11,7 @@ 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
|
||||
This demo embeds the Internet Explorer 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.)
|
||||
|
@@ -5,11 +5,6 @@ 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):
|
||||
@@ -28,7 +23,7 @@ class TestWindow(wxScrolledWindow):
|
||||
dc = wxClientDC(self)
|
||||
dc.SetFont(self.font)
|
||||
|
||||
w,h,d,e = dc.GetFullTextExtent("Wy") # a wide character and one that decends
|
||||
w,h,d,e = dc.GetFullTextExtent("Wy") # a wide character and one that descends
|
||||
self.textHeight = h + d
|
||||
self.lineHeight = self.textHeight + 5
|
||||
self.cellWidth = w
|
||||
@@ -120,6 +115,10 @@ class TestPanel(wxPanel):
|
||||
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
# This loads a whole bunch of new color names and values
|
||||
# into wxTheColourDatabase
|
||||
colourdb.updateColourDB()
|
||||
|
||||
win = TestPanel(nb)
|
||||
return win
|
||||
|
||||
|
@@ -81,8 +81,8 @@ def runTest(frame, nb, log):
|
||||
|
||||
|
||||
overview = """
|
||||
This demo shows how to encorporate Context Sensitive
|
||||
help into your applicaiton using the wxSimpleHelpProvider class.
|
||||
This demo shows how to incorporate Context Sensitive
|
||||
help into your application using the wxSimpleHelpProvider class.
|
||||
|
||||
"""
|
||||
|
||||
|
@@ -58,7 +58,7 @@ def makeRandomRectangles(num, W, H):
|
||||
|
||||
|
||||
def makeRandomText(num):
|
||||
Np = 8 # number of charcters in text
|
||||
Np = 8 # number of characters in text
|
||||
text = []
|
||||
for i in range(num):
|
||||
word = []
|
||||
@@ -386,7 +386,7 @@ drawing routines. Currently they are:
|
||||
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
|
||||
(x1,y1, x2,y2) and pens is either None, a single pen or a list
|
||||
of pens.
|
||||
|
||||
<pre>
|
||||
|
@@ -188,7 +188,7 @@ class InnerTile(wxPanel):
|
||||
r = InnerTile.START_COLOR_TUPLE[0] + (InnerTile.DELTAS[0] * percent)
|
||||
g = InnerTile.START_COLOR_TUPLE[1] + (InnerTile.DELTAS[1] * percent)
|
||||
b = InnerTile.START_COLOR_TUPLE[2] + (InnerTile.DELTAS[2] * percent)
|
||||
self.setColor(wxColor(r,g,b))
|
||||
self.setColor(wxColor(int(r), int(g), int(b)))
|
||||
|
||||
|
||||
|
||||
|
443
wxPython/demo/FloatCanvas.py
Normal file
443
wxPython/demo/FloatCanvas.py
Normal file
@@ -0,0 +1,443 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
|
||||
## Stuff to integrate FloatCanvas into wxPython Demo
|
||||
try:
|
||||
import Numeric
|
||||
haveNumeric = True
|
||||
except ImportError:
|
||||
haveNumeric = False
|
||||
|
||||
|
||||
if not haveNumeric:
|
||||
errorText = """\
|
||||
The FloatCanvas requires the Numeric module:
|
||||
You can get it at:
|
||||
http://sourceforge.net/projects/numpy
|
||||
"""
|
||||
def runTest(frame, nb, log):
|
||||
dlg = wxMessageDialog(frame, errorText,
|
||||
'Sorry', wxOK | wxICON_INFORMATION)
|
||||
dlg.ShowModal()
|
||||
dlg.Destroy()
|
||||
|
||||
overview = ""
|
||||
|
||||
else:
|
||||
def runTest(frame, nb, log):
|
||||
"""
|
||||
This method is used by the wxPython Demo Framework for integrating
|
||||
this demo with the rest.
|
||||
"""
|
||||
win = DrawFrame(NULL, -1, "FloatCanvas Drawing Window",wxDefaultPosition,wxSize(500,500))
|
||||
frame.otherWin = win
|
||||
win.Show(True)
|
||||
|
||||
|
||||
|
||||
from wxPython.lib import floatcanvas
|
||||
import wxPython.lib.colourdb
|
||||
|
||||
ID_ABOUT_MENU = wxNewId()
|
||||
ID_EXIT_MENU = wxNewId()
|
||||
ID_ZOOM_TO_FIT_MENU = wxNewId()
|
||||
ID_DRAWTEST_MENU = wxNewId()
|
||||
ID_LINETEST_MENU = wxNewId()
|
||||
ID_DRAWMAP_MENU = wxNewId()
|
||||
ID_DRAWMAP2_MENU = wxNewId()
|
||||
ID_CLEAR_MENU = wxNewId()
|
||||
|
||||
wxPython.lib.colourdb.updateColourDB()
|
||||
colors = wxPython.lib.colourdb.getColourList()
|
||||
|
||||
LineStyles = floatcanvas.draw_object.LineStyleList.keys()
|
||||
|
||||
class DrawFrame(wxFrame):
|
||||
|
||||
"""
|
||||
|
||||
A frame used for the FloatCanvas Demo
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,parent, id,title,position,size):
|
||||
wxFrame.__init__(self,parent, id,title,position, size)
|
||||
|
||||
## Set up the MenuBar
|
||||
|
||||
MenuBar = wxMenuBar()
|
||||
|
||||
file_menu = wxMenu()
|
||||
file_menu.Append(ID_EXIT_MENU, "&Close","Close this frame")
|
||||
EVT_MENU(self, ID_EXIT_MENU, self.OnQuit)
|
||||
MenuBar.Append(file_menu, "&File")
|
||||
|
||||
draw_menu = wxMenu()
|
||||
draw_menu.Append(ID_DRAWTEST_MENU, "&Draw Test","Run a test of drawing random components")
|
||||
EVT_MENU(self, ID_DRAWTEST_MENU,self.DrawTest)
|
||||
draw_menu.Append(ID_LINETEST_MENU, "&Line Test","Run a test of drawing random lines")
|
||||
EVT_MENU(self, ID_LINETEST_MENU,self.LineTest)
|
||||
draw_menu.Append(ID_DRAWMAP_MENU, "Draw &Map","Run a test of drawing a map")
|
||||
EVT_MENU(self, ID_DRAWMAP_MENU,self.DrawMap)
|
||||
draw_menu.Append(ID_CLEAR_MENU, "&Clear","Clear the Canvas")
|
||||
EVT_MENU(self, ID_CLEAR_MENU,self.Clear)
|
||||
MenuBar.Append(draw_menu, "&Draw")
|
||||
|
||||
|
||||
view_menu = wxMenu()
|
||||
view_menu.Append(ID_ZOOM_TO_FIT_MENU, "Zoom to &Fit","Zoom to fit the window")
|
||||
EVT_MENU(self, ID_ZOOM_TO_FIT_MENU,self.ZoomToFit)
|
||||
MenuBar.Append(view_menu, "&View")
|
||||
|
||||
help_menu = wxMenu()
|
||||
help_menu.Append(ID_ABOUT_MENU, "&About",
|
||||
"More information About this program")
|
||||
EVT_MENU(self, ID_ABOUT_MENU, self.OnAbout)
|
||||
MenuBar.Append(help_menu, "&Help")
|
||||
|
||||
self.SetMenuBar(MenuBar)
|
||||
|
||||
self.CreateStatusBar()
|
||||
self.SetStatusText("")
|
||||
|
||||
EVT_CLOSE(self, self.OnCloseWindow)
|
||||
|
||||
# Other event handlers:
|
||||
EVT_RIGHT_DOWN(self, self.RightButtonEvent)
|
||||
|
||||
# Add the Canvas
|
||||
self.Canvas = floatcanvas.FloatCanvas(self,-1,(500,500),
|
||||
ProjectionFun = 'FlatEarth',
|
||||
Debug = 1,
|
||||
EnclosingFrame = self,
|
||||
BackgroundColor = "DARK SLATE BLUE",
|
||||
UseBackground = 0,
|
||||
UseToolbar = 1)
|
||||
self.Show(True)
|
||||
|
||||
self.object_list = []
|
||||
|
||||
return None
|
||||
|
||||
def RightButtonEvent(self,event):
|
||||
print "Right Button has been clicked in DrawFrame"
|
||||
print "coords are: %i, %i"%(event.GetX(),event.GetY())
|
||||
event.Skip()
|
||||
|
||||
def OnAbout(self, event):
|
||||
dlg = wxMessageDialog(self, "This is a small program to demonstrate\n"
|
||||
"the use of the FloatCanvas\n",
|
||||
"About Me", wxOK | wxICON_INFORMATION)
|
||||
dlg.ShowModal()
|
||||
dlg.Destroy()
|
||||
|
||||
def SetMode(self,event):
|
||||
for id in [ID_ZOOM_IN_BUTTON,ID_ZOOM_OUT_BUTTON,ID_MOVE_MODE_BUTTON]:
|
||||
self.ToolBar.ToggleTool(id,0)
|
||||
self.ToolBar.ToggleTool(event.GetId(),1)
|
||||
if event.GetId() == ID_ZOOM_IN_BUTTON:
|
||||
self.Canvas.SetGUIMode("ZoomIn")
|
||||
elif event.GetId() == ID_ZOOM_OUT_BUTTON:
|
||||
self.Canvas.SetGUIMode("ZoomOut")
|
||||
elif event.GetId() == ID_MOVE_MODE_BUTTON:
|
||||
self.Canvas.SetGUIMode("Move")
|
||||
|
||||
def ZoomToFit(self,event):
|
||||
self.Canvas.ZoomToBB()
|
||||
|
||||
def Clear(self,event = None):
|
||||
self.Canvas.RemoveObjects(self.object_list)
|
||||
self.object_list = []
|
||||
self.Canvas.Draw()
|
||||
|
||||
def OnQuit(self,event):
|
||||
self.Close(True)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
def DrawTest(self,event):
|
||||
wxGetApp().Yield()
|
||||
import random
|
||||
import RandomArray
|
||||
Range = (-10,10)
|
||||
|
||||
Canvas = self.Canvas
|
||||
object_list = self.object_list
|
||||
|
||||
## Random tests of everything:
|
||||
|
||||
# Rectangles
|
||||
for i in range(5):
|
||||
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
|
||||
lw = random.randint(1,5)
|
||||
cf = random.randint(0,len(colors)-1)
|
||||
h = random.randint(1,5)
|
||||
w = random.randint(1,5)
|
||||
object_list.append(Canvas.AddRectangle(x,y,h,w,LineWidth = lw,FillColor = colors[cf]))
|
||||
|
||||
# Ellipses
|
||||
for i in range(5):
|
||||
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
|
||||
lw = random.randint(1,5)
|
||||
cf = random.randint(0,len(colors)-1)
|
||||
h = random.randint(1,5)
|
||||
w = random.randint(1,5)
|
||||
object_list.append(Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor = colors[cf]))
|
||||
|
||||
# Dots
|
||||
for i in range(5):
|
||||
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
|
||||
D = random.randint(1,50)
|
||||
lw = random.randint(1,5)
|
||||
cf = random.randint(0,len(colors)-1)
|
||||
cl = random.randint(0,len(colors)-1)
|
||||
object_list.append(Canvas.AddDot(x,y,D,LineWidth = lw,LineColor = colors[cl],FillColor = colors[cf]))
|
||||
|
||||
# Circles
|
||||
for i in range(5):
|
||||
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
|
||||
D = random.randint(1,5)
|
||||
lw = random.randint(1,5)
|
||||
cf = random.randint(0,len(colors)-1)
|
||||
cl = random.randint(0,len(colors)-1)
|
||||
object_list.append(Canvas.AddCircle(x,y,D,LineWidth = lw,LineColor = colors[cl],FillColor = colors[cf]))
|
||||
self.object_list.append(self.Canvas.AddText("Circle # %i"%(i),x,y,Size = 12,BackGround = None,Position = "cc"))
|
||||
|
||||
# Lines
|
||||
for i in range(5):
|
||||
points = []
|
||||
for j in range(random.randint(2,10)):
|
||||
point = (random.randint(Range[0],Range[1]),random.randint(Range[0],Range[1]))
|
||||
points.append(point)
|
||||
lw = random.randint(1,10)
|
||||
cf = random.randint(0,len(colors)-1)
|
||||
cl = random.randint(0,len(colors)-1)
|
||||
self.object_list.append(self.Canvas.AddLine(points, LineWidth = lw, LineColor = colors[cl]))
|
||||
|
||||
# Polygons
|
||||
for i in range(3):
|
||||
points = []
|
||||
for j in range(random.randint(2,6)):
|
||||
point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
|
||||
points.append(point)
|
||||
lw = random.randint(1,6)
|
||||
cf = random.randint(0,len(colors)-1)
|
||||
cl = random.randint(0,len(colors)-1)
|
||||
self.object_list.append(self.Canvas.AddPolygon(points,
|
||||
LineWidth = lw,
|
||||
LineColor = colors[cl],
|
||||
FillColor = colors[cf],
|
||||
FillStyle = 'Solid'))
|
||||
|
||||
|
||||
## Pointset
|
||||
for i in range(4):
|
||||
points = []
|
||||
points = RandomArray.uniform(Range[0],Range[1],(100,2))
|
||||
cf = random.randint(0,len(colors)-1)
|
||||
D = random.randint(1,4)
|
||||
self.object_list.append(self.Canvas.AddPointSet(points, Color = colors[cf], Diameter = D))
|
||||
|
||||
# Text
|
||||
String = "Some text"
|
||||
for i in range(10):
|
||||
ts = random.randint(10,40)
|
||||
cf = random.randint(0,len(colors)-1)
|
||||
x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
|
||||
self.object_list.append(self.Canvas.AddText(String,x,y,Size = ts,ForeGround = colors[cf],Position = "cc"))
|
||||
|
||||
self.Canvas.ZoomToBB()
|
||||
|
||||
def DrawMap(self,event = None):
|
||||
wxGetApp().Yield()
|
||||
import os, time
|
||||
## Test of Actual Map Data
|
||||
self.Clear()
|
||||
start = time.clock()
|
||||
Shorelines = Read_MapGen(os.path.join("data",'world.dat'),stats = 0)
|
||||
print "It took %f seconds to load %i shorelines"%(time.clock() - start,len(Shorelines) )
|
||||
start = time.clock()
|
||||
for segment in Shorelines:
|
||||
self.object_list.append(self.Canvas.AddLine(segment))
|
||||
print "It took %f seconds to add %i shorelines"%(time.clock() - start,len(Shorelines) )
|
||||
start = time.clock()
|
||||
self.Canvas.ZoomToBB()
|
||||
print "It took %f seconds to draw %i shorelines"%(time.clock() - start,len(Shorelines) )
|
||||
|
||||
## def LineTest(self,event = None):
|
||||
## wxGetApp().Yield()
|
||||
## import os, time
|
||||
## import random
|
||||
## Range = (-10,10)
|
||||
## ## Test of drawing lots of lines
|
||||
## self.Clear()
|
||||
## start = time.clock()
|
||||
## linepoints = []
|
||||
## linecolors = []
|
||||
## linewidths = []
|
||||
## linestyles = []
|
||||
## for i in range(500):
|
||||
## points = (random.randint(Range[0],Range[1]),
|
||||
## random.randint(Range[0],Range[1]))
|
||||
## linepoints.append(points)
|
||||
## points = (random.randint(Range[0],Range[1]),
|
||||
## random.randint(Range[0],Range[1]))
|
||||
## linepoints.append(points)
|
||||
## linewidths.append(random.randint(1,10) )
|
||||
## linecolors.append(colors[random.randint(0,len(colors)-1) ])
|
||||
## linestyles.append(LineStyles[random.randint(0, len(LineStyles)-1)])
|
||||
|
||||
## self.object_list.append(self.Canvas.AddLineSet(linepoints, LineWidths = linewidths, LineColors = linecolors, LineStyles = linestyles))
|
||||
## print "It took %f seconds to add %i lines"%(time.clock() - start,len(linepoints) )
|
||||
## start = time.clock()
|
||||
## self.Canvas.ZoomToBB()
|
||||
## print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) )
|
||||
|
||||
def LineTest(self,event = None):
|
||||
wxGetApp().Yield()
|
||||
import os, time
|
||||
import random
|
||||
Range = (-10,10)
|
||||
## Test of drawing lots of lines
|
||||
self.Clear()
|
||||
start = time.clock()
|
||||
linepoints = []
|
||||
linecolors = []
|
||||
linewidths = []
|
||||
for i in range(2000):
|
||||
points = (random.randint(Range[0],Range[1]),
|
||||
random.randint(Range[0],Range[1]),
|
||||
random.randint(Range[0],Range[1]),
|
||||
random.randint(Range[0],Range[1]))
|
||||
linepoints.append(points)
|
||||
linewidths.append(random.randint(1,10) )
|
||||
linecolors.append(random.randint(0,len(colors)-1) )
|
||||
for (points,color,width) in zip(linepoints,linecolors,linewidths):
|
||||
self.object_list.append(self.Canvas.AddLine((points[0:2],points[2:4]), LineWidth = width, LineColor = colors[color]))
|
||||
print "It took %f seconds to add %i lines"%(time.clock() - start,len(linepoints) )
|
||||
start = time.clock()
|
||||
self.Canvas.ZoomToBB()
|
||||
print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) )
|
||||
|
||||
class DemoApp(wxApp):
|
||||
"""
|
||||
How the demo works:
|
||||
|
||||
Under the Draw menu, there are three options:
|
||||
|
||||
*Draw Test: will put up a picture of a bunch of randomly generated
|
||||
objects, of each kind supported.
|
||||
|
||||
*Draw Map: will draw a map of the world. Be patient, it is a big map,
|
||||
with a lot of data, and will take a while to load and draw (about 10 sec
|
||||
on my 450Mhz PIII). Redraws take about 2 sec. This demonstrates how the
|
||||
performance is not very good for large drawings.
|
||||
|
||||
*Clear: Clears the Canvas.
|
||||
|
||||
Once you have a picture drawn, you can zoom in and out and move about
|
||||
the picture. There is a tool bar with three tools that can be
|
||||
selected.
|
||||
|
||||
The magnifying glass with the plus is the zoom in tool. Once selected,
|
||||
if you click the image, it will zoom in, centered on where you
|
||||
clicked. If you click and drag the mouse, you will get a rubber band
|
||||
box, and the image will zoom to fit that box when you release it.
|
||||
|
||||
The magnifying glass with the minus is the zoom out tool. Once selected,
|
||||
if you click the image, it will zoom out, centered on where you
|
||||
clicked. (note that this takes a while when you are looking at the map,
|
||||
as it has a LOT of lines to be drawn. The image is double buffered, so
|
||||
you don't see the drawing in progress)
|
||||
|
||||
The hand is the move tool. Once selected, if you click and drag on the
|
||||
image, it will move so that the part you clicked on ends up where you
|
||||
release the mouse. Nothing is changed while you are dragging. The
|
||||
drawing is too slow for that.
|
||||
|
||||
I'd like the cursor to change as you change tools, but the stock
|
||||
wxCursors didn't include anything I liked, so I stuck with the
|
||||
pointer. Please let me know if you have any nice cursor images for me to
|
||||
use.
|
||||
|
||||
|
||||
Any bugs, comments, feedback, questions, and especially code are welcome:
|
||||
|
||||
-Chris Barker
|
||||
|
||||
Chris.Barker@noaa.gov
|
||||
|
||||
"""
|
||||
|
||||
def OnInit(self):
|
||||
frame = DrawFrame(NULL, -1, "FloatCanvas Demo App",wxDefaultPosition,wxSize(700,700))
|
||||
|
||||
self.SetTopWindow(frame)
|
||||
|
||||
return True
|
||||
|
||||
def Read_MapGen(filename,stats = 0,AllLines=0):
|
||||
"""
|
||||
This function reads a MapGen Format file, and
|
||||
returns a list of NumPy arrays with the line segments in them.
|
||||
|
||||
Each NumPy array in the list is an NX2 array of Python Floats.
|
||||
|
||||
The demo should have come with a file, "world.dat" that is the
|
||||
shorelines of the whole world, in MapGen format.
|
||||
|
||||
"""
|
||||
import string
|
||||
from Numeric import array
|
||||
file = open(filename,'rt')
|
||||
data = file.readlines()
|
||||
data = map(string.strip,data)
|
||||
|
||||
Shorelines = []
|
||||
segment = []
|
||||
for line in data:
|
||||
if line:
|
||||
if line == "# -b": #New segment beginning
|
||||
if segment: Shorelines.append(array(segment))
|
||||
segment = []
|
||||
else:
|
||||
segment.append(map(float,string.split(line)))
|
||||
if segment: Shorelines.append(array(segment))
|
||||
|
||||
if stats:
|
||||
NumSegments = len(Shorelines)
|
||||
NumPoints = 0
|
||||
for segment in Shorelines:
|
||||
NumPoints = NumPoints + len(segment)
|
||||
AvgPoints = NumPoints / NumSegments
|
||||
print "Number of Segments: ", NumSegments
|
||||
print "Average Number of Points per segment: ",AvgPoints
|
||||
if AllLines:
|
||||
Lines = []
|
||||
for segment in Shorelines:
|
||||
Lines.append(segment[0])
|
||||
for point in segment[1:-1]:
|
||||
Lines.append(point)
|
||||
Lines.append(point)
|
||||
Lines.append(segment[-1])
|
||||
#print Shorelines
|
||||
#for point in Lines: print point
|
||||
return Lines
|
||||
else:
|
||||
return Shorelines
|
||||
|
||||
## for the wxPython demo:
|
||||
overview = floatcanvas.FloatCanvas.__doc__
|
||||
|
||||
if __name__ == "__main__":
|
||||
if not haveNumeric:
|
||||
print errorText
|
||||
else:
|
||||
app = DemoApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
@@ -83,7 +83,7 @@ class CustomDataTable(wxPyGridTableBase):
|
||||
|
||||
# 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.
|
||||
# natively by the editor/renderer if they know how to convert.
|
||||
def GetTypeName(self, row, col):
|
||||
return self.dataTypes[col]
|
||||
|
||||
|
@@ -160,7 +160,7 @@ class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin):
|
||||
|
||||
# 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
|
||||
# won't have any effect. Instead, set coordinates to move to in
|
||||
# idle time.
|
||||
value = self.GetCellValue(evt.GetRow(), evt.GetCol())
|
||||
if value == 'no good':
|
||||
|
@@ -28,6 +28,8 @@ _treeList = [
|
||||
('Recent Additions', [
|
||||
'wxVListBox',
|
||||
'wxListbook',
|
||||
'wxMaskedNumCtrl',
|
||||
'FloatCanvas',
|
||||
]),
|
||||
|
||||
# managed windows == things with a (optional) caption you can close
|
||||
@@ -100,7 +102,7 @@ _treeList = [
|
||||
'wxValidator',
|
||||
]),
|
||||
|
||||
# controls coming from other librairies
|
||||
# controls coming from other libraries
|
||||
('More Windows/Controls', [
|
||||
#'wxFloatBar', deprecated
|
||||
#'wxMVCTree', deprecated
|
||||
@@ -109,6 +111,7 @@ _treeList = [
|
||||
'ColourSelect',
|
||||
'ContextHelp',
|
||||
'FancyText',
|
||||
'FloatCanvas',
|
||||
'FileBrowseButton',
|
||||
'GenericButtons',
|
||||
'MaskedEditControls',
|
||||
@@ -128,6 +131,7 @@ _treeList = [
|
||||
'wxIntCtrl',
|
||||
'wxLEDNumberCtrl',
|
||||
'wxMimeTypesManager',
|
||||
'wxMaskedNumCtrl',
|
||||
'wxMultiSash',
|
||||
'wxPopupControl',
|
||||
'wxStyledTextCtrl_1',
|
||||
@@ -212,6 +216,7 @@ _treeList = [
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Show how to derive a custom wxLog class
|
||||
|
||||
class MyLog(wx.PyLog):
|
||||
def __init__(self, textCtrl, logTime=0):
|
||||
@@ -235,6 +240,7 @@ class MyTP(wx.PyTipProvider):
|
||||
# A class to be used to display source code in the demo. Try using the
|
||||
# wxSTC in the wxStyledTextCtrl_2 sample first, fall back to wxTextCtrl
|
||||
# if there is an error, such as the stc module not being present.
|
||||
#
|
||||
|
||||
try:
|
||||
##raise ImportError
|
||||
@@ -814,7 +820,7 @@ platform GUI library, which is written in C++.
|
||||
<p> Like Python and wxWindows, wxPython is <b>Open Source</b> which
|
||||
means that it is free for anyone to use and the source code is
|
||||
available for anyone to look at and modify. Or anyone can contribute
|
||||
fixes or enhnacments to the project.
|
||||
fixes or enhancements to the project.
|
||||
|
||||
<p> wxPython is a <b>cross-platform</b> toolkit. This means that the
|
||||
same program will run on multiple platforms without modification.
|
||||
|
@@ -1,10 +1,12 @@
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.maskededit import Field, wxMaskedTextCtrl, wxMaskedComboBox, wxIpAddrCtrl, states, months
|
||||
from wxPython.lib.maskededit import __doc__ as overviewdoc
|
||||
from wxPython.lib.maskededit import Field, wxMaskedTextCtrl, wxMaskedComboBox, wxIpAddrCtrl, states, state_names, months
|
||||
from wxPython.lib.maskededit import __doc__ as maskededit_doc
|
||||
from wxPython.lib.maskededit import autoformats
|
||||
from wxPython.lib.maskedctrl import wxMaskedCtrl, controlTypes, MASKEDCOMBO
|
||||
from wxPython.lib.scrolledpanel import wxScrolledPanel
|
||||
import string, sys, traceback
|
||||
|
||||
|
||||
class demoMixin:
|
||||
"""
|
||||
Centralized routines common to demo pages, to remove repetition.
|
||||
@@ -14,7 +16,7 @@ class demoMixin:
|
||||
mask = wxStaticText( self, -1, "Mask Value" )
|
||||
formatcode = wxStaticText( self, -1, "Format" )
|
||||
regex = wxStaticText( self, -1, "Regexp Validator(opt.)" )
|
||||
ctrl = wxStaticText( self, -1, "wxMaskedEdit Ctrl" )
|
||||
ctrl = wxStaticText( self, -1, "wxMaskedTextCtrl" )
|
||||
|
||||
description.SetFont( wxFont(9, wxSWISS, wxNORMAL, wxBOLD))
|
||||
mask.SetFont( wxFont(9, wxSWISS, wxNORMAL, wxBOLD))
|
||||
@@ -130,7 +132,7 @@ Smith, Jones, Williams). Signs on numbers can be toggled with the minus key.
|
||||
|
||||
def onHighlightEmpty( self, event ):
|
||||
""" Highlight empty values"""
|
||||
self.changeControlParams( event, "emptyBackgroundColor", "Blue", "White" )
|
||||
self.changeControlParams( event, "emptyBackgroundColour", "Blue", "White" )
|
||||
|
||||
def onShowFill( self, event ):
|
||||
""" Set fillChar parameter to '?' or ' ' """
|
||||
@@ -144,8 +146,9 @@ class demoPage2(wxScrolledPanel, demoMixin):
|
||||
self.sizer = wxBoxSizer( wxVERTICAL )
|
||||
|
||||
label = wxStaticText( self, -1, """\
|
||||
All these controls have been created by passing a single parameter, the autoformat code.
|
||||
The class contains an internal dictionary of types and formats (autoformats).
|
||||
All these controls have been created by passing a single parameter, the autoformat code,
|
||||
and use the factory class wxMaskedCtrl with its default controlType.
|
||||
The maskededit module contains an internal dictionary of types and formats (autoformats).
|
||||
Many of these already do complicated validation; To see some examples, try
|
||||
29 Feb 2002 vs. 2004 for the date formats, or email address validation.
|
||||
""")
|
||||
@@ -155,7 +158,7 @@ Many of these already do complicated validation; To see some examples, try
|
||||
|
||||
description = wxStaticText( self, -1, "Description")
|
||||
autofmt = wxStaticText( self, -1, "AutoFormat Code")
|
||||
ctrl = wxStaticText( self, -1, "wxMaskedEdit Control")
|
||||
ctrl = wxStaticText( self, -1, "wxMaskedCtrl")
|
||||
|
||||
description.SetFont( wxFont( 9, wxSWISS, wxNORMAL, wxBOLD ) )
|
||||
autofmt.SetFont( wxFont( 9, wxSWISS, wxNORMAL, wxBOLD ) )
|
||||
@@ -169,10 +172,10 @@ Many of these already do complicated validation; To see some examples, try
|
||||
for autoformat, desc in autoformats:
|
||||
grid.Add( wxStaticText( self, -1, desc), 0, wxALIGN_LEFT )
|
||||
grid.Add( wxStaticText( self, -1, autoformat), 0, wxALIGN_LEFT )
|
||||
grid.Add( wxMaskedTextCtrl( self, -1, "",
|
||||
autoformat = autoformat,
|
||||
demo = True,
|
||||
name = autoformat),
|
||||
grid.Add( wxMaskedCtrl( self, -1, "",
|
||||
autoformat = autoformat,
|
||||
demo = True,
|
||||
name = autoformat),
|
||||
0, wxALIGN_LEFT )
|
||||
|
||||
self.sizer.Add( grid, 0, wxALIGN_LEFT|wxALL, border=5 )
|
||||
@@ -208,7 +211,7 @@ has a legal range specified.
|
||||
controls = [
|
||||
#description mask excl format regexp range,list,initial
|
||||
("U.S. State (2 char)", "AA", "", 'F!_', "[A-Z]{2}", '',states, states[0]),
|
||||
("Integer (signed)", "#{6}", "", 'F-_R', "", '','', '0 '),
|
||||
("Integer (signed)", "#{6}", "", 'F-_', "", '','', ' 0 '),
|
||||
("Integer (unsigned)\n(1-399)","######", "", 'F_', "", (1,399),'', '1 '),
|
||||
("Float (signed)", "#{6}.#{9}", "", 'F-_R', "", '','', '000000.000000000'),
|
||||
("Date (MDY) + Time", "##/##/#### ##:##:## AM", 'BCDEFGHIJKLMNOQRSTUVWXYZ','DF!',"", '','', wxDateTime_Now().Format("%m/%d/%Y %I:%M:%S %p")),
|
||||
@@ -248,7 +251,7 @@ Page Up and Shift-Up arrow will similarly cycle backwards through the list.
|
||||
description = wxStaticText( self, -1, "Description" )
|
||||
autofmt = wxStaticText( self, -1, "AutoFormat Code" )
|
||||
fields = wxStaticText( self, -1, "Field Objects" )
|
||||
ctrl = wxStaticText( self, -1, "wxMaskedEdit Control" )
|
||||
ctrl = wxStaticText( self, -1, "wxMaskedTextCtrl" )
|
||||
|
||||
description.SetFont( wxFont( 9, wxSWISS, wxNORMAL, wxBOLD ) )
|
||||
autofmt.SetFont( wxFont( 9, wxSWISS, wxNORMAL, wxBOLD ) )
|
||||
@@ -325,12 +328,33 @@ class demoPage5(wxScrolledPanel, demoMixin):
|
||||
self.log = log
|
||||
wxScrolledPanel.__init__( self, parent, -1 )
|
||||
self.sizer = wxBoxSizer( wxVERTICAL )
|
||||
label = wxStaticText( self, -1, """\
|
||||
These are examples of wxMaskedComboBox and wxIpAddrCtrl, and more useful
|
||||
configurations of a wxMaskedTextCtrl for integer and floating point input.
|
||||
""")
|
||||
label.SetForegroundColour( "Blue" )
|
||||
self.sizer.Add( label, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
|
||||
|
||||
labelMaskedCombos = wxStaticText( self, -1, """\
|
||||
These are some examples of wxMaskedComboBox:""")
|
||||
labelMaskedCombos.SetForegroundColour( "Blue" )
|
||||
|
||||
|
||||
label_statecode = wxStaticText( self, -1, """\
|
||||
A state selector; only
|
||||
"legal" values can be
|
||||
entered:""")
|
||||
statecode = wxMaskedComboBox( self, -1, states[0],
|
||||
choices = states,
|
||||
autoformat="USSTATE")
|
||||
|
||||
label_statename = wxStaticText( self, -1, """\
|
||||
A state name selector,
|
||||
with auto-select:""")
|
||||
|
||||
# Create this one using factory function:
|
||||
statename = wxMaskedCtrl( self, -1, state_names[0],
|
||||
controlType = controlTypes.MASKEDCOMBO,
|
||||
choices = state_names,
|
||||
autoformat="USSTATENAME",
|
||||
autoSelect=True)
|
||||
statename.SetCtrlParameters(formatcodes = 'F!V_')
|
||||
|
||||
|
||||
numerators = [ str(i) for i in range(1, 4) ]
|
||||
denominators = [ string.ljust(str(i), 2) for i in [2,3,4,5,8,16,32,64] ]
|
||||
@@ -343,21 +367,22 @@ configurations of a wxMaskedTextCtrl for integer and floating point input.
|
||||
choices.append( '%s/%s' % (n,d) )
|
||||
|
||||
|
||||
text1 = wxStaticText( self, -1, """\
|
||||
label_fraction = wxStaticText( self, -1, """\
|
||||
A masked ComboBox for fraction selection.
|
||||
Choices for each side of the fraction can be
|
||||
selected with PageUp/Down:""")
|
||||
Choices for each side of the fraction can
|
||||
be selected with PageUp/Down:""")
|
||||
|
||||
fraction = wxMaskedComboBox( self, -1, "",
|
||||
choices = choices,
|
||||
choiceRequired = True,
|
||||
mask = "#/##",
|
||||
formatcodes = "F_",
|
||||
validRegex = "^\d\/\d\d?",
|
||||
fields = fieldsDict )
|
||||
fraction = wxMaskedCtrl( self, -1, "",
|
||||
controlType = MASKEDCOMBO,
|
||||
choices = choices,
|
||||
choiceRequired = True,
|
||||
mask = "#/##",
|
||||
formatcodes = "F_",
|
||||
validRegex = "^\d\/\d\d?",
|
||||
fields = fieldsDict )
|
||||
|
||||
|
||||
text2 = wxStaticText( self, -1, """
|
||||
label_code = wxStaticText( self, -1, """\
|
||||
A masked ComboBox to validate
|
||||
text from a list of numeric codes:""")
|
||||
|
||||
@@ -368,100 +393,155 @@ text from a list of numeric codes:""")
|
||||
formatcodes = "F_r",
|
||||
mask = "####")
|
||||
|
||||
label_selector = wxStaticText( self, -1, """\
|
||||
Programmatically set
|
||||
choice sets:""")
|
||||
self.list_selector = wxComboBox(self, -1, '', choices = ['list1', 'list2', 'list3'])
|
||||
self.dynamicbox = wxMaskedCtrl( self, -1, ' ',
|
||||
controlType = controlTypes.MASKEDCOMBO,
|
||||
mask = 'XXXX',
|
||||
formatcodes = 'F_',
|
||||
# these are to give dropdown some initial height,
|
||||
# as base control apparently only sets that size
|
||||
# during initial construction <sigh>:
|
||||
choices = ['', '1', '2', '3', '4', '5'] )
|
||||
|
||||
text3 = wxStaticText( self, -1, """\
|
||||
A masked state selector; only "legal" values
|
||||
can be entered:""")
|
||||
|
||||
state = wxMaskedComboBox( self, -1, states[0],
|
||||
choices = states,
|
||||
autoformat="USSTATE")
|
||||
|
||||
text4 = wxStaticText( self, -1, "An empty IP Address entry control:")
|
||||
ip_addr1 = wxIpAddrCtrl( self, -1, style = wxTE_PROCESS_TAB )
|
||||
self.dynamicbox.Clear() # get rid of initial choices used to size the dropdown
|
||||
|
||||
|
||||
text5 = wxStaticText( self, -1, "An IP Address control with a restricted mask:")
|
||||
ip_addr2 = wxIpAddrCtrl( self, -1, mask=" 10. 1.109.###" )
|
||||
labelIpAddrs = wxStaticText( self, -1, """\
|
||||
Here are some examples of wxIpAddrCtrl, a control derived from wxMaskedTextCtrl:""")
|
||||
labelIpAddrs.SetForegroundColour( "Blue" )
|
||||
|
||||
|
||||
text6 = wxStaticText( self, -1, """\
|
||||
An IP Address control with restricted choices
|
||||
of form: 10. (1|2) . (129..255) . (0..255)""")
|
||||
ip_addr3 = wxIpAddrCtrl( self, -1, mask=" 10. #.###.###")
|
||||
ip_addr3.SetFieldParameters(0, validRegex="1|2" ) # requires entry to match or not allowed
|
||||
label_ipaddr1 = wxStaticText( self, -1, "An empty control:")
|
||||
ipaddr1 = wxIpAddrCtrl( self, -1, style = wxTE_PROCESS_TAB )
|
||||
|
||||
|
||||
label_ipaddr2 = wxStaticText( self, -1, "A restricted mask:")
|
||||
ipaddr2 = wxIpAddrCtrl( self, -1, mask=" 10. 1.109.###" )
|
||||
|
||||
|
||||
label_ipaddr3 = wxStaticText( self, -1, """\
|
||||
A control with restricted legal values:
|
||||
10. (1|2) . (129..255) . (0..255)""")
|
||||
ipaddr3 = wxMaskedCtrl( self, -1,
|
||||
controlType = controlTypes.IPADDR,
|
||||
mask=" 10. #.###.###")
|
||||
ipaddr3.SetFieldParameters(0, validRegex="1|2",validRequired=False ) # requires entry to match or not allowed
|
||||
|
||||
# This allows any value in penultimate field, but colors anything outside of the range invalid:
|
||||
ip_addr3.SetFieldParameters(1, validRange=(129,255), validRequired=False )
|
||||
ipaddr3.SetFieldParameters(1, validRange=(129,255), validRequired=False )
|
||||
|
||||
text7 = wxStaticText( self, -1, """\
|
||||
A right-insert integer entry control:""")
|
||||
intctrl = wxMaskedTextCtrl(self, -1, name='intctrl', mask="#{9}", formatcodes = '_-r,F')
|
||||
|
||||
text8 = wxStaticText( self, -1, """\
|
||||
|
||||
labelNumerics = wxStaticText( self, -1, """\
|
||||
Here are some useful configurations of a wxMaskedTextCtrl for integer and floating point input that still treat
|
||||
the control as a text control. (For a true numeric control, check out the wxMaskedNumCtrl class!)""")
|
||||
labelNumerics.SetForegroundColour( "Blue" )
|
||||
|
||||
label_intctrl1 = wxStaticText( self, -1, """\
|
||||
An integer entry control with
|
||||
shifting insert enabled:""")
|
||||
self.intctrl1 = wxMaskedTextCtrl(self, -1, name='intctrl', mask="#{9}", formatcodes = '_-,F>')
|
||||
label_intctrl2 = wxStaticText( self, -1, """\
|
||||
Right-insert integer entry:""")
|
||||
self.intctrl2 = wxMaskedTextCtrl(self, -1, name='intctrl', mask="#{9}", formatcodes = '_-,Fr')
|
||||
|
||||
label_floatctrl = wxStaticText( self, -1, """\
|
||||
A floating point entry control
|
||||
with right-insert for ordinal:""")
|
||||
self.floatctrl = wxMaskedTextCtrl(self, -1, name='floatctrl', mask="#{9}.#{2}", formatcodes="F,_-R")
|
||||
self.floatctrl = wxMaskedTextCtrl(self, -1, name='floatctrl', mask="#{9}.#{2}", formatcodes="F,_-R", useParensForNegatives=False)
|
||||
self.floatctrl.SetFieldParameters(0, formatcodes='r<', validRequired=True) # right-insert, require explicit cursor movement to change fields
|
||||
self.floatctrl.SetFieldParameters(1, defaultValue='00') # don't allow blank fraction
|
||||
|
||||
text9 = wxStaticText( self, -1, """\
|
||||
Use this control to programmatically set
|
||||
the value of the above float control:""")
|
||||
number_combo = wxComboBox(self, -1, choices = [ '', '111', '222.22', '-3', '54321.666666666', '-1353.978',
|
||||
'1234567', '-1234567', '123456789', '-123456789.1',
|
||||
'1234567890.', '-1234567890.1' ])
|
||||
label_numselect = wxStaticText( self, -1, """\
|
||||
<= Programmatically set the value
|
||||
of the float entry ctrl:""")
|
||||
numselect = wxComboBox(self, -1, choices = [ '', '111', '222.22', '-3', '54321.666666666', '-1353.978',
|
||||
'1234567', '-1234567', '123456789', '-123456789.1',
|
||||
'1234567890.', '-1234567890.1' ])
|
||||
|
||||
grid = wxFlexGridSizer( 0, 2, vgap=10, hgap = 5 )
|
||||
grid.Add( text1, 0, wxALIGN_LEFT )
|
||||
grid.Add( fraction, 0, wxALIGN_LEFT )
|
||||
grid.Add( text2, 0, wxALIGN_LEFT )
|
||||
grid.Add( code, 0, wxALIGN_LEFT )
|
||||
grid.Add( text3, 0, wxALIGN_LEFT )
|
||||
grid.Add( state, 0, wxALIGN_LEFT )
|
||||
grid.Add( text4, 0, wxALIGN_LEFT )
|
||||
grid.Add( ip_addr1, 0, wxALIGN_LEFT )
|
||||
grid.Add( text5, 0, wxALIGN_LEFT )
|
||||
grid.Add( ip_addr2, 0, wxALIGN_LEFT )
|
||||
grid.Add( text6, 0, wxALIGN_LEFT )
|
||||
grid.Add( ip_addr3, 0, wxALIGN_LEFT )
|
||||
grid.Add( text7, 0, wxALIGN_LEFT )
|
||||
grid.Add( intctrl, 0, wxALIGN_LEFT )
|
||||
grid.Add( text8, 0, wxALIGN_LEFT )
|
||||
grid.Add( self.floatctrl, 0, wxALIGN_LEFT )
|
||||
grid.Add( text9, 0, wxALIGN_LEFT )
|
||||
grid.Add( number_combo, 0, wxALIGN_LEFT )
|
||||
parens_check = wxCheckBox(self, -1, "Use () to indicate negatives in above controls")
|
||||
|
||||
|
||||
|
||||
gridCombos = wxFlexGridSizer( 0, 4, vgap=10, hgap = 10 )
|
||||
gridCombos.Add( label_statecode, 0, wxALIGN_LEFT )
|
||||
gridCombos.Add( statecode, 0, wxALIGN_LEFT )
|
||||
gridCombos.Add( label_fraction, 0, wxALIGN_LEFT )
|
||||
gridCombos.Add( fraction, 0, wxALIGN_LEFT )
|
||||
gridCombos.Add( label_statename, 0, wxALIGN_LEFT )
|
||||
gridCombos.Add( statename, 0, wxALIGN_LEFT )
|
||||
gridCombos.Add( label_code, 0, wxALIGN_LEFT )
|
||||
gridCombos.Add( code, 0, wxALIGN_LEFT )
|
||||
gridCombos.Add( label_selector, 0, wxALIGN_LEFT)
|
||||
hbox = wxBoxSizer( wxHORIZONTAL )
|
||||
hbox.Add( self.list_selector, 0, wxALIGN_LEFT )
|
||||
hbox.Add(wxStaticText(self, -1, ' => '), 0, wxALIGN_LEFT)
|
||||
hbox.Add( self.dynamicbox, 0, wxALIGN_LEFT )
|
||||
gridCombos.Add( hbox, 0, wxALIGN_LEFT )
|
||||
|
||||
gridIpAddrs = wxFlexGridSizer( 0, 4, vgap=10, hgap = 15 )
|
||||
gridIpAddrs.Add( label_ipaddr1, 0, wxALIGN_LEFT )
|
||||
gridIpAddrs.Add( ipaddr1, 0, wxALIGN_LEFT )
|
||||
gridIpAddrs.Add( label_ipaddr2, 0, wxALIGN_LEFT )
|
||||
gridIpAddrs.Add( ipaddr2, 0, wxALIGN_LEFT )
|
||||
gridIpAddrs.Add( label_ipaddr3, 0, wxALIGN_LEFT )
|
||||
gridIpAddrs.Add( ipaddr3, 0, wxALIGN_LEFT )
|
||||
|
||||
gridNumerics = wxFlexGridSizer( 0, 4, vgap=10, hgap = 10 )
|
||||
gridNumerics.Add( label_intctrl1, 0, wxALIGN_LEFT )
|
||||
gridNumerics.Add( self.intctrl1, 0, wxALIGN_LEFT )
|
||||
gridNumerics.Add( label_intctrl2, 0, wxALIGN_RIGHT )
|
||||
gridNumerics.Add( self.intctrl2, 0, wxALIGN_LEFT )
|
||||
gridNumerics.Add( label_floatctrl, 0, wxALIGN_LEFT )
|
||||
gridNumerics.Add( self.floatctrl, 0, wxALIGN_LEFT )
|
||||
gridNumerics.Add( label_numselect, 0, wxALIGN_RIGHT )
|
||||
gridNumerics.Add( numselect, 0, wxALIGN_LEFT )
|
||||
|
||||
self.sizer.Add( labelMaskedCombos, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
self.sizer.Add( gridCombos, 0, wxALIGN_LEFT|wxALL, border=5 )
|
||||
self.sizer.Add( wxStaticLine(self, -1), 0, wxEXPAND|wxTOP|wxBOTTOM, border=8 )
|
||||
self.sizer.Add( labelIpAddrs, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
self.sizer.Add( gridIpAddrs, 0, wxALIGN_LEFT|wxALL, border=5 )
|
||||
self.sizer.Add( wxStaticLine(self, -1), 0, wxEXPAND|wxTOP|wxBOTTOM, border=8 )
|
||||
self.sizer.Add( labelNumerics, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
self.sizer.Add( gridNumerics, 0, wxALIGN_LEFT|wxALL, border=5 )
|
||||
self.sizer.Add( parens_check, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
|
||||
self.sizer.Add( grid, 0, wxALIGN_LEFT|wxALL, border=5 )
|
||||
self.SetSizer( self.sizer )
|
||||
self.SetAutoLayout(1)
|
||||
self.SetupScrolling()
|
||||
|
||||
EVT_COMBOBOX( self, fraction.GetId(), self.OnComboChange )
|
||||
EVT_COMBOBOX( self, code.GetId(), self.OnComboChange )
|
||||
EVT_COMBOBOX( self, state.GetId(), self.OnComboChange )
|
||||
EVT_TEXT( self, fraction.GetId(), self.OnComboChange )
|
||||
EVT_TEXT( self, code.GetId(), self.OnComboChange )
|
||||
EVT_TEXT( self, state.GetId(), self.OnComboChange )
|
||||
EVT_COMBOBOX( self, fraction.GetId(), self.OnComboSelection )
|
||||
EVT_COMBOBOX( self, code.GetId(), self.OnComboSelection )
|
||||
EVT_COMBOBOX( self, statecode.GetId(), self.OnComboSelection )
|
||||
EVT_COMBOBOX( self, statename.GetId(), self.OnComboSelection )
|
||||
EVT_TEXT( self, fraction.GetId(), self.OnTextChange )
|
||||
EVT_TEXT( self, code.GetId(), self.OnTextChange )
|
||||
EVT_TEXT( self, statecode.GetId(), self.OnTextChange )
|
||||
EVT_TEXT( self, statename.GetId(), self.OnTextChange )
|
||||
EVT_COMBOBOX( self, self.list_selector.GetId(), self.OnListSelection )
|
||||
|
||||
EVT_TEXT( self, ip_addr1.GetId(), self.OnIpAddrChange )
|
||||
EVT_TEXT( self, ip_addr2.GetId(), self.OnIpAddrChange )
|
||||
EVT_TEXT( self, ip_addr3.GetId(), self.OnIpAddrChange )
|
||||
EVT_TEXT( self, intctrl.GetId(), self.OnTextChange )
|
||||
EVT_TEXT( self, self.intctrl1.GetId(), self.OnTextChange )
|
||||
EVT_TEXT( self, self.intctrl2.GetId(), self.OnTextChange )
|
||||
EVT_TEXT( self, self.floatctrl.GetId(), self.OnTextChange )
|
||||
EVT_COMBOBOX( self, number_combo.GetId(), self.OnNumberSelect )
|
||||
EVT_COMBOBOX( self, numselect.GetId(), self.OnNumberSelect )
|
||||
EVT_CHECKBOX( self, parens_check.GetId(), self.OnParensCheck )
|
||||
|
||||
EVT_TEXT( self, ipaddr1.GetId(), self.OnIpAddrChange )
|
||||
EVT_TEXT( self, ipaddr2.GetId(), self.OnIpAddrChange )
|
||||
EVT_TEXT( self, ipaddr3.GetId(), self.OnIpAddrChange )
|
||||
|
||||
|
||||
def OnComboChange( self, event ):
|
||||
|
||||
|
||||
def OnComboSelection( self, event ):
|
||||
ctl = self.FindWindowById( event.GetId() )
|
||||
if not ctl.IsValid():
|
||||
self.log.write('current value not a valid choice')
|
||||
|
||||
def OnIpAddrChange( self, event ):
|
||||
ip_addr = self.FindWindowById( event.GetId() )
|
||||
if ip_addr.IsValid():
|
||||
self.log.write('new addr = %s\n' % ip_addr.GetAddress() )
|
||||
self.log.write('new value = %s' % ctl.GetValue())
|
||||
|
||||
def OnTextChange( self, event ):
|
||||
ctl = self.FindWindowById( event.GetId() )
|
||||
@@ -470,14 +550,8 @@ the value of the above float control:""")
|
||||
|
||||
def OnNumberSelect( self, event ):
|
||||
value = event.GetString()
|
||||
|
||||
# Format choice to fit into format for #{9}.#{2}, with sign position reserved:
|
||||
# (ordinal + fraction == 11 + decimal point + sign == 13)
|
||||
#
|
||||
# Note: since self.floatctrl a right-aligned control, you could also just use
|
||||
# "%.2f", but this wouldn't work properly for a left-aligned control.
|
||||
# (See .SetValue() documentation in Overview.)
|
||||
#
|
||||
if value:
|
||||
floattext = "%13.2f" % float(value)
|
||||
else:
|
||||
@@ -489,6 +563,37 @@ the value of the above float control:""")
|
||||
for line in traceback.format_exception_only(type, value):
|
||||
self.log.write(line)
|
||||
|
||||
def OnParensCheck( self, event ):
|
||||
self.intctrl1.SetCtrlParameters(useParensForNegatives=event.Checked())
|
||||
self.intctrl2.SetCtrlParameters(useParensForNegatives=event.Checked())
|
||||
self.floatctrl.SetCtrlParameters(useParensForNegatives=event.Checked())
|
||||
|
||||
def OnIpAddrChange( self, event ):
|
||||
ipaddr = self.FindWindowById( event.GetId() )
|
||||
if ipaddr.IsValid():
|
||||
self.log.write('new addr = %s\n' % ipaddr.GetAddress() )
|
||||
|
||||
def OnListSelection( self, event ):
|
||||
list = self.list_selector.GetStringSelection()
|
||||
formatcodes = 'F_'
|
||||
if list == 'list1':
|
||||
choices = ['abc', 'defg', 'hi']
|
||||
mask = 'aaaa'
|
||||
elif list == 'list2':
|
||||
choices = ['1', '2', '34', '567']
|
||||
formatcodes += 'r'
|
||||
mask = '###'
|
||||
else:
|
||||
choices = states
|
||||
mask = 'AA'
|
||||
formatcodes += '!'
|
||||
self.dynamicbox.SetCtrlParameters( mask = mask,
|
||||
choices = choices,
|
||||
choiceRequired=True,
|
||||
autoSelect=True,
|
||||
formatcodes=formatcodes)
|
||||
self.dynamicbox.SetValue(choices[0])
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
class TestMaskedTextCtrls(wxNotebook):
|
||||
def __init__(self, parent, id, log):
|
||||
@@ -530,7 +635,7 @@ if __name__ == "__main__":
|
||||
|
||||
overview = """<html>
|
||||
<PRE><FONT SIZE=-1>
|
||||
""" + overviewdoc + """
|
||||
""" + maskededit_doc + """
|
||||
</FONT></PRE>
|
||||
"""
|
||||
|
||||
|
@@ -69,7 +69,7 @@ class MyPrintout(wxPrintout):
|
||||
# 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
|
||||
# Calculate the position on the DC for centering the graphic
|
||||
posX = (w - (self.canvas.getWidth() * actualScale)) / 2.0
|
||||
posY = (h - (self.canvas.getHeight() * actualScale)) / 2.0
|
||||
|
||||
|
@@ -77,7 +77,7 @@ def runTest(frame, nb, log):
|
||||
|
||||
|
||||
overview = """\
|
||||
This demo is a contrived example of defining an event class in wxPython and sending it up the containment heirachy for processing.
|
||||
This demo is a contrived example of defining an event class in wxPython and sending it up the containment hierarchy for processing.
|
||||
"""
|
||||
|
||||
|
||||
|
@@ -362,7 +362,7 @@ theTests = [
|
||||
),
|
||||
|
||||
("Add a stretchable", makeSimpleBox3,
|
||||
"We've added one more button with the strechable flag turned on. Notice "
|
||||
"We've added one more button with the stretchable flag turned on. Notice "
|
||||
"how it grows to fill the extra space in the otherwise fixed dimension."
|
||||
),
|
||||
|
||||
@@ -372,7 +372,7 @@ theTests = [
|
||||
),
|
||||
|
||||
("Weighting factor", makeSimpleBox5,
|
||||
"This one shows more than one strechable, but one of them has a weighting "
|
||||
"This one shows more than one stretchable, but one of them has a weighting "
|
||||
"factor so it gets more of the free space."
|
||||
),
|
||||
|
||||
@@ -421,7 +421,7 @@ theTests = [
|
||||
),
|
||||
|
||||
("Boxes inside a Border", makeBoxInBorder,
|
||||
"Sizers of different types can be nested withing each other as well. "
|
||||
"Sizers of different types can be nested within each other as well. "
|
||||
"Here is a box sizer with several buttons embedded within a border sizer."
|
||||
),
|
||||
|
||||
@@ -434,7 +434,7 @@ theTests = [
|
||||
("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 "
|
||||
"fill their available space. The horizontal and vertical gaps are set to "
|
||||
"2 pixels each."
|
||||
),
|
||||
|
||||
@@ -461,7 +461,7 @@ theTests = [
|
||||
|
||||
("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."
|
||||
"wxSHAPED flag set and will resize proportional to its original size."
|
||||
),
|
||||
|
||||
("Proportional resize with Alignments", makeShapes,
|
||||
|
@@ -187,7 +187,7 @@ 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
|
||||
The initial class primarily contains a Table preview/printing class. There is a lot 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>
|
||||
|
@@ -1,5 +1,6 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib import newevent
|
||||
|
||||
import thread
|
||||
import time
|
||||
@@ -7,18 +8,8 @@ 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
|
||||
# This creates a new Event class and a EVT binder function
|
||||
UpdateBarEvent, EVT_UPDATE_BARGRAPH = newevent.NewEvent()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@@ -41,7 +32,7 @@ class CalcBarThread:
|
||||
|
||||
def Run(self):
|
||||
while self.keepGoing:
|
||||
evt = UpdateBarEvent(self.barNum, int(self.val))
|
||||
evt = UpdateBarEvent(barNum = self.barNum, value = int(self.val))
|
||||
wxPostEvent(self.win, evt)
|
||||
#del evt
|
||||
|
||||
@@ -232,7 +223,7 @@ 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
|
||||
thread, but this often severely 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
|
||||
|
61493
wxPython/demo/data/world.dat
Normal file
61493
wxPython/demo/data/world.dat
Normal file
File diff suppressed because it is too large
Load Diff
@@ -93,7 +93,7 @@ class MyApp(wx.App):
|
||||
while self.Pending():
|
||||
self.Dispatch()
|
||||
|
||||
# Send idle events to idle handlers. You may want to throtle
|
||||
# Send idle events to idle handlers. You may want to throttle
|
||||
# this back a bit so there is not too much CPU time spent in
|
||||
# the idle handlers. For this example, I'll just snooze a
|
||||
# little...
|
||||
|
@@ -1,4 +1,4 @@
|
||||
"""Basic regular expression demostration facility (Perl style syntax)."""
|
||||
"""Basic regular expression demonstration facility (Perl style syntax)."""
|
||||
|
||||
from wxPython.wx import *
|
||||
import re
|
||||
|
@@ -35,9 +35,9 @@
|
||||
When using wxPython, the call to app.Mainloop() takes over
|
||||
the thread from which it is called. This presents a
|
||||
problem for applications that want to use the standard
|
||||
Python command line user interface, while occasionaly
|
||||
Python command line user interface, while occasionally
|
||||
creating a GUI window for viewing an image, plot, etc.
|
||||
One soultion is to mangage the GUI in a second thread.
|
||||
One solution is to manage the GUI in a second thread.
|
||||
|
||||
wxPython does not behave well if windows are created in
|
||||
a thread other than the one where wxPython was originally
|
||||
|
@@ -481,7 +481,7 @@ class PrintCalend:
|
||||
|
||||
year, month = self.IncMonth(year, month)
|
||||
y = y + 3.5
|
||||
x = x + 4.0 # next colum
|
||||
x = x + 4.0 # next column
|
||||
|
||||
DC.EndDrawing()
|
||||
|
||||
|
@@ -13,7 +13,7 @@ class TestPanel(wxPanel):
|
||||
cal = wxCalendarCtrl(self, -1, wxDateTime_Now(), pos = (25,50),
|
||||
style = wxCAL_SHOW_HOLIDAYS
|
||||
| wxCAL_SUNDAY_FIRST
|
||||
#| wxCAL_SEQUENTIAL_MONTH_SELECTION
|
||||
| wxCAL_SEQUENTIAL_MONTH_SELECTION
|
||||
)
|
||||
|
||||
EVT_CALENDAR(self, cal.GetId(), self.OnCalSelected)
|
||||
|
@@ -194,7 +194,7 @@ class DragCanvas(wxScrolledWindow):
|
||||
if not self.dragShape or not evt.Dragging() or not evt.LeftIsDown():
|
||||
return
|
||||
|
||||
# if we have a shape, but havn't started dragging yet
|
||||
# if we have a shape, but haven't started dragging yet
|
||||
if self.dragShape and not self.dragImage:
|
||||
|
||||
# only start the drag after having moved a couple pixels
|
||||
|
@@ -16,7 +16,7 @@ def runTest(frame, nb, log):
|
||||
"This is a simple text editor, the class name is",
|
||||
"wxEditor. Type a few lines and try it out.",
|
||||
"",
|
||||
"It uses Windows-style key commands that can be overriden by subclassing.",
|
||||
"It uses Windows-style key commands that can be overridden by subclassing.",
|
||||
"Mouse select works. Here are the key commands:",
|
||||
"",
|
||||
"Cursor movement: Arrow keys or mouse",
|
||||
|
@@ -8,7 +8,7 @@ text = """\
|
||||
Right-click on the panel to get a menu. This menu will be managed by
|
||||
a wxFileHistory object and so the files you select will automatically
|
||||
be added to the end of the menu and will be selectable the next time
|
||||
the menu is viewed. The filename selcted, either via the Open menu
|
||||
the menu is viewed. The filename selected, either via the Open menu
|
||||
item, or from the history, will be displayed in the log window below.
|
||||
"""
|
||||
|
||||
|
@@ -287,7 +287,7 @@ value to fall within the current bounds.
|
||||
<DT><B>SetNoneAllowed(bool)</B>
|
||||
<DD>If called with a value of True, this function will cause the control
|
||||
to allow the value to be empty, representing a value of None.
|
||||
If called with a value of fakse, this function will prevent the value
|
||||
If called with a value of false, this function will prevent the value
|
||||
from being None. If the value of the control is currently None,
|
||||
ie. the control is empty, then the value will be changed to that
|
||||
of the lower bound of the control, or 0 if no lower bound is set.
|
||||
|
@@ -61,7 +61,7 @@ class TestVirtualList(wxListCtrl):
|
||||
# "virtualness" of the list... Normally you would
|
||||
# determine the text, attributes and/or image based
|
||||
# on values from some external data source, but for
|
||||
# this demo we'll just calcualte them
|
||||
# this demo we'll just calculate them
|
||||
def OnGetItemText(self, item, col):
|
||||
return "Item %d, column %d" % (item, col)
|
||||
|
||||
|
335
wxPython/demo/wxMaskedNumCtrl.py
Normal file
335
wxPython/demo/wxMaskedNumCtrl.py
Normal file
@@ -0,0 +1,335 @@
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.maskednumctrl import wxMaskedNumCtrl, EVT_MASKEDNUM
|
||||
from wxPython.lib.maskednumctrl import __doc__ as overviewdoc
|
||||
from wxPython.lib.maskededit import wxMaskedTextCtrl
|
||||
import string, sys, traceback
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestPanel( wxPanel ):
|
||||
def __init__( self, parent, log ):
|
||||
|
||||
wxPanel.__init__( self, parent, -1 )
|
||||
self.log = log
|
||||
panel = wxPanel( self, -1 )
|
||||
|
||||
header = wxStaticText(panel, -1, """\
|
||||
This shows the various options for wxMaskedNumCtrl.
|
||||
The controls at the top reconfigure the resulting control at the bottom.
|
||||
""")
|
||||
header.SetForegroundColour( "Blue" )
|
||||
|
||||
intlabel = wxStaticText( panel, -1, "Integer width:" )
|
||||
self.integerwidth = wxMaskedNumCtrl(
|
||||
panel, value=10,
|
||||
integerWidth=2,
|
||||
allowNegative=False)
|
||||
|
||||
fraclabel = wxStaticText( panel, -1, "Fraction width:" )
|
||||
self.fractionwidth = wxMaskedNumCtrl(
|
||||
panel, value=0,
|
||||
integerWidth=2,
|
||||
allowNegative=False )
|
||||
|
||||
groupcharlabel = wxStaticText( panel,-1, "Grouping char:" )
|
||||
self.groupchar = wxMaskedTextCtrl( panel, -1,
|
||||
value=',',
|
||||
mask='&',
|
||||
excludeChars = '-()',
|
||||
formatcodes='F',
|
||||
emptyInvalid=True,
|
||||
validRequired=True)
|
||||
|
||||
decimalcharlabel = wxStaticText( panel,-1, "Decimal char:" )
|
||||
self.decimalchar = wxMaskedTextCtrl( panel, -1,
|
||||
value='.',
|
||||
mask='&',
|
||||
excludeChars = '-()',
|
||||
formatcodes='F',
|
||||
emptyInvalid=True,
|
||||
validRequired=True)
|
||||
|
||||
self.set_min = wxCheckBox( panel, -1, "Set minimum value:" )
|
||||
# Create this wxMaskedNumCtrl using factory, to show how:
|
||||
self.min = wxMaskedNumCtrl( panel, integerWidth=5, fractionWidth=2 )
|
||||
self.min.Enable( False )
|
||||
|
||||
self.set_max = wxCheckBox( panel, -1, "Set maximum value:" )
|
||||
self.max = wxMaskedNumCtrl( panel, integerWidth=5, fractionWidth=2 )
|
||||
self.max.Enable( False )
|
||||
|
||||
|
||||
self.limit_target = wxCheckBox( panel, -1, "Limit control" )
|
||||
self.allow_none = wxCheckBox( panel, -1, "Allow empty control" )
|
||||
self.group_digits = wxCheckBox( panel, -1, "Group digits" )
|
||||
self.group_digits.SetValue( True )
|
||||
self.allow_negative = wxCheckBox( panel, -1, "Allow negative values" )
|
||||
self.allow_negative.SetValue( True )
|
||||
self.use_parens = wxCheckBox( panel, -1, "Use parentheses" )
|
||||
self.select_on_entry = wxCheckBox( panel, -1, "Select on entry" )
|
||||
self.select_on_entry.SetValue( True )
|
||||
|
||||
label = wxStaticText( panel, -1, "Resulting numeric control:" )
|
||||
font = label.GetFont()
|
||||
font.SetWeight(wxBOLD)
|
||||
label.SetFont(font)
|
||||
|
||||
self.target_ctl = wxMaskedNumCtrl( panel, -1, name="target control" )
|
||||
|
||||
label_numselect = wxStaticText( panel, -1, """\
|
||||
Programmatically set the above
|
||||
value entry ctrl:""")
|
||||
self.numselect = wxComboBox(panel, -1, choices = [ '0', '111', '222.22', '-3', '54321.666666666', '-1353.978',
|
||||
'1234567', '-1234567', '123456789', '-123456789.1',
|
||||
'1234567890.', '-9876543210.9' ])
|
||||
|
||||
grid1 = wxFlexGridSizer( 0, 4, 0, 0 )
|
||||
grid1.Add( intlabel, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5)
|
||||
grid1.Add( self.integerwidth, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
|
||||
grid1.Add( groupcharlabel, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5)
|
||||
grid1.Add( self.groupchar, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
|
||||
grid1.Add( fraclabel, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5 )
|
||||
grid1.Add( self.fractionwidth, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
|
||||
grid1.Add( decimalcharlabel, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5)
|
||||
grid1.Add( self.decimalchar, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
|
||||
grid1.Add( self.set_min, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5 )
|
||||
grid1.Add( self.min, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
grid1.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
|
||||
grid1.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
|
||||
|
||||
grid1.Add( self.set_max, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5 )
|
||||
grid1.Add( self.max, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
grid1.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
|
||||
grid1.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
|
||||
|
||||
|
||||
grid1.Add( self.limit_target, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
grid1.Add( self.allow_none, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
hbox1 = wxBoxSizer( wxHORIZONTAL )
|
||||
hbox1.Add( (17,5), 0, wxALIGN_LEFT|wxALL, 5)
|
||||
hbox1.Add( self.group_digits, 0, wxALIGN_LEFT|wxLEFT, 5 )
|
||||
grid1.Add( hbox1, 0, wxALIGN_LEFT|wxALL, 5)
|
||||
grid1.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
|
||||
|
||||
grid1.Add( self.allow_negative, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
grid1.Add( self.use_parens, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
hbox2 = wxBoxSizer( wxHORIZONTAL )
|
||||
hbox2.Add( (17,5), 0, wxALIGN_LEFT|wxALL, 5)
|
||||
hbox2.Add( self.select_on_entry, 0, wxALIGN_LEFT|wxLEFT, 5 )
|
||||
grid1.Add( hbox2, 0, wxALIGN_LEFT|wxALL, 5)
|
||||
grid1.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
|
||||
|
||||
|
||||
grid2 = wxFlexGridSizer( 0, 2, 0, 0 )
|
||||
grid2.Add( label, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5 )
|
||||
grid2.Add( self.target_ctl, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
grid2.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
|
||||
grid2.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
|
||||
grid2.Add( label_numselect, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5 )
|
||||
grid2.Add( self.numselect, 0, wxALIGN_LEFT|wxALL, 5 )
|
||||
grid2.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
|
||||
grid2.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
|
||||
grid2.AddGrowableCol(1)
|
||||
|
||||
self.outer_box = wxBoxSizer( wxVERTICAL )
|
||||
self.outer_box.Add(header, 0, wxALIGN_LEFT|wxTOP|wxLEFT, 20)
|
||||
self.outer_box.Add( grid1, 0, wxALIGN_CENTRE|wxLEFT|wxBOTTOM|wxRIGHT, 20 )
|
||||
self.outer_box.Add( grid2, 0, wxALIGN_LEFT|wxALL, 20 )
|
||||
self.grid2 = grid2
|
||||
|
||||
panel.SetAutoLayout( True )
|
||||
panel.SetSizer( self.outer_box )
|
||||
self.outer_box.Fit( panel )
|
||||
panel.Move( (50,10) )
|
||||
self.panel = panel
|
||||
|
||||
EVT_MASKEDNUM( self, self.integerwidth.GetId(), self.OnSetIntWidth )
|
||||
EVT_MASKEDNUM( self, self.fractionwidth.GetId(), self.OnSetFractionWidth )
|
||||
EVT_TEXT( self, self.groupchar.GetId(), self.OnSetGroupChar )
|
||||
EVT_TEXT( self, self.decimalchar.GetId(), self.OnSetDecimalChar )
|
||||
|
||||
EVT_CHECKBOX( self, self.set_min.GetId(), self.OnSetMin )
|
||||
EVT_CHECKBOX( self, self.set_max.GetId(), self.OnSetMax )
|
||||
EVT_MASKEDNUM( self, self.min.GetId(), self.SetTargetMinMax )
|
||||
EVT_MASKEDNUM( self, self.max.GetId(), self.SetTargetMinMax )
|
||||
|
||||
EVT_CHECKBOX( self, self.limit_target.GetId(), self.SetTargetMinMax )
|
||||
EVT_CHECKBOX( self, self.allow_none.GetId(), self.OnSetAllowNone )
|
||||
EVT_CHECKBOX( self, self.group_digits.GetId(), self.OnSetGroupDigits )
|
||||
EVT_CHECKBOX( self, self.allow_negative.GetId(), self.OnSetAllowNegative )
|
||||
EVT_CHECKBOX( self, self.use_parens.GetId(), self.OnSetUseParens )
|
||||
EVT_CHECKBOX( self, self.select_on_entry.GetId(), self.OnSetSelectOnEntry )
|
||||
|
||||
EVT_MASKEDNUM( self, self.target_ctl.GetId(), self.OnTargetChange )
|
||||
EVT_COMBOBOX( self, self.numselect.GetId(), self.OnNumberSelect )
|
||||
|
||||
|
||||
def OnSetIntWidth(self, event ):
|
||||
width = self.integerwidth.GetValue()
|
||||
if width < 1:
|
||||
self.log.write("integer width must be positive\n")
|
||||
self.integerwidth.SetForegroundColour(wxRED)
|
||||
else:
|
||||
self.integerwidth.SetForegroundColour(wxBLACK)
|
||||
self.log.write("setting integer width to %d\n" % width)
|
||||
self.target_ctl.SetParameters( integerWidth = width)
|
||||
# Now resize and fit the dialog as appropriate:
|
||||
self.grid2.SetItemMinSize(self.target_ctl, self.target_ctl.GetSize())
|
||||
self.outer_box.Fit( self.panel )
|
||||
self.outer_box.SetSizeHints( self.panel )
|
||||
|
||||
|
||||
def OnSetFractionWidth(self, event ):
|
||||
width = self.fractionwidth.GetValue()
|
||||
self.log.write("setting fraction width to %d\n" % width)
|
||||
self.target_ctl.SetParameters( fractionWidth = width)
|
||||
# Now resize and fit the dialog as appropriate:
|
||||
self.grid2.SetItemMinSize(self.target_ctl, self.target_ctl.GetSize())
|
||||
self.outer_box.Fit( self.panel )
|
||||
self.outer_box.SetSizeHints( self.panel )
|
||||
|
||||
|
||||
def OnSetGroupChar( self, event ):
|
||||
char = self.groupchar.GetValue()
|
||||
if self.target_ctl.GetDecimalChar() == char:
|
||||
self.log.write("group and decimal chars must be different\n")
|
||||
self.groupchar.SetForegroundColour(wxRED)
|
||||
else:
|
||||
self.groupchar.SetForegroundColour(wxBLACK)
|
||||
self.log.write("setting group char to %s\n" % char)
|
||||
self.target_ctl.SetGroupChar( char )
|
||||
|
||||
def OnSetDecimalChar( self, event ):
|
||||
char = self.decimalchar.GetValue()
|
||||
if self.target_ctl.GetGroupChar() == char:
|
||||
self.log.write("group and decimal chars must be different\n")
|
||||
self.decimalchar.SetForegroundColour(wxRED)
|
||||
else:
|
||||
self.decimalchar.SetForegroundColour(wxBLACK)
|
||||
self.log.write("setting decimal char to %s\n" % char)
|
||||
self.target_ctl.SetDecimalChar( char )
|
||||
|
||||
|
||||
def OnSetMin( self, event ):
|
||||
self.min.Enable( self.set_min.GetValue() )
|
||||
self.SetTargetMinMax()
|
||||
|
||||
def OnSetMax( self, event ):
|
||||
self.max.Enable( self.set_max.GetValue() )
|
||||
self.SetTargetMinMax()
|
||||
|
||||
|
||||
def SetTargetMinMax( self, event=None ):
|
||||
min = max = None
|
||||
self.target_ctl.SetLimited( self.limit_target.GetValue() )
|
||||
|
||||
if self.set_min.GetValue():
|
||||
min = self.min.GetValue()
|
||||
if self.set_max.GetValue():
|
||||
max = self.max.GetValue()
|
||||
|
||||
cur_min, cur_max = self.target_ctl.GetBounds()
|
||||
|
||||
if min != cur_min and not self.target_ctl.SetMin( min ):
|
||||
if self.target_ctl.GetMax() is None and cur_max > min:
|
||||
self.log.write( "min (%d) won't fit in control -- bound not set\n" % min )
|
||||
else:
|
||||
self.log.write( "min (%d) > current max (%d) -- bound not set\n" % ( min, self.target_ctl.GetMax() ) )
|
||||
self.min.SetParameters( signedForegroundColour=wxRED, foregroundColour=wxRED )
|
||||
else:
|
||||
self.min.SetParameters( signedForegroundColour=wxBLACK, foregroundColour=wxBLACK )
|
||||
self.min.Refresh()
|
||||
|
||||
if max != cur_max and not self.target_ctl.SetMax( max ):
|
||||
if self.target_ctl.GetMax() is None and cur_min < max:
|
||||
self.log.write( "max (%d) won't fit in control -- bound not set\n" % max )
|
||||
else:
|
||||
self.log.write( "max (%d) < current min (%d) -- bound not set\n" % ( max, self.target_ctl.GetMin() ) )
|
||||
self.max.SetParameters( signedForegroundColour=wxRED, foregroundColour=wxRED )
|
||||
else:
|
||||
self.max.SetParameters( signedForegroundColour=wxBLACK, foregroundColour=wxBLACK )
|
||||
self.max.Refresh()
|
||||
|
||||
if min != cur_min or max != cur_max:
|
||||
new_min, new_max = self.target_ctl.GetBounds()
|
||||
self.log.write( "current min, max: (%s, %s)\n" % ( str(new_min), str(new_max) ) )
|
||||
|
||||
|
||||
def OnSetAllowNone( self, event ):
|
||||
self.target_ctl.SetAllowNone( self.allow_none.GetValue() )
|
||||
|
||||
|
||||
def OnSetGroupDigits( self, event ):
|
||||
self.target_ctl.SetGroupDigits( self.group_digits.GetValue() )
|
||||
# Now resize and fit the dialog as appropriate:
|
||||
self.grid2.SetItemMinSize(self.target_ctl, self.target_ctl.GetSize())
|
||||
self.outer_box.Fit( self.panel )
|
||||
self.outer_box.SetSizeHints( self.panel )
|
||||
|
||||
|
||||
def OnSetAllowNegative( self, event ):
|
||||
if self.allow_negative.GetValue():
|
||||
self.use_parens.Enable(True)
|
||||
self.target_ctl.SetParameters(allowNegative=True,
|
||||
useParensForNegatives = self.use_parens.GetValue())
|
||||
else:
|
||||
self.target_ctl.SetAllowNegative(False)
|
||||
# Now resize and fit the dialog as appropriate:
|
||||
self.grid2.SetItemMinSize(self.target_ctl, self.target_ctl.GetSize())
|
||||
self.outer_box.Fit( self.panel )
|
||||
self.outer_box.SetSizeHints( self.panel )
|
||||
|
||||
|
||||
def OnSetUseParens( self, event ):
|
||||
self.target_ctl.SetUseParensForNegatives( self.use_parens.GetValue() )
|
||||
# Now resize and fit the dialog as appropriate:
|
||||
self.grid2.SetItemMinSize(self.target_ctl, self.target_ctl.GetSize())
|
||||
self.outer_box.Fit( self.panel )
|
||||
self.outer_box.SetSizeHints( self.panel )
|
||||
|
||||
|
||||
def OnSetSelectOnEntry( self, event ):
|
||||
self.target_ctl.SetSelectOnEntry( self.select_on_entry.GetValue() )
|
||||
|
||||
|
||||
def OnTargetChange( self, event ):
|
||||
ctl = event.GetEventObject()
|
||||
value = ctl.GetValue()
|
||||
ib_str = [ " (out of bounds)", "" ]
|
||||
self.log.write( "value = %s (%s)%s\n" % ( repr(value), repr(type(value)), ib_str[ ctl.IsInBounds(value) ] ) )
|
||||
|
||||
|
||||
def OnNumberSelect( self, event ):
|
||||
value = event.GetString()
|
||||
if value:
|
||||
if value.find('.') != -1:
|
||||
numvalue = float(value)
|
||||
else:
|
||||
numvalue = long(value)
|
||||
else:
|
||||
numvalue = value # try to clear the value again
|
||||
|
||||
try:
|
||||
self.target_ctl.SetValue(numvalue)
|
||||
except:
|
||||
type, value, tb = sys.exc_info()
|
||||
for line in traceback.format_exception_only(type, value):
|
||||
self.log.write(line)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def runTest( frame, nb, log ):
|
||||
win = TestPanel( nb, log )
|
||||
return win
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
overview = overviewdoc
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys,os
|
||||
import run
|
||||
run.main(['', os.path.basename(sys.argv[0])])
|
@@ -5,8 +5,11 @@ from wxPython.wx import *
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
data = wxPageSetupDialogData()
|
||||
data.SetMarginTopLeft(wxPoint(50,50))
|
||||
data.SetMarginBottomRight(wxPoint(50,50))
|
||||
data.SetMarginTopLeft( (15, 15) )
|
||||
data.SetMarginBottomRight( (15, 15) )
|
||||
#data.SetDefaultMinMargins(True)
|
||||
data.SetPaperId(wxPAPER_LETTER)
|
||||
|
||||
dlg = wxPageSetupDialog(frame, data)
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
data = dlg.GetPageSetupData()
|
||||
|
@@ -103,7 +103,7 @@ def runTest(frame, nb, log):
|
||||
overview = """<html><body>
|
||||
wxScrolledPanel fills a "hole" in the implementation of wxScrolledWindow,
|
||||
providing automatic scrollbar and scrolling behavior and the tab traversal
|
||||
mangement that wxScrolledWindow lacks.
|
||||
management that wxScrolledWindow lacks.
|
||||
</body></html>
|
||||
"""
|
||||
|
||||
|
@@ -6,7 +6,7 @@ from wxPython.wx import *
|
||||
def runTest(frame, nb, log):
|
||||
dlg = wxSingleChoiceDialog(frame, 'Test Single Choice', 'The Caption',
|
||||
['zero', 'one', 'two', 'three', 'four', 'five',
|
||||
'six', 'seven', 'eight'], wxDEFAULT_DIALOG_STYLE|wxOK|wxCANCEL)
|
||||
'six', 'seven', 'eight'], wxCHOICEDLG_STYLE)
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
log.WriteText('You selected: %s\n' % dlg.GetStringSelection())
|
||||
dlg.Destroy()
|
||||
|
@@ -16,7 +16,7 @@ the name suggests, you can define styles that can be applied to
|
||||
sections of text. This will typically be used for things like
|
||||
syntax highlighting code editors, but I'm sure that there are other
|
||||
applications as well. A style is a combination of font, point size,
|
||||
forground and background colours. The editor can handle
|
||||
foreground and background colours. The editor can handle
|
||||
proportional fonts just as easily as monospaced fonts, and various
|
||||
styles can use different sized fonts.
|
||||
|
||||
@@ -86,7 +86,7 @@ class MySTC(wxStyledTextCtrl):
|
||||
% (evt.GetX(), evt.GetY(), evt.GetPosition(), evt.GetDragResult()))
|
||||
|
||||
if debug and evt.GetPosition() < 250:
|
||||
evt.SetDragResult(wxDragNone) # prevent dropping at the begining of the buffer
|
||||
evt.SetDragResult(wxDragNone) # prevent dropping at the beginning of the buffer
|
||||
|
||||
|
||||
def OnDoDrop(self, evt):
|
||||
|
@@ -103,9 +103,9 @@ class PythonSTC(wxStyledTextCtrl):
|
||||
self.StyleSetSpec(wxSTC_STYLE_BRACEBAD, "fore:#000000,back:#FF0000,bold")
|
||||
|
||||
# Python styles
|
||||
# White space
|
||||
self.StyleSetSpec(wxSTC_P_DEFAULT, "fore:#808080,face:%(helv)s,size:%(size)d" % faces)
|
||||
# Comment
|
||||
# Default
|
||||
self.StyleSetSpec(wxSTC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
|
||||
# Comments
|
||||
self.StyleSetSpec(wxSTC_P_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % faces)
|
||||
# Number
|
||||
self.StyleSetSpec(wxSTC_P_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
|
||||
@@ -126,7 +126,7 @@ class PythonSTC(wxStyledTextCtrl):
|
||||
# Operators
|
||||
self.StyleSetSpec(wxSTC_P_OPERATOR, "bold,size:%(size)d" % faces)
|
||||
# Identifiers
|
||||
self.StyleSetSpec(wxSTC_P_IDENTIFIER, "fore:#808080,face:%(helv)s,size:%(size)d" % faces)
|
||||
self.StyleSetSpec(wxSTC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
|
||||
# Comment-blocks
|
||||
self.StyleSetSpec(wxSTC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % faces)
|
||||
# End of line where string is not closed
|
||||
|
@@ -29,7 +29,7 @@ class TestPanel(wxPanel):
|
||||
EVT_KILL_FOCUS(t1, self.OnKillFocus)
|
||||
EVT_WINDOW_DESTROY(t1, self.OnWindowDestroy)
|
||||
|
||||
l2 = wxStaticText(self, -1, "Passsword")
|
||||
l2 = wxStaticText(self, -1, "Password")
|
||||
t2 = wxTextCtrl(self, -1, "", size=(125, -1), style=wxTE_PASSWORD)
|
||||
EVT_TEXT(self, t2.GetId(), self.EvtText)
|
||||
|
||||
@@ -47,8 +47,6 @@ class TestPanel(wxPanel):
|
||||
b3 = wxButton(self, -1, "Test WriteText")
|
||||
EVT_BUTTON(self, b3.GetId(), self.OnTestWriteText)
|
||||
self.tc = t3
|
||||
b4 = wxButton(self, -1, "Test Simulated Event")
|
||||
EVT_BUTTON(self, b4.GetId(), self.OnTestEvent)
|
||||
|
||||
|
||||
l4 = wxStaticText(self, -1, "Rich Text")
|
||||
@@ -74,7 +72,6 @@ class TestPanel(wxPanel):
|
||||
bsizer.Add(b, 0, wxGROW|wxALL, 4)
|
||||
bsizer.Add(b2, 0, wxGROW|wxALL, 4)
|
||||
bsizer.Add(b3, 0, wxGROW|wxALL, 4)
|
||||
bsizer.Add(b4, 0, wxGROW|wxALL, 4)
|
||||
|
||||
sizer = wxFlexGridSizer(cols=3, hgap=6, vgap=6)
|
||||
sizer.AddMany([ l1, t1, (0,0),
|
||||
@@ -145,14 +142,6 @@ class TestPanel(wxPanel):
|
||||
% (ip, text[ip], lp, len(text)))
|
||||
|
||||
|
||||
def OnTestEvent(self, evt):
|
||||
ke = wxKeyEvent(wxEVT_CHAR)
|
||||
ke.SetEventObject(self.tc1)
|
||||
ke.SetId(self.tc1.GetId())
|
||||
ke.m_keyCode = ord('A')
|
||||
self.tc1.GetEventHandler().ProcessEvent(ke)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
|
Reference in New Issue
Block a user