Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
box_columns = set(box_columns or ())
for i, original in enumerate(widget_list):
w = original
if not isinstance(w, tuple):
self.contents.append((w, (WEIGHT, 1, i in box_columns)))
elif w[0] in (FLOW, PACK): # 'pack' used to be called 'flow'
f = PACK
_ignored, w = w
self.contents.append((w, (f, None, i in box_columns)))
elif len(w) == 2:
width, w = w
self.contents.append((w, (GIVEN, width, i in box_columns)))
elif w[0] == FIXED: # backwards compatibility
f = GIVEN
_ignored, width, w = w
self.contents.append((w, (GIVEN, width, i in box_columns)))
elif w[0] == WEIGHT:
f, width, w = w
self.contents.append((w, (f, width, i in box_columns)))
else:
raise ColumnsError(
"initial widget list item invalid: %r" % (original,))
if focus_column is None and w.selectable():
focus_column = i
self.dividechars = dividechars
if self.contents and focus_column is not None:
self.focus_position = focus_column
if focus_column is None:
for i, original in enumerate(widget_list):
w = original
if not isinstance(w, tuple):
self.contents.append((w, (WEIGHT, 1, i in box_columns)))
elif w[0] in (FLOW, PACK): # 'pack' used to be called 'flow'
f = PACK
_ignored, w = w
self.contents.append((w, (f, None, i in box_columns)))
elif len(w) == 2:
width, w = w
self.contents.append((w, (GIVEN, width, i in box_columns)))
elif w[0] == FIXED: # backwards compatibility
f = GIVEN
_ignored, width, w = w
self.contents.append((w, (GIVEN, width, i in box_columns)))
elif w[0] == WEIGHT:
f, width, w = w
self.contents.append((w, (f, width, i in box_columns)))
else:
raise ColumnsError(
"initial widget list item invalid: %r" % (original,))
if focus_column is None and w.selectable():
focus_column = i
self.dividechars = dividechars
if self.contents and focus_column is not None:
self.focus_position = focus_column
if focus_column is None:
focus_column = 0
self.pref_col = None
def normalize_width(width, err):
"""
Split width into (width_type, width_amount). Raise exception err
if width doesn't match a valid alignment.
"""
if width in (CLIP, PACK):
return (width, None)
elif type(width) == int:
return (GIVEN, width)
elif type(width) == tuple and len(width) == 2 and width[0] == RELATIVE:
return width
raise err("width value %r is not one of fixed number of columns, "
"'pack', ('relative', percentage of total width), 'clip'"
% (width,))
Override this method to define custom padding behaviour."""
maxcol = size[0]
if self._width_type == CLIP:
width, ignore = self._original_widget.pack((), focus=focus)
return calculate_left_right_padding(maxcol,
self._align_type, self._align_amount,
CLIP, width, None, self.left, self.right)
if self._width_type == PACK:
maxwidth = max(maxcol - self.left - self.right,
self.min_width or 0)
(width, ignore) = self._original_widget.pack((maxwidth,),
focus=focus)
return calculate_left_right_padding(maxcol,
self._align_type, self._align_amount,
GIVEN, width, self.min_width,
self.left, self.right)
return calculate_left_right_padding(maxcol,
self._align_type, self._align_amount,
self._width_type, self._width_amount,
self.min_width, self.left, self.right)
self.width_type, self.width_amount,
self.min_width, self.left, self.right)
if height:
# top_w is a fixed widget
top, bottom = calculate_top_bottom_filler(maxrow,
self.valign_type, self.valign_amount,
GIVEN, height, None, self.top, self.bottom)
if maxrow-top-bottom < height:
bottom = maxrow-top-height
elif self.height_type == PACK:
# top_w is a flow widget
height = self.top_w.rows((maxcol,),focus=focus)
top, bottom = calculate_top_bottom_filler(maxrow,
self.valign_type, self.valign_amount,
GIVEN, height, None, self.top, self.bottom)
if height > maxrow: # flow widget rendered too large
bottom = maxrow - height
else:
top, bottom = calculate_top_bottom_filler(maxrow,
self.valign_type, self.valign_amount,
self.height_type, self.height_amount,
self.min_height, self.top, self.bottom)
return left, right, top, bottom
elif valign[0] == 'fixed bottom':
bottom = valign[1]
valign = BOTTOM
# convert old flow mode parameter height=None to height='flow'
if height is None or height == FLOW:
height = PACK
self.top = top
self.bottom = bottom
self.valign_type, self.valign_amount = normalize_valign(valign,
FillerError)
self.height_type, self.height_amount = normalize_height(height,
FillerError)
if self.height_type not in (GIVEN, PACK):
self.min_height = min_height
else:
self.min_height = None
def normalize_height(height, err):
"""
Split height into (height_type, height_amount). Raise exception err
if height isn't valid.
"""
if height in (FLOW, PACK):
return (height, None)
elif (isinstance(height, tuple) and len(height) == 2 and
height[0] == RELATIVE):
return height
elif isinstance(height, int):
return (GIVEN, height)
raise err("height value %r is not one of fixed number of columns, "
"'pack', ('relative', percentage of total height)"
% (height,))
def __init__(self, cells, cell_width, h_sep, v_sep, align):
"""
:param cells: list of flow widgets to display
:param cell_width: column width for each cell
:param h_sep: blank columns between each cell horizontally
:param v_sep: blank rows between cells vertically
(if more than one row is required to display all the cells)
:param align: horizontal alignment of cells, one of\:
'left', 'center', 'right', ('relative', percentage 0=left 100=right)
"""
self._contents = MonitoredFocusList([
(w, (GIVEN, cell_width)) for w in cells])
self._contents.set_modified_callback(self._invalidate)
self._contents.set_focus_changed_callback(lambda f: self._invalidate())
self._contents.set_validate_contents_modified(self._contents_modified)
self._cell_width = cell_width
self.h_sep = h_sep
self.v_sep = v_sep
self.align = align
self._cache_maxcol = None
self.__super.__init__(None)
# set self._w to something other than None
self.get_display_widget(((h_sep+cell_width)*len(cells),))
def simplify_width(width_type, width_amount):
"""
Recombine (width_type, width_amount) into an width value.
Inverse of normalize_width.
"""
if width_type in (CLIP, PACK):
return width_type
elif width_type == GIVEN:
return width_amount
return (width_type, width_amount)
"""
Finish setting the offset and inset now that we have have a
maxcol & maxrow.
"""
(maxcol, maxrow) = size
vt,va = self.set_focus_valign_pending
self.set_focus_valign_pending = None
self.set_focus_pending = None
focus_widget, focus_pos = self._body.get_focus()
if focus_widget is None:
return
rows = focus_widget.rows((maxcol,), focus)
rtop, rbot = calculate_top_bottom_filler(maxrow,
vt, va, GIVEN, rows, None, 0, 0)
self.shift_focus((maxcol, maxrow), rtop)