MCPcopy Create free account
hub / github.com/bhowiebkr/PyFlowGraph / calculate_absolute_minimum_size

Method calculate_absolute_minimum_size

src/core/node.py:225–299  ·  view source on GitHub ↗

Calculate the absolute minimum size needed for this node's content. Returns: tuple[int, int]: (min_width, min_height) required for proper layout

(self)

Source from the content-addressed store, hash-verified

223 return title_height + pin_area_height + pin_margin_top + content_height + 1
224
225 def calculate_absolute_minimum_size(self):
226 """Calculate the absolute minimum size needed for this node's content.
227
228 Returns:
229 tuple[int, int]: (min_width, min_height) required for proper layout
230 """
231 from utils.debug_config import should_debug, DEBUG_LAYOUT
232
233 if should_debug(DEBUG_LAYOUT):
234 print(f"DEBUG: calculate_absolute_minimum_size() called for node '{self.title}'")
235
236 # Base measurements (matching existing constants)
237 title_height = 32
238 pin_spacing = 25
239 pin_margin_top = 15
240 node_padding = 10
241 resize_handle_size = 15
242
243 # Calculate minimum width
244 title_width = 0
245 if hasattr(self, '_title_item') and self._title_item:
246 title_width = self._title_item.boundingRect().width() + 20 # Title + padding
247
248 # Pin label widths (find longest on each side)
249 max_input_label_width = 0
250 if self.input_pins:
251 max_input_label_width = max([pin.label.boundingRect().width()
252 for pin in self.input_pins])
253
254 max_output_label_width = 0
255 if self.output_pins:
256 max_output_label_width = max([pin.label.boundingRect().width()
257 for pin in self.output_pins])
258
259 # Total pin label width with spacing for pin circles
260 pin_label_width = max_input_label_width + max_output_label_width + 40 # Labels + pin spacing
261
262 # GUI content minimum width
263 gui_min_width = 0
264 if hasattr(self, 'content_container') and self.content_container:
265 self.content_container.layout().activate()
266 gui_min_width = self.content_container.minimumSizeHint().width()
267
268 min_width = max(
269 self.base_width, # Default base width
270 title_width,
271 pin_label_width,
272 gui_min_width + node_padding
273 )
274
275 # Calculate minimum height
276 max_pins = max(len(self.input_pins), len(self.output_pins))
277 pin_area_height = (max_pins * pin_spacing) if max_pins > 0 else 0
278
279 # GUI content minimum height
280 gui_min_height = 0
281 if hasattr(self, 'content_container') and self.content_container:
282 gui_min_height = self.content_container.minimumSizeHint().height()

Callers 5

undoMethod · 0.95
fit_size_to_contentMethod · 0.95
executeMethod · 0.80
deserializeMethod · 0.80
final_load_updateMethod · 0.80

Calls 2

should_debugFunction · 0.90
boundingRectMethod · 0.45

Tested by

no test coverage detected