mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-05 03:20:08 +01:00
Fixes #579. TableSizer was never completed and only errors out when attempting to use it. Remove it and its references in the docs since it doesn't work and probably won't without considerable effort.
This commit is contained in:
@@ -93,243 +93,6 @@ minsize = { "fixed": wx.FIXED_MINSIZE,
|
||||
misc_flags = { "expand": wx.EXPAND, }
|
||||
|
||||
|
||||
class TableSizer(wx.Sizer):
|
||||
"""
|
||||
An attempt at creating a more intuitive replacement for nesting box sizers.
|
||||
"""
|
||||
def __init__(self, rows=0, cols=0):
|
||||
wx.Sizer.__init__(self)
|
||||
self.rows = rows
|
||||
self.cols = cols
|
||||
self.fixed_width = 0
|
||||
self.fixed_height = 0
|
||||
self.hgrow = 0
|
||||
self.vgrow = 0
|
||||
|
||||
self.row_widths = []
|
||||
self.col_heights = []
|
||||
|
||||
# allow us to use 'old-style' proportions when emulating box sizers
|
||||
self.isHorizontal = (self.rows == 1 and self.cols == 0)
|
||||
self.isVertical = (self.cols == 1 and self.rows == 0)
|
||||
|
||||
def CalcNumRowsCols(self):
|
||||
"""
|
||||
Calculate the number of rows and columns needed.
|
||||
|
||||
:returns: The number of rows and columns needed by the sizer.
|
||||
:rtype: `tuple`
|
||||
"""
|
||||
numrows = self.rows
|
||||
numcols = self.cols
|
||||
numchild = len(self.GetChildren())
|
||||
|
||||
if numrows == 0 and numcols == 0:
|
||||
return 0, 0
|
||||
|
||||
if numrows == 0:
|
||||
rows, mod = divmod(numchild, self.cols)
|
||||
if mod > 0:
|
||||
rows += 1
|
||||
numrows = rows
|
||||
|
||||
if numcols == 0:
|
||||
cols, mod = divmod(numchild, self.rows)
|
||||
if mod > 0:
|
||||
cols += 1
|
||||
numcols = cols
|
||||
|
||||
return numrows, numcols
|
||||
|
||||
def CalcMin(self):
|
||||
"""
|
||||
Calculate the minimum size.
|
||||
|
||||
:rtype: :ref:`wx.Size`
|
||||
|
||||
"""
|
||||
numrows, numcols = self.CalcNumRowsCols()
|
||||
numchild = len(self.GetChildren())
|
||||
|
||||
if numchild == 0:
|
||||
return wx.Size(10, 10)
|
||||
|
||||
if numrows == 0 and numcols == 0:
|
||||
print("TableSizer must have the number of rows or columns set. Cannot continue.")
|
||||
return wx.Size(10, 10)
|
||||
|
||||
self.row_widths = [0 for x in range(0, numrows)]
|
||||
self.col_heights = [0 for x in range(0, numcols)]
|
||||
currentRow = 0
|
||||
currentCol = 0
|
||||
counter = 0
|
||||
self.hgrow = 0
|
||||
self.vgrow = 0
|
||||
|
||||
# get the max row width and max column height
|
||||
for item in self.GetChildren():
|
||||
if self.cols != 0:
|
||||
currentRow, currentCol = divmod(counter, numcols)
|
||||
else:
|
||||
currentCol, currentRow = divmod(counter, numrows)
|
||||
|
||||
if item.IsShown():
|
||||
width, height = item.CalcMin()
|
||||
|
||||
if self.isVertical and item.GetProportion() > 0:
|
||||
self.hgrow += item.GetProportion()
|
||||
elif self.isHorizontal and item.GetProportion() > 0:
|
||||
self.vgrow += item.GetProportion()
|
||||
|
||||
if width > self.row_widths[currentRow]:
|
||||
self.row_widths[currentRow] = width
|
||||
|
||||
if height > self.col_heights[currentCol]:
|
||||
self.col_heights[currentCol] = height
|
||||
|
||||
counter += 1
|
||||
|
||||
minwidth = 0
|
||||
for row_width in self.row_widths:
|
||||
minwidth += row_width
|
||||
|
||||
minheight = 0
|
||||
for col_height in self.col_heights:
|
||||
minheight += col_height
|
||||
|
||||
self.fixed_width = minwidth
|
||||
self.fixed_height = minheight
|
||||
|
||||
return wx.Size(minwidth, minheight)
|
||||
|
||||
def RecalcSizes(self):
|
||||
"""
|
||||
Recalculate the sizes.
|
||||
"""
|
||||
|
||||
numrows, numcols = self.CalcNumRowsCols()
|
||||
numchild = len(self.GetChildren())
|
||||
|
||||
if numchild == 0:
|
||||
return
|
||||
currentRow = 0
|
||||
currentCol = 0
|
||||
counter = 0
|
||||
|
||||
print("cols %d, rows %d" % (self.cols, self.rows))
|
||||
print("fixed_height %d, fixed_width %d" % (self.fixed_height, self.fixed_width))
|
||||
#print("self.GetSize() = " + `self.GetSize()`)
|
||||
|
||||
row_widths = [0 for x in range(0, numrows)]
|
||||
col_heights = [0 for x in range(0, numcols)]
|
||||
item_sizes = [0 for x in range(0, len(self.GetChildren()))]
|
||||
grow_sizes = [0 for x in range(0, len(self.GetChildren()))]
|
||||
|
||||
curHPos = 0
|
||||
curVPos = 0
|
||||
curCol = 0
|
||||
curRow = 0
|
||||
# first, we set sizes for all children, and while doing so, calc
|
||||
# the maximum row heights and col widths. Then, afterwards we handle
|
||||
# the positioning of the controls
|
||||
|
||||
for item in self.GetChildren():
|
||||
if self.cols != 0:
|
||||
currentRow, currentCol = divmod(counter, numcols)
|
||||
else:
|
||||
currentCol, currentRow = divmod(counter, numrows)
|
||||
if item.IsShown():
|
||||
item_minsize = item.GetMinSizeWithBorder()
|
||||
width = item_minsize[0]
|
||||
height = item_minsize[1]
|
||||
|
||||
print("row_height %d, row_width %d" % (self.col_heights[currentCol], self.row_widths[currentRow]))
|
||||
growable_width = (self.GetSize()[0]) - width
|
||||
growable_height = (self.GetSize()[1]) - height
|
||||
|
||||
#if not self.isVertical and not self.isHorizontal:
|
||||
# growable_width = self.GetSize()[0] - self.row_widths[currentRow]
|
||||
# growable_height = self.GetSize()[1] - self.col_heights[currentCol]
|
||||
|
||||
#print("grow_height %d, grow_width %d" % (growable_height, growable_width))
|
||||
|
||||
item_vgrow = 0
|
||||
item_hgrow = 0
|
||||
# support wx.EXPAND for box sizers to be compatible
|
||||
if item.GetFlag() & wx.EXPAND:
|
||||
if self.isVertical:
|
||||
if self.hgrow > 0 and item.GetProportion() > 0:
|
||||
item_hgrow = (growable_width * item.GetProportion()) / self.hgrow
|
||||
item_vgrow = growable_height
|
||||
|
||||
elif self.isHorizontal:
|
||||
if self.vgrow > 0 and item.GetProportion() > 0:
|
||||
item_vgrow = (growable_height * item.GetProportion()) / self.vgrow
|
||||
item_hgrow = growable_width
|
||||
|
||||
if growable_width > 0 and item.GetHGrow() > 0:
|
||||
item_hgrow = (growable_width * item.GetHGrow()) / 100
|
||||
print("hgrow = %d" % (item_hgrow))
|
||||
|
||||
if growable_height > 0 and item.GetVGrow() > 0:
|
||||
item_vgrow = (growable_height * item.GetVGrow()) / 100
|
||||
print("vgrow = %d" % (item_vgrow))
|
||||
|
||||
grow_size = wx.Size(item_hgrow, item_vgrow)
|
||||
size = item_minsize #wx.Size(item_minsize[0] + item_hgrow, item_minsize[1] + item_vgrow)
|
||||
if size[0] + grow_size[0] > row_widths[currentRow]:
|
||||
row_widths[currentRow] = size[0] + grow_size[0]
|
||||
if size[1] + grow_size[1] > col_heights[currentCol]:
|
||||
col_heights[currentCol] = size[1] + grow_size[1]
|
||||
|
||||
grow_sizes[counter] = grow_size
|
||||
item_sizes[counter] = size
|
||||
|
||||
counter += 1
|
||||
|
||||
counter = 0
|
||||
for item in self.GetChildren():
|
||||
if self.cols != 0:
|
||||
currentRow, currentCol = divmod(counter, numcols)
|
||||
else:
|
||||
currentCol, currentRow = divmod(counter, numrows)
|
||||
|
||||
itempos = self.GetPosition()
|
||||
if item.IsShown():
|
||||
rowstart = itempos[0]
|
||||
for row in range(0, currentRow):
|
||||
rowstart += row_widths[row]
|
||||
|
||||
colstart = itempos[1]
|
||||
for col in range(0, currentCol):
|
||||
#print("numcols = %d, currentCol = %d, col = %d" % (numcols, currentCol, col))
|
||||
colstart += col_heights[col]
|
||||
|
||||
itempos[0] += rowstart
|
||||
itempos[1] += colstart
|
||||
|
||||
if item.GetFlag() & wx.ALIGN_RIGHT:
|
||||
itempos[0] += (row_widths[currentRow] - item_sizes[counter][0])
|
||||
elif item.GetFlag() & (wx.ALIGN_CENTER | wx.ALIGN_CENTER_HORIZONTAL):
|
||||
itempos[0] += (row_widths[currentRow] - item_sizes[counter][0]) / 2
|
||||
|
||||
if item.GetFlag() & wx.ALIGN_BOTTOM:
|
||||
itempos[1] += (col_heights[currentCol] - item_sizes[counter][1])
|
||||
elif item.GetFlag() & (wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL):
|
||||
itempos[1] += (col_heights[currentCol] - item_sizes[counter][1]) / 2
|
||||
|
||||
hgrowth = (grow_sizes[counter][0] - itempos[0])
|
||||
if hgrowth > 0:
|
||||
item_sizes[counter][0] += hgrowth
|
||||
|
||||
vgrowth = (grow_sizes[counter][1] - itempos[1])
|
||||
if vgrowth > 0:
|
||||
item_sizes[counter][1] += vgrowth
|
||||
#item_sizes[counter][1] -= itempos[1]
|
||||
item.SetDimension(itempos, item_sizes[counter])
|
||||
|
||||
counter += 1
|
||||
|
||||
def GetDefaultBorder(self):
|
||||
"""
|
||||
Return the platform specific default border.
|
||||
@@ -642,7 +405,7 @@ class SizedParent:
|
||||
to it.
|
||||
|
||||
:param string `type`: sizer type, valid values are "horizontal", "vertical",
|
||||
"form", "table" and "grid";
|
||||
"form", and "grid";
|
||||
:param dict `options`: dictionary of options depending on type.
|
||||
|
||||
"""
|
||||
@@ -650,26 +413,15 @@ class SizedParent:
|
||||
sizer = None
|
||||
self.sizerType = type
|
||||
if type == "horizontal":
|
||||
sizer = wx.BoxSizer(wx.HORIZONTAL) # TableSizer(0, 1)
|
||||
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
|
||||
elif type == "vertical":
|
||||
sizer = wx.BoxSizer(wx.VERTICAL) # TableSizer(1, 0)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
|
||||
elif type == "form":
|
||||
#sizer = TableSizer(2, 0)
|
||||
sizer = wx.FlexGridSizer(0, 2, 0, 0)
|
||||
#sizer.AddGrowableCol(1)
|
||||
|
||||
elif type == "table":
|
||||
rows = cols = 0
|
||||
if 'rows' in options:
|
||||
rows = int(options['rows'])
|
||||
|
||||
if 'cols' in options:
|
||||
cols = int(options['cols'])
|
||||
|
||||
sizer = TableSizer(rows, cols)
|
||||
|
||||
elif type == "grid":
|
||||
sizer = wx.FlexGridSizer(0, 0, 0, 0)
|
||||
if 'rows' in options:
|
||||
@@ -755,7 +507,7 @@ class SizedPanel(wx.Panel, SizedParent):
|
||||
"""
|
||||
|
||||
wx.Panel.__init__(self, *args, **kwargs)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL) #TableSizer(1, 0)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.SetSizer(sizer)
|
||||
self.sizerType = "vertical"
|
||||
|
||||
@@ -797,7 +549,7 @@ class SizedScrolledPanel(sp.ScrolledPanel, SizedParent):
|
||||
"""
|
||||
|
||||
sp.ScrolledPanel.__init__(self, *args, **kwargs)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL) #TableSizer(1, 0)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.SetSizer(sizer)
|
||||
self.sizerType = "vertical"
|
||||
self.SetupScrolling()
|
||||
|
||||
Reference in New Issue
Block a user