]> git.saurik.com Git - wxWidgets.git/commitdiff
new contributions
authorRobin Dunn <robin@alldunn.com>
Thu, 7 Oct 1999 18:48:14 +0000 (18:48 +0000)
committerRobin Dunn <robin@alldunn.com>
Thu, 7 Oct 1999 18:48:14 +0000 (18:48 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3879 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

utils/wxPython/demo/OldSizers.py
utils/wxPython/lib/sizers/__init__.py
utils/wxPython/lib/sizers/shape.py [new file with mode: 0644]

index 8fd2ffc7f5e85e4e363c8acb569560028f889f2f..308bcec7c4f0971d632979fc1632e9b813d46e3c 100644 (file)
@@ -106,6 +106,34 @@ def makeSimpleBorder3(win):
     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):
@@ -230,6 +258,13 @@ theTests = [
 
     ("", None, ""),
 
+
+    ("Proportional resize", makeShapes,
+     "The wxShapeSizer preserves the original proportions of the window."
+     ),
+
+    ("", None, ""),
+
     ("Boxes inside of boxes", makeBoxInBox,
      "This one shows nesting of boxes within boxes within boxes, using both "
      "orientations.  Notice also that button seven has a greater weighting "
@@ -275,7 +310,7 @@ class TestFrame(wxFrame):
 
 
 class TestSelectionPanel(wxPanel):
-    def __init__(self, parent, frame):
+    def __init__(self, parent, frame=NULL):
         wxPanel.__init__(self, parent, -1)
         self.frame = frame
 
index 1bfaf7bde12733aa0b245658ad3075ff10fbb661..74d416c1c59feefd3c0db3254075c3917a0da5f1 100644 (file)
@@ -14,6 +14,7 @@
 from sizer   import *
 from box     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'):
     dlg = wxMessageDialog(None,
-                          "Since wxWindows now includes sizers the classes in\n"
-                          "wxPython.lib.sizers have been depreciated.  Please\n"
-                          "see the Reference Manual for details of the new classes.\n"
-                          "\n"
-                          "To contiunue using wxPython.lib.sizers without this\n"
-                          "message you can set the WXP_OLDSIZERS envronment \n"
-                          "variable to any value.",
+"""\
+Since the wxWindows library now includes its own sizers, the
+classes in wxPython.lib.sizers have been depreciated.  Please
+see the Reference Manual for details of the new classes.
+
+To contiunue using wxPython.lib.sizers without this
+message you can set the WXP_OLDSIZERS envronment
+variable to any value.
+""",
                           "Depreciated Feature",
                           wxOK | wxICON_EXCLAMATION)
     dlg.ShowModal()
diff --git a/utils/wxPython/lib/sizers/shape.py b/utils/wxPython/lib/sizers/shape.py
new file mode 100644 (file)
index 0000000..cd38c23
--- /dev/null
@@ -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)