omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Popover for nav bar button

    Pythonista
    3
    4
    2049
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • robertiii
      robertiii last edited by

      I found this code somewhere on the internet heehee.

      def menuButton(sender):
      	pv = ui.View()
      	pv.name = 'popover'
      	pv.frame = (0,0,200,200)
      	x = sender.x + sender.width/2
      	y = sender.superview.titlebar_height + sender.y + sender.height/2
      	pv.present('popover',popover_location = (x,y))  
      

      However this doesn’t work with navbar buttons as they don’t have the location information. How can I get the location info?

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @robertiii last edited by

        @robertiii try this

        import ui
        from objc_util import *
        
        v = ui.View()
        v.background_color = 'white'
        
        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))
        
        b = ui.ButtonItem()
        b.title = 'popover'
        b.action = b_action
        v.right_button_items = (b,)
        v.present('fullscreen')
        
        
        1 Reply Last reply Reply Quote 0
        • cvp
          cvp last edited by

          You can also get position in a view with

          import ui
          from objc_util import *
          
          v = ui.View()
          v.background_color = 'white'
          
          def b_action(sender):
          	vi = ObjCInstance(b).view()
          	#r = vi.convertRect_toView_(vi.bounds(),None)
          	r = vi.convertRect_toView_(vi.bounds(),ObjCInstance(v))
          	# x,y in view coordinates
          	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))
          
          b = ui.ButtonItem()
          b.title = 'popover'
          b.action = b_action
          v.right_button_items = (b,)
          
          v.frame = (0,0,300,300)
          v.present('sheet')
          #v.present('fullscreen')
          
          

          1 Reply Last reply Reply Quote 0
          • stephen
            stephen last edited by

            @cvp AWESOME TY! i was going to need this info for item details in my inventory 🙃

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors