• JonB

    from  objc_util import *
    cdbatterysaver = ObjCClass('_CDBatterySaver')
    print(dir(cdbatterysaver))
    print(dir(cdbatterysaver.batterySaver()))
    print(cdbatterysaver.batterySaver().getPowerMode())
    err_ptr = c_void_p()
    cdbatterysaver.batterySaver().setPowerMode_error_(1,byref(err_ptr)) # or 1
    if err_ptr:
        err=ObjCInstance(err_ptr)
        print(err)
    else:
        print('no error')
    

    ObjCBlock lets you define blocks that can be used as completions. see for example https://forum.omz-software.com/topic/2152/help-with-blocks-again/4

    Often, you can use None as the completion, in which case just nothing gets called.
    It is entirely possible that this api has been locked down since that stack overflow post was written.

    posted in Pythonista read more
  • JonB

    Under the hood, it is all done in c... objc UIViews have a method you can define called tintColorDidChange that you would use to redraw whatever needs redrawing.

    if you were implementing your own version using draw, in python, you would indeed use @properties, and getters and setters.

    Another similar example of "composting": here is a vertical slider which is a ui.View containing a slider. Most of the key attributes are just sent to and read from the embedded slider. There may a more general approach using getattribute etc to route attributes, or force redraw, etc
    https://github.com/jsbain/uicomponents/blob/master/VerticalSlider.py

    posted in Pythonista read more
  • JonB

    One approach would be to simply use a ui.Button, under the hood, and just use the UI.View for touch.

    actually the best approach maybe to use @mikael's objc gestures which lets you define more detailed gestures on any UI item, by hooking into the underlying native objects and iOS gestures.

    There was also some discussion a while back on using some sort of mocking framework, which I forget the name of, to "extend" built in types, which involved some sort of metaclass magic. maybe @dgelessus or @mikael will remember...

    posted in Pythonista read more
  • JonB

    Those are custom attributes not custom arguments. what happens is the view is created, with no input args:

     v=PathView()
    

    then, arguments are set:

     v.width =....
     v.bc="oooo"
    

    and so on.
    if you need to take action based on the custom attributes, you need to have those as @property's, to implement a setter.

    posted in Pythonista read more
  • JonB

    Here is tan example from the docs:

    import boto3
    
    if __name__ == "__main__":
    
        imageFile='input.jpg'
        client=boto3.client('rekognition')
       
        with open(imageFile, 'rb') as image:
            response = client.detect_labels(Image={'Bytes': image.read()})
            
        print('Detected labels in ' + imageFile)    
        for label in response['Labels']:
            print (label['Name'] + ' : ' + str(label['Confidence']))
    
        print('Done...')
    
    

    It would be helpful if you could expand the error, and tap Print Traceback, then paste the full traceback here.

    It might be a good idea to set image.read() to a variable first, so you can ensure that it is not None, etc. There is nothing obviously wrong in your first example, but you should ensure that you are passing in a real image.

    posted in Pythonista read more
  • JonB

    make sure you have smart quotes turned off in ios keyboard settings

    posted in Pythonista read more
  • JonB

    you can set files as readonly, using

    os.chmod

    posted in Pythonista read more
  • JonB

    first, you need to call .alloc().init(). well, in this case you don't, but if you send this object to other objc code it will crash if you dont,

    second, you need to set encoding, and optionally restype, AND argtypes. (restype only works if argtypes is also specified). This must be done before you call create_objc_class. Most import is the encoding.

    Also, you just return normal python types, and the callback mechanism takes care of converting.

    Here is you code, updated, along with a description of the type encodings. see objc_util source for more details
    https://gist.github.com/d1b10d812306a749335e052eb5e1af9e

    posted in Pythonista read more
  • JonB

    on ipad, long pressing comma/exclamation point pops up a single quote.

    the other option is, in settings app to create a shortcut. for instance, typing the forward quote would be a shortcut for single quote.

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!