vanilla icon indicating copy to clipboard operation
vanilla copied to clipboard

adding ModalWindow

Open typemytype opened this issue 5 years ago • 15 comments

dialogKit had a ModalWindow, which is nice to have in some occasions

this can be added to vanillaWindow.py

from AppKit import NSModalPanelWindowLevel
from vanilla import Window


class ModalWindow(Window):

    nsWindowLevel = NSModalPanelWindowLevel

    def __init__(self, *args, **kwargs):
        kwargs["closable"] = False
        kwargs["miniaturizable"] = False
        self._doCenter = True
        if "center" in kwargs:
            self._doCenter = kwargs["center"]
            del kwargs["center"]

        super(ModalWindow, self).__init__(*args, **kwargs)

    def open(self):
        super(ModalWindow, self).open()
        if self._doCenter:
            self.center()
        NSApp().runModalForWindow_(self._window)

    def windowWillClose_(self, notification):
        super(ModalWindow, self).windowWillClose_(notification)
        NSApp().stopModal()

typemytype avatar Jun 30 '20 19:06 typemytype

Yeah, I think this will be pretty useful!

colinmford avatar Jul 09 '20 18:07 colinmford

Note that in general, modal windows are considered very poor UI design.

justvanrossum avatar Jul 09 '20 18:07 justvanrossum

True... its to have alternative for the archived dialogKit.ModalDialog.

sheet are also modal and there are cases where a modal window is a nice option.

typemytype avatar Jul 10 '20 09:07 typemytype

A sheet is only modal relative to its parent window.

A modal window is only "a nice option" if the code really can't be changed to support a non-modal UI.

A ModalDialog has no place in a modern application — ~that's probably why it was archived~.

justvanrossum avatar Jul 10 '20 09:07 justvanrossum

dialogKit is archived in favour of vanilla, to old to much FL code in there

typemytype avatar Jul 10 '20 09:07 typemytype

Ah of course, I forgot.

justvanrossum avatar Jul 10 '20 09:07 justvanrossum

Pop Up Tools is very nice, and uses a modal window…

gferreira avatar Jul 10 '20 09:07 gferreira

Pop Up Tools is very nice, and uses a modal window…

That's not a modal window at all, it's like a contextual menu. If you click somewhere else it disappears. It doesn't block you from doing something else.

justvanrossum avatar Jul 10 '20 09:07 justvanrossum

@justvanrossum I think the idea is that it doesn’t disappear… see Make the window better

gferreira avatar Jul 10 '20 09:07 gferreira

An frequent used example of a modal dialog is an Open panel. see https://developer.apple.com/design/human-interface-guidelines/macos/windows-and-views/dialogs/

I indicates a higher level of user attention: "the app cannot do anything until you give it a file to open..."

Its a convenient window class, and annoying to make it each time you needs it.

typemytype avatar Jul 10 '20 09:07 typemytype

I read that as "don't disappear if a click occurs inside the window, but outside of a control".

justvanrossum avatar Jul 10 '20 09:07 justvanrossum

On macOS 10.15 not even the actual Open panel is modal... (On 10.10 it is, I don't know when it changed.)

Modal windows/dialogs are a remnant of '80s & '90s UI design and should be avoided at all cost.

justvanrossum avatar Jul 10 '20 09:07 justvanrossum

"App-modal" I should say. There's obviously use for document-modal or window-modal windows, but those are "sheets" and we already have them.

justvanrossum avatar Jul 10 '20 09:07 justvanrossum

there are valid use cases for modal dialogs, see Modal & Nonmodal Dialogs: When (& When Not) to Use Them

Modal dialogs interrupt users and demand an action. They are appropriate when user’s attention needs to be directed toward important information.

the most reasonable course of action here seems to be:

  • make modal window available for convenience, so that developers don’t have to write their own every time they need it
  • add a warning to the docs saying that they should be avoided at all cost

gferreira avatar Jul 10 '20 10:07 gferreira

I was reading the latest release notes and noticed that sheets look like modal windows in macOS 11.

typesupply avatar Feb 01 '21 18:02 typesupply

I added the version that I created for ezui that was, in turn, based on the one in RoboFont.

import vanilla

class Test:

    def __init__(self):
        self.w = vanilla.ModalWindow((200, 200))
        self.w.b = vanilla.Button((10, 10, -10, 20), "Close", callback=self.closeCallback)
        self.w.open()

    def closeCallback(self, sender):
        self.w.close()

Test()

typesupply avatar Dec 20 '23 17:12 typesupply