new contributions
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3879 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -106,6 +106,34 @@ def makeSimpleBorder3(win):
|
|||||||
return bdr
|
return bdr
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
def makeShapes(win):
|
||||||
|
box =wxBoxSizer(wxVERTICAL)
|
||||||
|
box.Add(wxStaticLine(win, -1), 0)
|
||||||
|
for line in (
|
||||||
|
(wxANCHOR_NW, "NorthWest"),
|
||||||
|
(wxANCHOR_NORTH, "North"),
|
||||||
|
(wxANCHOR_NE, "NorthEast")
|
||||||
|
), (
|
||||||
|
(wxANCHOR_WEST, "West"),
|
||||||
|
(wxANCHOR_NONE, "Center"),
|
||||||
|
(wxANCHOR_EAST, "East")
|
||||||
|
), (
|
||||||
|
(wxANCHOR_SW, "SouthWest"),
|
||||||
|
(wxANCHOR_SOUTH, "South"),
|
||||||
|
(wxANCHOR_SE, "SouthEast")
|
||||||
|
):
|
||||||
|
linebox =wxBoxSizer(wxHORIZONTAL)
|
||||||
|
linebox.Add(wxStaticLine(win, -1, style=wxVERTICAL), 0)
|
||||||
|
for (anchor, label) in line:
|
||||||
|
sizer =wxShapeSizer(anchor)
|
||||||
|
sizer.Add(wxButton(win, -1, label, size=wxSize(100, 50)))
|
||||||
|
linebox.Add(sizer, 1)
|
||||||
|
linebox.Add(wxStaticLine(win, -1, style=wxVERTICAL), 0)
|
||||||
|
box.Add(linebox, 1)
|
||||||
|
box.Add(wxStaticLine(win, -1), 0)
|
||||||
|
return box
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
def makeBoxInBox(win):
|
def makeBoxInBox(win):
|
||||||
@@ -230,6 +258,13 @@ theTests = [
|
|||||||
|
|
||||||
("", None, ""),
|
("", None, ""),
|
||||||
|
|
||||||
|
|
||||||
|
("Proportional resize", makeShapes,
|
||||||
|
"The wxShapeSizer preserves the original proportions of the window."
|
||||||
|
),
|
||||||
|
|
||||||
|
("", None, ""),
|
||||||
|
|
||||||
("Boxes inside of boxes", makeBoxInBox,
|
("Boxes inside of boxes", makeBoxInBox,
|
||||||
"This one shows nesting of boxes within boxes within boxes, using both "
|
"This one shows nesting of boxes within boxes within boxes, using both "
|
||||||
"orientations. Notice also that button seven has a greater weighting "
|
"orientations. Notice also that button seven has a greater weighting "
|
||||||
@@ -275,7 +310,7 @@ class TestFrame(wxFrame):
|
|||||||
|
|
||||||
|
|
||||||
class TestSelectionPanel(wxPanel):
|
class TestSelectionPanel(wxPanel):
|
||||||
def __init__(self, parent, frame):
|
def __init__(self, parent, frame=NULL):
|
||||||
wxPanel.__init__(self, parent, -1)
|
wxPanel.__init__(self, parent, -1)
|
||||||
self.frame = frame
|
self.frame = frame
|
||||||
|
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
from sizer import *
|
from sizer import *
|
||||||
from box import *
|
from box import *
|
||||||
from border import *
|
from border import *
|
||||||
|
from shape import *
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -22,13 +23,15 @@ from wxPython.wx import wxMessageDialog, wxOK, wxICON_EXCLAMATION
|
|||||||
|
|
||||||
if not os.environ.has_key('WXP_OLDSIZERS'):
|
if not os.environ.has_key('WXP_OLDSIZERS'):
|
||||||
dlg = wxMessageDialog(None,
|
dlg = wxMessageDialog(None,
|
||||||
"Since wxWindows now includes sizers the classes in\n"
|
"""\
|
||||||
"wxPython.lib.sizers have been depreciated. Please\n"
|
Since the wxWindows library now includes its own sizers, the
|
||||||
"see the Reference Manual for details of the new classes.\n"
|
classes in wxPython.lib.sizers have been depreciated. Please
|
||||||
"\n"
|
see the Reference Manual for details of the new classes.
|
||||||
"To contiunue using wxPython.lib.sizers without this\n"
|
|
||||||
"message you can set the WXP_OLDSIZERS envronment \n"
|
To contiunue using wxPython.lib.sizers without this
|
||||||
"variable to any value.",
|
message you can set the WXP_OLDSIZERS envronment
|
||||||
|
variable to any value.
|
||||||
|
""",
|
||||||
"Depreciated Feature",
|
"Depreciated Feature",
|
||||||
wxOK | wxICON_EXCLAMATION)
|
wxOK | wxICON_EXCLAMATION)
|
||||||
dlg.ShowModal()
|
dlg.ShowModal()
|
||||||
|
97
utils/wxPython/lib/sizers/shape.py
Normal file
97
utils/wxPython/lib/sizers/shape.py
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
#----------------------------------------------------------------------
|
||||||
|
# Name: wxPython.lib.sizers.shape
|
||||||
|
# Purpose: A Sizer that preserves the shape (proportions)
|
||||||
|
# of the managed window
|
||||||
|
#
|
||||||
|
# Created: 7-October-1999
|
||||||
|
# RCS-ID: $Id$
|
||||||
|
# Copyright: SIA "ANK"
|
||||||
|
# Licence: wxWindows license
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
from sizer import wxSizer
|
||||||
|
|
||||||
|
wxANCHOR_NONE = 0
|
||||||
|
wxANCHOR_NORTH = 1
|
||||||
|
wxANCHOR_SOUTH = 2
|
||||||
|
wxANCHOR_EAST = 4
|
||||||
|
wxANCHOR_WEST = 8
|
||||||
|
wxANCHOR_NW = wxANCHOR_NORTH | wxANCHOR_WEST
|
||||||
|
wxANCHOR_NE = wxANCHOR_NORTH | wxANCHOR_EAST
|
||||||
|
wxANCHOR_SW = wxANCHOR_SOUTH | wxANCHOR_WEST
|
||||||
|
wxANCHOR_SE = wxANCHOR_SOUTH | wxANCHOR_EAST
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxShapeSizer(wxSizer):
|
||||||
|
"""
|
||||||
|
wxShapeSizer
|
||||||
|
|
||||||
|
This sizer preserves the proportional dimensions of the managed
|
||||||
|
window, leaving empty space either in horizontal or vertical
|
||||||
|
dimension.
|
||||||
|
|
||||||
|
By default, the managed window is centered within allowed size.
|
||||||
|
You may specify an anchor parameter to leave all of the extra
|
||||||
|
space on one side: wxANCHOR_NORTH and wxANCHOR_SOUTH manage
|
||||||
|
vertical dimension, leaving extra space on the bottom or top side,
|
||||||
|
respectively; wxANCHOR_EAST and wxANCHOR_WEST do the same in
|
||||||
|
horizontal dimension. wxANCHOR_NW, wxANCHOR_NE, wxANCHOR_SW
|
||||||
|
and wxANCHOR_SE are short-cut names for combinations north+west,
|
||||||
|
north+east, south+west, south+east.
|
||||||
|
|
||||||
|
If both anchors are specified in either direction, south and east
|
||||||
|
take precedence over north and west, respectively. (Because of
|
||||||
|
gravity, widgets tend to fall down.)
|
||||||
|
"""
|
||||||
|
def __init__(self, anchor =wxANCHOR_NONE):
|
||||||
|
wxSizer.__init__(self)
|
||||||
|
self.anchor =anchor
|
||||||
|
|
||||||
|
def Add(self, widget):
|
||||||
|
if self.children:
|
||||||
|
raise ValueError("wxShapeSizer can only contain one child.")
|
||||||
|
|
||||||
|
wxSizer.Add(self, widget)
|
||||||
|
|
||||||
|
def CalcMin(self):
|
||||||
|
isSizer, widget, width, height, borderSize = self.children[0]
|
||||||
|
|
||||||
|
if isSizer:
|
||||||
|
width, height = widget.CalcMin()
|
||||||
|
|
||||||
|
return width, height
|
||||||
|
|
||||||
|
def RecalcSizes(self):
|
||||||
|
isSizer, widget, width, height, borderSize = self.children[0]
|
||||||
|
width =self.size.width
|
||||||
|
height =self.size.height
|
||||||
|
px =self.origin.x
|
||||||
|
py =self.origin.y
|
||||||
|
anchor =self.anchor
|
||||||
|
# get current dimensions of the managed window
|
||||||
|
w, h =self.CalcMin()
|
||||||
|
ratio =float(w) /h
|
||||||
|
# in what direction space should be added:
|
||||||
|
# -1: horisontal
|
||||||
|
# 1: vertical
|
||||||
|
# 0: shape is ok
|
||||||
|
dir =cmp(ratio /width *height, 1)
|
||||||
|
if dir <0:
|
||||||
|
# recalculate width
|
||||||
|
old_width =width
|
||||||
|
width =height *ratio
|
||||||
|
if anchor & wxANCHOR_EAST:
|
||||||
|
px =px +old_width -width
|
||||||
|
elif not (anchor & wxANCHOR_WEST):
|
||||||
|
px =px +(old_width -width) /2
|
||||||
|
elif dir >0:
|
||||||
|
# recalculate height
|
||||||
|
old_height =height
|
||||||
|
height =width /ratio
|
||||||
|
if anchor & wxANCHOR_SOUTH:
|
||||||
|
py =py +old_height -height
|
||||||
|
elif not (anchor & wxANCHOR_NORTH):
|
||||||
|
py =py +(old_height -height) /2
|
||||||
|
|
||||||
|
widget.SetDimensions(px, py, width, height)
|
Reference in New Issue
Block a user