Does anyone have a workaround for rs.PopupMenu() popping up in the wrong position? By default it is supposed to popup under the cursor, but since V7 or earlier it always is way far away for me, most often in the lower right hand corner of the screen.
I have posted about this a long time ago, but nothing has been done. It may be that this phenomenon is due to display scaling? I just now tried to figure out how to get the cursor position and calculate myself in screen coordinates to feed to the method, but I failed miserably - I’m not very good with this stuff.
Partially (and hopefully correctly) answering my own question - the answer to it might be yes.
I tried scaling the X and Y coordinates of the cursor location according to the display scaling I have here - 225%:
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino, System
items=["A","B","C","D","None of the Above"]
ds=100/225 #display scaling factor
screen_point=System.Windows.Forms.Cursor.Position
screen_point.X*=ds
screen_point.Y*=ds
result=Rhino.UI.Dialogs.ShowContextMenu(items, screen_point, None)
print ("You chose {}".format(items[result]))
Running this on my laptop at 225% scaling, the menu then pops up pretty much where it’s supposed to, close to the location of the mouse cursor where one clicks, a little to the right and below.
@dale Well, I don’t know what to tell you - as the picture above attests to, PopupMenu() doesn’t work correctly here on either of my two computers/monitors with different dpi scaling. And this in Rhino 6, 7 and 8. Adding the correction (225 for my laptop and 150 for my desktop) via the script makes it position perfectly.