• bosco

    @dthomson You may want to look at this post.
    https://forum.omz-software.com/topic/7014/how-to-refresh-dropbox-access-token-with-the-older-dropbox-library-included-with-pythonista/2
    I installed dropbox version 11.7.0 a year ago and I appears to still be working today.

    posted in Pythonista read more
  • bosco

    @cvp No problem. I thought maybe your question was intended for @mikeno.

    posted in Pythonista read more
  • bosco

    @cvp I bought Pyto in 2019. I am currently running Pyto 17.1.1 I have tested barometer.py on iPhone 12 mini and iPad mini 4th gen.

    posted in Pythonista read more
  • bosco

    @cvp Correct. After my morning brain fog cleared, that is what you said in your last edit. :-)

    posted in Pythonista read more
  • bosco

    I dropped the 2nd parameter (error) because it caused an exception: "item 2 in argtypes has no from_param method", so I tried running without the error parameter.

    After reading the last comment by @JonB I now understand the proper use of @Block witch can be called directly.

    This works for me.

    # coding: utf-8
    from rubicon.objc import Block, ObjCClass, ObjCInstance, py_from_ns
    from rubicon.objc.runtime import objc_id
    
    pressure = None
    
    @Block
    def handler(altitudeData:ObjCInstance, err:ObjCInstance) -> None:
        nspressure = ObjCInstance(altitudeData).pressure
        global pressure
        pressure = py_from_ns(nspressure)
    
    """
    def bhandler(_data) -> None:
        nspressure = ObjCInstance(_data).pressure
        global pressure
        pressure = py_from_ns(nspressure)
    
    handler_block = Block(bhandler, None, (objc_id))
    """
    
    def get_pressure():
        CMAltimeter = ObjCClass('CMAltimeter')
        NSOperationQueue = ObjCClass('NSOperationQueue')
        if not CMAltimeter.isRelativeAltitudeAvailable():
            print('This device has no barometer.')
            return
        altimeter = CMAltimeter.new()
        main_q = NSOperationQueue.mainQueue
        #altimeter.startRelativeAltitudeUpdatesToQueue_withHandler_(main_q, handler_block)
        altimeter.startRelativeAltitudeUpdatesToQueue_withHandler_(main_q, handler)
        print('Started altitude updates.')
        try:
            while pressure is None:
                pass
        finally:
            altimeter.stopRelativeAltitudeUpdates()
            print('Updates stopped.')
            return pressure
    
    if __name__ == '__main__':
        result = get_pressure()
        print(result)
        del pressure

    posted in Pythonista read more
  • bosco

    @mikeno This code works for me with the latest version of pyto.

    # coding: utf-8
    from rubicon.objc import Block, ObjCClass, ObjCInstance, py_from_ns
    from rubicon.objc.runtime import objc_id
    
    pressure = None
    
    def handler(_data) -> None:
        nspressure = ObjCInstance(_data).pressure
        global pressure
        pressure = py_from_ns(nspressure)
    
    handler_block = Block(handler, None, (objc_id))
    
    def get_pressure():
        CMAltimeter = ObjCClass('CMAltimeter')
        NSOperationQueue = ObjCClass('NSOperationQueue')
        if not CMAltimeter.isRelativeAltitudeAvailable():
            print('This device has no barometer.')
            return
        altimeter = CMAltimeter.new()
        main_q = NSOperationQueue.mainQueue
        altimeter.startRelativeAltitudeUpdatesToQueue_withHandler_(main_q, handler_block)
        print('Started altitude updates.')
        try:
            while pressure is None:
                pass
        finally:
            altimeter.stopRelativeAltitudeUpdates()
            print('Updates stopped.')
            return pressure
    
    if __name__ == '__main__':
        result = get_pressure()
        print(result)
        del pressure

    posted in Pythonista read more
  • bosco

    This code works on my iPhone 12.

    I added @ui.in_background to def select_author(sender)

    I will also test the Lock code.

    import ui
    #
    def show_list_dialog(items=None, *args, **kwargs):
        items = items or []
        tbl = ui.TableView(**kwargs)
        tbl.data_source = ui.ListDataSource(items)
        my_sel = {'value': None}
        class MyTableViewDelegate (object):
            def tableview_did_select(self, tableview, section, row):
                print('items:', tableview.data_source.items)
                print('section, row:', section, row)
                my_sel['value'] = tableview.data_source.items[row]
                tableview.close()
                print('in delegate: my_sel',my_sel['value'])
        tbl.delegate = MyTableViewDelegate()
        tbl.present(style='sheet')
        tbl.wait_modal()
        print('after wait: ', my_sel['value'])
        return my_sel['value']
    #
    w, h = ui.get_screen_size()
    view = ui.View(name="Frank's Library", bg_color='lightblue', frame=(0, 0, w, h))
     
    @ui.in_background 
    def select_author(sender):
        author_unique = ['Baldacci,David', 'Barr,Nevada', 'Bartol,Amy', 'Bernt,Eric', 'Brandt,Kylie', 'Bruni,Riccardo', 'Bryndza,Robert', 'Burke,James Lee', 'Burton,Mary', 'Butcher,Jim', 'Carlson,Tucker', 'Carrol,Sean', 'Case,Andrew', 'Chernov,Ron', 'Clayton,MegWaite', 'Coben,Harlan', 'Cole,Bobby', 'Connelly,Michael', 'Cornwell,Bernard', 'Cornwell,Patricia', 'Cowie,Amber', 'Crombie,Deborah', 'Crosby,Ellen', 'Cross,Katie', 'Cussler,Clive', 'Delaney,Matthew B.J.', 'Dilts,Tyler', 'Dorsey,Tim']
        f = (0, 0, 400, 300)
        selected_author = show_list_dialog(author_unique, frame=f, name='Select an Author')
        print('list dialog returned:', selected_author)
        global author_result
        author_result.text = str(selected_author)
        return
     
    author_button = ui.Button(title='Author', frame=(10,5,350,100), border_color='black', border_width=2, background_color='#EAECEE', action=select_author, font=('Arial Rounded MT Bold',18))
    author_button.width=70
    author_button.height=40
    view.add_subview(author_button)
    #
    global author_result
    author_entry=''
    author_result = ui.TextView(name='author',frame=(100,5,250,40), border_color='black', border_width=3, text=author_entry, font=('Arial Rounded MT Bold',16))
    view.add_subview(author_result)
     
    view.present('sheet')
    #nav_view = ui.NavigationView(view)
    #nav_view.present('sheet')
    

    @

    posted in Pythonista read more
  • bosco

    @JonB Presenting the view directly without the nav view has the same issue on my iPhone 12. The first line in the console is after wait: None

    posted in Pythonista read more
  • bosco

    This appears to be a problem only when running iOS 15 on an iPhone 12. The @JonB example runs fine on my iPad mini, but does not work on my iPhone 12 mini.

    I have run into the same problem with some rubicon-objc code i developed.

    # works on iPad, but fails on iPhone 12 mini
    while self.ispresented:
        waituntil = NSDate.alloc().initWithTimeIntervalSinceNow(.2)
        runLoop = NSRunLoop.currentRunLoop
        runLoop.runUntilDate(waituntil)
    

    Here are some links to others with a similar problem.
    https://stackoverflow.com/questions/69312354/failed-to-block-main-thread-with-runloop-on-ios15-with-device-iphone12
    https://developer.apple.com/forums/thread/691941

    I have other Pythonista scripts that use modal_wait() that do seem to work, so maybe there is a work around

    posted in Pythonista read more
  • bosco

    fixed underscore

    Your_pyto_textview.__py_view__.TextView.objc_class.partial_methods.keys())
    

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!