Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#2903 ttk::menubutton -dir right wrong menu placement

obsolete: 8.5.9
open
Joe English
5
2011-05-24
2011-05-24
Harald Oehlmann
No

Bug report 3305175 descibes, that the menu is placed in screen center far away from the menu button, if the menu is posted with a widget at the lower screen border:
ttk::menubutton .b -direction right

IMHO, a good menu placement strategy is:

Given a Menubutton with y borders at by0, by1.

The menu to post with y borders my0,my1
and the menu height: dmy=my1-my0

If by0+dmy fits onto the screen, post the menu with: my0 = by0
If by0+dmy do not fit on the screen:
- current solution (I suppose): my1 = by0
- proposed solution: my1 = by1
E.g. allign the lower widget end if menu is posted upwards.

The following modification:
- implements that for directions left and right
- does hide bug 3305175

- File tcl8.5\lib\tk8.5\ttk\menubutton.tcl -
- Procedure ttk::menubutton::PostPosition
- insert below switch -- $dir {...}
(Line 101)
<code>
# Align the lower ends of button and menu, if no place to show menu
# downwards
if { $dir in {"left" "right"} && $y >= $sh } {
set y [expr {$y-$mh+$bh}] }
}
</code>

Discussion

  • Sorry, there is one closing curly brace to much. Code should read:
    <code>
    # Align the lower ends of button and menu, if no place to show menu
    # downwards
    if { $dir in {"left" "right"} && $y >= $sh } {
    set y [expr {$y-$mh+$bh}]
    }
    </code>

     
  • Joe English
    Joe English
    2011-05-25

    (Cannot replicate under X11 or OSX, and I don't have a Windows machine handy - this appears to be Windows-only).

    Does this happen with a plain [menubutton] as well as with [ttk::menubutton]?

    If so, this is probably bug#2548722 -- problem may be in tk_popup (specifically: tk::PostOverPoint), not ttk::menubutton.

     
  • The issue to place the menu far away is only tk_popup and propably windows.

    But this patch would beautify the behaviour also on all platforms, as the menu is still aligned to the button even if posted upwards.

     
  • Pat Thoyts
    Pat Thoyts
    2011-05-26

    I can reproduce this on windows however the suggested fix doesn't help. The problem is in tk::PostOverPoint which is called from tk_popup menu. When I post a menu near the bottom of my screen (tk_popup .menu 0 965) it actually gets placed at about 0,634. However, on the second monitor which has negative X coordinates the Y position is ok. In tk::PostOverPoint we have a special section for use in windows that deals with menus overlapping the bottom of the screen. This was added to fix a problem with placement of windows that would overlap the edge. It looks like this was a window manager issue that we are working around that is no longer required on Windows 7. On Windows XP the menus are placed correctly.
    So it looks like the correct fix is actually to disable this adjustmenu for Windows7 and possibly also for Vista.
    Harald, can you confirm you are using Windows 7? If so try the attached patch. And if someone has access to Vista we can see if this should be disabled for < 6.0 or not.

     
  • Pat Thoyts
    Pat Thoyts
    2011-05-26

    Patch for tk 8.5 branch menu.tcl

     
    Attachments
  • I am on German Vista Pro 32 bit.
    IMHO, this should be discussed at bug 3305175.

    The patch works for me if activated for Vista, e.g. "< 6.0".

    With or without the fix for bug 3305175, I still like the visual effect of the ttk::menubutton patch provided for this patch. It attaches the menu better to the Menubutton.

    Thank you,
    Harald