• shinyformica

    Thanks, I'll try the key/value observer method.
    Gotta say it's awfully weird that Apple provided no reasonable API for this...at least for observing the value, if not setting it.

    posted in Pythonista read more
  • shinyformica

    Anyone have a good way to do these things? From a cursory search of the forum and internet, I'm a little surprised to learn that it appears to be pretty hard to set and observe the volume value.

    I have a decent and reliable way to get the system volume:

    import objc_util
    AVAudioSession = objc_util.ObjCClass("AVAudioSession")
    audioSession = AVAudioSession.sharedInstance()
    audioSession.setActive_error_(True, None)
    volume = audioSession.outputVolume()
    

    and this, apparently, is the crazy way I found to set the volume:

    import objc_util
    MPVolumeView = objc_util.ObjCClass('MPVolumeView')
    
    value = 0.5
    volume_view = MPVolumeView.new().autorelease()
    for subview in volume_view.subviews():
        if subview.isKindOfClass_(ObjCClass('UISlider')):
            subview.value = value
            break
    

    does anyone have a better way?
    And does anyone know a way to observe changes in the volume level? I have a need to implement a view which shows the current system volume...and was hoping not to poll via update().

    posted in Pythonista read more
  • shinyformica

    Absolutely brilliant.

    posted in Pythonista read more
  • shinyformica

    As I said, this is for when the user launches the script via a shortcut on the home screen...so I assume that's a URL scheme type of launch.

    It's a UI, a fullscreen present(). I like the idea of using a singleton pattern, or storing info in the globals that don't clear between runs for it...I'll give that a try first.

    posted in Pythonista read more
  • shinyformica

    Is there a good, canonical way to prevent a script from launching again if there is already an instance running? Specifically, I want to prevent the scenario where a user launches the script from the home screen via an app shortcut, then goes back to the home screen and launches it again.

    Right now that causes duplicate instances of my script to run. My current method is to have the first instance put a small token in its directory which any other instance can look for and immediately return without running if it isn't the owner of that token. The token is removed by the first instance at exit. This requires quite a bit of careful negotiation and has many difficult edge cases...so I would prefer some simpler way to make sure only a single instance of the script can be running at any time.

    posted in Pythonista read more
  • shinyformica

    For reference, @cvp @JonB, the way I got authentication to work ended up being to use the brilliant WKWebView by @mikael, another pythonista master, which uses the more modern webkit library, and allows the user-agent to be set to whatever you want. That, combined with a bit of custom code for the authentication process worked fine.

    @FarmerPaco, if you find yourself stuck trying to get authentication to work even after you get past the pydrive module issues, I'll try to whittle down the stuff I did to a basic example.

    posted in Pythonista read more
  • shinyformica

    I am also using it right now in pythonista with python2.7, so I can verify it does work.

    My setup is a little strange, since I needed to keep the entire install of pydrive and its dependencies isolated to the same directory structure as my pythonista project itself (so, nothing it relies on which isn't part of the standard pythonista install is placed in the site-packages areas). Which means most of the issues I had getting it to work probably don't apply to your situation.

    I did run into problems with the webbrowser module way of trying to authenticate via oauth2 that pydrive uses by default - I was unable to get the method above by @cvp from a couple years back to work. From what I could gather, the issue was that as of 2017 Apple/Google no longer allow authentication from a web-view: https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html

    posted in Pythonista read more
  • shinyformica

    @cvp yeah...same here, no success with any of the things that seem like they should let me modify the back or left button items to something I am in control of.

    The good news is that @mikael 's pointer to the hidden notification works perfectly, so I'm good to go.

    posted in Pythonista read more
  • shinyformica

    @JonB I only didn't mention/dismissed notifications because none showed up when I searched for it. As it turns out, the "UINavigationControllerDidShowViewControllerNotification" (cripes Apple, I appreciate verbosity, but for goodness sake!) notification is actually technically an undocumented private API, which is generally a no-no. I'll use it for now, since it seems to be my only route without rolling my own navigation controller setup.

    @mikael notification for the WIN! Works like a charm, and can be isolated to the specific navigation controller I want to monitor.

    posted in Pythonista read more
  • shinyformica

    Whoa! Love this community :)

    Ok, in reverse order:

    @cvp - I thought about it, and did some tests, but on_screen would have to be checked manually, and the problem here is I need to know when a view is popped off the stack, not check at some point in the future if it has been popped - and I'm not willing to mess with an update_interval hack to do that. Also, on_screen would have issues when the navigationview itself hasn't been shown, or is itself hidden, which would require holding a bunch of state.

    @JonB - it's actually confusing, but you don't modify the back button on the currently visible view, you modify it on the view below that one, since that's what UIKit uses to populate the back button in the navigation bar. The whole thing is confusing, and Apple's docs are a bit hard to parse, but the applicable info is here: https://developer.apple.com/documentation/uikit/uinavigationcontroller?language=objc

    The Left Item
    For all but the root view controller on the navigation stack, the item on the left side of the navigation bar provides navigation back to the previous view controller. The contents of this left-most button are determined as follows:
    
    If the new top-level view controller has a custom left bar button item, that item is displayed. To specify a custom left bar button item, set the leftBarButtonItem property of the view controller’s navigation item.
    
    If the top-level view controller does not have a custom left bar button item, but the navigation item of the previous view controller has an object in its backBarButtonItem property, the navigation bar displays that item.
    
    If a custom bar button item is not specified by either of the view controllers, a default back button is used and its title is set to the value of the title property of the previous view controller—that is, the view controller one level down on the stack. (If there is only one view controller on the navigation stack, no back button is displayed.)
    

    anyway, it doesn't seem to matter if, in this two-view test stack, I set the back button item of the bottom view, or the left button item of the top view, I don't get my target action called. And the only time I even see the title of the back button change is when I set a custom back button item on the bottom view, as in the example.

    @cvp I've tried all the things I can think of to get my custom button or custom action to show up and be called...setting all the applicable flags, sticking custom buttons in...nothing seems to work.

    @mikael - what the?! I swear I searched for notifications which would let me know when the navigation view controller changes views...and didn't find any. And nobody seems to mention the existence of those in the discussions of the topic on stackoverflow, etc. but I think you've given me the winner...even though I feel like I'm doing a bit too much via the notification mechanism, it sure comes in handy!

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!