Forum Archive

Popover location coordinates for button in table row

crazyfox

Hi all-

I’m trying to present a popover triggered by a button in a TableViewCell.
My underlying table is a TreeNode (from File Picker) and so I can’t use row_height * row index calculation.
Converting button.center to screen_coordinates is where I’m getting stuck (I think this is how to accomplish the task)

Any thoughts?

cvp

@crazyfox see how here

def b_action(sender):
    vi = ObjCInstance(b).view()
    r = vi.convertRect_toView_(vi.bounds(),None)
    # x,y in screen coordinates, not in view
    x,y,w,h = r.origin.x,r.origin.y,r.size.width,r.size.height
    po = ui.View()
    po.frame = (0,0,200,200)
    po.present('popover',popover_location=(x+w/2,y+h)) 
crazyfox

@cvp

Thank you again for saving my project (and sanity)
I had read that thread before, but didn’t make the connection.

Here’s what worked for me:
I ended up using

vi = ObjCInstance(b)

Since my object ‘b’ is ui.Button

Also, the popover location was off by the title bar height. Used GetTitleBarHeight() from here. Adjusted popover padding with help from here.

I appreciate how helpful this community is. I’m learning a lot.

mikael

@crazyfox, for future reference, note the convenient ui module functions convert_point and convert_rect.