python / cpython

The Python programming language
https://www.python.org
Other
63.32k stars 30.31k forks source link

Tkinter: make X window & macOS recognize dialogs as such #87821

Closed 6c7b96b7-a3f3-4ea4-bbdb-caf182a9cd23 closed 3 years ago

6c7b96b7-a3f3-4ea4-bbdb-caf182a9cd23 commented 3 years ago
BPO 43655
Nosy @terryjreedy, @taleinat, @serhiy-storchaka, @miss-islington, @E-Paine, @patrickmelix
PRs
  • python/cpython#25061
  • python/cpython#25187
  • python/cpython#25588
  • python/cpython#25592
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = 'https://github.com/terryjreedy' closed_at = created_at = labels = ['expert-tkinter', '3.9', '3.10', '3.8', 'expert-IDLE', 'type-feature'] title = 'Tkinter: make X window & macOS recognize dialogs as such' updated_at = user = 'https://github.com/patrickmelix' ``` bugs.python.org fields: ```python activity = actor = 'serhiy.storchaka' assignee = 'terry.reedy' closed = True closed_date = closer = 'serhiy.storchaka' components = ['IDLE', 'Tkinter'] creation = creator = 'patrickmelix' dependencies = [] files = [] hgrepos = [] issue_num = 43655 keywords = ['patch'] message_count = 12.0 messages = ['389676', '389681', '389683', '389862', '390204', '390209', '390210', '390215', '390216', '391847', '391854', '391855'] nosy_count = 6.0 nosy_names = ['terry.reedy', 'taleinat', 'serhiy.storchaka', 'miss-islington', 'epaine', 'patrickmelix'] pr_nums = ['25061', '25187', '25588', '25592'] priority = 'normal' resolution = 'fixed' stage = 'resolved' status = 'closed' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue43655' versions = ['Python 3.8', 'Python 3.9', 'Python 3.10'] ```

    6c7b96b7-a3f3-4ea4-bbdb-caf182a9cd23 commented 3 years ago

    While trying to fix window behaviour in a python project (ASE: https://wiki.fysik.dtu.dk/ase/), I came across this problem:

    Tkinter does not set the _NET_WM_WINDOW_TYPE when using the FileDialog class or it's derivatives. I could not find a reason for this and it leads to my window manager (i3) not automatically recognising the window as a dialogue (and thus not enabling floating). I think the window types are there exactly for that purpose, so I don't see why not to set this as the default for the FileDialog class.

    I was able to change this by adding the line self.top.wm_attributes('-type', 'dialog') to the initialization of the FileDialog class. See also MR on GitHub.

    Since I am an absolute beginner at this please do forgive if I missed something.

    serhiy-storchaka commented 3 years ago

    Thank you for your report and PR Patrick.

    I agree, it would be better to to set the "type" attribute to "dialog" for the FileDialog window. Tk does it for its dialog windows. But it is more complex.

    And in ::tk_dialog and ::tk::MessageBox :

        if {$windowingsystem eq "aqua"} {
            ::tk::unsupported::MacWindowStyle style $w moveableModal {}
        } elseif {$windowingsystem eq "x11"} {
            wm attributes $w -type dialog
        }

    And ::tk::dialog::error::bgerror uses moveableAlert instead of moveableModal.

    6c7b96b7-a3f3-4ea4-bbdb-caf182a9cd23 commented 3 years ago

    Thank you for your feedback Serhiy!

    I obviously totally forgot about compatibility issues with other OS... If you are already aware of this and working on a solution even better. Did I miss this during my search or is it not public anywhere yet?

    For now one can easily avoid the issue by always setting the type manually, will have to see how to avoid the OS issue you mention then.

    Perhaps you can point me to the place to watch for your progress on the matter so I can keep track of this? Thanks again!

    serhiy-storchaka commented 3 years ago

    No, it is not ready for publishing yet. I'll try to work on it on the next weekend. Since it is a large change, there is a risk of breaking user code, so perhaps it would be worth to separate changes related to this issue which can be backported.

    serhiy-storchaka commented 3 years ago

    PR 25187 makes all Tkinter dialog windows and most IDLE dialog windows (except about and help windows) be recognized as dialogs by window managers on macOS and X Window. It conforms the behavior of standard Tk dialog windows.

    This change is harmless enough to be backported.

    terryjreedy commented 3 years ago

    Epaine (or Tal?): please test PR-25187 on Mac.

    terryjreedy commented 3 years ago

    I presume 'floatable' means 'can move dialog around on top of the parent window'. On my Mac Air, with 3.8 and 8.6.8, all the dialogs I checked, including About, are already floatable in this sense, not just the search boxes (which already had "::tk::unsupported::MacWindowsStyle" call). Since tk::unsupported is not listed on https://www.tcl.tk/man/tcl8.6/TkCmd/contents.htm, (nor on the 8.5 page) I wonder if it is obsolete, or just hidden.

    If no one knows, we might ask Kevin Walzer.

    serhiy-storchaka commented 3 years ago

    See https://wiki.tcl-lang.org/page/MacWindowStyle . I suppose it affects window decoration.

    terryjreedy commented 3 years ago

    Excuse me, it is the query boxes, not the search boxes, that already have the call. Unlike the other boxes I initially tested, they do not have the traffic lights. I believe that this, not movability, is the effect on mac of 'movableModal'. I tested a messagebox and it also had no traffic lights.

    What effect does the change have on Linux?

    On my MacBook, IDLE preferences is too tall, so that the bottom buttons are not visible and the only way to reliably cancel is to click the red button on the title bar. So remove the change for that at least until we have redesigned the dialog to be wide instead of tall. There is also an IDLE issue questioning whether Preferences (and Search) should even be modal.

    Currently, IDLE file open and save-as drop down from the center of title bar, have no traffic lights, and cannot be moved. Open is the entire width of the screen and could only go up and down. For Open, the underlying window is moved to the center. For Safari, Save as is the same, so I question whether it should be changed. Safari's Open is movable. Neither window for either app currently has traffic lights.

    serhiy-storchaka commented 3 years ago

    New changeset 3bb3fb3be09d472a43cdc3d9d9578bd49f3dfb8c by Serhiy Storchaka in branch 'master': bpo-43655: Tkinter and IDLE dialog windows are now recognized as dialogs by window managers on macOS and X Window (bpo-25187) https://github.com/python/cpython/commit/3bb3fb3be09d472a43cdc3d9d9578bd49f3dfb8c

    serhiy-storchaka commented 3 years ago

    New changeset 9a165399aec930f27639dd173426ccc33586662b by Serhiy Storchaka in branch '3.9': [3.9] bpo-43655: Tkinter and IDLE dialog windows are now recognized as dialogs by window managers on macOS and X Window (GH-25187). (GH-25588) https://github.com/python/cpython/commit/9a165399aec930f27639dd173426ccc33586662b

    serhiy-storchaka commented 3 years ago

    New changeset 6077efa2b2be17e736d061fe74f933dc616c64b2 by Miss Islington (bot) in branch '3.8': [3.9] bpo-43655: Tkinter and IDLE dialog windows are now recognized as dialogs by window managers on macOS and X Window (GH-25187). (GH-25588) (GH-25592) https://github.com/python/cpython/commit/6077efa2b2be17e736d061fe74f933dc616c64b2