Pythonista-Issues icon indicating copy to clipboard operation
Pythonista-Issues copied to clipboard

Displaying modal Scene from Scene that has no children gives `max() arg is an empty sequence` error

Open weirdnik opened this issue 1 year ago • 2 comments
trafficstars

This is quite simple problem in the scene.py.

Replication: I'm writing an app that will present a series of Scenes based on timing or user actions (mostly tapping to skip, like in the Stories on social apps). The app is managed by the base Scene that just sets the background colour and manages the timing in the did_evaluate_actions method. This base scene has no children. And when the Base.show_modal_scene(otherScene) is called it gives max() arg is an empty sequence, because the scene.py code assumes (line 125) that the base Scene that displays a modal has other children, as seen on the screenshot: IMG_2800

Fix: add a check if for children existing:

other_scene.z_position = 1 + max(n.z_position for n in self.children) if self.children else 0

weirdnik avatar Dec 02 '23 15:12 weirdnik

if self.children:
    self.present_model_scene(...

cclauss avatar Dec 02 '23 15:12 cclauss

I did other workaround, but the points are:

  • nowhere in the docs it says that Scene should have children first to display a modal scene on top;
  • it would be an illogical design decision to make it that way;
  • the fix is trivial, I gave one at the end of my report.

weirdnik avatar Dec 03 '23 10:12 weirdnik