• shinyformica

    Is there any way to make a custom home screen shortcut icon for a script?
    The normal pathway to make a shortcut only lets you choose installed icons.

    posted in Pythonista read more
  • shinyformica

    @JonB thanks!

    Amazingly, yanking out just the "disable global clearing" part of that pythonista_startup magic worked to allow relaunch from the home shortcut.

    So, the ugly tinkering is relatively short: replace the existing pythonista startup module with a new module object containing the globals for the current pythonista_startup module, and which returns all the globals in main when asked for its contents.

    This will effectively short-circuit the preflight system from clearing out any globals, since it skips any which are inside the pythonista startup module itself.

    Here's the shortened code just to solve this one issue, if anyone else is encountering it:

    print(u"Executing pythonista_startup...")
    
    try:
        print(u"Preventing globals clearing...")
        
        import sys
        import types
        
        class SaveGlobals(types.ModuleType):
            import __main__
            
            def __dir__(self):
                return dir(type(self).__main__)
        
        # THESE LINES MUST COME LAST.
        # Anything past this point is executed in the context of the old
        # pythonista_startup module, which may already be partially
        # garbage-collected.
        saved = SaveGlobals(__name__, __doc__)
        vars(saved).update(vars(sys.modules["pythonista_startup"]))
        sys.modules["pythonista_startup"] = saved
        
        del sys
        del types
        del SaveGlobals
        del saved
        
        print(u"Done preventing globals clearing.")
    except: # Catch everything
        import sys
        import traceback
        
        print(u"Swallowed exception:", file=sys.stderr)
        traceback.print_exc()
        
        print(u"Attempt to re-raise", file=sys.stderr)
        del sys
        del traceback
        raise
    
    print(u"Done executing pythonista_startup.")
    

    posted in Pythonista read more
  • shinyformica

    Just revisiting this issue, since it's once again on my plate to try and find a working solution.

    When we left off, I'd tried various attempts using different ideas discussed above. None of them are really successful. I can successfully prevent a new instance from trying to launch, keeping a token in the ui module which let's me know if an instance is already running, and which is cleared when the running instance is closed.

    The trouble is still with what happens when a script is launched via a home screen shortcut.

    In that case, the pykit_preflight.py script is in some way being run (it's not clear exactly when and how that occurs @omz...any hints?), and it clears out the sys.modules and globals before it runs the script. So even though the newly launched script sees that an instance is already running, and bails immediately, the previous instance is left in a broken state.

    The clearing of the modules and globals means the existing instance is suddenly left with all of its module-level global data pointing at None, so it ends up raising an exception as soon as it tries to do anything.

    So...I tried all sorts of ways to prevent or replace how pykit_preflight does it's thing to no avail. I even tried stashing away the globals for every module in my codebase and restoring them all. No luck.

    Anyone have any ideas or better knowledge of how to prevent the clearing when a script is launched from the home screen shortcut, while pythonista is already open and running?

    posted in Pythonista read more
  • shinyformica

    @JonB you can blame @cvp for the ping...in the thread referenced here: https://forum.omz-software.com/topic/1551/open-close-console you mentioned showing the console, but I don't see a way to just make the console pop/slide up? Is there some trick which will bring the console up, even if a view is being presented full screen?

    posted in Pythonista read more
  • shinyformica

    Thanks all, as usual!

    The wait for the table view to become valid can be very short, as short as 0.01 seconds, apparently. Unfortunately there's no simple way to be notified when a UIView becomes visible (anyone have a generic notification-y way of doing that?), and even then I don't know that just being visible for a table view is the same as it having valid rows/indices.

    Also, to scroll to a specific row turns out to be very easy, once you have a table view with valid indexes displayed:

    UITableViewScrollPositionMiddle = 2
    tvobjc = self.tableview.objc_instance
    NSIndexPath = objc_util.ObjCClass("NSIndexPath")
    nsindex = NSIndexPath.indexPathForRow_inSection_(index,0)
    tvobjc.scrollToRowAtIndexPath_atScrollPosition_animated_(nsindex, UITableViewScrollPositionMiddle, True)
    

    Works great, set that last parameter to False to scroll without animation.

    posted in Pythonista read more
  • shinyformica

    @cvp interesting...I'm not super psyched about hunting for and grabbing the contents of the console text view, seems a bit fragile.

    I like the idea in that thread you pointed to, of showing the console, but presenting a button to hide it...but I don't see a way of just "presenting" the console? hide_output() will hide the console...but how do I just make it pop up? Do I have to "show_image()" with an empty path or empty image or something?

    posted in Pythonista read more
  • shinyformica

    Looking in the console module, I see the console.hide_output() function, but no console.show_output()...is it possible to slide the console in on top of a view being presented fullscreen? I want to be able to show/hide the console for debugging purposes without closing my fullscreen presentation window.

    posted in Pythonista read more
  • shinyformica

    Yeah, that's exactly the error I was getting. Got it when trying to reuse a popover view as well.
    The result I have by creating my own title bar is actually better for my purposes, so I'll stick with it.

    Interesting to know about removing the view controller to disconnect the closed view from the animation state of the presenting controller.
    Thanks.

    posted in Pythonista read more
  • shinyformica

    Yep, that's what I ended up doing. Making my view a subview of a larger view which can show an "x" and title or not.
    The answer to my question is a resounding "no"...you can't re-present a view, even after attempting to close it.

    There might be a way, but it is not worth the ugliness and effort compared to just doing it as suggested above.

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!