• omz

    I don’t think getting a list of all networks is actually possible without jailbreak.

    It would be possible with the (private) MobileWiFi framework, but in order to use it, an app needs special entitlements that 3rd-party apps can’t get.

    posted in Pythonista read more
  • omz

    @chibill This comment under the StackOverflow answer (that I assume you have this from) suggests that the original code does the same.

    posted in Pythonista read more
  • omz

    Not possible, I'm afraid.

    posted in General Discussion read more
  • omz

    It’s possible to use AudioServicesAddSystemSoundCompletion, but I guess it would be easier to just calculate the sum of the vibration durations, and wait that amount of time.

    posted in Pythonista read more
  • omz

    It’s possible, though it requires using private APIs (might break in future iOS updates etc.). Here’s an example, adapted from this StackOverflow answer:

    from objc_util import *
    from ctypes import c_ulong
    
    def vibrate_pattern(on_off_times):
        pattern = ns([])
        for i, t in enumerate(on_off_times):
            on = NSNumber.numberWithBool_(i % 2 == 0)
            pattern.addObject_(on)
            pattern.addObject_(t)
        c.AudioServicesPlaySystemSoundWithVibration.argtypes = [c_ulong, c_void_p, c_void_p]
        c.AudioServicesPlaySystemSoundWithVibration.restype = None
        vibe_info = ns({'VibePattern': pattern, 'Intensity': 1.0})
        c.AudioServicesPlaySystemSoundWithVibration(4095, None, vibe_info.ptr)
    
    if __name__ == '__main__':
        vibrate_pattern([200, 50, 200, 50, 200, 50, 800])
    

    The on_off_times parameter should be a list of numbers, specifying a sequence of “vibrate” and “pause” durations in milliseconds.

    posted in Pythonista read more
  • omz

    @bruceathome CoreImage filters are certainly an interesting use case for ObjC bridging, but I understand that it can be a bit daunting to figure out how to get started. So I've made this little wrapper module that allows you to use CoreImage in a more “pythonic” manner, without needing to know very much about Objective-C or Cocoa.

    → core_image.py (Gist)

    It's meant to be used as a module, though you can also run it directly for a quick demo.

    Save the script above as core_image.py in the same folder as your other script. Then try something like this:

    import photos
    from core_image import CImage
    
    img = CImage(photos.pick_asset())
    img2 = img.filter('CIGaussianBlur', radius=10)
    img2.show()
    # or:
    # img2.save_jpeg('output.jpg')
    

    You can find a bunch of other examples, and details on how to set different kinds of filter parameters in the gist.

    You'll also need Apple's Core Image Filter Reference to look up filter names and their different parameters. There are a lot.

    Have fun!

    posted in Pythonista read more
  • omz

    @donnieh Hmm, I can't reproduce this. That line works fine here, just tested this both in the App Store version and the beta (on iOS 11).

    Is this the entire code that causes the freezing?

    posted in Pythonista read more
  • omz

    The easiest way to export a file programmatically would be to use console.open_in(some_file). You'll get a menu that includes a “Save to Files” option (on iOS 11 at least). This doesn’t require the beta, and should even work in Pythonista 2.x.

    posted in Pythonista read more
  • omz

    There is no built-in “Show Preview” action, and there isn’t really a Python interface for this either. The good news is that Editorial can call native Objective-C code, using the objc_util module, so this hack should work (via a “Run Python Script” action):

    from objc_util import UIApplication, on_main_thread
    
    @on_main_thread
    def main():
        app=UIApplication.sharedApplication()
        vc=app.keyWindow().rootViewController()
        vc.showAccessoryWithAnimationDuration_(0.3)
        avc = vc.accessoryViewController()
        avc.showPreview()
    
    main()
    

    Caveat: This might break at some point, when I change the internals. It should be possible to adapt it though.

    posted in Editorial read more
  • omz

    Instead of copy-paste, you could also create a script that runs other scripts in the share sheet.

    Create a new file in the main app, call it something like “Run Script.py and add the following code:

    import appex, os, runpy
    
    def main():
        py_file = appex.get_file_path()
        if not py_file or os.path.splitext(py_file)[1] != '.py':
            print('No Python file')
            return
        runpy.run_path(py_file)
    
    if __name__ == '__main__':
        main()
    

    Then in the “Run Pythonista Script” action, tap the Edit button, then (+), and select the script you just created. This will create a shortcut in the share extension to run this script, which will run the script you selected before invoking the share sheet.

    posted in General Discussion read more

Internal error.

Oops! Looks like something went wrong!