0

私はosxプログラミングが初めてです。pyobjc を使用してアラートを作成しています。モーダル ウィンドウまたはダイアログについての私の理解では、モーダル ウィンドウは続行する前にユーザーのアクションを必要とします。ただし、NSAlert の runModal を使用すると、アラートがまだ表示されている間でも他のアプリに移動できます。モーダル ダイアログに対する私の理解は間違っていますか。

class Alert(object):

    def __init__(self, messageText):
        super(Alert, self).__init__()
        self.messageText = messageText
        self.informativeText = ""
        self.buttons = []

    def displayAlert(self):
        alert = NSAlert.alloc().init()
        alert.setMessageText_(self.messageText)
        alert.setInformativeText_(self.informativeText)
        # alert.setAlertStyle_(NSInformationalAlertStyle)
        alert.setAlertStyle_(NSCriticalAlertStyle)
        for button in self.buttons:
            alert.addButtonWithTitle_(button)
        NSApp.activateIgnoringOtherApps_(True)
        self.buttonPressed = alert.runModal()


def alert(message="Default Message", info_text="", buttons=["OK"]):
    ap = Alert(message)
    ap.informativeText = info_text
    ap.buttons = buttons
    ap.displayAlert()
    return ap.buttonPressed
4

1 に答える 1

2

モーダル ダイアログがシステムモーダル ダイアログの場合、他のアプリに切り替えることはできません。アプリの場合、他のアプリケーションではなく、独自のアプリケーションのユーザー インターフェイスで先に進むことができなくなります。

コードの場合、NSAlertのドキュメントで説明されているように、アプリケーション モーダル ダイアログを作成しています。

于 2014-08-05T17:59:30.803 に答える