def _generate_constraints(self, layout_table): """ Creates the list of casuarius LinearConstraint objects for the widgets for which this container owns the layout. This method walks over the items in the given layout table and aggregates their constraints into a single list of casuarius LinearConstraint objects which can be given to the layout manager. Parameters ---------- layout_table : list The layout table created by a call to _build_layout_table. Returns ------- result : list The list of casuarius LinearConstraints instances to pass to the layout manager. """ # The list of raw casuarius constraints which will be returned # from this method to be added to the casuarius solver. cns = self.contents_cns[:] d = self.declaration cns.extend(hard_constraints(d)) cns.extend(expand_constraints(d, d.layout_constraints())) # The first element in a layout table item is its offset index # which is not relevant to constraints generation. The child # size hint constraints are refreshed unconditionally. This # accounts for the potential changes in the size hint of a # widget between relayouts. for _, updater in layout_table: child = updater.item del child.size_hint_cns d = child.declaration cns.extend(hard_constraints(d)) if isinstance(child, QtContainer): if child.transfer_layout_ownership(self): cns.extend(expand_constraints(d, d.layout_constraints())) cns.extend(child.contents_cns) else: cns.extend(child.size_hint_cns) else: cns.extend(expand_constraints(d, d.layout_constraints())) cns.extend(child.size_hint_cns) return cns
def _collect_constraints(self): """ The constraints to use for the component. This will return the expanded list of constraints to use for the component. It will not include the hard constraints. """ cns = self.constraints if not cns: cns = self._get_default_constraints() cns += self._component_constraints() return list(expand_constraints(self, cns))
def _generate_constraints(self): """ Creates a list of constraint info dictionaries. This method converts the list of symbolic constraints returned by the call to '_collect_constraints' into a list of constraint info dictionaries which can be serialized and sent to clients. Returns ------- result : list of dicts A list of dictionaries which are serializable versions of the symbolic constraints defined for the widget. """ cns = self._collect_constraints() cns = [cn.as_dict() for cn in expand_constraints(self, cns)] return cns