• Thanks! I’d already checked in locals() and globals() looking for some place where the running view was still accessible; I couldn’t find it. I double-checked again and it still isn’t there.

    Capturing only the necessary exception makes sense, but for me I needed to capture AttributeError.

    Another thing I tried to do was check that builtins.navigation was an instance of StuffView, my own subclass of ui.View, so as to be even more certain that the saved view I’m finding is the view for this app. But isinstance returned False; I’m assuming this is because the StuffView class was not in locals/globals, and so I had to recreate it; but once recreated, it isn’t the same StuffView that the previous run of Pythonista created navigation from. Whereas it is the same ui.View that each incarnation’s StuffView inherits from.

    Here’s my current code to restore my views from a previous run if they exist:

    try: navigation = builtins.navigation except AttributeError: navigation = None if navigation and isinstance(navigation, ui.View) and navigation.on_screen: reviewView = navigation.subviews[0] inventoryView = navigation.subviews[1] else: reviewView = ui.load_view('views/reviews') inventoryView = ui.load_view('views/inventory') reviewView.flex = 'WH' inventoryView.flex = 'WH' if isPhone: inventoryView.remove_subview(inventoryView['kinds']) titleView = inventoryView['titles'] titleView.width = inventoryView.width-12 navigation = StuffView(frame=inventoryView.frame, name='Books & Stuff') navigation.add_subview(reviewView) navigation.add_subview(inventoryView) navigation.present() builtins.navigation = navigation

    One of the things I’m assuming here is that .add_subview will always add subviews in the same order. I couldn’t find any means of getting a subview back by name that wouldn’t have been more work than just saving the subviews on builtins.

  • Thanks. Both of these work great.

  • Thank you! That was the issue. For future reference, here is the code that works:

    from scene import * import photos class MyScene(Scene): def __init__(self, mapimage): self.mapimage = mapimage.convert('RGBA') super(MyScene, self).__init__() def setup(self): self.mapimage = load_pil_image(self.mapimage) def draw(self): background(1, 1, .5) image(self.mapimage, 0, 0) # Draw a red circle for every finger that touches the screen: fill(1, 0, 0) for touch in self.touches.values(): ellipse(touch.location.x - 50, touch.location.y - 50, 100, 100) mapimage = photos.pick_image(show_albums=True) if mapimage: scene = MyScene(mapimage) run(scene, frame_interval=1) else: print 'Canceled or invalid image.'
Internal error.

Oops! Looks like something went wrong!