X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d14a1e28567de23c586bc80017073d0c39f8d18f..75c39820b88ff60e7ce26d3598d5275d8c9dc339:/wxPython/wx/lib/grids.py diff --git a/wxPython/wx/lib/grids.py b/wxPython/wx/lib/grids.py index 5425d1adf4..5adfc20fce 100644 --- a/wxPython/wx/lib/grids.py +++ b/wxPython/wx/lib/grids.py @@ -10,15 +10,30 @@ # Copyright: (c) 1999 by Total Control Software # Licence: wxWindows license #---------------------------------------------------------------------- +# 12/07/2003 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o 2.5 Compatability changes +# +# 12/20/2003 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o In keeping with the common idiom, the sizers in this module +# have been given the 'Py' prefix to avoid confusion with the +# native sizers of the same name. However, the reverse renamer +# still has the old wx*Sizer since the whole point of the +# reverse renamer is backward compatability. +# o wxGridSizer -> PyGridSizer +# o wxFlexGridSizer -> PyFlexGridSizer +# o Deprecation warning added. +# """ -In this module you will find wxGridSizer and wxFlexGridSizer. Please -note that these sizers have since been ported to C++ and those -versions are now exposed in the regular wxPython wrappers. However I -am also leaving them here in the library so they can serve as an -example of how to implement sizers in Python. +In this module you will find PyGridSizer and PyFlexGridSizer. Please +note that these sizers have since been ported to C++ (as wx.GridSizer +and wx.FlexGridSizer) and those versions are now exposed in the regular +wxPython wrappers. However I am also leaving them here in the library +so they can serve as an example of how to implement sizers in Python. -wxGridSizer: Sizes and positions items such that all rows are the same +PyGridSizer: Sizes and positions items such that all rows are the same height and all columns are the same width. You can specify a gap in pixels to be used between the rows and/or the columns. When you create the sizer you specify the number of rows or the number of @@ -29,24 +44,38 @@ center of the space. When the sizer is resized, all the items are resized the same amount so all rows and all columns remain the same size. -wxFlexGridSizer: Derives from wxGridSizer and adds the ability for +PyFlexGridSizer: Derives from PyGridSizer and adds the ability for particular rows and/or columns to be marked as growable. This means that when the sizer changes size, the growable rows and colums are the ones that stretch. The others remain at their initial size. - -See the demo for a couple examples for how to use them. """ -from wxPython.wx import * +import operator +import warnings +import wx + +warningmsg = r"""\ + +################################################\ +# THIS MODULE IS DEPRECATED | +# | +# You should use the native wx.GridSizer and | +# wx.FlexGridSizer unless there is a compelling | +# need to use this module. | +################################################/ + -import operator +""" + +warnings.warn(warningmsg, DeprecationWarning, stacklevel=2) + #---------------------------------------------------------------------- -class wxGridSizer(wxPySizer): +class PyGridSizer(wx.PySizer): def __init__(self, rows=0, cols=0, hgap=0, vgap=0): - wxPySizer.__init__(self) + wx.PySizer.__init__(self) if rows == 0 and cols == 0: raise ValueError, "rows and cols cannot both be zero" @@ -104,8 +133,8 @@ class wxGridSizer(wxPySizer): w = max(w, size.width) h = max(h, size.height) - return wxSize(ncols * w + (ncols-1) * self.hgap, - nrows * h + (nrows-1) * self.vgap) + return wx.Size(ncols * w + (ncols-1) * self.hgap, + nrows * h + (nrows-1) * self.vgap) #-------------------------------------------------- @@ -136,7 +165,9 @@ class wxGridSizer(wxPySizer): i = r * ncols + c if i < nitems: self.SetItemBounds(items[i], x, y, w, h) + y = y + h + self.vgap + x = x + w + self.hgap @@ -144,21 +175,21 @@ class wxGridSizer(wxPySizer): def SetItemBounds(self, item, x, y, w, h): # calculate the item's size and position within # its grid cell - ipt = wxPoint(x, y) + ipt = wx.Point(x, y) isz = item.CalcMin() flag = item.GetFlag() - if flag & wxEXPAND or flag & wxSHAPED: - isz = wxSize(w, h) + if flag & wx.EXPAND or flag & wx.SHAPED: + isz = (w, h) else: - if flag & wxALIGN_CENTER_HORIZONTAL: + if flag & wx.ALIGN_CENTER_HORIZONTAL: ipt.x = x + (w - isz.width) / 2 - elif flag & wxALIGN_RIGHT: + elif flag & wx.ALIGN_RIGHT: ipt.x = x + (w - isz.width) - if flag & wxALIGN_CENTER_VERTICAL: + if flag & wx.ALIGN_CENTER_VERTICAL: ipt.y = y + (h - isz.height) / 2 - elif flag & wxALIGN_BOTTOM: + elif flag & wx.ALIGN_BOTTOM: ipt.y = y + (h - isz.height) item.SetDimension(ipt, isz) @@ -168,9 +199,9 @@ class wxGridSizer(wxPySizer): -class wxFlexGridSizer(wxGridSizer): +class PyFlexGridSizer(PyGridSizer): def __init__(self, rows=0, cols=0, hgap=0, vgap=0): - wxGridSizer.__init__(self, rows, cols, hgap, vgap) + PyGridSizer.__init__(self, rows, cols, hgap, vgap) self.rowHeights = [] self.colWidths = [] self.growableRows = [] @@ -197,6 +228,7 @@ class wxFlexGridSizer(wxGridSizer): # Find the max width and height for any component. self.rowHeights = [0] * nrows self.colWidths = [0] * ncols + for i in range(len(items)): size = items[i].CalcMin() row = i / ncols @@ -208,8 +240,8 @@ class wxFlexGridSizer(wxGridSizer): cellsWidth = reduce(operator.__add__, self.colWidths) cellHeight = reduce(operator.__add__, self.rowHeights) - return wxSize(cellsWidth + (ncols-1) * self.hgap, - cellHeight + (nrows-1) * self.vgap) + return wx.Size(cellsWidth + (ncols-1) * self.hgap, + cellHeight + (nrows-1) * self.vgap) #-------------------------------------------------- @@ -243,7 +275,7 @@ class wxFlexGridSizer(wxGridSizer): self.colWidths[idx] = self.colWidths[idx] + delta # bottom right corner - sz = wxSize(pt.x + sz.width, pt.y + sz.height) + sz = wx.Size(pt.x + sz.width, pt.y + sz.height) # Layout each cell x = pt.x @@ -251,11 +283,14 @@ class wxFlexGridSizer(wxGridSizer): y = pt.y for r in range(nrows): i = r * ncols + c + if i < nitems: w = max(0, min(self.colWidths[c], sz.width - x)) h = max(0, min(self.rowHeights[r], sz.height - y)) self.SetItemBounds(items[i], x, y, w, h) + y = y + self.rowHeights[r] + self.vgap + x = x + self.colWidths[c] + self.hgap #----------------------------------------------------------------------